com.gridsystems.nextgrid.api.pom
Class ProcessImpl

java.lang.Object
  extended by com.gridsystems.nextgrid.api.pom.PemHelper
      extended by com.gridsystems.nextgrid.api.pom.ProcessImpl
All Implemented Interfaces:
Enactable, java.io.Serializable, java.lang.Cloneable, nextgrid.api.pom.Process
Direct Known Subclasses:
AbstractProcessImpl, ControlProcessImpl, ServiceImpl

public abstract class ProcessImpl
extends PemHelper
implements Enactable

Base implementation for Processes.

To enact a process, the programmer should invoke the following operation:

 EnactorContext context = ...;
 Process p = ...;
 try {
   p.enact(context);
 } catch (Exception e) {
   ...
 }
 

Author:
Rodrigo Ruiz
See Also:
Serialized Form

Nested Class Summary
protected static class ProcessImpl.ValidationType
          Validation types.
 
Field Summary
static int DFA_INITIAL_STATE
          Initial state of the internal DFA.
protected static org.apache.commons.logging.Log ENACTOR_LOG
          Enaction logger.
 
Constructor Summary
protected ProcessImpl()
          Creates a new instance with a default empty model.
 
Method Summary
protected  void attachListeners(nextgrid.api.env.ProcessEnvironment env)
          Attaches listeners configured in the environment to this process.
 nextgrid.api.pom.Process copy()
          
abstract  void doEvaluate(nextgrid.api.env.ProcessEnvironment env)
          Performs the actual actions needed for evaluating this process instance.
protected abstract  void doReset()
          Performs specific reset actions in each subclass.
protected abstract  void doValidate(ProcessImpl.ValidationType type)
          Performs any validation action needed for the process implementation.
 nextgrid.api.pom.ProcessController enact(nextgrid.api.env.ProcessEnvironment env)
          
 void evaluate(nextgrid.api.env.ProcessEnvironment env)
          
 void evaluate(nextgrid.api.env.ProcessEnvironment env, boolean force)
          Evaluates this process.
 nextgrid.api.pom.Process findRoot()
          Searches up through the process hierarchy to find the root process of the workflow this process is defined in.
 java.lang.String getAttribute(javax.xml.namespace.QName name)
          
 java.lang.String getAttribute(java.lang.String name)
          
 java.lang.String getAttribute(java.lang.String ns, java.lang.String local)
          
 java.util.Map<javax.xml.namespace.QName,java.lang.String> getAttributes()
          
 java.lang.String getDescription()
          Gets a human-readable description of this process.
 java.net.URI getId()
          Gets the id of this process instance.
 nextgrid.api.pom.Reference<?> getInput(java.lang.String key)
          Gets an input parameter by its name.
 java.util.Map<java.lang.String,nextgrid.api.pom.Reference<?>> getInputs()
          Gets the map of references to input parameters.
protected  void getInputs(java.util.Map<java.lang.String,nextgrid.api.pom.Reference<?>> map)
          Gets all inputs of this process, including inherited ones into the specified map.
 java.lang.Class<?> getInputType(java.lang.String name)
          
 java.lang.String getName()
          Gets the name of this process.
 nextgrid.api.pom.Reference<?> getOutput(java.lang.String key)
          Gets an output parameter by its name.
 java.util.Map<java.lang.String,nextgrid.api.pom.Reference<?>> getOutputs()
          Gets the map of references to output parameters.
protected  void getOutputs(java.util.Map<java.lang.String,nextgrid.api.pom.Reference<?>> map)
          Gets all outputs of this process, including inherited ones into the specified map.
 java.lang.Class<?> getOutputType(java.lang.String name)
          
 nextgrid.api.pom.Process getParent()
          Gets the parent process, or null if there is no parent.
 int getState()
          Gets the internal DFA state of this process.
 java.lang.String[] getUsedInputNames()
          
 java.lang.String[] getUsedOutputNames()
          
 void invalidate()
          
 boolean isEvaluated()
          
 boolean isLazy()
          
 boolean isValidated()
          
protected  java.util.PriorityQueue<nextgrid.api.pom.Process> prioritise(nextgrid.api.env.ProcessEnvironment env)
          Shortcut for the interface method prioritise.
 void putInput(java.lang.String key, nextgrid.api.pom.Reference<?> input)
          Puts a reference into the map of input parameters for this process.
 void putOutput(java.lang.String key, nextgrid.api.pom.Reference<?> output)
          Puts a reference into the map of output parameters for this process.
 void removeInput(java.lang.String key)
          Removes a reference from the input map.
 void removeOutput(java.lang.String key)
          Removes a reference from the output map.
 void reset()
          
protected abstract  void resetChildren()
          Resets any child process.
 void setAttribute(javax.xml.namespace.QName name, java.lang.String value)
          
 void setAttribute(java.lang.String name, java.lang.String value)
          
 void setDescription(java.lang.String description)
          Sets the description of this process.
protected  void setEvaluated(boolean evaluated)
          Sets the evaluation flag value.
 void setId(java.net.URI id)
          Sets the id of this process instance.
 void setLazy(boolean lazy)
          
 void setName(java.lang.String name)
          Sets this process name.
 void setParent(nextgrid.api.pom.Process parent)
          Sets the parent process instance.
protected  void setState(int state)
          Sets the internal DFA state of this process.
 void unuseInput(java.lang.String... names)
          
 void unuseOutput(java.lang.String... names)
          
 void useInput(java.lang.String name, java.lang.Class<?> type)
          
 void useOutput(java.lang.String name, java.lang.Class<?> type)
          
 void validate()
          
protected  void waitForInputs()
          Waits until all input parameters are available for reading.
 
Methods inherited from class com.gridsystems.nextgrid.api.pom.PemHelper
addListener, fireDiscovererSelected, fireDiscoveryFailed, fireDiscoveryFinished, fireDiscoveryStarting, fireEvent, fireProcessEvaluated, fireProcessFailed, fireProcessFailed, fireProcessFinished, fireProcessFinished, fireProcessSelected, fireProcessStarted, removeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.gridsystems.nextgrid.api.pom.Enactable
run
 
Methods inherited from interface nextgrid.api.pom.Process
discover, findProcessById, prioritise
 

Field Detail

ENACTOR_LOG

protected static final org.apache.commons.logging.Log ENACTOR_LOG
Enaction logger.


DFA_INITIAL_STATE

public static final int DFA_INITIAL_STATE
Initial state of the internal DFA.

See Also:
Constant Field Values
Constructor Detail

ProcessImpl

protected ProcessImpl()
Creates a new instance with a default empty model.

Method Detail

getAttributes

public final java.util.Map<javax.xml.namespace.QName,java.lang.String> getAttributes()

Specified by:
getAttributes in interface nextgrid.api.pom.Process

getAttribute

public final java.lang.String getAttribute(javax.xml.namespace.QName name)

Specified by:
getAttribute in interface nextgrid.api.pom.Process

getAttribute

public final java.lang.String getAttribute(java.lang.String name)

Specified by:
getAttribute in interface nextgrid.api.pom.Process

getAttribute

public final java.lang.String getAttribute(java.lang.String ns,
                                           java.lang.String local)

Specified by:
getAttribute in interface nextgrid.api.pom.Process

setAttribute

public final void setAttribute(javax.xml.namespace.QName name,
                               java.lang.String value)

Specified by:
setAttribute in interface nextgrid.api.pom.Process

setAttribute

public final void setAttribute(java.lang.String name,
                               java.lang.String value)

Specified by:
setAttribute in interface nextgrid.api.pom.Process

getId

public final java.net.URI getId()
Gets the id of this process instance. The id must be unique within the scope this instance is defined in.

Specified by:
getId in interface Enactable
Specified by:
getId in interface nextgrid.api.pom.Process
Returns:
The process id

getName

public final java.lang.String getName()
Gets the name of this process. This is just a human-readable label for presentation purposes.

Specified by:
getName in interface nextgrid.api.pom.Process
Returns:
The process name

getDescription

public final java.lang.String getDescription()
Gets a human-readable description of this process.

Specified by:
getDescription in interface nextgrid.api.pom.Process
Returns:
A human-readable description of this process

getParent

public final nextgrid.api.pom.Process getParent()
Gets the parent process, or null if there is no parent.

Specified by:
getParent in interface nextgrid.api.pom.Process
Returns:
The parent process

getState

public final int getState()
Gets the internal DFA state of this process.

Returns:
The internal DFA state

setState

protected final void setState(int state)
Sets the internal DFA state of this process.

Parameters:
state - The internal DFA state

findRoot

public final nextgrid.api.pom.Process findRoot()
Searches up through the process hierarchy to find the root process of the workflow this process is defined in.

Specified by:
findRoot in interface nextgrid.api.pom.Process
Returns:
The root process of the workflow

setId

public final void setId(java.net.URI id)
Sets the id of this process instance.

Specified by:
setId in interface nextgrid.api.pom.Process
Parameters:
id - A unique identifier
Throws:
java.lang.NullPointerException - If id is null

setName

public final void setName(java.lang.String name)
Sets this process name.

Specified by:
setName in interface nextgrid.api.pom.Process
Parameters:
name - The process name

setDescription

public final void setDescription(java.lang.String description)
Sets the description of this process.

Specified by:
setDescription in interface nextgrid.api.pom.Process
Parameters:
description - A textual description

setParent

public final void setParent(nextgrid.api.pom.Process parent)
Sets the parent process instance.

Specified by:
setParent in interface nextgrid.api.pom.Process
Parameters:
parent - The parent process

validate

public final void validate()
                    throws nextgrid.api.pom.ProcessException

Specified by:
validate in interface nextgrid.api.pom.Process
Throws:
nextgrid.api.pom.ProcessException

invalidate

public final void invalidate()

Specified by:
invalidate in interface nextgrid.api.pom.Process

isLazy

public final boolean isLazy()

Specified by:
isLazy in interface nextgrid.api.pom.Process

setLazy

public final void setLazy(boolean lazy)

Specified by:
setLazy in interface nextgrid.api.pom.Process

isValidated

public final boolean isValidated()

Specified by:
isValidated in interface nextgrid.api.pom.Process

isEvaluated

public final boolean isEvaluated()

Specified by:
isEvaluated in interface nextgrid.api.pom.Process

setEvaluated

protected final void setEvaluated(boolean evaluated)
Sets the evaluation flag value.

Parameters:
evaluated - The new value

prioritise

protected final java.util.PriorityQueue<nextgrid.api.pom.Process> prioritise(nextgrid.api.env.ProcessEnvironment env)
                                                                      throws nextgrid.api.pom.ProcessException
Shortcut for the interface method prioritise.

Parameters:
env - The process environment to use
Returns:
A set of abstract processes
Throws:
nextgrid.api.pom.ProcessException - If an error occurs

doValidate

protected abstract void doValidate(ProcessImpl.ValidationType type)
                            throws nextgrid.api.pom.ProcessException
Performs any validation action needed for the process implementation.

Parameters:
type - Specifies when this validation is being invoked
Throws:
nextgrid.api.pom.ProcessException - If the validation fails

evaluate

public final void evaluate(nextgrid.api.env.ProcessEnvironment env)
                    throws nextgrid.api.pom.ProcessException

Specified by:
evaluate in interface nextgrid.api.pom.Process
Throws:
nextgrid.api.pom.ProcessException

evaluate

public final void evaluate(nextgrid.api.env.ProcessEnvironment env,
                           boolean force)
                    throws nextgrid.api.pom.ProcessException
Evaluates this process. It uses the "force" parameter to override the value of the lazy attribute.

Parameters:
env - The environment to use
force - Whether to force the evaluation or not
Throws:
nextgrid.api.pom.ProcessException - If an error occurs

doEvaluate

public abstract void doEvaluate(nextgrid.api.env.ProcessEnvironment env)
                         throws nextgrid.api.pom.ProcessException
Performs the actual actions needed for evaluating this process instance.

Parameters:
env - The process environment
Throws:
nextgrid.api.pom.ProcessException - If an error occurs

enact

public final nextgrid.api.pom.ProcessController enact(nextgrid.api.env.ProcessEnvironment env)
                                               throws nextgrid.api.pom.ProcessException

Specified by:
enact in interface nextgrid.api.pom.Process
Throws:
nextgrid.api.pom.ProcessException

doReset

protected abstract void doReset()
Performs specific reset actions in each subclass.


resetChildren

protected abstract void resetChildren()
Resets any child process.


reset

public final void reset()

Specified by:
reset in interface nextgrid.api.pom.Process

attachListeners

protected final void attachListeners(nextgrid.api.env.ProcessEnvironment env)
Attaches listeners configured in the environment to this process.

Parameters:
env - The environment

getInputs

public final java.util.Map<java.lang.String,nextgrid.api.pom.Reference<?>> getInputs()
Gets the map of references to input parameters.

Specified by:
getInputs in interface nextgrid.api.pom.Process
Returns:
the input parameter reference map

getInputs

protected final void getInputs(java.util.Map<java.lang.String,nextgrid.api.pom.Reference<?>> map)
Gets all inputs of this process, including inherited ones into the specified map.

Parameters:
map - The map to fill

getOutputs

public final java.util.Map<java.lang.String,nextgrid.api.pom.Reference<?>> getOutputs()
Gets the map of references to output parameters.

Specified by:
getOutputs in interface nextgrid.api.pom.Process
Returns:
the output parameter reference map

getOutputs

protected final void getOutputs(java.util.Map<java.lang.String,nextgrid.api.pom.Reference<?>> map)
Gets all outputs of this process, including inherited ones into the specified map.

Parameters:
map - The map to fill

getInput

public final nextgrid.api.pom.Reference<?> getInput(java.lang.String key)
Gets an input parameter by its name.

Parameters are inheritable, so if a local parameter is not found, the search will be continued on the parent process.

Specified by:
getInput in interface nextgrid.api.pom.Process
Parameters:
key - The parameter name
Returns:
The parameter, or null if none exists with the specified name

getOutput

public final nextgrid.api.pom.Reference<?> getOutput(java.lang.String key)
Gets an output parameter by its name.

Parameters are inheritable, so if a local parameter is not found, the search will be continued on the parent process.

Specified by:
getOutput in interface nextgrid.api.pom.Process
Parameters:
key - The parameter name
Returns:
The parameter, or null if none exists with the specified name

putInput

public final void putInput(java.lang.String key,
                           nextgrid.api.pom.Reference<?> input)
Puts a reference into the map of input parameters for this process.

Specified by:
putInput in interface nextgrid.api.pom.Process
Parameters:
key - The parameter name
input - The parameter

putOutput

public final void putOutput(java.lang.String key,
                            nextgrid.api.pom.Reference<?> output)
Puts a reference into the map of output parameters for this process.

Specified by:
putOutput in interface nextgrid.api.pom.Process
Parameters:
key - The parameter name
output - The parameter

removeInput

public final void removeInput(java.lang.String key)
Removes a reference from the input map.

Specified by:
removeInput in interface nextgrid.api.pom.Process
Parameters:
key - The name of the reference to remove

removeOutput

public final void removeOutput(java.lang.String key)
Removes a reference from the output map.

Specified by:
removeOutput in interface nextgrid.api.pom.Process
Parameters:
key - The name of the reference to remove

useInput

public final void useInput(java.lang.String name,
                           java.lang.Class<?> type)

Specified by:
useInput in interface nextgrid.api.pom.Process

useOutput

public final void useOutput(java.lang.String name,
                            java.lang.Class<?> type)

Specified by:
useOutput in interface nextgrid.api.pom.Process

unuseInput

public final void unuseInput(java.lang.String... names)

Specified by:
unuseInput in interface nextgrid.api.pom.Process

unuseOutput

public final void unuseOutput(java.lang.String... names)

Specified by:
unuseOutput in interface nextgrid.api.pom.Process

getUsedInputNames

public final java.lang.String[] getUsedInputNames()

Specified by:
getUsedInputNames in interface nextgrid.api.pom.Process

getUsedOutputNames

public final java.lang.String[] getUsedOutputNames()

Specified by:
getUsedOutputNames in interface nextgrid.api.pom.Process

getInputType

public final java.lang.Class<?> getInputType(java.lang.String name)

Specified by:
getInputType in interface nextgrid.api.pom.Process

getOutputType

public final java.lang.Class<?> getOutputType(java.lang.String name)

Specified by:
getOutputType in interface nextgrid.api.pom.Process

waitForInputs

protected void waitForInputs()
                      throws java.lang.InterruptedException
Waits until all input parameters are available for reading.

Throws:
java.lang.InterruptedException - If the thread is interrupted

copy

public nextgrid.api.pom.Process copy()

Specified by:
copy in interface nextgrid.api.pom.Process
Overrides:
copy in class PemHelper


Copyright © 2006-2008 Grid Systems, S.A.. All Rights Reserved.