com.path.android.jobqueue
Class JobManager

java.lang.Object
  extended by com.path.android.jobqueue.JobManager
All Implemented Interfaces:
NetworkEventProvider.Listener

public class JobManager
extends java.lang.Object
implements NetworkEventProvider.Listener

a JobManager that supports; -> Persistent / Non Persistent Jobs -> Job Priority -> Running Jobs in Parallel -> Grouping jobs so that they won't run at the same time -> Stats like waiting Job Count


Nested Class Summary
static class JobManager.DefaultQueueFactory
          Default implementation of QueueFactory that creates one SqliteJobQueue and one NonPersistentPriorityQueue both are wrapped inside a CachedJobQueue to improve performance
 
Field Summary
static long NOT_DELAYED_JOB_DELAY
           
static long NOT_RUNNING_SESSION_ID
           
static long NS_PER_MS
           
 
Constructor Summary
JobManager(Context context)
          Default constructor that will create a JobManager with 1 SqliteJobQueue and 1 NonPersistentPriorityQueue
JobManager(Context context, Configuration config)
           
JobManager(Context context, java.lang.String id)
          Default constructor that will create a JobManager with a default Configuration
 
Method Summary
 long addJob(int priority, BaseJob baseJob)
          Deprecated. 
 long addJob(int priority, long delay, BaseJob baseJob)
          Deprecated. 
 long addJob(Job job)
          Adds a new Job to the list and returns an ID for it.
 void addJobInBackground(int priority, BaseJob baseJob)
          Deprecated. 
 void addJobInBackground(int priority, long delay, BaseJob baseJob)
          Deprecated. 
protected  void addJobInBackground(int priority, long delay, BaseJob baseJob, AsyncAddCallback callback)
           
 void addJobInBackground(Job job)
          Non-blocking convenience method to add a job in background thread.
 void addJobInBackground(Job job, AsyncAddCallback callback)
           
 void clear()
           
 int count()
          returns the # of jobs that are waiting to be executed.
 JobStatus getJobStatus(long id, boolean isPersistent)
          Returns the current status of a Job.
 void onNetworkChange(boolean isConnected)
          if NetworkUtil implements NetworkEventProvider, this method is called when network is recovered
 void start()
          restarts the JobManager.
 void stop()
          Stops consuming jobs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NS_PER_MS

public static final long NS_PER_MS
See Also:
Constant Field Values

NOT_RUNNING_SESSION_ID

public static final long NOT_RUNNING_SESSION_ID
See Also:
Constant Field Values

NOT_DELAYED_JOB_DELAY

public static final long NOT_DELAYED_JOB_DELAY
See Also:
Constant Field Values
Constructor Detail

JobManager

public JobManager(Context context)
Default constructor that will create a JobManager with 1 SqliteJobQueue and 1 NonPersistentPriorityQueue

Parameters:
context - job manager will use applicationContext.

JobManager

public JobManager(Context context,
                  java.lang.String id)
Default constructor that will create a JobManager with a default Configuration

Parameters:
context - application context
id - an id that is unique to this JobManager

JobManager

public JobManager(Context context,
                  Configuration config)
Parameters:
context - used to acquire ApplicationContext
config -
Method Detail

stop

public void stop()
Stops consuming jobs. Currently running jobs will be finished but no new jobs will be run.


start

public void start()
restarts the JobManager. Will create a new consumer if necessary.


count

public int count()
returns the # of jobs that are waiting to be executed. This might be a good place to decide whether you should wake your app up on boot etc. to complete pending jobs.

Returns:
# of total jobs.

addJob

public long addJob(Job job)
Adds a new Job to the list and returns an ID for it.

Parameters:
job - to add
Returns:
id for the job.

addJobInBackground

public void addJobInBackground(Job job)
Non-blocking convenience method to add a job in background thread.

Parameters:
job - job to add
See Also:
addJob(Job)

addJobInBackground

public void addJobInBackground(Job job,
                               AsyncAddCallback callback)

getJobStatus

public JobStatus getJobStatus(long id,
                              boolean isPersistent)
Returns the current status of a Job.

You should not call this method on the UI thread because it may make a db request.

This is not a very fast call so try not to make it unless necessary. Consider using events if you need to be informed about a job's lifecycle.

Parameters:
id - the ID, returned by the addJob method
isPersistent - Jobs are added to different queues depending on if they are persistent or not. This is necessary because each queue has independent id sets.
Returns:

clear

public void clear()

onNetworkChange

public void onNetworkChange(boolean isConnected)
if NetworkUtil implements NetworkEventProvider, this method is called when network is recovered

Specified by:
onNetworkChange in interface NetworkEventProvider.Listener
Parameters:
isConnected - network connection state.

addJob

@Deprecated
public long addJob(int priority,
                              BaseJob baseJob)
Deprecated. 

Deprecated, please use addJob(Job).

Adds a job with given priority and returns the JobId.

Parameters:
priority - Higher runs first
baseJob - The actual job to run
Returns:
job id

addJob

@Deprecated
public long addJob(int priority,
                              long delay,
                              BaseJob baseJob)
Deprecated. 

Deprecated, please use addJob(Job).

Adds a job with given priority and returns the JobId.

Parameters:
priority - Higher runs first
delay - number of milliseconds that this job should be delayed
baseJob - The actual job to run
Returns:
a job id. is useless for now but we'll use this to cancel jobs in the future.

addJobInBackground

@Deprecated
public void addJobInBackground(int priority,
                                          BaseJob baseJob)
Deprecated. 

Please use addJobInBackground(Job).

Non-blocking convenience method to add a job in background thread.

See Also:
addJob(priority, job).

addJobInBackground

@Deprecated
public void addJobInBackground(int priority,
                                          long delay,
                                          BaseJob baseJob)
Deprecated. 

Deprecated, please use addJobInBackground(Job).

Non-blocking convenience method to add a job in background thread.

See Also:
addJob(priority, delay, job).

addJobInBackground

protected void addJobInBackground(int priority,
                                  long delay,
                                  BaseJob baseJob,
                                  AsyncAddCallback callback)