edu.harvard.cfa.vo.tapclient.tap
Class AsyncJob

java.lang.Object
  extended by edu.harvard.cfa.vo.tapclient.tap.Job
      extended by edu.harvard.cfa.vo.tapclient.tap.AsyncJob

public class AsyncJob
extends Job

An object used for executing an asynchronous data query.

            AsyncJob asyncJob = new AsyncJob(service);

            System.out.println("Set the parameters");
            asyncJob.setParameter("QUERY", "SELECT TOP 10 * FROM TAP_SCHEMA.columns");
            asyncJob.setParameter("LANG", "ADQL");
            asyncJob.setParameter("FORMAT", "votable");
            asyncJob.setParameter("MAXREC", "1000");

            System.out.println("Run the job");
            asyncJob.run();

            while (! asyncJob.isFinished()) {
                Thread.sleep(5000); 
                System.out.println("Update the job status");
                asyncJob.synchronize();
            }

            if (asyncJob.isCompleted()) {
                System.out.println("Job has completed");
                // List resultList = asyncJob.getResults();
                Result result = asyncJob.getResult();
                InputStream resultStream = null;
                try {
                    resultStream = result.openStream();
                    // ...
                } finally {
                    try { 
                        resultStream.close();
                    } catch (Exception ignore) {
                    }
                }
            } else if (asyncJob.isError()) {
                System.out.println("Job has an error");
                Error error = asyncJob.getError();
                System.out.println("The service has encountered a "+error.getType()+" error: "+error.getMessage());
                if (error.isDetailedErrorAvailable()) {
                    System.out.println("Additional details follow:");
                    InputStream errorStream = null;
                    try {
                        errorStream = error.openStream();
                        // ...
                    } finally {
                        try {
                            errorStream.close();
                        } catch (Exception ignore) {
                        }
                    }
                } 
            } else if (asyncJob.isAborted()) {
                System.out.println("The service has 'ABORTED' this job.");
            } else if (asyncJob.isHeld()) {
                System.out.println("The service has 'HELD' this job.  Please run this job again at a later time.");
            } 
 


Field Summary
static java.lang.String ADQL_LANG
           
static java.lang.String VOTABLE_FORMAT
           
 
Fields inherited from class edu.harvard.cfa.vo.tapclient.tap.Job
inlineContent, parameters
 
Constructor Summary
AsyncJob(TapService service)
          Creates an asynchronous job object associated with the TAP service at TapService.
AsyncJob(TapService service, java.lang.String jobId)
          Creates an asynchronous job object associated with the TAP service and job at service and jobId.
 
Method Summary
 void abort()
          Sends a request to the TAP service to abort this job.
protected  void createJobOnServer()
           
 void delete()
          Sends a request to the TAP service to delete this job and all of its resources.
 java.util.Calendar getDestruction()
          Returns the destruction of this job as returned by the TAP service
 java.util.Calendar getEndTime()
          Returns the end time of this job as returned by the TAP service
 Error getError()
          Returns the error summary of this job as returned by the TAP service
 java.lang.Integer getExecutionDuration()
          Returns the execution duration of this job as returned by the TAP service
 java.lang.String getJobId()
          Returns the job id of this job as returned by the TAP service
 java.lang.Object getJobInfo()
          Returns the job info of this job as returned by the TAP service
 java.lang.String getOwnerId()
          Returns the owner id of this job as returned by the TAP service
 java.util.Map<java.lang.String,java.lang.String> getParameters()
          Returns the parameters of this job as returned by the TAP service
 java.lang.String getPhase()
          Returns the execution phase of this job as returned by the TAP service
 java.util.Calendar getQuote()
          Returns the quote of this job as returned by the TAP service
 Result getResult()
          Returns the main result of this job
 java.util.Set<Result> getResults()
          Returns the results of this job as returned by the TAP service
 java.lang.String getRunId()
          Returns the run id of this job as returned by the TAP service
 java.util.Calendar getStartTime()
          Returns the start time of this job as returned by the TAP service
 void handleJobSummaryResponse(java.io.InputStream inputStream)
           
 boolean isAborted()
          Returns true is the execution phase of the job is ABORTED
 boolean isCompleted()
          Returns true is the execution phase of the job is COMPLETED
 boolean isError()
          Returns true is the execution phase of the job is ERROR
 boolean isFinished()
          Returns true if the job has an execution phase that is completed, error, aborted, or held.
 boolean isHeld()
          Returns true is the execution phase of the job is HELD.
 void list(java.io.PrintStream output)
           
protected  net.ivoa.xml.uws.v10.JobDocument parseJobDocument(java.io.InputStream inputStream)
           
protected  void readJobFromServer()
           
 void run()
          Sends a request to the TAP service to run this job.
 void setDestruction(java.util.Calendar newValue)
          Sets the destruction of this job.
 void setExecutionDuration(java.lang.Integer newValue)
          Sets the execution duration of this job.
 void setParameter(java.lang.String id, java.lang.String value)
          Sets a parameter of this job.
 void setPhase(java.lang.String newValue)
          Sets the execution phase of this job.
 void synchronize()
          Propagates parameter updates to the server and refreshes the state of this object with the server response.
protected  void updateDestructionOnServer()
           
protected  void updateExecutionDurationOnServer()
           
protected  void updateExecutionPhaseOnServer(java.lang.String phaseValue)
           
protected  void updateParametersOnServer()
           
 
Methods inherited from class edu.harvard.cfa.vo.tapclient.tap.Job
addInlineUpload, addUpload, setFormat, setInlineUpload, setLang, setMaxRec, setParameter, setQuery, setRunId, setUpload
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ADQL_LANG

public static final java.lang.String ADQL_LANG
See Also:
Constant Field Values

VOTABLE_FORMAT

public static final java.lang.String VOTABLE_FORMAT
See Also:
Constant Field Values
Constructor Detail

AsyncJob

public AsyncJob(TapService service)
Creates an asynchronous job object associated with the TAP service at TapService.


AsyncJob

public AsyncJob(TapService service,
                java.lang.String jobId)
Creates an asynchronous job object associated with the TAP service and job at service and jobId.

Method Detail

run

public void run()
         throws HttpException,
                ResponseFormatException,
                java.io.IOException
Sends a request to the TAP service to run this job.

Throws:
HttpException - if the service response to the run request is an unexpected HTTP status.
ResponseFormatException - if an error occurs parsing the service response into a UWS job summary document.
java.io.IOException - if an error occurs creating an input stream.

abort

public void abort()
           throws HttpException,
                  ResponseFormatException,
                  java.io.IOException
Sends a request to the TAP service to abort this job.

Throws:
HttpException - if the service response to the abort request is an unexpected HTTP status.
ResponseFormatException - if an error occurs parsing the service response into a UWS job summary document.
java.io.IOException - if an error occurs creating an input stream.

delete

public void delete()
            throws HttpException,
                   ResponseFormatException,
                   java.io.IOException
Sends a request to the TAP service to delete this job and all of its resources.

Throws:
HttpException - if the service response to the delete request is an unexpected HTTP status.
ResponseFormatException - if an error occurs parsing the service response into a UWS job list document.
java.io.IOException - if an error occurs creating an input stream.

getJobId

public java.lang.String getJobId()
Returns the job id of this job as returned by the TAP service

Returns:
job id provided by the TAP service

getRunId

public java.lang.String getRunId()
Returns the run id of this job as returned by the TAP service

Returns:
run id

getOwnerId

public java.lang.String getOwnerId()
Returns the owner id of this job as returned by the TAP service

Returns:
owner id provided by the TAP service

getPhase

public java.lang.String getPhase()
Returns the execution phase of this job as returned by the TAP service

Returns:
execution phase

isFinished

public boolean isFinished()
Returns true if the job has an execution phase that is completed, error, aborted, or held.

Returns:
true if the job has an execution phase that is completed, error, aborted, or held, false otherwise

isCompleted

public boolean isCompleted()
Returns true is the execution phase of the job is COMPLETED

Returns:
true if the job has successfully completed, false otherwise

isError

public boolean isError()
Returns true is the execution phase of the job is ERROR

Returns:
true if the job had an error, false otherwise.

isAborted

public boolean isAborted()
Returns true is the execution phase of the job is ABORTED

Returns:
true if the job was aborted, false otherwise.

isHeld

public boolean isHeld()
Returns true is the execution phase of the job is HELD. If true, it may be possible to rerun this job.

Returns:
true if the job was held by the service, false otherwise.

getQuote

public java.util.Calendar getQuote()
Returns the quote of this job as returned by the TAP service

Returns:
quote for job execution from the TAP service

getStartTime

public java.util.Calendar getStartTime()
Returns the start time of this job as returned by the TAP service

Returns:
start time of the job on the TAP service

getEndTime

public java.util.Calendar getEndTime()
Returns the end time of this job as returned by the TAP service

Returns:
end time of the job on the TAP service

getExecutionDuration

public java.lang.Integer getExecutionDuration()
Returns the execution duration of this job as returned by the TAP service

Returns:
execution duration in seconds

getDestruction

public java.util.Calendar getDestruction()
Returns the destruction of this job as returned by the TAP service

Returns:
destruction timestamp

getParameters

public java.util.Map<java.lang.String,java.lang.String> getParameters()
Returns the parameters of this job as returned by the TAP service

Returns:
parameter list

getResults

public java.util.Set<Result> getResults()
Returns the results of this job as returned by the TAP service

Returns:
result list

getResult

public Result getResult()
Returns the main result of this job

Returns:
result

getError

public Error getError()
Returns the error summary of this job as returned by the TAP service

Returns:
error summary if the job was run an there was an error, null otherwise

getJobInfo

public java.lang.Object getJobInfo()
Returns the job info of this job as returned by the TAP service

Returns:
additional job info, service dependent.

setPhase

public void setPhase(java.lang.String newValue)
Sets the execution phase of this job. The value is sent to the TAP service when #run or #update is called.

Parameters:
newValue - the run id

setExecutionDuration

public void setExecutionDuration(java.lang.Integer newValue)
Sets the execution duration of this job. The value is sent to the TAP service when #run or #update is called.

Parameters:
newValue - the execution duration in seconds

setDestruction

public void setDestruction(java.util.Calendar newValue)
Sets the destruction of this job. The value is sent to the TAP service when #run or #update is called.

Parameters:
newValue - the destruction timestamp

setParameter

public void setParameter(java.lang.String id,
                         java.lang.String value)
Sets a parameter of this job. The value is sent to the TAP service when #run or #update is called.

Specified by:
setParameter in class Job
Parameters:
id - the parameter identifier
value - the parameter value

handleJobSummaryResponse

public void handleJobSummaryResponse(java.io.InputStream inputStream)
                              throws java.io.IOException,
                                     org.apache.xmlbeans.XmlException
Throws:
java.io.IOException
org.apache.xmlbeans.XmlException

parseJobDocument

protected net.ivoa.xml.uws.v10.JobDocument parseJobDocument(java.io.InputStream inputStream)
                                                     throws javax.xml.stream.XMLStreamException,
                                                            org.apache.xmlbeans.XmlException,
                                                            java.io.IOException
Throws:
javax.xml.stream.XMLStreamException
org.apache.xmlbeans.XmlException
java.io.IOException

synchronize

public void synchronize()
                 throws HttpException,
                        ResponseFormatException,
                        java.io.IOException
Propagates parameter updates to the server and refreshes the state of this object with the server response.

Throws:
java.io.IOException - if an error occurs with communicating with the server.
HttpException
ResponseFormatException

createJobOnServer

protected void createJobOnServer()
                          throws HttpException,
                                 ResponseFormatException,
                                 java.io.IOException,
                                 org.apache.xmlbeans.XmlException
Throws:
HttpException
ResponseFormatException
java.io.IOException
org.apache.xmlbeans.XmlException

updateParametersOnServer

protected void updateParametersOnServer()
                                 throws HttpException,
                                        ResponseFormatException,
                                        java.io.IOException,
                                        org.apache.xmlbeans.XmlException
Throws:
HttpException
ResponseFormatException
java.io.IOException
org.apache.xmlbeans.XmlException

updateExecutionDurationOnServer

protected void updateExecutionDurationOnServer()
                                        throws HttpException,
                                               ResponseFormatException,
                                               java.io.IOException,
                                               org.apache.xmlbeans.XmlException
Throws:
HttpException
ResponseFormatException
java.io.IOException
org.apache.xmlbeans.XmlException

updateDestructionOnServer

protected void updateDestructionOnServer()
                                  throws HttpException,
                                         ResponseFormatException,
                                         java.io.IOException,
                                         org.apache.xmlbeans.XmlException
Throws:
HttpException
ResponseFormatException
java.io.IOException
org.apache.xmlbeans.XmlException

updateExecutionPhaseOnServer

protected void updateExecutionPhaseOnServer(java.lang.String phaseValue)
                                     throws HttpException,
                                            ResponseFormatException,
                                            java.io.IOException,
                                            org.apache.xmlbeans.XmlException
Throws:
HttpException
ResponseFormatException
java.io.IOException
org.apache.xmlbeans.XmlException

readJobFromServer

protected void readJobFromServer()
                          throws HttpException,
                                 ResponseFormatException,
                                 java.io.IOException,
                                 org.apache.xmlbeans.XmlException
Throws:
HttpException
ResponseFormatException
java.io.IOException
org.apache.xmlbeans.XmlException

list

public void list(java.io.PrintStream output)