outputStrategy
Class Batch

java.lang.Object
  extended by outputStrategy.Batch

final class Batch
extends java.lang.Object

Data structure used to stores processed messages until output is requested (see putOutBatch()). Then, all messages in the buffer are submitted to the InputOutputHandler, which sends them to their destination. Messages are added in sorted manner (alphabetic, ascending order) to prevent linkability of (incoming and outgoing) messages due to their position in the input and output stream.

This class is thread-safe.

Author:
Karl-Peter Fuchs

Field Summary
private  boolean BELONGS_TO_LAST_MIX
          Indicates whether this Batch belongs to the last mix of a cascade or not.
private  java.util.ArrayList<Message> buffer
          ArrayList containing the messages.
private  int correctPosition
          Position, the message currently processed shall be saved to (in buffer).
private  InputOutputHandlerController inputOutputHandler
          Reference on InputOutputHandler used to send messages to their destination when putOutBatch() was called.
private  boolean IS_REQUEST_BATCH
          Indicates whether this Batch is used to collect Requests or Replyies.
 
Constructor Summary
protected Batch(int initialMessageBufferSize, boolean isRequestBatch, boolean belongsToLastMix, InputOutputHandlerController inputOutputHandlerController)
          Constructs a new Batch that can be used to stores processed messages until output is requested (see putOutBatch()).
 
Method Summary
protected  void addMessage(Message message)
          Adds the bypassed message to the local buffer (at the correct position according to alphabetic, ascending order).
private  void findCorrectPosition(Message message, int startIndex, int endIndex)
          Finds the correct position (alphabetic, ascending order) the bypassed message shall be saved to (in buffer).
protected  void putOutBatch()
          Puts out the current batch, by submitting all messages in buffer to the InputOutputHandler, which sends them to their destination.
protected  int size()
          Returns the total number of messages currently in this Batch.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IS_REQUEST_BATCH

private final boolean IS_REQUEST_BATCH
Indicates whether this Batch is used to collect Requests or Replyies.


BELONGS_TO_LAST_MIX

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


buffer

private java.util.ArrayList<Message> buffer
ArrayList containing the messages.


correctPosition

private int correctPosition
Position, the message currently processed shall be saved to (in buffer). Calculated by findCorrectPosition(Message message, int startIndex, int endIndex).

See Also:
buffer, findCorrectPosition(Message, int, int)

inputOutputHandler

private InputOutputHandlerController inputOutputHandler
Reference on InputOutputHandler used to send messages to their destination when putOutBatch() was called.

Constructor Detail

Batch

protected Batch(int initialMessageBufferSize,
                boolean isRequestBatch,
                boolean belongsToLastMix,
                InputOutputHandlerController inputOutputHandlerController)
Constructs a new Batch that can be used to stores processed messages until output is requested (see putOutBatch()).

Parameters:
initialMessageBufferSize - Initial size for the data structure (ArrayList) used to store messages.
isRequestBatch - Indicates whether this Batch is used to collect Requests or Replyies.
belongsToLastMix - Indicates whether this Batch belongs to the last mix of a cascade or not.
inputOutputHandlerController - Reference on component InputOutputHandler (used to send messages to their destination when putOutBatch() was called).
Method Detail

size

protected int size()
Returns the total number of messages currently in this Batch.

Returns:
Total number of messages currently in this Batch.

addMessage

protected void addMessage(Message message)
Adds the bypassed message to the local buffer (at the correct position according to alphabetic, ascending order).

Parameters:
message - Message to be added to local buffer.

findCorrectPosition

private void findCorrectPosition(Message message,
                                 int startIndex,
                                 int endIndex)
Finds the correct position (alphabetic, ascending order) the bypassed message shall be saved to (in buffer). (Recursive; divide and conquer).

See Also:
correctPosition, buffer, Message.compareTo(Message)

putOutBatch

protected void putOutBatch()
Puts out the current batch, by submitting all messages in buffer to the InputOutputHandler, which sends them to their destination.