jpl.mipl.mdms.FileService.komodo.api
Class RequestTerminationHandler

java.lang.Object
  extended by jpl.mipl.mdms.FileService.komodo.api.RequestTerminationHandler
All Implemented Interfaces:
Runnable

public abstract class RequestTerminationHandler
extends Object
implements Runnable

Purpose: Handler that waits for invocation to begin a shutdown procedure. Implementors must overwrite the shutdown() method with operation shutdown logic. If the method expectsConfirmation() returns true, then this handler will wait until it receives a confirmation or is stopped. Otherwise, handler will stop once shutdown procedure completes.

   Copyright 2005, California Institute of Technology.
   ALL RIGHTS RESERVED.
   U.S. Government Sponsorship acknowledge. 2005.
   
 ============================================================================
 Modification History :
 ----------------------

 Date              Who              What
 ----------------------------------------------------------------------------
 08/30/2005        Nick             Initial Release
 ============================================================================
 

Version:
$Id: RequestTerminationHandler.java,v 1.1 2005/08/31 23:59:56 ntt Exp $
Author:
Nicholas Toole (Nicholas.T.Toole@jpl.nasa.gov)

Field Summary
protected  boolean[] _done
           
protected  boolean[] _expectsConfirmation
           
protected  int[] _state
           
static int STATE_ABORTED
           
static int STATE_INITIALIZED
           
static int STATE_RUNNING
           
static int STATE_SUCCESS
           
static int STATE_WAITING
           
 
Constructor Summary
RequestTerminationHandler()
          Constructor.
RequestTerminationHandler(boolean expectsConfirmation)
          Constructor.
 
Method Summary
protected  void abort()
          Notifies that shutdown procedure should be aborted.
protected  void cleanup()
          Performs any initialization that might be required for handler.
 void confirm()
          Called to signify that shutdown is complete and successful, so that the request can return.
 boolean expectsConfirm()
          Returns true if this handler waits for external confirmation after its been invoked, but before it completes successfully.
 int getState()
          Returns state of this handler.
protected  void initialize()
          Performs any initialization that might be required for handler.
 boolean isRunning()
          Convenience method that returns true if state of handler is either running or waiting.
 boolean isSuccessful()
          Convenience method that returns true if state of handler is complete and successful.
protected  void postShutdown()
          Performs any post shutdown logic like cleanup or status reporting.
 void run()
          Implementation of the Runnable interface.
protected abstract  void shutdown()
          Contains all shutdown logic for this handler.
 void start()
          Instructs implementation to perform the necessary shutdown request to the server.
 void stop()
          Stops the handler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATE_INITIALIZED

public static final int STATE_INITIALIZED
See Also:
Constant Field Values

STATE_RUNNING

public static final int STATE_RUNNING
See Also:
Constant Field Values

STATE_WAITING

public static final int STATE_WAITING
See Also:
Constant Field Values

STATE_SUCCESS

public static final int STATE_SUCCESS
See Also:
Constant Field Values

STATE_ABORTED

public static final int STATE_ABORTED
See Also:
Constant Field Values

_done

protected boolean[] _done

_state

protected final int[] _state

_expectsConfirmation

protected final boolean[] _expectsConfirmation
Constructor Detail

RequestTerminationHandler

public RequestTerminationHandler()
Constructor. Defaults expectsConfirmation to false.


RequestTerminationHandler

public RequestTerminationHandler(boolean expectsConfirmation)
Constructor.

Parameters:
expectsConfirmation - Flag indicating whether handler expects to receive confirmation from external caller before exiting.
Method Detail

run

public final void run()
Implementation of the Runnable interface. Initializes handler, waits for call to invoke before performing shutdown. May wait for call to done for notification that shutdown is fully complete. A call to abort() can dismiss waiting for these events, to exit this method quickly.

Specified by:
run in interface Runnable

start

public final void start()
Instructs implementation to perform the necessary shutdown request to the server. The request is synchronous, so that once complete, it waits until shuwdownComplete() is called before returning.


confirm

public final void confirm()
Called to signify that shutdown is complete and successful, so that the request can return.


abort

protected final void abort()
Notifies that shutdown procedure should be aborted. If invocation has not yet occurred, then it is skipped. If confirmation has not yet occurred, that too is skipped.


stop

public final void stop()
Stops the handler. If start was never called, then stopping handler puts it in a non-startable state. If start() was already invoked but not complete, then state is set to ABORT. If handler has already completed, then state is unaffected.


getState

public final int getState()
Returns state of this handler. One of STATE_{INITIATED,RUNNING, WAITING,ABORTED,SUCCESS} as defined by this class.

Returns:
Handler state.

isRunning

public final boolean isRunning()
Convenience method that returns true if state of handler is either running or waiting.

Returns:
running state

isSuccessful

public final boolean isSuccessful()
Convenience method that returns true if state of handler is complete and successful.

Returns:
Success state

expectsConfirm

public final boolean expectsConfirm()
Returns true if this handler waits for external confirmation after its been invoked, but before it completes successfully. If true, then shutdown logic will perform a wait until one of confirm(), abort(), stop() is called.

Returns:
True if handler expects external confirmation.

shutdown

protected abstract void shutdown()
Contains all shutdown logic for this handler. If the handler expects external notification of success, it will wait until a call is made. If no such notification is required, then simply add a call to done() at the end of this method.


initialize

protected void initialize()
Performs any initialization that might be required for handler.


cleanup

protected void cleanup()
Performs any initialization that might be required for handler.


postShutdown

protected void postShutdown()
Performs any post shutdown logic like cleanup or status reporting.