I - The type of the input this communication stack element handles.O - The type of the value this communication stack element returns.public abstract class CommunicationStackTerminator<I,O> extends java.lang.Object implements CommunicationStack<I,O>
CommunicationStack. 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 appropriate
CommunicationStackException.
Concrete communication stack terminators must implement
processInputAndReturn(URI, Object) and
shutdownStackLayer().
| Modifier and Type | Field and Description |
|---|---|
protected java.util.logging.Logger |
logger
The logger.
|
protected int[] |
syncObject
Object for sync purposes.
|
| Modifier | Constructor and Description |
|---|---|
protected |
CommunicationStackTerminator(LogService logService)
Initialises the instance variables appropriately.
|
| Modifier and Type | Method and Description |
|---|---|
O |
process(java.net.URI remoteIdentifier,
I input)
Handles the request and returns the response.
|
protected abstract O |
processInputAndReturn(java.net.URI remoteIdentifier,
I input)
Transforms the given input of type
I accordingly to the
functionality this communication stack element is designed for and returns
the result of type O of this transformation process. |
void |
shutdown()
Initiate the shutdown of this communication stack layer.
|
protected abstract void |
shutdownStackLayer()
Shuts down this CommunicationStackLayer.
|
protected final java.util.logging.Logger logger
protected final int[] syncObject
protected CommunicationStackTerminator(LogService logService)
logService - The log service to retrieve the logger from.public final O process(java.net.URI remoteIdentifier, I input) throws CommunicationStackException
CommunicationStackIt 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 appropriate CommunicationStackException.
process in interface CommunicationStack<I,O>remoteIdentifier - The identifier of the object/service the request is
targeted at. This may be null in case the information
is not available for the communication service. This information
may also be provided by the input parameter (for instance in an
InvocationMessage.input - The request in the form of what this layer expects.CommunicationStackException - If there are problems processing the
request, a CommunicationStackException will be
thrown. This may encapsulate any occurred exception.protected abstract O processInputAndReturn(java.net.URI remoteIdentifier, I input) throws CommunicationStackException
I accordingly to the
functionality this communication stack element is designed for and returns
the result of type O 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
appropriate CommunicationStackException.
remoteIdentifier - The URI identifying the object this communication
call is meant for.input - The input that should be transformed.CommunicationStackException - If there are problems processing the
input, a CommunicationStackException will be thrown.
This may encapsulate any occurred exception.protected abstract void shutdownStackLayer()
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.
public final void shutdown()
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.
shutdown in interface CommunicationStack<I,O>CommunicationStack.shutdown()