com.bigdata.relation.rule.eval
Class AbstractStepTask

java.lang.Object
  extended by com.bigdata.service.FederationCallable<T>
      extended by com.bigdata.service.DataServiceCallable<RuleStats>
          extended by com.bigdata.relation.rule.eval.AbstractStepTask
All Implemented Interfaces:
IStepTask, IDataServiceCallable, IFederationCallable, Serializable, Cloneable, Callable<RuleStats>
Direct Known Subclasses:
MutationTask, QueryTask

public abstract class AbstractStepTask
extends DataServiceCallable<RuleStats>
implements IStepTask, Cloneable

Version:
$Id: AbstractStepTask.java 3511 2010-09-06 20:45:37Z thompsonbry $
Author:
Bryan Thompson
See Also:
Serialized Form

Field Summary
protected  ActionEnum action
           
protected  IIndexManager indexManager
           
protected  IJoinNexusFactory joinNexusFactory
           
protected static org.apache.log4j.Logger log
           
protected  IStep step
           
 
Constructor Summary
protected AbstractStepTask(ActionEnum action, IJoinNexusFactory joinNexusFactory, IStep step, IIndexManager indexManager, DataService dataService)
          Base class handles submit either to the caller's ExecutorService or to the ConcurrencyManager IFF the task was submitted to a DataService.
 
Method Summary
 AbstractStepTask clone()
          Strengthens the return type and masquerades the CloneNotSupportedException.
protected  Set<String> getIndexNames(Collection<IRelation> c)
          Returns the names of the indices maintained by the relations.
protected  Map<String,IBuffer<ISolution[]>> getMutationBuffers(IJoinNexus joinNexus, Map<String,IRelation> relations)
          Create the appropriate buffers to absorb writes by the rules in the program that target an IMutableRelation.
protected  Map<String,IRelation> getReadRelations(IIndexManager indexManager, IStep step, long timestamp)
          Locate the distinct relation identifiers corresponding to the tail(s) of each rule and resolve them to their relations.
protected  Set<String> getWriteRelationNames(IStep step)
          The set of distinct relations identified by the head of each rule in the program.
protected  Map<String,IRelation> getWriteRelations(IIndexManager indexManager, IStep step, long timestamp)
          Locate the distinct relation identifiers corresponding to the head of each rule and resolve them to their relations.
protected  RuleStats runOne(IJoinNexus joinNexus, IStep program, Callable<RuleStats> task)
          Run a single step (sequence of one).
protected  RuleStats runParallel(IJoinNexus joinNexus, IStep program, List<Callable<RuleStats>> tasks)
          Run program steps in parallel.
protected  RuleStats runSequential(IJoinNexus joinNexus, IStep program, List<Callable<RuleStats>> tasks)
          Run program steps in sequence.
 Future<RuleStats> submit()
          Run this task.
 String toString()
           
 
Methods inherited from class com.bigdata.service.DataServiceCallable
getDataService, isDataService, setDataService
 
Methods inherited from class com.bigdata.service.FederationCallable
getFederation, setFederation
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.bigdata.relation.rule.eval.IStepTask
call
 
Methods inherited from interface com.bigdata.service.IFederationCallable
getFederation, setFederation
 

Field Detail

log

protected static final transient org.apache.log4j.Logger log

action

protected final ActionEnum action

joinNexusFactory

protected final IJoinNexusFactory joinNexusFactory

indexManager

protected IIndexManager indexManager

step

protected final IStep step
Constructor Detail

AbstractStepTask

protected AbstractStepTask(ActionEnum action,
                           IJoinNexusFactory joinNexusFactory,
                           IStep step,
                           IIndexManager indexManager,
                           DataService dataService)
Base class handles submit either to the caller's ExecutorService or to the ConcurrencyManager IFF the task was submitted to a DataService.

Note: The DataService will notice the IDataServiceCallable interface and set a reference to itself using DataServiceCallable.setDataService(DataService). submit() notices this case and causes this task to be clone()ed, the ExecutorService set on the clone, and the clone is then submitted to the ConcurrencyManager for the DataService.

Parameters:
action - Indicate whether this is a query or a mutation operation.
joinNexusFactory - Various goodies.
step - The rule or program.
indexManager -
dataService - non-null iff the caller is already running on a DataService.
Throws:
IllegalArgumentException - if action is null.
IllegalArgumentException - if joinNexusFactory is null.
IllegalArgumentException - if step is null.
Method Detail

toString

public String toString()
Overrides:
toString in class Object

runParallel

protected RuleStats runParallel(IJoinNexus joinNexus,
                                IStep program,
                                List<Callable<RuleStats>> tasks)
                         throws InterruptedException,
                                ExecutionException
Run program steps in parallel.

Parameters:
program -
tasks -
Throws:
InterruptedException
ExecutionException
TODO:
adapt the ClientIndexView code so that we notice all errors, log them all, and report them all in a single thrown exception. note that we may be running asynchronously inside of a task after the caller has an iterator that is draining the buffer. when an error occurs in that context the buffer should be flagged to indicate an exception and closed and the iterator should report the exception to the client.

Do the same thing for running a program as a sequence.


runSequential

protected RuleStats runSequential(IJoinNexus joinNexus,
                                  IStep program,
                                  List<Callable<RuleStats>> tasks)
                           throws InterruptedException,
                                  ExecutionException
Run program steps in sequence.

Parameters:
program -
tasks -
Returns:
Throws:
InterruptedException
ExecutionException

runOne

protected RuleStats runOne(IJoinNexus joinNexus,
                           IStep program,
                           Callable<RuleStats> task)
                    throws InterruptedException,
                           ExecutionException
Run a single step (sequence of one).

Note: use #runOne(IStep, Callable) rather than either #runParallel(IStep, List) or #runSequential(IStep, List) when there is only one task to execute in order to avoid an unnecessary layering of the RuleStats (this is due to a coupling between the RuleStats reporting structure and the control structure for executing the tasks).

Parameters:
program -
tasks -
Returns:
Throws:
InterruptedException
ExecutionException

submit

public Future<RuleStats> submit()
Run this task.

If we are executing on a DataService then DataServiceCallable.getDataService() will have been set automatically and the task will be submitted to the ConcurrencyManager for that DataService.

This condition occurs when this Callable is sent to the DataService using DataService.submit(Callable). In order to gain access to the named indices for the relation, we have to wrap up this Callable as an AbstractTask that declares the appropriate timestamp and resources. The AbstractTask is then submitted to the ConcurrencyManager for execution. Once the AbstractTask is actually running, the inner task overrides the indexManager to be AbstractTask.getJournal(). This provides access to the indices, relations, etc. appropriate for the isolation level granted to the task by the ConcurrencyManager - without this step the AbstractTask will wind up using an IClientIndex view and lose the benefits of access to unisolated indices.


clone

public AbstractStepTask clone()
Strengthens the return type and masquerades the CloneNotSupportedException.

Overrides:
clone in class Object

getWriteRelationNames

protected Set<String> getWriteRelationNames(IStep step)
The set of distinct relations identified by the head of each rule in the program.


getWriteRelations

protected Map<String,IRelation> getWriteRelations(IIndexManager indexManager,
                                                  IStep step,
                                                  long timestamp)
Locate the distinct relation identifiers corresponding to the head of each rule and resolve them to their relations.

Parameters:
timestamp - The timestamp associated with the relation views on which the rule(s) will write.
Throws:
RuntimeException - if any relation can not be resolved.

getReadRelations

protected Map<String,IRelation> getReadRelations(IIndexManager indexManager,
                                                 IStep step,
                                                 long timestamp)
Locate the distinct relation identifiers corresponding to the tail(s) of each rule and resolve them to their relations. Note that a tail predicate can read on a fused view of more than one relation.

Throws:
RuntimeException - if any relation can not be resolved.

getMutationBuffers

protected Map<String,IBuffer<ISolution[]>> getMutationBuffers(IJoinNexus joinNexus,
                                                              Map<String,IRelation> relations)
Create the appropriate buffers to absorb writes by the rules in the program that target an IMutableRelation.

Returns:
the map from relation identifier to the corresponding buffer.
Throws:
IllegalStateException - if the program is being executed as mutation.
RuntimeException - If a rule requires mutation for a relation (it will write on the relation) and the corresponding entry in the map does not implement IMutableRelation.

getIndexNames

protected Set<String> getIndexNames(Collection<IRelation> c)
Returns the names of the indices maintained by the relations.

Parameters:
c - A collection of IRelations.
Returns:
The names of the indices maintained by those relations.


Copyright © 2006-2011 SYSTAP, LLC. All Rights Reserved.