uk.org.ogsadai.engine
Class RequestEngine

java.lang.Object
  |
  +--java.util.Observable
        |
        +--uk.org.ogsadai.engine.RequestEngine
All Implemented Interfaces:
Engine

public class RequestEngine
extends java.util.Observable
implements Engine

This implementation of the Engine interface is designed to process perform documents containing sequences of activity elements that correspond to Activity implementations. The RequestEngine can not process mutliple request simultaneously and a ActivityUserException will be thrown by the invoke method is an attempt is made to do so. The ObservableStatus contained in the EngineConfiguration can be monitored to determine the status of the current request.

Author:
The OGSA-DAI Project Team

Field Summary
private static java.lang.String COPYRIGHT_NOTICE
          Copyright statement.
private static DAILogger LOG
          Logger object for logging in this class.
private  EngineConfiguration mConfiguration
          Engine configuration information.
private  boolean mHasQueue
          Flags whether this instance has been configured with a queue or not.
private  java.util.HashSet mProcessingPool
          Processing pool of active requests
private  java.util.Observer mProgressMonitor
          Observer that monitors the processing status of active requests and removes them from the processing pool once they have stopped.
private  boolean mProgressMonitorEnabled
          Flag for enabling/disabling the progress monitor (see below)
private  Queue mQueue
          Queue of requests in waiting
 
Fields inherited from class java.util.Observable
 
Constructor Summary
RequestEngine(EngineConfiguration config)
          Constructs an engine with the specified configuration.
 
Method Summary
 int activeLoad()
          Return the active load of the request queue.
private  void fillUpPool()
          Manages the flow of requests from the queue to the processing pool.
 boolean isProcessing(Request request)
          Is the given request processing?
 boolean isQueueing(Request request)
          Is the given request queueing?
private  void joinSession(Request request)
          Joins the request to a session.
 int latentLoad()
          Return the latent load of the request queue.
private  void logStartOfRequest(org.w3c.dom.Document request)
          Logs the start of a request.
 void perform(Request request, RequestContext context, ResponseBuilder builder)
          Submits a request, in the form of a request object, and initiates its processing by the engine.
private  boolean process(Request request)
          Attempts to admit a request for active processing in the processing pool.
private  boolean processingPoolFull()
          Tests whether the processing pool can admit any further requests.
private  void releaseSession(Request request)
          Releases the request from its session.
 void terminate()
          Terminates the requests that are currently processing.
 void terminate(SessionID sessionID)
          Terminates any requests that are joined to the specified session.
private  void terminateActiveRequests(SessionID sessionID)
          Terminates any requests contained in the specified iterator that are joined to the specified session.
private  void terminateQueuedRequests(SessionID sessionID)
          Terminates any requests contained in the specified iterator that are joined to the specified session.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
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.


mConfiguration

private final EngineConfiguration mConfiguration
Engine configuration information.


mProcessingPool

private final java.util.HashSet mProcessingPool
Processing pool of active requests


mQueue

private final Queue mQueue
Queue of requests in waiting


mHasQueue

private final boolean mHasQueue
Flags whether this instance has been configured with a queue or not.


mProgressMonitorEnabled

private boolean mProgressMonitorEnabled
Flag for enabling/disabling the progress monitor (see below)


mProgressMonitor

private final java.util.Observer mProgressMonitor
Observer that monitors the processing status of active requests and removes them from the processing pool once they have stopped.

Constructor Detail

RequestEngine

public RequestEngine(EngineConfiguration config)
Constructs an engine with the specified configuration.

Parameters:
config - An EngineConfiguration object holding the configuration information requeired by the engine.
Method Detail

perform

public void perform(Request request,
                    RequestContext context,
                    ResponseBuilder builder)
             throws RequestAuthorizationException,
                    RequestSpecificationException,
                    RequestExecutionException
Description copied from interface: Engine
Submits a request, in the form of a request object, and initiates its processing by the engine.

Specified by:
perform in interface Engine
Parameters:
request - The request to be processed.
context - The context within which the request is to be processed.
builder - ResponseBuilder to use for assembling the response to the request.
Throws:
RequestAuthorizationException - if the request fails because of an authorization problem.
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.

terminate

public void terminate()
Description copied from interface: Engine
Terminates the requests that are currently processing. If no request is processing, no action is taken.

Specified by:
terminate in interface Engine

terminate

public void terminate(SessionID sessionID)
Description copied from interface: Engine
Terminates any requests that are joined to the specified session. If there are no requests joined to this session, then no action is taken.

Specified by:
terminate in interface Engine
Parameters:
sessionID - The identity of the session

terminateActiveRequests

private void terminateActiveRequests(SessionID sessionID)
Terminates any requests contained in the specified iterator that are joined to the specified session.

Parameters:
sessionID - Session whose requests are to be terminated.

terminateQueuedRequests

private void terminateQueuedRequests(SessionID sessionID)
Terminates any requests contained in the specified iterator that are joined to the specified session.

Parameters:
sessionID - Session whose requests are to be terminated.

logStartOfRequest

private final void logStartOfRequest(org.w3c.dom.Document request)
Logs the start of a request.

Parameters:
request - The request.

latentLoad

public int latentLoad()
Return the latent load of the request queue.

Specified by:
latentLoad in interface Engine
Returns:
latent load.

activeLoad

public int activeLoad()
Return the active load of the request queue.

Specified by:
activeLoad in interface Engine
Returns:
active load.

isProcessing

public boolean isProcessing(Request request)
Is the given request processing?

Parameters:
request - A request.
Returns:
true if request is processing, false otherwise.

isQueueing

public boolean isQueueing(Request request)
Is the given request queueing?

Parameters:
request - A request.
Returns:
true if request is queueing, false otherwise.

joinSession

private void joinSession(Request request)
                  throws RequestSpecificationException,
                         RequestExecutionException
Joins the request to a session.

Parameters:
request - The request to join to a session
Throws:
RequestSpecificationException - If the request is not allowed to join the session or the session is not known.
RequestExecutionException - If some internal problem prevents the request from joining the session.

releaseSession

private void releaseSession(Request request)
Releases the request from its session. If a problem occurs at this stage it is logged rather than being returned to the user.

Parameters:
request - The request to release. EX-TODO - THROW THESE?
Throws:
RequestSpecificationException - If the session is not known.
RequestExecutionException - If some internal problem prevents the request from being released from the session.

processingPoolFull

private final boolean processingPoolFull()
Tests whether the processing pool can admit any further requests.

Returns:
true if the processing pool can admit further requests, false otherwise.

process

private final boolean process(Request request)
Attempts to admit a request for active processing in the processing pool.

If successful, it changes the status of the request to ProcessingStatus.PROCESSING by invoking the (non-blocking) process() method in Request.

Assumes that no changes are being made externally to the status of the request.

Parameters:
request - The request to be admitted, assumed non-null. Unless this has a current status of ProcessingStatus.INITIALISING the method will fail.
Returns:
true if the request was successfully admitted, false otherwise.

fillUpPool

private final void fillUpPool()
Manages the flow of requests from the queue to the processing pool. In order to maximise throughput, it attempts to move as many requests from the queue as possible. A call to processingPoolFull() should normally follow each invocation of this method to check whether the pool has become entirely full.