|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectome.util.tasks.Task
public abstract class Task
Base task class which defines the template methods for running a task. The
base class ensures that a ServiceFactory
and a Properties
instance will be available in the task runtime.
Task
implements Runnable
and therefore can be placed directly
in a Thread
for execution. The Runnable.run()
method,
however, has been marked final and instead other Task
methods must be
overwritten.
Execution begins with a call to init()
, then doTask()
is
called in a try/catch/finally block. If doTask()
returns normally,
the value of completedSuccessfully()
will be true, otherwise it will
remain false and execution will be passed to
handleException(RuntimeException)
. Finally, close()
is
called. Subclasses should most likely check the value of
completedSuccessfully()
before attempting close()
;
Runnable
Constructor Summary | |
---|---|
protected |
Task(Properties properties)
Protected constructor for subclasses who may not wish to use sf . |
|
Task(ServiceFactory serviceFactory,
Properties properties)
Sole constructor. |
Method Summary | |
---|---|
abstract void |
close()
Performs cleanup of the Task . |
boolean |
completedSuccessfully()
returns true if doTask() returned normally or false if an
exception was thrown. |
abstract void |
doTask()
Performs the actual work of the Task . |
protected String |
enumValue(Enum e)
returns the value of the string representation of the enum argument from the Properties instance for this task. |
org.apache.commons.logging.Log |
getLogger()
returns the logger instance active for this class. |
Properties |
getProperties()
returns the Properties instance defined during construction. |
ServiceFactory |
getServiceFactory()
returns the ServiceFactory instance provided during construction. |
abstract void |
handleException(RuntimeException re)
If an exception is thrown during doTask() , then it will be
passed to the handleException(RuntimeException) method during
the catch-block of run() . |
abstract void |
init()
Performs initialization of the Task . |
void |
run()
Marked final so that the Task lifecycle will never vary. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected Task(Properties properties)
sf
.
public Task(ServiceFactory serviceFactory, Properties properties)
ServiceFactory
. If a null
Properties
instance is provided, the
System properties
will be used.
serviceFactory
- Cannot be null.properties
- Context variables for the task. Optional (can be null).Method Detail |
---|
public final ServiceFactory getServiceFactory()
ServiceFactory
instance provided during construction.
ServiceFactory
. Never null.public final Properties getProperties()
Properties
instance defined during construction. If
none was provided at construction, the System properties will be used.
Properties
. Never null.public final org.apache.commons.logging.Log getLogger()
public final boolean completedSuccessfully()
doTask()
returned normally or false if an
exception was thrown.
public final void run()
Task
lifecycle will never vary.
run
in interface Runnable
public abstract void init()
Task
.
Subclasses should make a best effort attempt to not throw any exceptions.
public abstract void doTask() throws RuntimeException
Task
. Execution takes place in a
try/catch/finally-block, and subclasses can throw any
RuntimeException
.
RuntimeException
public abstract void handleException(RuntimeException re)
doTask()
, then it will be
passed to the handleException(RuntimeException)
method during
the catch-block of run()
.
Subclasses can handle the exception or rethrow.
re
- Non-null.public abstract void close()
Task
.
Subclasses should make a best effort attempt to not throw any exceptions.
protected String enumValue(Enum e)
Properties
instance for this task.
e
- Any enumeration. May not be null.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Version: Beta-4.1.1-r5927-b91
Copyright © 2009 The University of Dundee. All Rights Reserved.