outputStrategy
Class OutputStrategyController

java.lang.Object
  extended by outputStrategy.OutputStrategyController
All Implemented Interfaces:
OutputStrategyInterface

public class OutputStrategyController
extends java.lang.Object
implements OutputStrategyInterface

Controller class of component OutputStrategy.

Collects messages until an output criterion is fulfilled (certain number of messages collected or timeout reached).

Messages are added by component MessageProcessor. When the output criterion is fulfilled, the collected messages are bypassed to the InputOutputHandler (component), which sends them to their destination.

Author:
Karl-Peter Fuchs

Nested Class Summary
private  class OutputStrategyController.OutputTask
          Simple TimerTask, which puts out the batch it is linked to.
 
Field Summary
private  int batchSize
          Number of messages the upcoming batch will contain (according to the OutputStrategy component on this mix' predecessor).
private  boolean BELONGS_TO_FIRST_MIX
          Indicates whether this OutputStrategyController belongs to the first mix of the cascade or not.
private  boolean BELONGS_TO_LAST_MIX
          Indicates whether this OutputStrategyController belongs to the last mix of the cascade or not.
private  int INITIAL_BUFFER_SIZE
          Initial size of the Buffer used to store messages until output.
private  InputOutputHandlerController inputOutputHandler
          Reference on component InputOutputHandler.
private static InternalInformationPortController internalInformationPort
          Reference on component InternalInformationPort.
private  boolean isReplyBatchPending
          Indicates whether the batch sent lastly has already been answered.
private static java.util.logging.Logger LOGGER
          Logger used to log and display information.
private  int neededChannelEstablishMessages
          Minimum number of ChannelEstablishMessages that must be collected, before putting out the request batch (if at least one ChannelEstablishMessage is in the batch).
private  int neededForwardChannelMessages
          Minimum number of ForwardChannelMessages that must be collected, before putting out the request batch.
private  int neededReplyMessages
          Minimum number of ReplyMessagess that must be collected, before putting out the reply batch.
private  int numberOfChannelEstablishMessages
          Number of ChannelEstablishMessages currently in request batch.
private  int numberOfChannelReleaseMessages
          Number of ChannelReleaseMessages currently in request batch.
private  int numberOfForwardChannelMessages
          Number of ForwardChannelMessages currently in request batch.
private  Batch replyBatch
          Data structure used to store replies before output.
private  java.util.Timer replyTimeoutTimer
          Timer used to detect TIMEOUT for replies.
private  Batch requestBatch
          Data structure used to store requests before output.
private  java.util.Timer requestTimeoutTimer
          Timer used to detect TIMEOUT for requests.
private  long TIMEOUT
          Amount of time, after which the batch is put out, no matter how many messages it contains.
 
Constructor Summary
OutputStrategyController()
          Generates a new OutputStrategy component, which collects messages until an output criterion is fulfilled (certain number of messages collected or timeout reached).
 
Method Summary
 void addReply(Reply reply)
          Can be used to add a Reply, that shall be put out according to the underlying output strategy.
 void addRequest(Request request)
          Can be used to add a Request, that shall be put out according to the underlying output strategy.
private static java.lang.String getProperty(java.lang.String key)
          Simply used to shorten method calls (calls internalInformationPort.getProperty(key)).
 void initialize(InputOutputHandlerController inputOutputHandler)
          Initialization method for this component.
private  boolean isOutputCriterionForReplyBatchFulfilled()
          Indicates whether the output criterion for replyBatch is fulfilled or not.
private  boolean isOutputCriterionForRequestBatchFulfilled()
          Indicates whether the output criterion for requestBatch is fulfilled or not.
private  void putOutReplyBatch()
          Puts out collected messages in replyBatch.
private  void putOutRequestBatch()
          Puts out collected messages in requestBatch and prepares variables for next batch.
 void setBatchSize(int newSize)
          Number of messages the upcoming batch will contain (according to the OutputStrategy component on this mix' predecessor).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

internalInformationPort

private static InternalInformationPortController internalInformationPort
Reference on component InternalInformationPort. Used to display and/or log data and read general settings.


LOGGER

private static final java.util.logging.Logger LOGGER
Logger used to log and display information.


inputOutputHandler

private InputOutputHandlerController inputOutputHandler
Reference on component InputOutputHandler. Used to bypass collected messages, when output criterion fulfilled.


INITIAL_BUFFER_SIZE

private final int INITIAL_BUFFER_SIZE
Initial size of the Buffer used to store messages until output. Gets resized automatically if it runs out of space.


BELONGS_TO_LAST_MIX

private boolean BELONGS_TO_LAST_MIX
Indicates whether this OutputStrategyController belongs to the last mix of the cascade or not.


BELONGS_TO_FIRST_MIX

private boolean BELONGS_TO_FIRST_MIX
Indicates whether this OutputStrategyController belongs to the first mix of the cascade or not.


TIMEOUT

private final long TIMEOUT
Amount of time, after which the batch is put out, no matter how many messages it contains.


requestBatch

private Batch requestBatch
Data structure used to store requests before output.


replyBatch

private Batch replyBatch
Data structure used to store replies before output.


requestTimeoutTimer

private java.util.Timer requestTimeoutTimer
Timer used to detect TIMEOUT for requests.


replyTimeoutTimer

private java.util.Timer replyTimeoutTimer
Timer used to detect TIMEOUT for replies.


neededChannelEstablishMessages

private int neededChannelEstablishMessages
Minimum number of ChannelEstablishMessages that must be collected, before putting out the request batch (if at least one ChannelEstablishMessage is in the batch).

See Also:
requestBatch

neededForwardChannelMessages

private int neededForwardChannelMessages
Minimum number of ForwardChannelMessages that must be collected, before putting out the request batch. Will be adjusted automatically.

See Also:
requestBatch

neededReplyMessages

private int neededReplyMessages
Minimum number of ReplyMessagess that must be collected, before putting out the reply batch. Will be adjusted automatically.

See Also:
replyBatch

isReplyBatchPending

private boolean isReplyBatchPending
Indicates whether the batch sent lastly has already been answered.

Note: Synchronous batch.


batchSize

private int batchSize
Number of messages the upcoming batch will contain (according to the OutputStrategy component on this mix' predecessor).

Used for batch synchronization.

See Also:
BatchSizeMessage

numberOfChannelEstablishMessages

private int numberOfChannelEstablishMessages
Number of ChannelEstablishMessages currently in request batch.

See Also:
neededChannelEstablishMessages

numberOfForwardChannelMessages

private int numberOfForwardChannelMessages
Number of ForwardChannelMessages currently in request batch.

See Also:
neededForwardChannelMessages

numberOfChannelReleaseMessages

private int numberOfChannelReleaseMessages
Number of ChannelReleaseMessages currently in request batch.

Constructor Detail

OutputStrategyController

public OutputStrategyController()
Generates a new OutputStrategy component, which collects messages until an output criterion is fulfilled (certain number of messages collected or timeout reached).

Messages are added by component MessageProcessor. When the output criterion is fulfilled, the collected messages are bypassed to the InputOutputHandler (component), which sends them to their destination.

Can handle Requests and Replies in parallel.

Component can't be used before calling initialize(InputOutputHandlerController).

See Also:
initialize(InputOutputHandlerController)
Method Detail

initialize

public void initialize(InputOutputHandlerController inputOutputHandler)
Initialization method for this component. Makes this component ready for accepting messages.

Parameters:
inputOutputHandler - Reference on component InputOutputHandler (used to send messages after output).

addRequest

public void addRequest(Request request)
Can be used to add a Request, that shall be put out according to the underlying output strategy.

Return immediately (asynchronous behavior), internal output decision is deferred.

Specified by:
addRequest in interface OutputStrategyInterface
Parameters:
request - Request, that shall be put out according to the underlying output strategy.

addReply

public void addReply(Reply reply)
Can be used to add a Reply, that shall be put out according to the underlying output strategy.

Returns immediately (asynchronous behavior), internal output decision is deferred.

Specified by:
addReply in interface OutputStrategyInterface
Parameters:
reply - Reply, that shall be put out according to the underlying output strategy.

setBatchSize

public void setBatchSize(int newSize)
Number of messages the upcoming batch will contain (according to the OutputStrategy component on this mix' predecessor).

Used for batch synchronization.

See Also:
BatchSizeMessage

isOutputCriterionForRequestBatchFulfilled

private boolean isOutputCriterionForRequestBatchFulfilled()
Indicates whether the output criterion for requestBatch is fulfilled or not.

Returns:
Whether the output criterion for requestBatch is fulfilled or not.

isOutputCriterionForReplyBatchFulfilled

private boolean isOutputCriterionForReplyBatchFulfilled()
Indicates whether the output criterion for replyBatch is fulfilled or not.

Returns:
Whether the output criterion for replyBatch is fulfilled or not.

putOutRequestBatch

private void putOutRequestBatch()
Puts out collected messages in requestBatch and prepares variables for next batch.


putOutReplyBatch

private void putOutReplyBatch()
Puts out collected messages in replyBatch.


getProperty

private static java.lang.String getProperty(java.lang.String key)
Simply used to shorten method calls (calls internalInformationPort.getProperty(key)). Returns the property with the specified key from the property file.

Parameters:
key - The property key.
Returns:
The property with the specified key in the property file.