uk.org.ogsadai.sessions
Class SimpleSessionStreamManager

java.lang.Object
  |
  +--uk.org.ogsadai.sessions.SimpleSessionStreamManager
All Implemented Interfaces:
SessionStreamManager

public class SimpleSessionStreamManager
extends java.lang.Object
implements SessionStreamManager

A simple SessionStreamManager that retrieves data from and inserts data onto output and input streams of the current requests of sessions.

Author:
The OGSA-DAI Project Team
See Also:
SessionStreamManager

Field Summary
private static int ALL_BLOCKS
          A constant to indicate that all blocks of data should be read
private static java.lang.String COPYRIGHT_NOTICE
          Copyright statement.
private static DAILogger LOG
          Logger object for logging in this class
private  SessionManager mManager
          The session manager containing the live sessions
 
Constructor Summary
SimpleSessionStreamManager(SessionManager manager)
          Creates a new instance that will use a specified session manager to retrieve the sessions and so allow access to the input and output streams of their current requests.
 
Method Summary
 java.lang.Object getBlock(SessionStreamID id)
          Gets the next block of data available from the specified session output stream.
private  BlockReader getBlockReader(SessionStreamID id)
          Gets the BlockReader for the identified session output stream.
private  BlockWriter getBlockWriter(SessionStreamID id)
          Gets the BlockWriter for the identified session input stream.
 java.lang.Object getFully(SessionStreamID id)
          Gets an aggregate of all the data from the specified session output stream.
 java.lang.Object getNBlocks(SessionStreamID id, int numberOfBlocks)
          Gets an aggregate of a number of available blocks of data from a session output stream.
private  Session getSession(SessionID sessionID)
          Retrieves the specified session from the session manager.
 boolean hasInput(SessionStreamID id)
          Determines whether or not an input stream with the specified identity exists and is open for writing to.
 boolean hasOutput(SessionStreamID id)
          Determines whether or not an output stream with the specified identity exists.
 boolean hasSession(SessionID id)
          Determines whether or not a session with the specified identity exists.
 void putBlock(SessionStreamID id, java.lang.Object data)
          Puts a block of data onto a specified session stream.
 void putFully(SessionStreamID id, java.lang.Object data)
          Puts a block containing all the input data for a specified session stream into the stream and then closes the stream for further input.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYRIGHT_NOTICE

private static final java.lang.String COPYRIGHT_NOTICE
Copyright statement.

See Also:
Constant Field Values

LOG

private static final DAILogger LOG
Logger object for logging in this class


mManager

private final SessionManager mManager
The session manager containing the live sessions


ALL_BLOCKS

private static final int ALL_BLOCKS
A constant to indicate that all blocks of data should be read

See Also:
Constant Field Values
Constructor Detail

SimpleSessionStreamManager

public SimpleSessionStreamManager(SessionManager manager)
Creates a new instance that will use a specified session manager to retrieve the sessions and so allow access to the input and output streams of their current requests.

Parameters:
manager - Session manager.
Method Detail

hasSession

public boolean hasSession(SessionID id)
                   throws SessionLookupException
Description copied from interface: SessionStreamManager
Determines whether or not a session with the specified identity exists.

Specified by:
hasSession in interface SessionStreamManager
Parameters:
id - The session identifier.
Returns:
true if the session exists otherwise false.
Throws:
SessionLookupException - if there is a problem in accessing the session.

hasInput

public boolean hasInput(SessionStreamID id)
                 throws SessionNotFoundException,
                        SessionLookupException
Description copied from interface: SessionStreamManager
Determines whether or not an input stream with the specified identity exists and is open for writing to.

Specified by:
hasInput in interface SessionStreamManager
Parameters:
id - The session stream identifier for the input stream.
Returns:
true if the stream exists and is open, otherwise false.
Throws:
SessionLookupException - if there is a problem in accessing the session.
SessionNotFoundException - if the session in id does not exist.

hasOutput

public boolean hasOutput(SessionStreamID id)
                  throws SessionNotFoundException,
                         SessionLookupException
Description copied from interface: SessionStreamManager
Determines whether or not an output stream with the specified identity exists.

If it exists but contains no more data then a EngineConstants.NO_MORE_DATA block will be returned from the getBlock and getNBlocks methods.

Specified by:
hasOutput in interface SessionStreamManager
Parameters:
id - The session stream identifier for the output stream.
Returns:
true if the stream exists and is open, otherwise false.
Throws:
SessionLookupException - if there is a problem in accessing the session.
SessionNotFoundException - if the session in id does not exist.

getFully

public java.lang.Object getFully(SessionStreamID id)
                          throws SessionNotFoundException,
                                 SessionLookupException,
                                 SessionStreamNotFoundException,
                                 SessionStreamRequestNotProcessingException,
                                 SessionStreamIOException
Description copied from interface: SessionStreamManager
Gets an aggregate of all the data from the specified session output stream.

Specified by:
getFully in interface SessionStreamManager
Parameters:
id - The session stream identifier
Returns:
an Object containing an aggregate of all the blocks of data.
Throws:
SessionLookupException - if there is a problem in accessing the session.
SessionNotFoundException - if the session in id does not exist.
SessionStreamIOException - if there is a problem when reading from the specified session stream.
SessionStreamRequestNotProcessingException - if the request to which the stream belongs has not started processing.
SessionStreamNotFoundException - if there is no such session or no such stream in the session.

getNBlocks

public java.lang.Object getNBlocks(SessionStreamID id,
                                   int numberOfBlocks)
                            throws SessionNotFoundException,
                                   SessionLookupException,
                                   SessionStreamNotFoundException,
                                   SessionStreamRequestNotProcessingException,
                                   SessionStreamIOException
Description copied from interface: SessionStreamManager
Gets an aggregate of a number of available blocks of data from a session output stream.

To indicate to the caller that no more data is available, a no-more-data block - a qualified name {https://ogsadai.org.uk/namespaces/2005/10/properties}NoMoreData (see the constant uk.org.ogsadai.engine.EngineConstants.NO_MORE_DATA) can be expected to be provided by this method after retrieval of the final block of data.

Specified by:
getNBlocks in interface SessionStreamManager
Parameters:
id - The session stream identifier.
numberOfBlocks - The number of blocks to attempt to aggregate. If less than this number are contained in the stream then an aggregate of the maximum available will be returned.
Returns:
an Object containing an aggregate of a number of blocks of data.
Throws:
SessionLookupException - if there is a problem in accessing the session.
SessionStreamNotFoundException - if there is no such session or no such stream in the session.
SessionStreamIOException - if there is a problem when reading from the specified session stream.
SessionStreamRequestNotProcessingException - if the request to which the stream belongs has not started processing.
SessionNotFoundException - if the session in id does not exist.

getBlock

public java.lang.Object getBlock(SessionStreamID id)
                          throws SessionNotFoundException,
                                 SessionLookupException,
                                 SessionStreamNotFoundException,
                                 SessionStreamRequestNotProcessingException,
                                 SessionStreamIOException
Description copied from interface: SessionStreamManager
Gets the next block of data available from the specified session output stream.

To indicate to the caller that no more data is available, a no-more-data block - a qualified name {https://ogsadai.org.uk/namespaces/2005/10/properties}NoMoreData (see the constant uk.org.ogsadai.engine.EngineConstants.NO_MORE_DATA) can be expected to be provided by this method after retrieval of the final block of data.

Specified by:
getBlock in interface SessionStreamManager
Parameters:
id - The session stream identifier.
Returns:
an Object containing a single block of data.
Throws:
SessionNotFoundException - if the session in id does not exist.
SessionLookupException - if there is a problem in accessing the session.
SessionStreamIOException - if there is a problem when reading from the specified session stream.
SessionStreamRequestNotProcessingException - if the request to which the stream belongs has not started processing.
SessionStreamNotFoundException - if there is no such session or no such stream in the session.

putBlock

public void putBlock(SessionStreamID id,
                     java.lang.Object data)
              throws SessionNotFoundException,
                     SessionLookupException,
                     SessionStreamNotFoundException,
                     SessionStreamRequestNotProcessingException,
                     SessionStreamClosedException
Description copied from interface: SessionStreamManager
Puts a block of data onto a specified session stream.

To indicate that no more data is available, a no-more-data block - a qualified name {"https://ogsadai.org.uk/namespaces/2005/10/properties"}NoMoreData (see the constant uk.org.ogsadai.engine.EngineConstants.NO_MORE_DATA) should be provided to this method after putting the final block of data.

Specified by:
putBlock in interface SessionStreamManager
Parameters:
id - The session stream identifier.
data - The block of data.
Throws:
SessionNotFoundException - if the session in id does not exist.
SessionLookupException - if there is a problem in accessing the session.
SessionStreamClosedException - if the stream has already been closed via provision of a no-more-data block.
SessionStreamNotFoundException - if there is no such session or no such stream in the session.
SessionStreamRequestNotProcessingException - if the request to which the stream belongs has not started processing.

putFully

public void putFully(SessionStreamID id,
                     java.lang.Object data)
              throws SessionNotFoundException,
                     SessionLookupException,
                     SessionStreamNotFoundException,
                     SessionStreamRequestNotProcessingException,
                     SessionStreamClosedException
Description copied from interface: SessionStreamManager
Puts a block containing all the input data for a specified session stream into the stream and then closes the stream for further input.

Specified by:
putFully in interface SessionStreamManager
Parameters:
id - The session stream identifier.
data - The block containing all the data for the stream.
Throws:
SessionStreamClosedException - if the stream has already been closed via provision of a no-more-data block.
SessionStreamRequestNotProcessingException - if the request to which the stream belongs has not started processing.
SessionNotFoundException - if the session in id does not exist.
SessionLookupException - if there is a problem in accessing the session.
SessionStreamNotFoundException - if there is no such session or no such stream in the session.

getSession

private Session getSession(SessionID sessionID)
                    throws SessionNotFoundException,
                           SessionLookupException
Retrieves the specified session from the session manager.

Parameters:
sessionID - The session stream ID containing the session ID.
Returns:
the session.
Throws:
SessionNotFoundException - if the session in id does not exist.
SessionLookupException - if there is a problem in accessing the session.

getBlockReader

private BlockReader getBlockReader(SessionStreamID id)
                            throws SessionNotFoundException,
                                   SessionLookupException,
                                   SessionStreamNotFoundException
Gets the BlockReader for the identified session output stream.

Parameters:
id - The session containing the output stream.
Returns:
a BlockReader.
Throws:
SessionNotFoundException - if the session in id does not exist.
SessionLookupException - if there is a problem in accessing the session.
SessionStreamNotFoundException - if there is no such session or no such stream in the session.

getBlockWriter

private BlockWriter getBlockWriter(SessionStreamID id)
                            throws SessionNotFoundException,
                                   SessionLookupException,
                                   SessionStreamNotFoundException
Gets the BlockWriter for the identified session input stream.

Parameters:
id - The session and stream ID.
Returns:
a BlockWriter.
Throws:
SessionNotFoundException - if the session in id does not exist.
SessionLookupException - if there is a problem in accessing the session.
SessionStreamNotFoundException - if there is no such session or no such stream in the session.