orc.orchard
Class AbstractExecutorService

java.lang.Object
  extended by orc.orchard.AbstractExecutorService
All Implemented Interfaces:
java.rmi.Remote, ExecutorServiceInterface
Direct Known Subclasses:
ExecutorService, ExecutorService, ExecutorService

public abstract class AbstractExecutorService
extends java.lang.Object
implements ExecutorServiceInterface

Standard implementation of an ExecutorService. Extenders should implement createJobService.

TODO: add executor oil validation to only allow "safe" sites

Author:
quark

Field Summary
protected  java.util.logging.Logger logger
           
 
Constructor Summary
protected AbstractExecutorService(AbstractAccounts accounts)
           
protected AbstractExecutorService(java.util.logging.Logger logger, AbstractAccounts accounts)
           
 
Method Summary
 void cancelPrompt(java.lang.String devKey, java.lang.String job, int promptID)
          Cancel a prompt (initiated by the Prompt site).
 java.lang.String compileAndSubmit(java.lang.String devKey, java.lang.String program)
          Combine compilation and submission into a single step.
 java.lang.String compileAndSubmitConfigured(java.lang.String devKey, java.lang.String program, JobConfiguration configuration)
          Combine compilation and submission into a single step.
 void finishJob(java.lang.String devKey, java.lang.String job)
          Indicate that the client is done with the job.
protected static JobConfiguration getDefaultJobConfiguration()
           
protected static java.util.logging.Logger getDefaultLogger()
           
protected  Waiter getWaiter()
           
 void haltJob(java.lang.String devKey, java.lang.String job)
          Halt the job safely, using the same termination semantics as the "pull" combinator.
 java.util.List<JobEvent> jobEvents(java.lang.String devKey, java.lang.String job)
          Retrieve events.
 java.util.Set<java.lang.String> jobs(java.lang.String devKey)
          URIs of unfinished jobs started from this executor.
 java.lang.String jobState(java.lang.String devKey, java.lang.String job)
          What is the job's state? Possible return values: NEW: not yet started.
 void purgeJobEvents(java.lang.String devKey, java.lang.String job)
          Purge all events from the event buffer which have been returned by jobEvents.
 void respondToPrompt(java.lang.String devKey, java.lang.String job, int promptID, java.lang.String response)
          Submit a response to a prompt (initiated by the Prompt site).
 void startJob(java.lang.String devKey, java.lang.String job)
          Begin executing the job.
 java.lang.String submit(java.lang.String devKey, Oil program)
          Register a new job for execution, using a default JobConfiguration.
 java.lang.String submitConfigured(java.lang.String devKey, Oil program, JobConfiguration configuration)
          Register a new job for execution, using the provided job configuration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected java.util.logging.Logger logger
Constructor Detail

AbstractExecutorService

protected AbstractExecutorService(java.util.logging.Logger logger,
                                  AbstractAccounts accounts)

AbstractExecutorService

protected AbstractExecutorService(AbstractAccounts accounts)
Method Detail

submit

public java.lang.String submit(java.lang.String devKey,
                               Oil program)
                        throws QuotaException,
                               InvalidOilException,
                               java.rmi.RemoteException
Description copied from interface: ExecutorServiceInterface
Register a new job for execution, using a default JobConfiguration.

Specified by:
submit in interface ExecutorServiceInterface
Throws:
QuotaException
InvalidOilException
java.rmi.RemoteException

submitConfigured

public java.lang.String submitConfigured(java.lang.String devKey,
                                         Oil program,
                                         JobConfiguration configuration)
                                  throws QuotaException,
                                         InvalidOilException,
                                         UnsupportedFeatureException,
                                         java.rmi.RemoteException
Description copied from interface: ExecutorServiceInterface
Register a new job for execution, using the provided job configuration.

Specified by:
submitConfigured in interface ExecutorServiceInterface
Returns:
String Job ID of new job.
Throws:
QuotaException - if registering this job would exceed quotas.
InvalidOilException - if the program is invalid.
UnsupportedFeatureException - if the executor does not support some part of the configuration.
java.rmi.RemoteException

jobs

public java.util.Set<java.lang.String> jobs(java.lang.String devKey)
Description copied from interface: ExecutorServiceInterface
URIs of unfinished jobs started from this executor.

Specified by:
jobs in interface ExecutorServiceInterface

compileAndSubmit

public java.lang.String compileAndSubmit(java.lang.String devKey,
                                         java.lang.String program)
                                  throws QuotaException,
                                         InvalidProgramException,
                                         InvalidOilException,
                                         java.rmi.RemoteException
Description copied from interface: ExecutorServiceInterface
Combine compilation and submission into a single step. This is useful for simple clients that don't want to bother calling a separate compiler.

Specified by:
compileAndSubmit in interface ExecutorServiceInterface
Throws:
QuotaException
InvalidProgramException
InvalidOilException
java.rmi.RemoteException

compileAndSubmitConfigured

public java.lang.String compileAndSubmitConfigured(java.lang.String devKey,
                                                   java.lang.String program,
                                                   JobConfiguration configuration)
                                            throws QuotaException,
                                                   InvalidProgramException,
                                                   InvalidOilException,
                                                   UnsupportedFeatureException,
                                                   java.rmi.RemoteException
Description copied from interface: ExecutorServiceInterface
Combine compilation and submission into a single step.

Specified by:
compileAndSubmitConfigured in interface ExecutorServiceInterface
Throws:
QuotaException
InvalidProgramException
InvalidOilException
UnsupportedFeatureException
java.rmi.RemoteException

getDefaultJobConfiguration

protected static JobConfiguration getDefaultJobConfiguration()

getDefaultLogger

protected static java.util.logging.Logger getDefaultLogger()

getWaiter

protected Waiter getWaiter()

finishJob

public void finishJob(java.lang.String devKey,
                      java.lang.String job)
               throws InvalidJobStateException,
                      java.rmi.RemoteException,
                      InvalidJobException
Description copied from interface: ExecutorServiceInterface
Indicate that the client is done with the job. The job will be halted if necessary.

Once this method is called, the service provider is free to garbage collect the service and the service URL may become invalid, so no other methods should be called after this.

Specified by:
finishJob in interface ExecutorServiceInterface
Throws:
InvalidJobStateException - if the job is RUNNING or WAITING.
java.rmi.RemoteException
InvalidJobException

haltJob

public void haltJob(java.lang.String devKey,
                    java.lang.String job)
             throws java.rmi.RemoteException,
                    InvalidJobException
Description copied from interface: ExecutorServiceInterface
Halt the job safely, using the same termination semantics as the "pull" combinator.

Specified by:
haltJob in interface ExecutorServiceInterface
Throws:
java.rmi.RemoteException
InvalidJobException

jobEvents

public java.util.List<JobEvent> jobEvents(java.lang.String devKey,
                                          java.lang.String job)
                                   throws java.rmi.RemoteException,
                                          java.lang.InterruptedException,
                                          InvalidJobException
Description copied from interface: ExecutorServiceInterface
Retrieve events. If no events occurred, block until at least one occurs. If the job finishes without any more events happening, an empty list will be returned.

FIXME: ensure clients like web/orc.js can recover from connection timeouts.

Specified by:
jobEvents in interface ExecutorServiceInterface
Throws:
java.lang.InterruptedException - if the request times out.
java.rmi.RemoteException
InvalidJobException

jobState

public java.lang.String jobState(java.lang.String devKey,
                                 java.lang.String job)
                          throws java.rmi.RemoteException,
                                 InvalidJobException
Description copied from interface: ExecutorServiceInterface
What is the job's state? Possible return values: NEW: not yet started. RUNNING: started and processing tokens. WAITING: started and waiting for response from a site. DONE: finished executing.

Specified by:
jobState in interface ExecutorServiceInterface
Returns:
the current state of the job.
Throws:
java.rmi.RemoteException
InvalidJobException

purgeJobEvents

public void purgeJobEvents(java.lang.String devKey,
                           java.lang.String job)
                    throws java.rmi.RemoteException,
                           InvalidJobException
Description copied from interface: ExecutorServiceInterface
Purge all events from the event buffer which have been returned by jobEvents. The client is responsible for calling this method regularly to keep the event buffer from filling up.

Specified by:
purgeJobEvents in interface ExecutorServiceInterface
Throws:
java.rmi.RemoteException
InvalidJobException

startJob

public void startJob(java.lang.String devKey,
                     java.lang.String job)
              throws InvalidJobStateException,
                     java.rmi.RemoteException,
                     InvalidJobException
Description copied from interface: ExecutorServiceInterface
Begin executing the job.

Specified by:
startJob in interface ExecutorServiceInterface
Throws:
InvalidJobStateException - if the job was already started, or was aborted.
java.rmi.RemoteException
InvalidJobException

respondToPrompt

public void respondToPrompt(java.lang.String devKey,
                            java.lang.String job,
                            int promptID,
                            java.lang.String response)
                     throws InvalidPromptException,
                            java.rmi.RemoteException,
                            InvalidJobException
Description copied from interface: ExecutorServiceInterface
Submit a response to a prompt (initiated by the Prompt site).

Specified by:
respondToPrompt in interface ExecutorServiceInterface
Throws:
InvalidPromptException - if the promptID is not valid.
java.rmi.RemoteException
InvalidJobException

cancelPrompt

public void cancelPrompt(java.lang.String devKey,
                         java.lang.String job,
                         int promptID)
                  throws InvalidJobException,
                         InvalidPromptException,
                         java.rmi.RemoteException
Description copied from interface: ExecutorServiceInterface
Cancel a prompt (initiated by the Prompt site).

Specified by:
cancelPrompt in interface ExecutorServiceInterface
Throws:
InvalidPromptException - if the promptID is not valid.
InvalidJobException
java.rmi.RemoteException