use of com.birbit.android.jobqueue.messaging.message.PublicQueryMessage in project android-priority-jobqueue by yigit.
the class JobManager method getJobStatus.
/**
* Returns the current status of a given job
* <p>
* You cannot call this method on the main thread because it may potentially block it for a long
* time.
* @param id The id of the job ({@link Job#getId()})
*
* @return The current status of the Job
*/
public JobStatus getJobStatus(String id) {
assertNotInMainThread();
assertNotInJobManagerThread("Cannot call getJobStatus on JobManager's thread");
PublicQueryMessage message = messageFactory.obtain(PublicQueryMessage.class);
message.set(PublicQueryMessage.JOB_STATUS, id, null);
Integer status = new IntQueryFuture<>(messageQueue, message).getSafe();
return JobStatus.values()[status];
}
use of com.birbit.android.jobqueue.messaging.message.PublicQueryMessage in project android-priority-jobqueue by yigit.
the class JobManager method clear.
/**
* Clears all waiting Jobs in the JobManager. Note that this won't touch any job that is
* currently running.
* <p>
* You cannot call this method on the main thread because it may potentially block it for a long
* time.
*/
public void clear() {
assertNotInMainThread();
assertNotInJobManagerThread("Cannot call clear on JobManager's thread");
final PublicQueryMessage message = messageFactory.obtain(PublicQueryMessage.class);
message.set(PublicQueryMessage.CLEAR, null);
new IntQueryFuture<>(messageQueue, message).getSafe();
}
use of com.birbit.android.jobqueue.messaging.message.PublicQueryMessage in project android-priority-jobqueue by yigit.
the class JobManager method start.
/**
* Starts the JobManager if it is not already running.
*
* @see #stop()
*/
public void start() {
PublicQueryMessage message = messageFactory.obtain(PublicQueryMessage.class);
message.set(PublicQueryMessage.START, null);
messageQueue.post(message);
}
use of com.birbit.android.jobqueue.messaging.message.PublicQueryMessage in project android-priority-jobqueue by yigit.
the class JobManager method countReadyJobs.
/**
* Returns the number of jobs that are ready to be executed but waiting in the queue.
* <p>
* You cannot call this method on the main thread because it may potentially block it for a long
* time.
* @return The number of jobs that are ready to be executed but waiting in the queue.
*/
public int countReadyJobs() {
assertNotInMainThread();
assertNotInJobManagerThread("Cannot call countReadyJobs sync method on JobManager's thread");
PublicQueryMessage message = messageFactory.obtain(PublicQueryMessage.class);
message.set(PublicQueryMessage.COUNT_READY, null);
return new IntQueryFuture<>(messageQueue, message).getSafe();
}
use of com.birbit.android.jobqueue.messaging.message.PublicQueryMessage in project android-priority-jobqueue by yigit.
the class JobManager method internalRunInJobManagerThread.
void internalRunInJobManagerThread(final Runnable runnable) throws Throwable {
final Throwable[] error = new Throwable[1];
final PublicQueryMessage message = messageFactory.obtain(PublicQueryMessage.class);
message.set(PublicQueryMessage.INTERNAL_RUNNABLE, null);
new IntQueryFuture<PublicQueryMessage>(messageQueue, message) {
@Override
public void onResult(int result) {
// this is hacky but alright
try {
runnable.run();
} catch (Throwable t) {
error[0] = t;
}
super.onResult(result);
}
}.getSafe();
if (error[0] != null) {
throw error[0];
}
}
Aggregations