org.apache.stanbol.enhancer.jobmanager.event.impl
Class EnhancementJob

java.lang.Object
  extended by org.apache.stanbol.enhancer.jobmanager.event.impl.EnhancementJob

public class EnhancementJob
extends Object

Represents the enhancement of a ContentItem by following the execution plan provided by a Chain as parsed to an EnhancementJobManager.

TODO: This might become part of the Stanbol Enhancer Services API.

Author:
Rupert Westenthaler

Constructor Summary
EnhancementJob(org.apache.stanbol.enhancer.servicesapi.ContentItem contentItem)
          Creates an EnhancemenJob based on already existing execution metadata present for a ContentItem.
EnhancementJob(org.apache.stanbol.enhancer.servicesapi.ContentItem contentItem, String chainName, org.apache.clerezza.rdf.core.Graph executionPlan, boolean isDefaultChain)
          Constructor used to create and initialise a new enhancement job.
 
Method Summary
 String getChainName()
          This returns the name of the Chain used to initialise the execution plan for this enhancement job.
 Set<org.apache.clerezza.rdf.core.NonLiteral> getCompleted()
          Getter for a read only view over the completed execution.
 org.apache.stanbol.enhancer.servicesapi.ContentItem getContentItem()
          The ContentItem enhanced by this job.
 Exception getError()
          if isFailed() this may contain the Exception that caused the enhancement job to fail.
 String getErrorMessage()
           
 Set<org.apache.clerezza.rdf.core.NonLiteral> getExecutable()
          Getter for the executable nodes.
 org.apache.clerezza.rdf.core.NonLiteral getExecution(org.apache.clerezza.rdf.core.NonLiteral executionNode)
          Getter for the em:Execution linked to a ep:ExecutionNode
 org.apache.clerezza.rdf.core.MGraph getExecutionMetadata()
          Getter for the ExecutionMetadata.
 org.apache.clerezza.rdf.core.NonLiteral getExecutionNode(org.apache.clerezza.rdf.core.NonLiteral execution)
          Getter for the ep:ExecutionNode linked to a em:Execution
 org.apache.clerezza.rdf.core.Graph getExecutionPlan()
          The used execution plan for processing the ContentItem
 ReadWriteLock getLock()
          Getter for the lock used to synchronise read/write to this enhancement job.
 Set<org.apache.clerezza.rdf.core.NonLiteral> getRunning()
          Getter for a read only view over the currently running executions.
 boolean isFailed()
          Getter for the failed state.
 boolean isFinished()
          Returns true if this chain has finished.
 void setCompleted(org.apache.clerezza.rdf.core.NonLiteral execution)
          Sets the state of the parsed executionNode to completed.
 void setFailed(org.apache.clerezza.rdf.core.NonLiteral execution, org.apache.stanbol.enhancer.servicesapi.EnhancementEngine engine, Exception exception)
           
 void setRunning(org.apache.clerezza.rdf.core.NonLiteral execution)
          Sets the state of the parsed execution to running.
 void startProcessing()
          Marks the execution of the enhancement process as started.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EnhancementJob

public EnhancementJob(org.apache.stanbol.enhancer.servicesapi.ContentItem contentItem,
                      String chainName,
                      org.apache.clerezza.rdf.core.Graph executionPlan,
                      boolean isDefaultChain)
Constructor used to create and initialise a new enhancement job. This will create the initial set of ExecutionMetadata and add them as ContentPart with the URI ExecutionMetadata.CHAIN_EXECUTION to the ContentItem.

Parameters:
contentItem -
chainName -
executionPlan -
isDefaultChain -

EnhancementJob

public EnhancementJob(org.apache.stanbol.enhancer.servicesapi.ContentItem contentItem)
Creates an EnhancemenJob based on already existing execution metadata present for a ContentItem.

Parameters:
contentItem - the ContentItem with an already existing content part containing an MGraph with all required execution metadata and the execution plan.
Throws:
IllegalArgumentException - if the parsed ContentItem does not provide the required data to (re)initialise the EnhancementJob.
Method Detail

getExecutionNode

public org.apache.clerezza.rdf.core.NonLiteral getExecutionNode(org.apache.clerezza.rdf.core.NonLiteral execution)
Getter for the ep:ExecutionNode linked to a em:Execution

Returns:
the ep:ExecutionNode instance
Throws:
IllegalArgumentException - if the parsed em:Execution is not part of the execution metadata of this enhancement job

getExecution

public org.apache.clerezza.rdf.core.NonLiteral getExecution(org.apache.clerezza.rdf.core.NonLiteral executionNode)
Getter for the em:Execution linked to a ep:ExecutionNode

Returns:
the em:Execution instance
Throws:
IllegalArgumentException - if the parsed ep:ExecutionNode is not part of the execution plan of this enhancement job

getExecutionPlan

public final org.apache.clerezza.rdf.core.Graph getExecutionPlan()
The used execution plan for processing the ContentItem

Returns:
the executionPlan

getContentItem

public final org.apache.stanbol.enhancer.servicesapi.ContentItem getContentItem()
The ContentItem enhanced by this job.

Returns:

getChainName

public final String getChainName()
This returns the name of the Chain used to initialise the execution plan for this enhancement job.

NOTE that because chains can change (activate, change, deactivate) at any moment there is no guarantee that the a chain with that name is still available nor that calling Chain.getExecutionPlan() will be equals to the getExecutionPlan() used by this enhancement job. This is the reason why this method just returns the name of the chain and not the Chain instance.

Returns:

getLock

public final ReadWriteLock getLock()
Getter for the lock used to synchronise read/write to this enhancement job. This returns the lock provided by ContentItem.getLock()

Returns:
the read/write lock for this enhancement job

getRunning

public Set<org.apache.clerezza.rdf.core.NonLiteral> getRunning()
Getter for a read only view over the currently running executions.

Returns:
the currently running executions.

getCompleted

public Set<org.apache.clerezza.rdf.core.NonLiteral> getCompleted()
Getter for a read only view over the completed execution.

Returns:
the completed execution nodes

setCompleted

public void setCompleted(org.apache.clerezza.rdf.core.NonLiteral execution)
Sets the state of the parsed executionNode to completed. This also validates if the new state confirms to the ExectionPlan (e.g. if all nodes the parsed node depends on are also marked as completed).

Parameters:
execution - the exection to be marked as running
Throws:
IllegalArgumentException - if null is parsed as execution node
IllegalStateException - if the parsed execution node can not be marked as completed because some of its depended nodes are not yet marked as completed.

setRunning

public void setRunning(org.apache.clerezza.rdf.core.NonLiteral execution)
Sets the state of the parsed execution to running. This also validates if the new state confirms to the ExectionPlan (e.g. if all nodes the parsed node depends on are already marked as completed).

Parameters:
execution - the execution to be marked as running
Throws:
IllegalArgumentException - if null is parsed as execution node
IllegalStateException - if the parsed execution node can not be marked as running because some of its depended nodes are not yet marked as completed.

getExecutable

public Set<org.apache.clerezza.rdf.core.NonLiteral> getExecutable()
Getter for the executable nodes.

Returns:
the nodes that can be executed next based on the completed and currently running engines.

isFinished

public boolean isFinished()
Returns true if this chain has finished.

Returns:
if this enhancement job is finished.

setFailed

public void setFailed(org.apache.clerezza.rdf.core.NonLiteral execution,
                      org.apache.stanbol.enhancer.servicesapi.EnhancementEngine engine,
                      Exception exception)

isFailed

public boolean isFailed()
Getter for the failed state. Note that EnhancementJobs might be already failed but not yet finished.

Returns:
if the EnhancementJob has failed or not.

toString

public String toString()
Overrides:
toString in class Object

getError

public Exception getError()
if isFailed() this may contain the Exception that caused the enhancement job to fail.

Returns:
The Exception or null if no exception is available

getErrorMessage

public String getErrorMessage()

getExecutionMetadata

public org.apache.clerezza.rdf.core.MGraph getExecutionMetadata()
Getter for the ExecutionMetadata.

Returns:
the execution metadata.

startProcessing

public void startProcessing()
Marks the execution of the enhancement process as started. In other words this sets the status of the 'em:ChainExecution' instance that 'em:enhances' the ContentItem to ExecutionMetadata.STATUS_IN_PROGRESS



Copyright © 2012-2013 The Apache Software Foundation. All Rights Reserved.