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 a 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().

Author:
Markus Lauer, Ulrich Kreher
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final Logger
    The logger.
    protected final int[]
    Object for sync purposes.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Initialises the instance variables appropriately.
  • Method Summary

    Modifier and Type
    Method
    Description
    final 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 type I accordingly to the functionality this communication stack element is designed for and returns the result of type O of this transformation process.
    final void
    Initiate the shutdown of this communication stack layer.
    protected abstract void
    Shuts down this CommunicationStackLayer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • logger

      protected final Logger logger
      The logger.
    • syncObject

      protected final int[] syncObject
      Object for sync purposes.
  • Constructor Details

    • CommunicationStackTerminator

      protected CommunicationStackTerminator(LogService logService)
      Initialises the instance variables appropriately.
      Parameters:
      logService - The log service to retrieve the logger from.
  • Method Details

    • 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 appropriate CommunicationStackException.

      Specified by:
      process in interface CommunicationStack<I,O>
      Parameters:
      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.
      Returns:
      The response
      Throws:
      de.aristaflow.adept2.model.communication.CommunicationStackException - If there are problems processing the request, a CommunicationStackException 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 type 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.

      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, a CommunicationStackException 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 interface CommunicationStack<I,O>
      See Also: