ome.services
Class JobBean

java.lang.Object
  extended by ome.services.AbstractStatefulBean
      extended by ome.services.JobBean
All Implemented Interfaces:
Serializable, JobHandle, ServiceInterface, StatefulServiceInterface, ProcessCallback, SelfConfigurableService

@Transactional(readOnly=true)
public class JobBean
extends AbstractStatefulBean
implements JobHandle, ProcessCallback

Provides methods for submitting asynchronous tasks.

Since:
3.0-Beta2
Author:
Josh Moore, josh at glencoesoftware.com
See Also:
Serialized Form

Field Summary
 
Fields inherited from class ome.services.AbstractStatefulBean
iQuery, iUpdate, modified, sec
 
Fields inherited from interface ome.api.JobHandle
CANCELLED, ERROR, FINISHED, QUEUED, REQUEUED, RESUBMITTED, RUNNING, SUBMITTED, WAITING
 
Constructor Summary
JobBean()
          default constructor
 
Method Summary
 void activate()
          Does almost nothing.
 ome.model.jobs.JobStatus attach(long id)
           
 void cancelJob()
          Marks a job for cancellation.
protected  void checkAndRegister()
           
 void close()
          signals the end of the service lifecycle.
protected  void errorIfInvalidState()
           
 ome.model.jobs.Job getJob()
           
 Class<? extends ServiceInterface> getServiceInterface()
           
 boolean jobError()
          Returns true if the Job has thrown an error.
 Timestamp jobFinished()
           
 String jobMessage()
           
 boolean jobRunning()
          Returns true if the Job is running, i.e. has an attached Process.
 ome.model.jobs.JobStatus jobStatus()
           
 void passivate()
          Does nothing.
 void processCancelled(Process proc)
           
 void processFinished(Process proc)
           
 String setMessage(String message)
          Sets the job's message string, and returns the previous value.
 void setProcessManager(IProcessManager procMgr)
          Process Manager Bean injector.
 String setStatus(String status)
          Updates the JobStatus for the current job.
 String setStatusAndMessage(String status, String message)
          Like JobHandle.setStatus(String) but also sets the message.
 void setTypesService(ITypes typesService)
          Types service Bean injector.
 long submit(ome.model.jobs.Job newJob)
          Submits a Job and returns its database id.
 
Methods inherited from class ome.services.AbstractStatefulBean
getBeanHelper, getCurrentEventContext, isModified, modified, selfConfigure, setQueryService, setSecuritySystem, setUpdateService
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ome.api.StatefulServiceInterface
getCurrentEventContext
 

Constructor Detail

JobBean

public JobBean()
default constructor

Method Detail

getServiceInterface

public Class<? extends ServiceInterface> getServiceInterface()
Specified by:
getServiceInterface in interface SelfConfigurableService

passivate

@Transactional
public void passivate()
Does nothing. The only non-shared state that this instance holds on to is the jobId and resetId -- two longs -- making passivation for the moment unimportant. This method should do what errorIfInvalidState does and reattach the process if we've been passivated. That will wait for larger changes later. At which time, proper locking will be necessary!

Specified by:
passivate in interface StatefulServiceInterface

activate

@Transactional
public void activate()
Does almost nothing. Since nothing is passivated, nothing needs to be activated. However, since we are still using errorIfInvalidState, if the jobId is non-null, then this instance will need to handle re-loading on first access. (Previously it could not be done here, because the security system was not configured for transactions during JavaEE callbacks. This is no longer true.)

Specified by:
activate in interface StatefulServiceInterface

close

@Transactional(readOnly=true)
public void close()
Description copied from interface: StatefulServiceInterface
signals the end of the service lifecycle. Resources such as Sessions can be released. All further calls will throw an exception.

Specified by:
close in interface StatefulServiceInterface

submit

@Transactional(readOnly=false)
public long submit(ome.model.jobs.Job newJob)
Description copied from interface: JobHandle
Submits a Job and returns its database id. The only fields directly on status which are editable are message, scheduledFor and status. The latter two must be sensible.

Specified by:
submit in interface JobHandle
Parameters:
newJob - Not null
Returns:
id

attach

public ome.model.jobs.JobStatus attach(long id)
Specified by:
attach in interface JobHandle
Returns:
the current JobStatus for the id

setTypesService

public void setTypesService(ITypes typesService)
Types service Bean injector.

Parameters:
typesService - an ITypes.

setProcessManager

public void setProcessManager(IProcessManager procMgr)
Process Manager Bean injector.

Parameters:
processManager - a ProcessManager.

errorIfInvalidState

protected void errorIfInvalidState()

checkAndRegister

protected void checkAndRegister()

getJob

public ome.model.jobs.Job getJob()
Specified by:
getJob in interface JobHandle
Returns:
the current Job

jobFinished

public Timestamp jobFinished()
Specified by:
jobFinished in interface JobHandle
Returns:
null if the Job is not finished, otherwise the Timestamp for when it completed.

jobStatus

public ome.model.jobs.JobStatus jobStatus()
Specified by:
jobStatus in interface JobHandle
Returns:
the current JobStatus. Will never return null.

jobMessage

public String jobMessage()
Specified by:
jobMessage in interface JobHandle
Returns:
current message for job. May be set during processing.

jobRunning

public boolean jobRunning()
Description copied from interface: JobHandle
Returns true if the Job is running, i.e. has an attached Process.

Specified by:
jobRunning in interface JobHandle

jobError

public boolean jobError()
Description copied from interface: JobHandle
Returns true if the Job has thrown an error.

Specified by:
jobError in interface JobHandle

cancelJob

@Transactional(readOnly=false)
public void cancelJob()
Description copied from interface: JobHandle
Marks a job for cancellation. Not every processor will check for the cancelled flag for a running job, but no non-running job will start if it has been cancelled.

Specified by:
cancelJob in interface JobHandle

setStatus

@Transactional(readOnly=false)
public String setStatus(String status)
Description copied from interface: JobHandle
Updates the JobStatus for the current job. The previous status is returned as a string. If the status is JobHandle.CANCELLED, this method is equivalent to JobHandle.cancelJob().

Specified by:
setStatus in interface JobHandle

setMessage

@Transactional(readOnly=false)
public String setMessage(String message)
Description copied from interface: JobHandle
Sets the job's message string, and returns the previous value.

Specified by:
setMessage in interface JobHandle
Returns:

setStatusAndMessage

@Transactional(readOnly=false)
public String setStatusAndMessage(String status,
                                                String message)
Description copied from interface: JobHandle
Like JobHandle.setStatus(String) but also sets the message.

Specified by:
setStatusAndMessage in interface JobHandle

processCancelled

public void processCancelled(Process proc)
Specified by:
processCancelled in interface ProcessCallback

processFinished

public void processFinished(Process proc)
Specified by:
processFinished in interface ProcessCallback


OmeroJava Api

Version: Beta4.2.1-r8614-Beta4.2-b41

Copyright © 2009 The University of Dundee. All Rights Reserved.