nl.astron.lofar.odtb.mom2otdbadapter.otdblistener
Class TaskExecutor

java.lang.Object
  extended by java.lang.Thread
      extended by nl.astron.lofar.odtb.mom2otdbadapter.otdblistener.TaskExecutor
All Implemented Interfaces:
java.lang.Runnable

public class TaskExecutor
extends java.lang.Thread

Execute the tasks that are in the queue

Author:
Bastiaan Verhoef

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
private  nl.astron.util.http.AstronHttpClient httpClient
           
private  org.apache.commons.logging.Log log
           
private  java.lang.String momUrl
           
private  java.lang.String password
           
private  Queue queue
           
private static int SLEEP_MILLISECONDS
           
private  java.lang.String username
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
TaskExecutor(Queue queue, java.lang.String username, java.lang.String password, java.lang.String authUrl, java.lang.String momUrl)
          Constructor
 
Method Summary
protected  org.w3c.dom.Document convertStringToDocument(java.lang.String myXML)
          Converts a xml to a document
protected  boolean equal(org.w3c.dom.Node node, java.lang.String nodeName)
          The equal method compares if an node has the given name
protected  java.lang.String getValue(org.w3c.dom.Node node)
          The getValue method returns the value of an node
protected  boolean isSucceed(java.lang.String string)
          Analyzed the mom2 output and return if the task is done
protected  boolean processTask(Task task)
          Process task.
 void run()
          start the taskExecutor thread
protected  void sleep()
          If some error occured, the task executor going to sleep for a while
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SLEEP_MILLISECONDS

private static final int SLEEP_MILLISECONDS
See Also:
Constant Field Values

log

private org.apache.commons.logging.Log log

httpClient

private nl.astron.util.http.AstronHttpClient httpClient

queue

private Queue queue

username

private java.lang.String username

password

private java.lang.String password

momUrl

private java.lang.String momUrl
Constructor Detail

TaskExecutor

public TaskExecutor(Queue queue,
                    java.lang.String username,
                    java.lang.String password,
                    java.lang.String authUrl,
                    java.lang.String momUrl)
Constructor

Parameters:
queue - Queue to retrieve tasks
username - username of mom2
password - password of mom2
authUrl - authorization module url
momUrl - mom2 module url
Method Detail

run

public void run()
start the taskExecutor thread

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

processTask

protected boolean processTask(Task task)
Process task. It logs in to MoM2, it post the task xml to MoM2 and logouts.

Parameters:
task - tass to process
Returns:
If MoM2 result is ok, it returns true

sleep

protected void sleep()
If some error occured, the task executor going to sleep for a while


isSucceed

protected boolean isSucceed(java.lang.String string)
Analyzed the mom2 output and return if the task is done

Parameters:
string -
Returns:
true, if task is successfull executed

convertStringToDocument

protected org.w3c.dom.Document convertStringToDocument(java.lang.String myXML)
                                                throws java.lang.Exception
Converts a xml to a document

Parameters:
myXML -
Returns:
Document
Throws:
java.lang.Exception

equal

protected boolean equal(org.w3c.dom.Node node,
                        java.lang.String nodeName)
The equal method compares if an node has the given name

Parameters:
node -
nodeName -
Returns:
true, if equal

getValue

protected java.lang.String getValue(org.w3c.dom.Node node)
The getValue method returns the value of an node

Parameters:
node -
Returns:
value of the node