com.sun.jini.mahalo
Class Job

java.lang.Object
  extended by com.sun.jini.mahalo.Job
Direct Known Subclasses:
AbortJob, CommitJob, PrepareAndCommitJob, PrepareJob

public abstract class Job
extends Object

A Job manages the division of work for a problem whose solution is obtained by assembling partial results to original problem.

Author:
Sun Microsystems, Inc.

Field Summary
(package private)  int[] attempts
           
(package private) static Logger logger
           
private  int pending
           
private  TaskManager pool
           
(package private)  Object[] results
           
private  Map tasks
           
private  WakeupManager wm
           
 
Constructor Summary
Job(TaskManager pool, WakeupManager wm)
          Create the Job object giving it the TaskManager responsible for the pool of threads which perform the necessary work.
 
Method Summary
(package private)  int attempt(TaskManager.Task who)
          Given a TaskManager.Task, this method returns the current number of attempts it has made.
private  void awaitPending(long waitFor)
           
(package private) abstract  Object computeResult()
          Generate the solution to the original problem.
(package private) abstract  TaskManager.Task[] createTasks()
          Create the tasks required to compute all of the PartialResult objects necessary for the solution to the original problem.
private  void decrementPending()
           
(package private) abstract  Object doWork(TaskManager.Task who, Object param)
          The work performed is implemented here.
protected  WakeupManager getMgr()
          Returns a reference to the WakeupManager which provides the scheduling of tasks created by this Job
protected  TaskManager getPool()
          Returns a reference to the TaskManager which supplies the threads used to executed tasks created by this Job
 boolean isCompleted(long waitFor)
          Check to see if the Job execution has completed.
(package private)  boolean performWork(TaskManager.Task who, Object param)
          Used by a task to do a piece of work and record the number of attempts.
private  void reportDone(TaskManager.Task who, Object param)
           
 void scheduleTasks()
          Schedules tasks for execution
private  void setPending(int num)
           
 void stop()
          Halt all of the work being performed by the Job
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pool

private TaskManager pool

wm

private WakeupManager wm

pending

private int pending

results

Object[] results

attempts

int[] attempts

tasks

private Map tasks

logger

static final Logger logger
Constructor Detail

Job

public Job(TaskManager pool,
           WakeupManager wm)
Create the Job object giving it the TaskManager responsible for the pool of threads which perform the necessary work.

Parameters:
pool - the TaskManager which provides the threads
Method Detail

performWork

boolean performWork(TaskManager.Task who,
                    Object param)
              throws JobException
Used by a task to do a piece of work and record the number of attempts.

Parameters:
who - The task which is performing the work
param - A parameter used in performing the work
Throws:
JobException

attempt

int attempt(TaskManager.Task who)
      throws JobException
Given a TaskManager.Task, this method returns the current number of attempts it has made.

Parameters:
who - The task for which the number of attempts is inquired
Throws:
JobException

doWork

abstract Object doWork(TaskManager.Task who,
                       Object param)
                throws JobException
The work performed is implemented here. A null return value indicates failure while a non-null return value indicates success and contains the result.

Parameters:
who - The task performing the work
param - A parameter used to do the work
Throws:
JobException

createTasks

abstract TaskManager.Task[] createTasks()
Create the tasks required to compute all of the PartialResult objects necessary for the solution to the original problem.


scheduleTasks

public void scheduleTasks()
Schedules tasks for execution


awaitPending

private void awaitPending(long waitFor)

setPending

private void setPending(int num)

decrementPending

private void decrementPending()

getPool

protected TaskManager getPool()
Returns a reference to the TaskManager which supplies the threads used to executed tasks created by this Job


getMgr

protected WakeupManager getMgr()
Returns a reference to the WakeupManager which provides the scheduling of tasks created by this Job


reportDone

private void reportDone(TaskManager.Task who,
                        Object param)
                 throws JobException
Throws:
JobException

isCompleted

public boolean isCompleted(long waitFor)
                    throws JobException
Check to see if the Job execution has completed.

Parameters:
waitFor - The amount of time the caller is willing to wait for the completion status to arrive.
Throws:
JobException

computeResult

abstract Object computeResult()
                       throws JobException
Generate the solution to the original problem. The subclass decides how it computes the final outcome.

Throws:
JobException

stop

public void stop()
Halt all of the work being performed by the Job



Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.