Class MessageConnector
- 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
SchedulingConnector scheduler selects buffers from the channels' send queues; this connector advances that scheduled work to
an MessageConnector.IMessageConnection provider, which owns the transport and reports asynchronous send completion. A provider may represent
either an outgoing client connection or a server-side connection accepted by an independently managed server.
The connector submits at most one send transaction at a time. Scheduler completion means that a selected channel's queue head has been consumed by the connector; provider acceptance is a separate event, and an accepted buffer remains pinned until the provider's terminal callback proves that it no longer accesses the storage. The send pump serializes this progression without creating another queue or scheduler. A rejected send retains no provider borrow and waits for a writable notification before retrying.
Incoming messages use one unit of provider demand at a time. Accepted frames enter a connection-ordered ingress queue, then per-channel serial queues so a blocking handler on one channel does not stall another. Receive demand is replenished after ingress acceptance, independently of handler completion and buffer release. The connector retains provider storage without copying within a per-activation byte budget, then copies under a second byte budget; exhausting both fails the connection. Activation generations identify callbacks and send records belonging to a particular provider binding, so stale callbacks cannot advance a later connection. Shutdown detaches accepted sends but cannot reclaim their buffers until terminal completion; aborting a connection does not itself end a provider's borrow.
- Since:
- 4.23
- Author:
- Eike Stepper
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA reliable, ordered, bidirectional message connection for complete Net4j frames.Nested classes/interfaces inherited from class SchedulingConnector
SchedulingConnector.ISchedulerNested 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
Fields inherited from class SchedulingConnector
CONTROL_CHANNEL_ID, CONTROL_OPCODE_NEGOTIATIONFields 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
ConstructorsConstructorDescriptionCreates a message connector with the default per-connection receive budgets.MessageConnector(long zeroCopyReceiveBudgetBytes, long copyReceiveBudgetBytes) Creates a message connector with bounded per-activation receive storage budgets. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidDrains currently queued Net4j messages and then requests graceful local closure of the underlying connection.protected org.eclipse.net4j.util.security.INegotiationContextprotected voidprotected voidprotected voidprotected voidvoidfireElementAddedEvent(IChannel channel) Routes queued receive frames after a channel has been added to the multiplexer.voidfireElementRemovedEvent(IChannel channel) Removes a channel's receive queue after the multiplexer has removed it, releasing any frames that can no longer be delivered.final ILocationAware.LocationReturns the configured client or server role used for signed Net4j channel identifiers.protected voidCalled after a provider terminates while this connector is still undergoing deferred activation.protected voidCalled when the scheduler becomes idle.protected voidCalled when the scheduler transitions from idle to having pending work.final voidsetConnection(MessageConnector.IMessageConnection connection) Sets the provider connection before activation.final voidsetLocation(ILocationAware.Location location) Sets whether this connector represents a Net4j client or a server-side accepted connection.voidsetState(ConnectorState newState) Updates this connector's transport and negotiation state.protected final voidEnds a deferred activation when its owner explicitly aborts the provider connection.Methods inherited from class SchedulingConnector
closeChannel, completeScheduledChannel, deregisterChannelFromPeer, getControlChannel, getInternalControlChannel, getScheduler, multiplexChannel, registerChannelWithPeer, restoreSendingInterest, selectScheduledChannel, setScheduler, stopSendingIfIdleMethods inherited from class Connector
close, connect, connect, connectAsync, doBeforeOpenChannel, getBufferCapacity, getNegotiationContext, getNegotiationException, getNegotiator, getState, getURL, getUserID, initChannel, isClient, isClosed, isConnected, isConnecting, isDeferredActivation, isDisconnected, isNegotiating, isServer, leaveConnecting, provideBuffer, retainBuffer, setNegotiationException, setNegotiator, 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, 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, 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
-
Constructor Details
-
MessageConnector
public MessageConnector(long zeroCopyReceiveBudgetBytes, long copyReceiveBudgetBytes) Creates a message connector with bounded per-activation receive storage budgets.The default budgets allow one megabyte of outstanding zero-copy storage and four megabytes of copied receive storage per connection. When the zero-copy budget is full, incoming messages are copied while copy budget remains. Exhausting both budgets fails the connection.
- Parameters:
zeroCopyReceiveBudgetBytes- maximum bytes retained from provider-owned receive storagecopyReceiveBudgetBytes- maximum bytes retained in copied receive storage- Throws:
IllegalArgumentException- if either budget is negative- Since:
- 4.23
-
MessageConnector
public MessageConnector()Creates a message connector with the default per-connection receive budgets.- Since:
- 4.23
-
-
Method Details
-
setConnection
Sets the provider connection before activation. The supplied connection may initiate a client connection or attach to an already accepted server connection.- Parameters:
connection- the provider connection to bind
-
setState
Updates this connector's transport and negotiation state. AConnectorState.CONNECTEDtransition is accepted only for the current ready provider generation and is arbitrated with deferred activation failure; other state transitions use the inherited connector behavior.- Overrides:
setStatein classConnector- Parameters:
newState- the state to publish- Throws:
ConnectorException- if a connector operation required by the transition fails
-
getLocation
Returns the configured client or server role used for signed Net4j channel identifiers.- Specified by:
getLocationin interfaceILocationAware- Overrides:
getLocationin classConnector- Returns:
- this connector's configured location
- Since:
- 4.23
-
setLocation
Sets whether this connector represents a Net4j client or a server-side accepted connection. The server itself remains owned and managed by its provider.- Parameters:
location-ILocationAware.Location#CLIENTfor an outgoing client, orILocationAware.Location#SERVERfor an accepted server connection- Since:
- 4.23
-
fireElementAddedEvent
Routes queued receive frames after a channel has been added to the multiplexer. The map update occurs before this container event, so a dependent data frame can resolve its channel even if protocol connection setup continues with a nested signal.- Overrides:
fireElementAddedEventin classorg.eclipse.net4j.util.container.Container<IChannel>- Parameters:
channel- channel registered with this connector
-
fireElementRemovedEvent
Removes a channel's receive queue after the multiplexer has removed it, releasing any frames that can no longer be delivered.- Overrides:
fireElementRemovedEventin classorg.eclipse.net4j.util.container.Container<IChannel>- Parameters:
channel- channel removed from this connector
-
closeGracefully
public final void closeGracefully()Drains currently queued Net4j messages and then requests graceful local closure of the underlying connection. Callers should stop producing new messages before invoking this method. -
onSendingRequired
protected void onSendingRequired()Description copied from class:SchedulingConnectorCalled 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.- Specified by:
onSendingRequiredin classSchedulingConnector
-
onSendingNoLongerRequired
protected void onSendingNoLongerRequired()Description copied from class:SchedulingConnectorCalled when the scheduler becomes idle. Implementations should asynchronously stop requesting transport write readiness without performing transport I/O or blocking.- Overrides:
onSendingNoLongerRequiredin classSchedulingConnector
-
createNegotiationContext
protected org.eclipse.net4j.util.security.INegotiationContext createNegotiationContext()- Specified by:
createNegotiationContextin classSchedulingConnector
-
doBeforeActivate
- Overrides:
doBeforeActivatein classConnector- Throws:
Exception
-
doActivate
- Overrides:
doActivatein classSchedulingConnector- Throws:
Exception
-
doDeactivate
- Overrides:
doDeactivatein classSchedulingConnector- Throws:
Exception
-
doCancelActivation
protected void doCancelActivation()- Overrides:
doCancelActivationin classorg.eclipse.net4j.util.lifecycle.Lifecycle
-
terminatePendingActivation
protected final void terminatePendingActivation()Ends a deferred activation when its owner explicitly aborts the provider connection. The method arbitrates against readiness and negotiation completion, detaches the current provider generation, and completes the lifecycle attempt as failed. It is safe to call after a provider has already reported closure and does not depend onMessageConnector.IMessageConnection.abort()producing a callback.- Since:
- 4.23
-
onActivationFailed
protected void onActivationFailed()Called after a provider terminates while this connector is still undergoing deferred activation. Subclasses that are tracked by an owner can remove themselves from that owner's registry here because the failed deferred activation does not publish a normalDEACTIVATEDlifecycle event.- Since:
- 4.23
-