public class Oddjob extends StructuralJob<java.lang.Object> implements Loadable, ConfigurationOwner, BeanDirectoryOwner, Describer
Oddjob creates a 'root' job on which to create the hierarchy. Through this root Oddjob aquires the first job to run and also exposes some of it's own properties for the jobs in the configuration to use. The root job's properties are:
For these properties to be accessible the root oddjob must be given an id.
As can be seen from the examples, the author uses the id 'this'
but the choice is arbitrary.
An Oddjob job allows an Oddjob instance to be created within an existing Oddjob configuration. This way complicated processes can be created in manageable and separately testable units.
Properties of jobs in a nested Oddjob can be accessed using the notation ${nested-oddjob-id/job-id.property} where nested-oddjob-id is the id in the outer configuration, not the inner one.
The persister property on a nested Oddjob will allow it's state to
be saved. See the
User Guide
for more information on how to set a persister.
Oddjob's descriptorFactory and classLoader properties
allow bespoke components and
types to be used. The
developer guide
is all about writing custom job's for Oddjob.
EchoJob job.
<oddjob>
<job>
<echo id="echo">Hello World</echo>
</job>
</oddjob>
<oddjob id="this">
<job>
<sequential>
<jobs>
<state:if xmlns:state="http://rgordon.co.uk/oddjob/state">
<jobs>
<check value="${this.args[0]}"/>
<properties>
<values>
<value key="our.file.name" value="${this.args[0]}"/>
</values>
</properties>
<input>
<requests>
<input-text prompt="File Name?" property="our.file.name"/>
</requests>
</input>
</jobs>
</state:if>
<echo>File Name is ${our.file.name}</echo>
</jobs>
</sequential>
</job>
</oddjob>
dir property of the
Oddjob root is used as the path of the nested configuration file.
<oddjob id="this">
<job>
<sequential>
<jobs>
<oddjob id="nested" file="${this.dir}/HelloWorld.xml"/>
<echo>Nested job said: ${nested/echo.text}</echo>
</jobs>
</sequential>
</job>
</oddjob>
The nested job is the first example:
<oddjob>
<job>
<echo id="echo">Hello World</echo>
</job>
</oddjob>
This example also shows how a property within the nested file can be
accessed within the parent configuration.
<oddjob id="this">
<job>
<oddjob id="nested" file="${this.dir}/EchoArg.xml">
<args>
<list>
<values>
<value value="Hello World"/>
</values>
</list>
</args>
</oddjob>
</job>
</oddjob>
And EchoArg.xml:
<oddjob id="this">
<job>
<echo id="echo">${this.args[0]}</echo>
</job>
</oddjob>
<oddjob id="this">
<job>
<oddjob id="nested" file="${this.dir}/EchoProperty.xml">
<properties>
<properties>
<values>
<value key="our.greeting" value="Hello World"/>
</values>
</properties>
</properties>
</oddjob>
</job>
</oddjob>
And EchoProperty.xml:
<oddjob id="this">
<job>
<echo id="echo">${our.greeting}</echo>
</job>
</oddjob>
Unlike the properties of jobs, free format properties like this can't be
accessed using the nested convention.
${nested/our.greeting} DOES NOT WORK!
This may be fixed in future versions.
<oddjob>
<job>
<sequential>
<jobs>
<folder>
<jobs>
<echo id="secret">I'm a secret job</echo>
</jobs>
</folder>
<oddjob id="inner">
<export>
<value key="secret" value="${secret}"/>
</export>
<configuration>
<arooa:configuration xmlns:arooa="http://rgordon.co.uk/oddjob/arooa">
<xml>
<xml>
<oddjob>
<job>
<run job="${secret}"/>
</job>
</oddjob>
</xml>
</xml>
</arooa:configuration>
</configuration>
</oddjob>
</jobs>
</sequential>
</job>
</oddjob>
Here a job is exported into a nested Oddjob. The
exported object is actually a ValueType. The value is converted back
to the job when the job property of the run job is set. Expressions such
as ${secret.text} are not valid (because value does not have a
text property!). Even ${secret.value.text} will not work because
of value wraps the job in yet another layer of complexity.
| Modifier and Type | Class and Description |
|---|---|
class |
Oddjob.OddjobRoot
The object which is the Oddjob root.
|
static class |
Oddjob.OddjobRootArooa
Provide an
ArooaBeanDescriptor for the root Oddjob bean. |
| Modifier and Type | Field and Description |
|---|---|
static ArooaElement |
ODDJOB_ELEMENT
The document root for an Oddjob configuration file.
|
childHelper, destroy, stop, structuralState| Constructor and Description |
|---|
Oddjob()
Only constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addOwnerStateListener(OwnerStateListener listener)
Add a listener.
|
java.util.Map<java.lang.String,java.lang.String> |
describe(java.lang.Object bean)
Describe a bean.
|
protected void |
execute()
Execute this job.
|
java.lang.String[] |
getArgs() |
java.lang.ClassLoader |
getClassLoader()
Return a class loader.
|
ArooaDescriptorFactory |
getDescriptorFactory()
Getter.
|
java.io.File |
getDir() |
ArooaValue |
getExport(java.lang.String key)
Getter
|
java.io.File |
getFile() |
OddjobInheritance |
getInheritance()
Getter.
|
protected StateOperator |
getInitialStateOp()
Subclasses must provide the
StateOperator that will decide
how to evaluate the children's state. |
InputHandler |
getInputHandler()
Getter.
|
org.oddjob.Oddjob.Reset |
getLastReset()
Getter for last reset.
|
OddjobExecutors |
getOddjobExecutors()
Getter for
OddjobExecutors that have been given to this
instance of Oddjob. |
OddjobServices |
getOddjobServices()
Getter for
OddjobServices. |
OddjobPersister |
getPersister() |
java.util.Properties |
getProperties()
Getter.
|
java.lang.String |
getVersion() |
boolean |
hardReset()
Perform a hard reset.
|
boolean |
isLoadable()
Is the component currently loadable.
|
void |
load()
Load the component.
|
protected void |
onDestroy()
Subclasses override this method to clear up resources.
|
BeanDirectory |
provideBeanDirectory()
Get the
BeanDirectory. |
ConfigurationSession |
provideConfigurationSession()
Provide a
ConfigurationSession. |
void |
removeOwnerStateListener(OwnerStateListener listener)
Remove a listener.
|
SerializableDesignFactory |
rootDesignFactory()
Get the design factory for the configuration.
|
ArooaElement |
rootElement()
Get the root element.
|
void |
setArgs(java.lang.String[] args) |
void |
setClassLoader(java.lang.ClassLoader classLoader) |
void |
setConfiguration(ArooaConfiguration config)
Setter for configuration.
|
void |
setDescriptorFactory(ArooaDescriptorFactory descriptorFactory)
Setter.
|
void |
setExport(java.lang.String key,
ArooaValue value)
Setter.
|
void |
setFile(java.io.File file) |
void |
setInheritance(OddjobInheritance inheritance)
Setter.
|
void |
setInputHandler(InputHandler inputHandler)
Setter.
|
void |
setOddjobExecutors(OddjobExecutors executors)
Setter.
|
void |
setOddjobServices(OddjobServices oddjobServices)
Allow for injection of
OddjobServices |
void |
setPersister(OddjobPersister persister) |
void |
setProperties(java.util.Properties properties)
Setter.
|
boolean |
softReset()
Perform a soft reset on the job.
|
java.lang.String |
toString()
Override toString.
|
void |
unload()
Unload the component.
|
addStructuralListener, fireDestroyedState, force, getStateChanger, iconHelper, isStop, onHardReset, onReset, onSoftReset, onStop, postStop, removeStructuralListener, run, startChildStateReflector, stateHandler, stop, stopChildStateReflector, waitForChildrenOnStopconfigure, getName, logger, logger, loggerName, save, setNameaddIconListener, addPropertyChangeListener, addStateListener, configure, destroy, firePropertyChange, getArooaSession, iconForId, initialise, lastStateEvent, onConfigured, onInitialised, removeIconListener, removePropertyChangeListener, removeStateListener, save, setArooaContext, setArooaSessionclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddStateListener, lastStateEvent, removeStateListenerpublic static final ArooaElement ODDJOB_ELEMENT
public void setFile(java.io.File file)
Property: file
Description: The name of the configuration file. to configure this oddjob.
Required: No.
public java.io.File getFile()
public void setConfiguration(ArooaConfiguration config)
config - public void setClassLoader(java.lang.ClassLoader classLoader)
Property: classLoader
Description: The classLoader to use when loading the configuration. This classloader will also be made available to child components that inject a classloader. This might not always be what is required as this classloader defaults to the application classloader not the Oddball classloader that will have loaded an Oddball component. This might be changed in future versions of Oddjob.
See also URLClassLoaderType
Required: No.
public java.lang.ClassLoader getClassLoader()
public ConfigurationSession provideConfigurationSession()
ConfigurationOwnerConfigurationSession.provideConfigurationSession in interface ConfigurationOwnerConfigurationSession. May be null if no session is available.public void addOwnerStateListener(OwnerStateListener listener)
ConfigurationOwneraddOwnerStateListener in interface ConfigurationOwnerpublic void removeOwnerStateListener(OwnerStateListener listener)
ConfigurationOwnerremoveOwnerStateListener in interface ConfigurationOwnerpublic SerializableDesignFactory rootDesignFactory()
ConfigurationOwner
Note that this is a SerializableDesignFactory so that
this interface can be represented remotely.
rootDesignFactory in interface ConfigurationOwnerConfigurationSession
is available.public ArooaElement rootElement()
ConfigurationOwnerrootElement in interface ConfigurationOwnerConfigurationSession is available.protected StateOperator getInitialStateOp()
StructuralJobStateOperator that will decide
how to evaluate the children's state.getInitialStateOp in class StructuralJob<java.lang.Object>public boolean isLoadable()
LoadableisLoadable in interface LoadableProperty: loadable
Description: Can Oddjob be loaded. Used by the Load/Unload actions.
Required: Read only.
public void load()
Loadableprotected void execute()
throws java.lang.Exception
StructuralJobexecute in class StructuralJob<java.lang.Object>java.lang.Exception - If the unexpected occurs.public void unload()
Loadableprotected void onDestroy()
BaseComponentonDestroy in class StructuralJob<java.lang.Object>public boolean softReset()
StructuralJobsoftReset in interface ResettablesoftReset in class StructuralJob<java.lang.Object>public boolean hardReset()
hardReset in interface ResettablehardReset in class StructuralJob<java.lang.Object>public OddjobPersister getPersister()
public void setPersister(OddjobPersister persister)
persister - The persister to set.public BeanDirectory provideBeanDirectory()
BeanDirectoryOwnerBeanDirectory. This method may return null if
the BeanDirectory isn't available.provideBeanDirectory in interface BeanDirectoryOwnerBeanDirectory or null.public java.util.Map<java.lang.String,java.lang.String> describe(java.lang.Object bean)
Describerpublic org.oddjob.Oddjob.Reset getLastReset()
public java.lang.String[] getArgs()
public void setArgs(java.lang.String[] args)
args - The args to set.public ArooaValue getExport(java.lang.String key)
key - The key.public void setExport(java.lang.String key,
ArooaValue value)
key - value - public java.util.Properties getProperties()
public void setProperties(java.util.Properties properties)
properties - Optional properties.public OddjobInheritance getInheritance()
public void setInheritance(OddjobInheritance inheritance)
inheritance - Inheritance property.public java.io.File getDir()
Property: dir
Description: The name of the directory the configuration file is in.
Required: R/O
public java.lang.String getVersion()
Property: version
Description: This Oddjob's version.
public ArooaDescriptorFactory getDescriptorFactory()
public void setDescriptorFactory(ArooaDescriptorFactory descriptorFactory)
descriptorFactory - And ArooaDescriptorFactory.public OddjobExecutors getOddjobExecutors()
OddjobExecutors that have been given to this
instance of Oddjob. This getter does not expose the internal executors.public void setOddjobExecutors(OddjobExecutors executors)
executors - OddjobExecutorspublic OddjobServices getOddjobServices()
OddjobServices.@Inject public void setOddjobServices(OddjobServices oddjobServices)
OddjobServicesoddjobServices - public java.lang.String toString()
BasePrimarytoString in class BasePrimarypublic InputHandler getInputHandler()
public void setInputHandler(InputHandler inputHandler)
inputHandler - An InputHandler.