Class SchedulingConnector

java.lang.Object
org.eclipse.net4j.util.event.Notifier
org.eclipse.net4j.util.lifecycle.Lifecycle
org.eclipse.net4j.util.lifecycle.ShareableLifecycle
org.eclipse.net4j.util.container.Container<IChannel>
All Implemented Interfaces:
IBufferProvider, IChannelMultiplexer, IConnector, ILocationAware, ITransportConfigAware, org.eclipse.net4j.util.collection.Closeable, org.eclipse.net4j.util.concurrent.IExecutorServiceProvider, org.eclipse.net4j.util.container.IContainer<IChannel>, 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.properties.IPropertiesContainer, org.eclipse.net4j.util.security.INegotiatorAware, org.eclipse.net4j.util.security.IUserAware, InternalChannelMultiplexer, InternalConnector, InverseCloseable
Direct Known Subclasses:
MessageConnector

public abstract class SchedulingConnector extends Connector
A connector base for transports that send channel buffers over a shared connection. It owns the common channel scheduler and control channel while leaving transport execution and I/O to subclasses. The lifecycle lock serializes scheduling state with shutdown; scheduler operations acquire channel queue locks before scheduler state locks, and release scheduler locks before returning to transport hooks.
Since:
4.23
Author:
Eike Stepper
  • Field Details

    • CONTROL_CHANNEL_ID

      public static final short CONTROL_CHANNEL_ID
      The reserved channel identifier used for shared control messages.
      See Also:
    • CONTROL_OPCODE_NEGOTIATION

      public static final byte CONTROL_OPCODE_NEGOTIATION
      The opcode used for negotiation messages on the shared control channel.
      See Also:
  • Constructor Details

    • SchedulingConnector

      public SchedulingConnector()
  • Method Details

    • getScheduler

      public final SchedulingConnector.IScheduler getScheduler()
      Returns the scheduler used to select channels with pending outgoing buffers.
      Returns:
      the current channel scheduler
    • setScheduler

      public final void setScheduler(SchedulingConnector.IScheduler scheduler)
      Sets the scheduler before activation.
      Parameters:
      scheduler - the scheduler to use
    • getControlChannel

      public final IChannel getControlChannel()
      Returns the shared control channel through the public channel interface. The channel is null before activation and after deactivation.
      Returns:
      the shared control channel
    • multiplexChannel

      public final void multiplexChannel(InternalChannel channel)
      Description copied from interface: InternalChannelMultiplexer
      Called by a channel each time a new buffer is available for multiplexing. This or another buffer can be dequeued from the send queue of the channel.
    • closeChannel

      public void closeChannel(InternalChannel channel) throws ChannelException
      Specified by:
      closeChannel in interface InternalChannelMultiplexer
      Overrides:
      closeChannel in class ChannelMultiplexer
      Throws:
      ChannelException
    • getInternalControlChannel

      protected final InternalChannel getInternalControlChannel()
      Returns the shared control channel for transport implementations that need the internal buffer-dispatch contract.
      Returns:
      the shared internal control channel
    • onSendingRequired

      protected abstract void onSendingRequired()
      Called when the scheduler transitions from idle to having pending work. Implementations should arrange a send attempt without blocking the producer that enqueued the buffer. The hook runs outside the scheduling lifecycle lock, so it must only arrange asynchronous work and must not perform transport I/O or block.
    • onSendingNoLongerRequired

      protected void onSendingNoLongerRequired()
      Called when the scheduler becomes idle. Implementations should asynchronously stop requesting transport write readiness without performing transport I/O or blocking.
    • completeScheduledChannel

      protected final boolean completeScheduledChannel(InternalChannel channel, boolean bufferCompleted)
      Called by a transport sender after a send attempt. An incomplete current buffer keeps that channel selected; a completed buffer allows it to rotate to the tail if more work remains. After a successful completion, this method requests another send attempt when scheduled work remains. The transport hook must enqueue or wake an asynchronous sender rather than sending reentrantly.
      Parameters:
      channel - the serviced channel
      bufferCompleted - whether the current buffer completed successfully
      Returns:
      true if the sender should continue because scheduled work remains
    • selectScheduledChannel

      protected final InternalChannel selectScheduledChannel()
      Selects the current channel for a transport sender.
      Returns:
      the current eligible channel or null
    • restoreSendingInterest

      protected final void restoreSendingInterest(boolean additionalWork)
      Restores transport write readiness according to scheduler work and any transport-specific work that must be serviced on the write path. The check and notification are serialized with channel offers and removals to prevent lost selector wakeups.
      Parameters:
      additionalWork - whether the transport has work that must be serviced by its write-ready callback
    • stopSendingIfIdle

      protected final void stopSendingIfIdle()
      Stops transport write readiness if no channel remains scheduled. The check is serialized with channel offers and removals.
    • registerChannelWithPeer

      protected void registerChannelWithPeer(short channelID, long timeout, IProtocol<?> protocol) throws ChannelException
      Specified by:
      registerChannelWithPeer in class ChannelMultiplexer
      Throws:
      ChannelException
    • deregisterChannelFromPeer

      protected void deregisterChannelFromPeer(InternalChannel channel) throws ChannelException
      Overrides:
      deregisterChannelFromPeer in class Connector
      Throws:
      ChannelException
    • doActivate

      protected void doActivate() throws Exception
      Overrides:
      doActivate in class Connector
      Throws:
      Exception
    • doDeactivate

      protected void doDeactivate() throws Exception
      Overrides:
      doDeactivate in class Connector
      Throws:
      Exception
    • createNegotiationContext

      protected abstract org.eclipse.net4j.util.security.INegotiationContext createNegotiationContext()
      Specified by:
      createNegotiationContext in class Connector