Class CommunicationStackTerminator<I,O>
- java.lang.Object
-
- de.aristaflow.adept2.base.communication.CommunicationStackTerminator<I,O>
-
- Type Parameters:
I
- The type of the input this communication stack element handles.O
- The type of the value this communication stack element returns.
- All Implemented Interfaces:
CommunicationStack<I,O>
public abstract class CommunicationStackTerminator<I,O> extends Object implements CommunicationStack<I,O>
Provides the base implementation for the last layer, i. e. the terminator, within aCommunicationStack
. It represents the last step within a request and response handling strategy.It provides a default shutdown behaviour. That is: If a shutdown is initiated by
shutdown()
, all active threads are allowed to finish their job, but no other requests are accepted any more. Attempts are answered with an appropriateCommunicationStackException
.Concrete communication stack terminators must implement
processInputAndReturn(URI, Object)
andshutdownStackLayer()
.- Author:
- Markus Lauer, Ulrich Kreher
-
-
Field Summary
Fields Modifier and Type Field Description protected Logger
logger
The logger.protected int[]
syncObject
Object for sync purposes.
-
Constructor Summary
Constructors Modifier Constructor Description protected
CommunicationStackTerminator(LogService logService)
Initialises the instance variables appropriately.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description O
process(URI remoteIdentifier, I input)
Handles the request and returns the response.protected abstract O
processInputAndReturn(URI remoteIdentifier, I input)
Transforms the given input of typeI
accordingly to the functionality this communication stack element is designed for and returns the result of typeO
of this transformation process.void
shutdown()
Initiate the shutdown of this communication stack layer.protected abstract void
shutdownStackLayer()
Shuts down this CommunicationStackLayer.
-
-
-
Field Detail
-
logger
protected final Logger logger
The logger.
-
syncObject
protected final int[] syncObject
Object for sync purposes.
-
-
Constructor Detail
-
CommunicationStackTerminator
protected CommunicationStackTerminator(LogService logService)
Initialises the instance variables appropriately.- Parameters:
logService
- The log service to retrieve the logger from.
-
-
Method Detail
-
process
public final O process(URI remoteIdentifier, I input) throws de.aristaflow.adept2.model.communication.CommunicationStackException
Description copied from interface:CommunicationStack
Handles the request and returns the response.It accepts the request as input, modifies it accordingly to the functionality this layer is meant for and delegates it to the lower communication stack layer. Beside it modifies the response returned by the lower communication stack layer and returns the result.
If this component is instructed to shutdown by calling
CommunicationStack.shutdown()
this method returns immediately by throwing a appropriateCommunicationStackException
.- Specified by:
process
in interfaceCommunicationStack<I,O>
- Parameters:
remoteIdentifier
- The identifier of the object/service the request is targeted at. This may benull
in case the information is not available for the communication service. This information may also be provided by the input parameter (for instance in anInvocationMessage
.input
- The request in the form of what this layer expects.- Returns:
- The response
- Throws:
de.aristaflow.adept2.model.communication.CommunicationStackException
- If there are problems processing the request, aCommunicationStackException
will be thrown. This may encapsulate any occurred exception.
-
processInputAndReturn
protected abstract O processInputAndReturn(URI remoteIdentifier, I input) throws de.aristaflow.adept2.model.communication.CommunicationStackException
Transforms the given input of typeI
accordingly to the functionality this communication stack element is designed for and returns the result of typeO
of this transformation process.Hint: It is ensured that this method is not called any more after the shutdown was initiated by
shutdown()
. The attempt to call after a requested shutdown is answered with an appropriateCommunicationStackException
.- Parameters:
remoteIdentifier
- The URI identifying the object this communication call is meant for.input
- The input that should be transformed.- Returns:
- The result of this transformation process.
- Throws:
de.aristaflow.adept2.model.communication.CommunicationStackException
- If there are problems processing the input, aCommunicationStackException
will be thrown. This may encapsulate any occurred exception.
-
shutdownStackLayer
protected abstract void shutdownStackLayer()
Shuts down this CommunicationStackLayer.This method should be overwritten for communication stack layer depended shutdown behaviour.
This method is called not until all active requests are handled. Further requests are refused.
-
shutdown
public final void shutdown()
Initiate the shutdown of this communication stack layer.It ensures that no other requests are handled any more and that this stack layer shuts down as soon as there are no more running jobs.
- Specified by:
shutdown
in interfaceCommunicationStack<I,O>
- See Also:
CommunicationStack.shutdown()
-
-