HPSearch

cgl.hpsearch.engine
Class TaskSchedulerEngine

java.lang.Object
  extended bycgl.hpsearch.engine.TaskSchedulerEngine
All Implemented Interfaces:
SystemConstants, TimerExpiryListener

public class TaskSchedulerEngine
extends Object
implements SystemConstants, TimerExpiryListener

The task scheduler engine helps to distribute activities to disparate nodes. As each request comes in, it spawns off a new RequestHandler.
The RequestHandler then reads the request and starts the appropriate Handler.

Author:
Harshawardhan Gadgil
See Also:
RequestHandler, Handler

Field Summary
 
Fields inherited from interface cgl.hpsearch.common.SystemConstants
ABANDON_HANDLER, ABANDONED, BROKER_HOST, BROKER_PORT, BUF_SIZE, EOT, EXCEPTION, FAILURE, FILESEPARTOR, FLOW_LOGGING_MANAGER, FLOW_MANAGER, HPSEARCH_CONFIG, HPSEARCH_HOME, HPSEARCH_SHELL, HPSEARCH_WS, MARKER, NB_HOME, NB_PERFORMANCE_DATA_TOPIC, OS_TYPE, OS_UNIX, OS_WIN, PORT, PROTOCOL, READY, RESUME, RUNNING, SCRIPT_ARGS, SCRIPT_PATH, SHELLWS_PORT, START_HANDLER, STREAM_MARKER_DATA, STREAM_MARKER_EOF, STX, SUCCESS, SUSPEND, TASK_DEFINED, TASK_SCHEDULER_ENGINE, TASKSCHEDULER_AUTO_CONNECT_COMM_LINK, TASKSCHEDULER_ENGINE_COMM_LINK, THREAD_SLEEP_INTERVAL, UNKNOWN, WAITING, WSCONTEXT_RESULT_BIN, WSCONTEXT_SERVICE
 
Constructor Summary
TaskSchedulerEngine()
          Initializes a TaskSchedulerEngine.
 
Method Summary
 String getEngine(int engine)
          Returns the id of the best possible engine to run this particular task
 int getFlowStatus(String flowID)
          Returns the status of the specified flow
 void handlerFinished(RequestHandler rh)
          Called by the RequestHandlers to tell the TaskSchedulerEngine that it is done with the task assigned to it.
 void onTimerExpiry(Object o)
          If a timer expires for a particular engine we just assume the engine to be dead.
 void processEvent(Object o)
          Processes an event sent from another engine to this engine...
 TaskHandler processFlowRequest(Vector flowComponents, String flowID)
          Creates a new TaskHandler that handles the flow specified by the flowComponents
 void requestHandlerRegistered(RequestHandler rh)
          Requests the TaskSchedulerengine to register the init stage of te RequestHandler.
 void sendEventMessage(HandlerEvent msg, RequestHandler _rh)
          Sends the Event message to the specified Engine
 void sendTaskSchedulerEvent(String event)
          Sends the command to the Engine running on another node.
 void startEngine()
          Initializes the TaskScheduler engine instance.
 void stopEngine()
          Stops the TaskScheduler engine. sends the "GOODBYE" event to all engines to signify graceful shutdown
 boolean tryInitCOMMLink(String h, int p, String prot)
          Tries to initialize the communication link to a broker using the protocol specified as defined by the following parameters
 void waitForFlowToStart(String flowID)
          Waits for the specified flow to start
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TaskSchedulerEngine

public TaskSchedulerEngine()
Initializes a TaskSchedulerEngine. Must explicitly call the ServerStart to connect the Engine to a broker and start listening on a particular stream.

Method Detail

startEngine

public void startEngine()
Initializes the TaskScheduler engine instance.


tryInitCOMMLink

public boolean tryInitCOMMLink(String h,
                               int p,
                               String prot)
Tries to initialize the communication link to a broker using the protocol specified as defined by the following parameters

Parameters:
h - - Host of the broker
p - - Port to which connection must be tried
prot - - Protocol to use
Returns:
TRUE if connection was successful, FALSE otherwise

stopEngine

public void stopEngine()
Stops the TaskScheduler engine. sends the "GOODBYE" event to all engines to signify graceful shutdown


processEvent

public void processEvent(Object o)
Processes an event sent from another engine to this engine...

Parameters:
o - Object representing the event
Returns:
Nothing.

requestHandlerRegistered

public void requestHandlerRegistered(RequestHandler rh)
Requests the TaskSchedulerengine to register the init stage of te RequestHandler. The TaskSchedulerEngine then creates a TSE event to notify the init to the requesting engine

Parameters:
rh - - The RequestHandler

onTimerExpiry

public void onTimerExpiry(Object o)
If a timer expires for a particular engine we just assume the engine to be dead.
Protocol to be followed:
The heartbeat is sent every 30 seconds while the timer is set to expire evry minute. We allow for extra 30 seconds for the heartbeat to reach the engine. If a heartbeat does not reach withing 1 minute, we assume the engine dead

Specified by:
onTimerExpiry in interface TimerExpiryListener

processFlowRequest

public TaskHandler processFlowRequest(Vector flowComponents,
                                      String flowID)
Creates a new TaskHandler that handles the flow specified by the flowComponents

Parameters:
flowComponents - The components of the flow
flowID - The unique flow ID
Returns:
TaskHandler

waitForFlowToStart

public void waitForFlowToStart(String flowID)
Waits for the specified flow to start

Parameters:
flowID - - The ID representing the flowHandler in question

getFlowStatus

public int getFlowStatus(String flowID)
Returns the status of the specified flow

Parameters:
flowID - - the UUID of the flow
Returns:
The flow status

handlerFinished

public void handlerFinished(RequestHandler rh)
Called by the RequestHandlers to tell the TaskSchedulerEngine that it is done with the task assigned to it. The TaskSchedulerEngine then sends out a EngineEvent notifying the others.


sendEventMessage

public void sendEventMessage(HandlerEvent msg,
                             RequestHandler _rh)
Sends the Event message to the specified Engine

Parameters:
msg - - The message to be sent

sendTaskSchedulerEvent

public void sendTaskSchedulerEvent(String event)
Sends the command to the Engine running on another node.

Parameters:
event - event as an XML string

getEngine

public String getEngine(int engine)
Returns the id of the best possible engine to run this particular task

Returns:
String representing the id of the engine

HPSearch

For comments and suggestions please send e-mail to Harshawardhan Gadgil
Last updated: June 9 2006