uk.org.ogsadai.activity
Class ActivityRequest

java.lang.Object
  |
  +--uk.org.ogsadai.activity.ActivityRequest
All Implemented Interfaces:
Request, SessionParticipant

public class ActivityRequest
extends java.lang.Object
implements Request, SessionParticipant

Implementation of interface Request that encapsulates all of the objects required to create, process and obtain responses from a single request. It also encapsulates the state-machine logic used to track down the processing status of the request.

Author:
The OGSA-DAI Project Team

Nested Class Summary
private  class ActivityRequest.TimeOutTask
          Auxialliary timer task class associated with the timeout timer
 
Field Summary
private static java.lang.String COPYRIGHT_NOTICE
          Copyright statement.
private static DAILogger LOG
          Logger object for this request.
private  ActivityContext mActivityContext
          Activity context for the activities in the request.
private  EngineConfiguration mConfiguration
          Engine configuration information.
private  ProcessingStatusObserver mObserver
          Observer object for detecting completion
private  RequestComponent mRequest
          References the top-level component of the composite object representing a single request.
private  RequestContext mRequestContext
          Context for this request.
private  ResponseBuilder mResponseBuilder
          Response builder used for assembling the response to the request.
private  Session mSession
          The session that the request has joined.
private  ProcessingStatus mStatus
          The observable status for this request.
private  SessionStrategy mStrategy
          The session access strategy for the request.
private  java.lang.Thread mThread
          Thread used for processing this request.
private  java.util.Timer mTimeOutTimer
          The timer object responsible for effectinbg time-outs.
 
Constructor Summary
ActivityRequest(RequestComponent composite, SessionStrategy strategy)
          Constructs an instance associated with a specific request component and session strategy.
 
Method Summary
private  void endProcessing()
          Ends the processing of this request, leaving the status unaffected.
(package private)  RequestComponent getRequestComposite()
          Returns the composite RequestComponent for the request.
 Session getSession()
          Gets the Session that the session participant is joined to.
 SessionStrategy getSessionStrategy()
          Gets the SessionStrategy object for the session participant.
 ProcessingStatus getStatus()
          Returns the processing status of this request.
 void initialise(EngineConfiguration config, RequestContext context, ResponseBuilder builder)
          Initialises this request before its processing can commence.
 void process()
          Initiates the processing of the request.
private  void processAsynchronously()
          Spawn a processing thread and process the request asynchronously.
private  void reportError(java.lang.Exception cause)
          This is invoked when an error occurs while processing the request.
 void setSession(Session session)
          Provides the session participant with the session to which it is joined.
 void terminate()
          Terminates the request.
 void waitForResponse()
          Waits for the response building to complete.
 
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 this request.


mRequest

private RequestComponent mRequest
References the top-level component of the composite object representing a single request.


mThread

private java.lang.Thread mThread
Thread used for processing this request.


mStatus

private final ProcessingStatus mStatus
The observable status for this request.


mStrategy

private SessionStrategy mStrategy
The session access strategy for the request.


mSession

private Session mSession
The session that the request has joined.


mRequestContext

private RequestContext mRequestContext
Context for this request.


mActivityContext

private ActivityContext mActivityContext
Activity context for the activities in the request.


mResponseBuilder

private ResponseBuilder mResponseBuilder
Response builder used for assembling the response to the request.


mConfiguration

private EngineConfiguration mConfiguration
Engine configuration information.


mObserver

private ProcessingStatusObserver mObserver
Observer object for detecting completion


mTimeOutTimer

private java.util.Timer mTimeOutTimer
The timer object responsible for effectinbg time-outs. Set to null if timeouts aren't used.

Constructor Detail

ActivityRequest

public ActivityRequest(RequestComponent composite,
                       SessionStrategy strategy)
Constructs an instance associated with a specific request component and session strategy.

Parameters:
composite - Request component.
strategy - Session strategy.
Method Detail

getStatus

public ProcessingStatus getStatus()
Returns the processing status of this request.

Specified by:
getStatus in interface Request
Returns:
the current processing status as a Status object.

initialise

public void initialise(EngineConfiguration config,
                       RequestContext context,
                       ResponseBuilder builder)
                throws java.lang.IllegalStateException,
                       RequestSpecificationException,
                       RequestExecutionException
Description copied from interface: Request
Initialises this request before its processing can commence.

Initialisation may be performed once only, prior to invoking any of the other methods on the Request interface.

Specified by:
initialise in interface Request
Throws:
java.lang.IllegalStateException - If invoked after the processing of the request has been initiated or terminated.
RequestExecutionException - if the request fails to execute due to a problem in the e.g. a database connection disappears or a file is corrupted.
RequestSpecificationException - if the request fails to execute due to a problem in the request e.g. it specifies an unsupported activity or a query expression is has incorrect syntax.

process

public void process()
             throws java.lang.IllegalStateException
Description copied from interface: Request
Initiates the processing of the request. After this method returns the response will be available via the ResponseBuilder passed into the process method.

All implementations of this method must ensure that processing is a non-blocking operation; e.g., by delegating the actual processing to a separate thread. This method should return as soon as processing is suitably initiated and should not wait until processing completes.

Specified by:
process in interface Request
Throws:
java.lang.IllegalStateException - if invoked before the request has been initialised, or after processing has commenced, completed or terminated.

terminate

public void terminate()
Description copied from interface: Request
Terminates the request. When this method returns, any threads and other resources associated with the request must be finished with.

Specified by:
terminate in interface Request

endProcessing

private void endProcessing()
Ends the processing of this request, leaving the status unaffected.


waitForResponse

public void waitForResponse()
Description copied from interface: Request
Waits for the response building to complete. After this method returns, the response product can be retrieved from the ResponseBuilder. This may or may not indicate that the request processing is complete, depending on the type of request. For example some requests produce no response data, so the response may be available before processing completes.

Specified by:
waitForResponse in interface Request

reportError

private final void reportError(java.lang.Exception cause)
This is invoked when an error occurs while processing the request.

Parameters:
cause - The cause of the error

processAsynchronously

private void processAsynchronously()
Spawn a processing thread and process the request asynchronously.


getSessionStrategy

public SessionStrategy getSessionStrategy()
Description copied from interface: SessionParticipant
Gets the SessionStrategy object for the session participant.

This object understands how to obtain the session from the SessionManager for this session participant.

Specified by:
getSessionStrategy in interface SessionParticipant
Returns:
SessionStrategy object.

setSession

public void setSession(Session session)
Description copied from interface: SessionParticipant
Provides the session participant with the session to which it is joined. After this method has been invoked, the session participant may access and interact with the session via the getSession() method.

Specified by:
setSession in interface SessionParticipant
Parameters:
session - The Session for the participant to join.

getSession

public Session getSession()
Description copied from interface: SessionParticipant
Gets the Session that the session participant is joined to.

This can only be invoked after the setSession() method has been invoked.

Specified by:
getSession in interface SessionParticipant
Returns:
session associated with this session participant

getRequestComposite

RequestComponent getRequestComposite()
Returns the composite RequestComponent for the request. This accessor method provided for testing purposes.

Returns:
ResourceComponent