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>
org.eclipse.spi.net4j.ChannelMultiplexer
org.eclipse.spi.net4j.Connector
org.eclipse.spi.net4j.SchedulingConnector
- 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
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceSchedules channels that have outgoing buffers.Nested classes/interfaces inherited from class org.eclipse.net4j.util.event.Notifier
org.eclipse.net4j.util.event.Notifier.CancelationNested classes/interfaces inherited from interface IBufferProvider
IBufferProvider.Introspection, IBufferProvider.NotificationNested classes/interfaces inherited from interface org.eclipse.net4j.util.container.IContainer
org.eclipse.net4j.util.container.IContainer.Modifiable<E>, org.eclipse.net4j.util.container.IContainer.Persistable<E>, org.eclipse.net4j.util.container.IContainer.Persistence<E>Nested classes/interfaces inherited from interface org.eclipse.net4j.util.lifecycle.ILifecycle
org.eclipse.net4j.util.lifecycle.ILifecycle.DeferrableActivationNested classes/interfaces inherited from interface ILocationAware
ILocationAware.LocationNested classes/interfaces inherited from interface org.eclipse.net4j.util.event.INotifier
org.eclipse.net4j.util.event.INotifier.INotifier2Nested classes/interfaces inherited from interface InternalChannelMultiplexer
InternalChannelMultiplexer.BufferMultiplexer -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final shortThe reserved channel identifier used for shared control messages.static final byteThe opcode used for negotiation messages on the shared control channel.Fields inherited from class org.eclipse.net4j.util.lifecycle.Lifecycle
USE_LABELFields inherited from interface IChannelMultiplexer
DEFAULT_OPEN_CHANNEL_TIMEOUT, NO_CHANNEL_TIMEOUTFields inherited from interface IConnector
NO_TIMEOUTFields inherited from interface InternalChannelMultiplexer
CONTEXT_MULTIPLEXER, RESERVED_CHANNEL -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidadvanceConnectionAfterHandshake(long generation) Advances the connector after a compatible HELLO.voidcloseChannel(InternalChannel channel) protected final booleancompleteScheduledChannel(InternalChannel channel, boolean bufferCompleted) Called by a transport sender after a send attempt.protected final voidcontrolBufferSent(InternalChannel channel, IBuffer buffer) Completes the local half of HELLO after a transport confirms that the control buffer was sent successfully.protected final voidcontrolBufferSent(InternalChannel channel, IBuffer buffer, long generation) Identifies a completed control buffer only for the activation that submitted it.final voidcontrolHandshakeCompleted(long generation) Completes the normal connector connection progression after the peer's HELLO has been validated.protected final longReturns the activation generation associated with the current control handshake.protected final voidCompletes the local HELLO half after a transport finishes transmitting it.protected final voidcontrolHelloSent(long generation) Completes the local HELLO half only if the captured activation still owns the pending handshake.protected abstract org.eclipse.net4j.util.security.INegotiationContextprotected voidderegisterChannelFromPeer(InternalChannel channel) protected voidprotected voidfinal voidfailControlHandshake(long generation, ConnectorException failure) Records and publishes a control-protocol failure so waiters receive its diagnostic instead of a connection timeout.protected final voidFails a pending handshake when the transport closes before it advertises a control version.final IChannelReturns the shared control channel through the public channel interface.protected final InternalChannelReturns the shared control channel for transport implementations that need the internal buffer-dispatch contract.Returns the scheduler used to select channels with pending outgoing buffers.protected final booleanisControlHelloBuffer(InternalChannel channel, IBuffer buffer) Returns whether a complete frame is the HELLO sent on this connector's control channel.protected final booleanisCurrentControlHandshakeGeneration(long generation) Returns whether the supplied control-handshake generation still belongs to the current activation.protected voidfinal voidmultiplexChannel(InternalChannel channel) protected voidonControlHandshakeCompleted(long generation) Called after normal connector progression resumes so transports can restart work deferred during the handshake.protected voidCalled when the scheduler becomes idle.protected abstract voidCalled when the scheduler transitions from idle to having pending work.protected voidregisterChannelWithPeer(short channelID, long timeout, IProtocol<?> protocol) protected final voidrestoreSendingInterest(boolean additionalWork) Restores transport write readiness according to scheduler work and any transport-specific work that must be serviced on the write path.protected final InternalChannelSelects the current channel for a transport sender.final voidsetScheduler(SchedulingConnector.IScheduler scheduler) Sets the scheduler before activation.protected final voidStops transport write readiness if no channel remains scheduled.Methods inherited from class Connector
close, connect, connect, connectAsync, doBeforeActivate, doBeforeOpenChannel, getBufferCapacity, getLocation, getNegotiationContext, getNegotiationException, getNegotiator, getState, getURL, getUserID, initChannel, isClient, isClosed, isConnected, isConnecting, isDeferredActivation, isDisconnected, isNegotiating, isServer, provideBuffer, retainBuffer, setNegotiationException, setNegotiator, setState, setUserID, waitForConnectionMethods inherited from class ChannelMultiplexer
createChannel, createProtocol, createProtocolFactoryKey, getChannel, getChannels, getConfig, getElements, getExecutorService, getOpenChannelTimeout, inverseClose, inverseCloseChannel, inverseOpenChannel, inverseOpenChannel, isEmpty, needsBufferProvider, openChannel, openChannel, openChannel, properties, setConfig, setOpenChannelTimeoutMethods inherited from class org.eclipse.net4j.util.container.Container
fireContainerEvent, fireContainerEvent, fireContainerEvent, fireElementAddedEvent, fireElementRemovedEvent, fireElementsAddedEvent, fireElementsRemovedEvent, fireEvent, newContainerEvent, newContainerEventMethods inherited from class org.eclipse.net4j.util.lifecycle.Lifecycle
activate, checkActive, checkArg, checkArg, checkInactive, checkNull, checkState, checkState, deactivate, deferredActivate, doAfterActivate, doBeforeDeactivate, doCancelActivation, dump, getLifecycleState, isActive, toStringMethods inherited from class org.eclipse.net4j.util.event.Notifier
addListener, addUniqueListener, fireEvent, fireEvent, fireThrowable, firstListenerAdded, getListeners, getNotificationService, hasListener, hasListeners, lastListenerRemoved, listenerAdded, listenerRemoved, removeListenerMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface IChannelMultiplexer
getChannels, getOpenChannelTimeout, openChannel, openChannel, openChannel, setOpenChannelTimeoutMethods inherited from interface org.eclipse.net4j.util.container.IContainer
getElements, isEmptyMethods inherited from interface org.eclipse.net4j.util.event.INotifier
addListener, getListeners, hasListeners, removeListenerMethods inherited from interface InternalChannelMultiplexer
needsBufferProviderMethods inherited from interface org.eclipse.net4j.util.properties.IPropertiesContainer
propertiesMethods inherited from interface ITransportConfigAware
getConfig, setConfig
-
Field Details
-
CONTROL_CHANNEL_ID
public static final short CONTROL_CHANNEL_IDThe reserved channel identifier used for shared control messages.- See Also:
-
CONTROL_OPCODE_NEGOTIATION
public static final byte CONTROL_OPCODE_NEGOTIATIONThe opcode used for negotiation messages on the shared control channel.- See Also:
-
-
Constructor Details
-
SchedulingConnector
public SchedulingConnector()
-
-
Method Details
-
getScheduler
Returns the scheduler used to select channels with pending outgoing buffers.- Returns:
- the current channel scheduler
-
setScheduler
Sets the scheduler before activation.- Parameters:
scheduler- the scheduler to use
-
getControlChannel
Returns the shared control channel through the public channel interface. The channel isnullbefore activation and after deactivation.- Returns:
- the shared control channel
-
multiplexChannel
Description copied from interface:InternalChannelMultiplexerCalled by achanneleach time a newbufferis available for multiplexing. This or another buffer can be dequeued from thesend queueof the channel. -
closeChannel
- Specified by:
closeChannelin interfaceInternalChannelMultiplexer- Overrides:
closeChannelin classChannelMultiplexer- Throws:
ChannelException
-
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:
leaveConnectingin classConnector
-
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
Fails a pending handshake when the transport closes before it advertises a control version. -
failControlHandshake
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 failurefailure- the incompatibility or malformed-message failure
-
controlBufferSent
Completes the local half of HELLO after a transport confirms that the control buffer was sent successfully.- Parameters:
channel- the channel whose buffer completedbuffer- the complete frame accepted by the transport
-
controlBufferSent
Identifies a completed control buffer only for the activation that submitted it. -
isControlHelloBuffer
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
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 channelbufferCompleted- whether the current buffer completed successfully- Returns:
trueif the sender should continue because scheduled work remains
-
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:
registerChannelWithPeerin classChannelMultiplexer- Throws:
ChannelException
-
deregisterChannelFromPeer
- Overrides:
deregisterChannelFromPeerin classConnector- Throws:
ChannelException
-
doActivate
- Overrides:
doActivatein classConnector- Throws:
Exception
-
doDeactivate
- Overrides:
doDeactivatein classConnector- Throws:
Exception
-
createNegotiationContext
protected abstract org.eclipse.net4j.util.security.INegotiationContext createNegotiationContext()- Specified by:
createNegotiationContextin classConnector
-