Class ProtonEngine
- java.lang.Object
-
- org.apache.qpid.protonj2.engine.impl.ProtonEngine
-
- All Implemented Interfaces:
java.util.function.Consumer<ProtonBuffer>,Engine
public class ProtonEngine extends java.lang.Object implements Engine
The default proton Engine implementation.
-
-
Constructor Summary
Constructors Constructor Description ProtonEngine()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ProtonEngineConfigurationconfiguration()Gets the Configuration for this engine.ProtonConnectionconnection()Gets theConnectioninstance that is associated with thisEngineinstance.EngineStateExceptionengineFailed(java.lang.Throwable cause)Transition theEngineto a failed state if not already closed or closing.ProtonEngineerrorHandler(EventHandler<Engine> handler)Sets a handler instance that will be notified when the engine encounters a fatal error.java.lang.ThrowablefailureCause()ProtonEngineingest(ProtonBuffer input)Provide data input for this Engine from some external source.booleanisFailed()booleanisRunning()booleanisShutdown()booleanisWritable()Returns true if the engine is accepting input from the ingestion entry points.ProtonEngineoutputHandler(java.util.function.BiConsumer<ProtonBuffer,java.lang.Runnable> handler)Sets aBiConsumerinstance that will be notified when data from the engine is ready to be written to some output sink (socket etc).EnginePipelinepipeline()Gets the EnginePipeline for this Engine.voidregisterSaslDriver(EngineSaslDriver saslDriver)Allows for registration of a customEngineSaslDriverthat will convey SASL state and configuration for this engine.EngineSaslDriversaslDriver()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.ProtonEngineshutdown()Shutdown the engine preventing any future outbound or inbound processing.ProtonEngineshutdownHandler(EventHandler<Engine> handler)Sets a handler instance that will be notified when the engine is shut down via a call to theEngine.shutdown()method is called.ProtonConnectionstart()Starts the engine and returns theConnectioninstance that is bound to this Engine.EngineStatestate()longtick(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.ProtonEnginetickAuto(java.util.concurrent.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 theEngine.tick(long)methods.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.qpid.protonj2.engine.Engine
accept, outputConsumer, outputHandler
-
-
-
-
Method Detail
-
connection
public ProtonConnection connection()
Description copied from interface:EngineGets theConnectioninstance that is associated with thisEngineinstance. It is valid for an engine implementation to not return aConnectioninstance prior to the engine having been started.- Specified by:
connectionin interfaceEngine- Returns:
- the
Connectionthat is linked to this engine instance.
-
isWritable
public boolean isWritable()
Description copied from interface:EngineReturns 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.
- Specified by:
isWritablein interfaceEngine- Returns:
- true if the engine is current accepting more input.
-
isRunning
public boolean isRunning()
-
isShutdown
public boolean isShutdown()
- Specified by:
isShutdownin interfaceEngine- Returns:
- true if the Engine has been shutdown and is no longer usable.
-
isFailed
public boolean isFailed()
-
failureCause
public java.lang.Throwable failureCause()
- Specified by:
failureCausein interfaceEngine- Returns:
- the error that caused the
Enginefail and shutdown (or null if not failed).
-
state
public EngineState state()
-
start
public ProtonConnection start() throws EngineStateException
Description copied from interface:EngineStarts the engine and returns theConnectioninstance 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 theEngine.connection()method cannot produce any outbound data.- Specified by:
startin interfaceEngine- Returns:
- the Connection instance that is linked to this
Engine - Throws:
EngineStateException- if the Engine state has already transition to shutdown or failed.
-
shutdown
public ProtonEngine shutdown()
Description copied from interface:EngineShutdown the engine preventing any future outbound or inbound processing. When the engine is shut down any resources,Connection,SessionorLinkinstances 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.
-
tick
public long tick(long currentTime) throws java.lang.IllegalStateException, EngineStateExceptionDescription copied from interface:EnginePrompt 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 ifEngine.tickAuto(ScheduledExecutorService)was called.- Specified by:
tickin interfaceEngine- 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:
java.lang.IllegalStateException- if theEngineis already performing auto tick handling.EngineStateException- if the Engine state precludes accepting new input.
-
tickAuto
public ProtonEngine tickAuto(java.util.concurrent.ScheduledExecutorService executor) throws java.lang.IllegalStateException, EngineStateException
Description copied from interface:EngineAllows 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 theEngine.tick(long)methods.- Specified by:
tickAutoin interfaceEngine- Parameters:
executor- The single threaded execution context where all engine work takes place.- Returns:
- this
Engine - Throws:
java.lang.IllegalStateException- if theEngineis already performing auto tick handling.EngineStateException- if the Engine state precludes accepting new input.
-
ingest
public ProtonEngine ingest(ProtonBuffer input) throws EngineStateException
Description copied from interface:EngineProvide data input for this Engine from some external source. If the engine is not writable when this method is called anEngineNotWritableExceptionwill 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 appropriateEngineStateExceptionwill be thrown to indicate the reason.- Specified by:
ingestin interfaceEngine- Parameters:
input- The data to feed into to Engine.- Returns:
- this
Engine - Throws:
EngineStateException- if the Engine state precludes accepting new input.
-
engineFailed
public EngineStateException engineFailed(java.lang.Throwable cause)
Description copied from interface:EngineTransition theEngineto 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 appropriateEngineFailedExceptionthat wraps the given cause. If called after the engine was shutdown the method returns anEngineShutdownExceptionindicating 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.- Specified by:
engineFailedin interfaceEngine- Parameters:
cause- The exception that caused the engine to be forcibly transitioned to the failed state.- Returns:
- an
EngineStateExceptionthat can be thrown indicating the failure and engine state.
-
outputHandler
public ProtonEngine outputHandler(java.util.function.BiConsumer<ProtonBuffer,java.lang.Runnable> handler)
Description copied from interface:EngineSets aBiConsumerinstance that will be notified when data from the engine is ready to be written to some output sink (socket etc). TheRunnablevalue 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 theEngineshould be marked failed via a call toEngine.engineFailed(Throwable).- Specified by:
outputHandlerin interfaceEngine- Parameters:
handler- TheProtonBufferhandler instance that performs IO for the engine output.- Returns:
- this
Engine
-
errorHandler
public ProtonEngine errorHandler(EventHandler<Engine> handler)
Description copied from interface:EngineSets a handler instance that will be notified when the engine encounters a fatal error.- Specified by:
errorHandlerin interfaceEngine- Parameters:
handler- TheProtonExceptionhandler instance that will be notified if the engine fails.- Returns:
- this
Engine
-
shutdownHandler
public ProtonEngine shutdownHandler(EventHandler<Engine> handler)
Description copied from interface:EngineSets a handler instance that will be notified when the engine is shut down via a call to theEngine.shutdown()method is called.- Specified by:
shutdownHandlerin interfaceEngine- Parameters:
handler- TheEngineinstance that was was explicitly shut down.- Returns:
- this
Engine
-
pipeline
public EnginePipeline pipeline()
Description copied from interface:EngineGets the EnginePipeline for this Engine.- Specified by:
pipelinein interfaceEngine- Returns:
- the
EnginePipelinefor thisEngine.
-
configuration
public ProtonEngineConfiguration configuration()
Description copied from interface:EngineGets the Configuration for this engine.- Specified by:
configurationin interfaceEngine- Returns:
- the configuration object for this engine.
-
saslDriver
public EngineSaslDriver saslDriver()
Description copied from interface:EngineGets 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. AnEngineimplementation can support pluggable SASL drivers or exert tight control over the driver as it sees fit.- Specified by:
saslDriverin interfaceEngine- Returns:
- the SASL driver for the engine.
-
registerSaslDriver
public void registerSaslDriver(EngineSaslDriver saslDriver) throws EngineStateException
Allows for registration of a customEngineSaslDriverthat will convey SASL state and configuration for this engine.- Parameters:
saslDriver- TheEngineSaslDriverthat this engine will use.- Throws:
EngineStateException- if the engine state doesn't allow for changes
-
-