Search in sources :

Example 6 with Job

use of org.cristalise.kernel.entity.agent.Job in project kernel by cristal-ise.

the class UserCodeProcess method run.

@Override
public void run() {
    Thread.currentThread().setName("Usercode Process");
    // subscribe to job list - this will initialise the jobs using the ProxyObserver interface as callback
    agent.subscribe(new MemberSubscription<Job>(this, ClusterType.JOB.getName(), true));
    while (active) {
        Job thisJob = getActualJob();
        if (thisJob != null) {
            String jobKey = thisJob.getItemPath() + ":" + thisJob.getStepPath();
            int transitionId = thisJob.getTransition().getId();
            try {
                if (transitionId == START)
                    start(thisJob, jobKey);
                else if (transitionId == COMPLETE)
                    complete(thisJob, jobKey);
            } catch (InvalidTransitionException ex) {
            // must have already been done by someone else - ignore
            } catch (Exception ex) {
                Logger.error("Error executing job:" + thisJob);
                Logger.error(ex);
            }
        }
        try {
            synchronized (jobs) {
                if (jobs.size() == 0) {
                    Logger.msg("UserCodeProcess.run() - Sleeping");
                    while (active && jobs.size() == 0) jobs.wait(2000);
                }
            }
        } catch (InterruptedException ex) {
        }
    }
    // shut down
    try {
        Gateway.close();
    } catch (Exception ex) {
        Logger.error(ex);
    }
}
Also used : InvalidTransitionException(org.cristalise.kernel.common.InvalidTransitionException) Job(org.cristalise.kernel.entity.agent.Job) ObjectAlreadyExistsException(org.cristalise.kernel.common.ObjectAlreadyExistsException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ScriptErrorException(org.cristalise.kernel.scripting.ScriptErrorException) AccessRightsException(org.cristalise.kernel.common.AccessRightsException) InvalidTransitionException(org.cristalise.kernel.common.InvalidTransitionException)

Example 7 with Job

use of org.cristalise.kernel.entity.agent.Job in project kernel by cristal-ise.

the class UserCodeProcess method remove.

/**
 * Job removal notification from the AgentProxy.
 */
@Override
public void remove(String id) {
    synchronized (jobs) {
        Job job = (Job) jobs.remove(id);
        Logger.msg(7, "UserCodeProcess.remove() - Removed job:" + job);
    }
}
Also used : Job(org.cristalise.kernel.entity.agent.Job)

Aggregations

Job (org.cristalise.kernel.entity.agent.Job)7 ArrayList (java.util.ArrayList)2 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)2 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)1 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)1 InvalidTransitionException (org.cristalise.kernel.common.InvalidTransitionException)1 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)1 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)1 PersistencyException (org.cristalise.kernel.common.PersistencyException)1 GraphPoint (org.cristalise.kernel.graph.model.GraphPoint)1 Transition (org.cristalise.kernel.lifecycle.instance.stateMachine.Transition)1 ScriptErrorException (org.cristalise.kernel.scripting.ScriptErrorException)1