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.
    • leaveConnecting

      protected void leaveConnecting()
      Overrides:
      leaveConnecting in class Connector
    • controlHandshakeCompleted

      public final void controlHandshakeCompleted(long generation)
      Completes the normal connector connection progression after the peer's HELLO has been validated. This preserves the configured authentication negotiation and connected transition while ensuring neither can begin before control compatibility is established.
      Parameters:
      generation - the activation generation that received and validated the HELLO
    • advanceConnectionAfterHandshake

      protected void advanceConnectionAfterHandshake(long generation)
      Advances the connector after a compatible HELLO. The default implementation uses the base connector lifecycle transition and guards it against activation changes. A transport with additional readiness arbitration can override this method, but must retain the supplied handshake generation when publishing its state.
      Parameters:
      generation - the activation generation that completed the HELLO exchange
    • isCurrentControlHandshakeGeneration

      protected final boolean isCurrentControlHandshakeGeneration(long generation)
      Returns whether the supplied control-handshake generation still belongs to the current activation.
      Parameters:
      generation - the generation captured by a handshake callback
      Returns:
      whether that callback may affect the current activation
    • onControlHandshakeCompleted

      protected void onControlHandshakeCompleted(long generation)
      Called after normal connector progression resumes so transports can restart work deferred during the handshake.
    • failControlHandshakeIfPending

      protected final void failControlHandshakeIfPending(Throwable cause)
      Fails a pending handshake when the transport closes before it advertises a control version.
    • failControlHandshake

      public final void failControlHandshake(long generation, ConnectorException failure)
      Records and publishes a control-protocol failure so waiters receive its diagnostic instead of a connection timeout.
      Parameters:
      generation - the activation generation that observed the failure
      failure - the incompatibility or malformed-message failure
    • controlBufferSent

      protected final void controlBufferSent(InternalChannel channel, IBuffer buffer)
      Completes the local half of HELLO after a transport confirms that the control buffer was sent successfully.
      Parameters:
      channel - the channel whose buffer completed
      buffer - the complete frame accepted by the transport
    • controlBufferSent

      protected final void controlBufferSent(InternalChannel channel, IBuffer buffer, long generation)
      Identifies a completed control buffer only for the activation that submitted it.
    • isControlHelloBuffer

      protected final boolean isControlHelloBuffer(InternalChannel channel, IBuffer buffer)
      Returns whether a complete frame is the HELLO sent on this connector's control channel.
    • controlHelloSent

      protected final void controlHelloSent()
      Completes the local HELLO half after a transport finishes transmitting it.
    • controlHelloSent

      protected final void controlHelloSent(long generation)
      Completes the local HELLO half only if the captured activation still owns the pending handshake.
    • controlHandshakeGeneration

      protected final long controlHandshakeGeneration()
      Returns the activation generation associated with the current control handshake.
    • 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