Class Channel

java.lang.Object
org.eclipse.net4j.util.event.Notifier
org.eclipse.net4j.util.lifecycle.Lifecycle
org.eclipse.spi.net4j.Channel
All Implemented Interfaces:
IBufferHandler, IBufferProvider, IChannel, ILocationAware, org.eclipse.net4j.util.collection.Closeable, org.eclipse.net4j.util.concurrent.IExecutorServiceProvider, org.eclipse.net4j.util.container.IManagedContainerProvider, org.eclipse.net4j.util.event.INotifier, org.eclipse.net4j.util.event.INotifier.INotifier2, org.eclipse.net4j.util.lifecycle.IDeactivateable, org.eclipse.net4j.util.lifecycle.ILifecycle, org.eclipse.net4j.util.lifecycle.ILifecycle.DeferrableActivation, org.eclipse.net4j.util.security.IUserAware, InternalChannel

public class Channel extends org.eclipse.net4j.util.lifecycle.Lifecycle implements InternalChannel, org.eclipse.net4j.util.concurrent.IExecutorServiceProvider, org.eclipse.net4j.util.container.IManagedContainerProvider
Implements a logical Net4j channel that sends and receives buffers through a channel multiplexer and dispatches received data to its configured receiver.
Since:
2.0
Author:
Eike Stepper
  • Constructor Details

    • Channel

      public Channel()
  • Method Details

    • getContainer

      public org.eclipse.net4j.util.container.IManagedContainer getContainer()
      Specified by:
      getContainer in interface org.eclipse.net4j.util.container.IManagedContainerProvider
    • getUserID

      public String getUserID()
      Specified by:
      getUserID in interface org.eclipse.net4j.util.security.IUserAware
    • setUserID

      public void setUserID(String userID)
      Specified by:
      setUserID in interface InternalChannel
    • getLocation

      public ILocationAware.Location getLocation()
      Description copied from interface: ILocationAware
      Returns the location of this object in a client/server scenario.
      Specified by:
      getLocation in interface ILocationAware
    • isClient

      public boolean isClient()
      Description copied from interface: ILocationAware
      Specified by:
      isClient in interface ILocationAware
    • isServer

      public boolean isServer()
      Description copied from interface: ILocationAware
      Specified by:
      isServer in interface ILocationAware
    • getMultiplexer

      public IChannelMultiplexer getMultiplexer()
      Description copied from interface: IChannel
      Returns the multiplexer this channel is associated with. This channel multiplexer can be used, for example, to open additional channels that will be multiplexed through the same transport medium.
      Specified by:
      getMultiplexer in interface IChannel
    • setMultiplexer

      public void setMultiplexer(IChannelMultiplexer channelMultiplexer)
      Specified by:
      setMultiplexer in interface InternalChannel
    • getID

      public short getID()
      Description copied from interface: IChannel
      Returns the ID of this channel. The ID is unique at any time among all channels of the associated multiplexer.
      Specified by:
      getID in interface IChannel
    • setID

      public void setID(short id)
      Specified by:
      setID in interface InternalChannel
    • getExecutorService

      public ExecutorService getExecutorService()
      Specified by:
      getExecutorService in interface org.eclipse.net4j.util.concurrent.IExecutorServiceProvider
      Since:
      4.5
    • getReceiveExecutor

      @Deprecated public ExecutorService getReceiveExecutor()
      Deprecated.
      Specified by:
      getReceiveExecutor in interface InternalChannel
    • setReceiveExecutor

      @Deprecated public void setReceiveExecutor(ExecutorService receiveExecutor)
      Deprecated.
      Specified by:
      setReceiveExecutor in interface InternalChannel
    • getReceiveHandler

      public IBufferHandler getReceiveHandler()
      Description copied from interface: IChannel
      Returns the IBufferHandler that handles buffers received from the peer channel.
      Specified by:
      getReceiveHandler in interface IChannel
    • setReceiveHandler

      public void setReceiveHandler(IBufferHandler receiveHandler)
      Description copied from interface: IChannel
      Sets the IBufferHandler to handle buffers received from the peer channel.
      Specified by:
      setReceiveHandler in interface IChannel
    • getSentBuffers

      public long getSentBuffers()
      Description copied from interface: IChannel
      Returns the number of buffers that are sent to the multiplexer of this channel.
      Specified by:
      getSentBuffers in interface IChannel
      Since:
      3.0
    • getSentBytes

      public final long getSentBytes()
      Description copied from interface: IChannel
      Returns the number of bytes that are sent to the multiplexer of this channel.
      Specified by:
      getSentBytes in interface IChannel
      Since:
      4.13
    • getReceivedBuffers

      public long getReceivedBuffers()
      Description copied from interface: IChannel
      Returns the number of buffers that are received from the multiplexer of this channel and are passed on to the receive handler of this channel.
      Specified by:
      getReceivedBuffers in interface IChannel
      Since:
      3.0
    • getReceivedBytes

      public final long getReceivedBytes()
      Description copied from interface: IChannel
      Returns the number of bytes that are received from the multiplexer of this channel and are passed on to the receive handler of this channel.
      Specified by:
      getReceivedBytes in interface IChannel
      Since:
      4.13
    • getSendQueue

      public Queue<IBuffer> getSendQueue()
      Specified by:
      getSendQueue in interface InternalChannel
    • pinSendBuffer

      public final boolean pinSendBuffer(IBuffer buffer)
      Pins the active send-queue head while an asynchronous transport borrows its storage. The pin prevents channel deactivation from releasing a buffer while the transport may still access it.
      Parameters:
      buffer - the buffer at the head of this channel's send queue
      Returns:
      true if the buffer was pinned
      Since:
      4.23
    • finishPinnedSendBuffer

      public final boolean finishPinnedSendBuffer(Queue<IBuffer> queue, IBuffer buffer, boolean release)
      Ends the pin for an asynchronous send. A completed send is removed and released; a rejected send remains queued for retry while the channel is active. The original queue is supplied because the channel may have closed or been activated again since selection.
      Parameters:
      queue - the queue from which the buffer was selected
      buffer - the buffer whose provider lease has ended
      release - whether a terminally completed send should be removed and released
      Returns:
      true if this call removed and released the buffer
      Since:
      4.23
    • sendBuffer

      public void sendBuffer(IBuffer buffer)
      Description copied from interface: IChannel
      Asynchronously sends the given buffer to the receive handler of the peer channel.
      Specified by:
      sendBuffer in interface IChannel
    • handleBuffer

      public void handleBuffer(IBuffer buffer)
      Handles the given buffer. Ensures it is in the PUTTING state (otherwise ignores it) and sends it on behalf of the send queue.
      Specified by:
      handleBuffer in interface IBufferHandler
      Parameters:
      buffer - The buffer to be handled.
      See Also:
    • handleBufferFromMultiplexer

      public void handleBufferFromMultiplexer(IBuffer buffer)
      Handles a buffer sent by the multiplexer. Adds work to the receive queue or releases the buffer.
      Specified by:
      handleBufferFromMultiplexer in interface InternalChannel
      See Also:
    • createReceiverWork

      @Deprecated protected Channel.ReceiverWork createReceiverWork(IBuffer buffer)
      Deprecated.
      As of 4.10 scheduled for future removal.
    • getBufferCapacity

      public short getBufferCapacity()
      Description copied from interface: IBufferProvider
      Returns the capacity, in bytes, of buffers returned by IBufferProvider.provideBuffer().
      Specified by:
      getBufferCapacity in interface IBufferProvider
    • provideBuffer

      public IBuffer provideBuffer()
      Description copied from interface: IBufferProvider
      Provides a buffer and transfers its current ownership to the caller.
      Specified by:
      provideBuffer in interface IBufferProvider
    • retainBuffer

      public void retainBuffer(IBuffer buffer)
      Description copied from interface: IBufferProvider
      Accepts a buffer whose caller has relinquished ownership. Implementations may keep it for reuse or release its storage; callers must not use the buffer after handing it over.
      Specified by:
      retainBuffer in interface IBufferProvider
    • toString

      public String toString()
      Overrides:
      toString in class org.eclipse.net4j.util.lifecycle.Lifecycle
    • doBeforeActivate

      protected void doBeforeActivate() throws Exception
      Overrides:
      doBeforeActivate in class org.eclipse.net4j.util.lifecycle.Lifecycle
      Throws:
      Exception
    • doActivate

      protected void doActivate() throws Exception
      Overrides:
      doActivate in class org.eclipse.net4j.util.lifecycle.Lifecycle
      Throws:
      Exception
    • doDeactivate

      protected void doDeactivate() throws Exception
      Overrides:
      doDeactivate in class org.eclipse.net4j.util.lifecycle.Lifecycle
      Throws:
      Exception
    • unregisterFromMultiplexer

      protected void unregisterFromMultiplexer()
    • close

      public void close()
      Specified by:
      close in interface org.eclipse.net4j.util.collection.Closeable
    • isClosed

      public boolean isClosed()
      Specified by:
      isClosed in interface org.eclipse.net4j.util.collection.Closeable