Package org.apache.qpid.protonj2.engine
Interface Engine
- All Superinterfaces:
Consumer<ProtonBuffer>
- All Known Implementing Classes:
ProtonEngine
AMQP Engine interface.
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
accept
(ProtonBuffer input) Provide data input for this Engine from some external source.Gets the Configuration for this engine.Gets theConnection
instance that is associated with thisEngine
instance.engineFailed
(Throwable cause) Transition theEngine
to a failed state if not already closed or closing.errorHandler
(EventHandler<Engine> engineFailure) Sets a handler instance that will be notified when the engine encounters a fatal error.ingest
(ProtonBuffer input) Provide data input for this Engine from some external source.boolean
isFailed()
boolean
boolean
boolean
Returns true if the engine is accepting input from the ingestion entry points.default Engine
outputConsumer
(Consumer<ProtonBuffer> consumer) Sets aConsumer
instance that will be notified when data from the engine is ready to be written to some output sink (socket etc).outputHandler
(BiConsumer<ProtonBuffer, Runnable> output) Sets aBiConsumer
instance that will be notified when data from the engine is ready to be written to some output sink (socket etc).default Engine
outputHandler
(EventHandler<ProtonBuffer> output) Sets a handler instance that will be notified when data from the engine is ready to be written to some output sink (socket etc).pipeline()
Gets the EnginePipeline for this Engine.Gets the SASL driver for this engine, if no SASL layer is configured then a default no-op driver must be returned that indicates this.shutdown()
Shutdown the engine preventing any future outbound or inbound processing.shutdownHandler
(EventHandler<Engine> engineShutdownEventHandler) Sets a handler instance that will be notified when the engine is shut down via a call to theshutdown()
method is called.start()
Starts the engine and returns theConnection
instance that is bound to this Engine.state()
long
tick
(long currentTime) Prompt the engine to perform idle-timeout/heartbeat handling, and return an absolute deadline in milliseconds that tick must again be called by/at, based on the provided current time in milliseconds, to ensure the periodic work is carried out as necessary.tickAuto
(ScheduledExecutorService executor) Allows the engine to manage idle timeout processing by providing it the single threaded executor context where all transport work is done which ensures singled threaded access while removing the need for the client library or server application to manage calls to thetick(long)
methods.Allows the engine to manage idle timeout processing by providing it the single threaded executor context where all transport work is done which ensures singled threaded access while removing the need for the client library or server application to manage calls to thetick(long)
methods.
-
Method Details
-
isWritable
boolean isWritable()Returns true if the engine is accepting input from the ingestion entry points.When false any attempts to write more data into the engine will result in an error being returned from the write operation. An engine that has not been started or that has been failed or shutdown will report as not writable.
- Returns:
- true if the engine is current accepting more input.
-
isRunning
boolean isRunning()- Returns:
- true if the Engine has entered the running state and is not failed or shutdown.
-
isShutdown
boolean isShutdown()- Returns:
- true if the Engine has been shutdown and is no longer usable.
-
isFailed
boolean isFailed()- Returns:
- true if the Engine has encountered a critical error and cannot produce new data.
-
failureCause
Throwable failureCause()- Returns:
- the error that caused the
Engine
fail and shutdown (or null if not failed).
-
state
EngineState state()- Returns:
- the current state of the engine.
-
connection
Connection connection()Gets theConnection
instance that is associated with thisEngine
instance. It is valid for an engine implementation to not return aConnection
instance prior to the engine having been started.- Returns:
- the
Connection
that is linked to this engine instance.
-
start
Starts the engine and returns theConnection
instance that is bound to this Engine. A non-started Engine will not allow ingestion of any inbound data and a Connection linked to the engine that was obtained from theconnection()
method cannot produce any outbound data.- Returns:
- the Connection instance that is linked to this
Engine
- Throws:
EngineStateException
- if the Engine state has already transition to shutdown or failed.
-
shutdown
Engine shutdown()Shutdown the engine preventing any future outbound or inbound processing. When the engine is shut down any resources,Connection
,Session
orLink
instances that have an engine shutdown event handler registered will be notified and should react by locally closing that resource if they wish to ensure that the resource's local close event handler gets signaled if that resource is not already locally closed.- Returns:
- this
Engine
-
engineFailed
Transition theEngine
to a failed state if not already closed or closing. If called when the engine has not failed the engine will be transitioned to the failed state and the method will return an appropriateEngineFailedException
that wraps the given cause. If called after the engine was shutdown the method returns anEngineShutdownException
indicating that the engine was already shutdown. Repeated calls to this method while the engine is in the failed state must not alter the original failure error or elicit new engine failed event notifications.- Parameters:
cause
- The exception that caused the engine to be forcibly transitioned to the failed state.- Returns:
- an
EngineStateException
that can be thrown indicating the failure and engine state.
-
ingest
Provide data input for this Engine from some external source. If the engine is not writable when this method is called anEngineNotWritableException
will be thrown if unless the reason for the not writable state is due to engine failure or the engine already having been shut down in which case the appropriateEngineStateException
will be thrown to indicate the reason.- Parameters:
input
- The data to feed into to Engine.- Returns:
- this
Engine
- Throws:
EngineStateException
- if the Engine state precludes accepting new input.
-
accept
Provide data input for this Engine from some external source. If the engine is not writable when this method is called anEngineNotWritableException
will be thrown if unless the reason for the not writable state is due to engine failure or the engine already having been shut down in which case the appropriateEngineStateException
will be thrown to indicate the reason.- Specified by:
accept
in interfaceConsumer<ProtonBuffer>
- Parameters:
input
- The data to feed into to Engine.- Throws:
EngineStateException
- if the Engine state precludes accepting new input.
-
tick
Prompt the engine to perform idle-timeout/heartbeat handling, and return an absolute deadline in milliseconds that tick must again be called by/at, based on the provided current time in milliseconds, to ensure the periodic work is carried out as necessary. It is an error to call this method if the connection has not been opened. A returned deadline of 0 indicates there is no periodic work necessitating tick be called, e.g. because neither peer has defined an idle-timeout value. The provided milliseconds time values should be derived from a monotonic source such asSystem.nanoTime()
to prevent wall clock changes leading to erroneous behaviour. Note that forSystem.nanoTime()
derived values in particular that the returned deadline could be a different sign than the originally given value, and so (if non-zero) the returned deadline should have the current time originally provided subtracted from it in order to establish a relative time delay to the next deadline. SupplyingSystem.currentTimeMillis()
derived values can lead to erroneous behaviour during wall clock changes and so is not recommended. It is an error to call this method iftickAuto(ScheduledExecutorService)
was called.- Parameters:
currentTime
- the current time of this tick call.- Returns:
- the absolute deadline in milliseconds to next call tick by/at, or 0 if there is none.
- Throws:
IllegalStateException
- if theEngine
is already performing auto tick handling.EngineStateException
- if the Engine state precludes accepting new input.
-
tickAuto
Engine tickAuto(ScheduledExecutorService executor) throws IllegalStateException, EngineStateException Allows the engine to manage idle timeout processing by providing it the single threaded executor context where all transport work is done which ensures singled threaded access while removing the need for the client library or server application to manage calls to thetick(long)
methods.- Parameters:
executor
- The single threaded execution context where all engine work takes place.- Returns:
- this
Engine
- Throws:
IllegalStateException
- if theEngine
is already performing auto tick handling.EngineStateException
- if the Engine state precludes accepting new input.
-
tickAuto
Allows the engine to manage idle timeout processing by providing it the single threaded executor context where all transport work is done which ensures singled threaded access while removing the need for the client library or server application to manage calls to thetick(long)
methods.- Parameters:
scheduler
- The single threaded execution context where all engine work takes place.- Returns:
- this
Engine
- Throws:
IllegalStateException
- if theEngine
is already performing auto tick handling.EngineStateException
- if the Engine state precludes accepting new input.
-
pipeline
EnginePipeline pipeline()Gets the EnginePipeline for this Engine.- Returns:
- the
EnginePipeline
for thisEngine
.
-
configuration
EngineConfiguration configuration()Gets the Configuration for this engine.- Returns:
- the configuration object for this engine.
-
saslDriver
EngineSaslDriver saslDriver()Gets the SASL driver for this engine, if no SASL layer is configured then a default no-op driver must be returned that indicates this. The SASL driver provides the engine with client and server side SASL handshaking support. AnEngine
implementation can support pluggable SASL drivers or exert tight control over the driver as it sees fit.- Returns:
- the SASL driver for the engine.
-
outputHandler
Sets a handler instance that will be notified when data from the engine is ready to be written to some output sink (socket etc).- Parameters:
output
- TheProtonBuffer
handler instance that performs IO for the engine output.- Returns:
- this
Engine
-
outputConsumer
Sets aConsumer
instance that will be notified when data from the engine is ready to be written to some output sink (socket etc).- Parameters:
consumer
- TheProtonBuffer
consumer instance that performs IO for the engine output.- Returns:
- this
Engine
-
outputHandler
Sets aBiConsumer
instance that will be notified when data from the engine is ready to be written to some output sink (socket etc). TheRunnable
value provided (if non-null) should be invoked once the I/O operation has completely successfully. If the event of an error writing the data the handler should throw an error or if performed asynchronously theEngine
should be marked failed via a call toengineFailed(Throwable)
.- Parameters:
output
- TheProtonBuffer
handler instance that performs IO for the engine output.- Returns:
- this
Engine
-
errorHandler
Sets a handler instance that will be notified when the engine encounters a fatal error.- Parameters:
engineFailure
- TheProtonException
handler instance that will be notified if the engine fails.- Returns:
- this
Engine
-
shutdownHandler
Sets a handler instance that will be notified when the engine is shut down via a call to theshutdown()
method is called.
-