com.path.android.jobqueue.cachedQueue
Class CachedJobQueue

java.lang.Object
  extended by com.path.android.jobqueue.cachedQueue.CachedJobQueue
All Implemented Interfaces:
JobQueue

public class CachedJobQueue
extends java.lang.Object
implements JobQueue

a class that implements JobQueue interface, wraps another JobQueue and caches results to avoid unnecessary queries to wrapped JobQueue. does very basic caching but should be sufficient for most of the repeated cases element


Constructor Summary
CachedJobQueue(JobQueue delegate)
           
 
Method Summary
 void clear()
          clear all jobs in the queue.
 int count()
          Returns the # of jobs that are waiting to be run
 int countReadyJobs(boolean hasNetwork, java.util.Collection<java.lang.String> excludeGroups)
          counts the # of jobs that can run now.
 JobHolder findJobById(long id)
          returns the job with the given id if it exists in the queue
 java.lang.Long getNextJobDelayUntilNs(boolean hasNetwork)
          returns when the next job should run (in nanoseconds), should return null if there are no jobs to run.
 long insert(JobHolder jobHolder)
          Inserts the given JobHolder, assigns it a unique id and returns the id back Is called when a job is added
 long insertOrReplace(JobHolder jobHolder)
          Does the same thing with insert but the only difference is that if job has an ID, it should replace the existing one should also reset running session id to JobManager.NOT_RUNNING_SESSION_ID Is called when a job is re-added (due to exception during run)
 JobHolder nextJobAndIncRunCount(boolean hasNetwork, java.util.Collection<java.lang.String> excludeGroups)
          Returns the next available job in the data set It should also assign the sessionId as the RunningSessionId and persist that data if necessary.
 void remove(JobHolder jobHolder)
          Removes the job from the data store.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachedJobQueue

public CachedJobQueue(JobQueue delegate)
Method Detail

insert

public long insert(JobHolder jobHolder)
Description copied from interface: JobQueue
Inserts the given JobHolder, assigns it a unique id and returns the id back Is called when a job is added

Specified by:
insert in interface JobQueue
Returns:

insertOrReplace

public long insertOrReplace(JobHolder jobHolder)
Description copied from interface: JobQueue
Does the same thing with insert but the only difference is that if job has an ID, it should replace the existing one should also reset running session id to JobManager.NOT_RUNNING_SESSION_ID Is called when a job is re-added (due to exception during run)

Specified by:
insertOrReplace in interface JobQueue
Returns:

remove

public void remove(JobHolder jobHolder)
Description copied from interface: JobQueue
Removes the job from the data store. Is called after a job is completed (or cancelled)

Specified by:
remove in interface JobQueue

count

public int count()
Description copied from interface: JobQueue
Returns the # of jobs that are waiting to be run

Specified by:
count in interface JobQueue
Returns:

countReadyJobs

public int countReadyJobs(boolean hasNetwork,
                          java.util.Collection<java.lang.String> excludeGroups)
Description copied from interface: JobQueue
counts the # of jobs that can run now. if there are more jobs from the same group, they are count as 1 since they cannot be run in parallel exclude groups are guaranteed to be ordered in natural order

Specified by:
countReadyJobs in interface JobQueue
Returns:

nextJobAndIncRunCount

public JobHolder nextJobAndIncRunCount(boolean hasNetwork,
                                       java.util.Collection<java.lang.String> excludeGroups)
Description copied from interface: JobQueue
Returns the next available job in the data set It should also assign the sessionId as the RunningSessionId and persist that data if necessary. It should filter out all running jobs and exclude groups are guaranteed to be ordered in natural order

Specified by:
nextJobAndIncRunCount in interface JobQueue
Parameters:
hasNetwork - if true, should return any job, if false, should return jobs that do NOT require network
excludeGroups - if provided, jobs from these groups will NOT be returned
Returns:

getNextJobDelayUntilNs

public java.lang.Long getNextJobDelayUntilNs(boolean hasNetwork)
Description copied from interface: JobQueue
returns when the next job should run (in nanoseconds), should return null if there are no jobs to run.

Specified by:
getNextJobDelayUntilNs in interface JobQueue
Parameters:
hasNetwork - if true, should return nanoseconds for any job, if false, should return nanoseconds for next job's delay until.
Returns:

clear

public void clear()
Description copied from interface: JobQueue
clear all jobs in the queue. should probably be called when user logs out.

Specified by:
clear in interface JobQueue

findJobById

public JobHolder findJobById(long id)
Description copied from interface: JobQueue
returns the job with the given id if it exists in the queue

Specified by:
findJobById in interface JobQueue
Parameters:
id - id of the job, returned by insert method
Returns:
JobHolder with the given id or null if it does not exists