Search in sources :

Example 6 with PublicQueryMessage

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];
}
Also used : PublicQueryMessage(com.birbit.android.jobqueue.messaging.message.PublicQueryMessage)

Example 7 with PublicQueryMessage

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();
}
Also used : PublicQueryMessage(com.birbit.android.jobqueue.messaging.message.PublicQueryMessage)

Example 8 with PublicQueryMessage

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);
}
Also used : PublicQueryMessage(com.birbit.android.jobqueue.messaging.message.PublicQueryMessage)

Example 9 with PublicQueryMessage

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();
}
Also used : PublicQueryMessage(com.birbit.android.jobqueue.messaging.message.PublicQueryMessage)

Example 10 with PublicQueryMessage

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];
    }
}
Also used : PublicQueryMessage(com.birbit.android.jobqueue.messaging.message.PublicQueryMessage) SchedulerConstraint(com.birbit.android.jobqueue.scheduling.SchedulerConstraint)

Aggregations

PublicQueryMessage (com.birbit.android.jobqueue.messaging.message.PublicQueryMessage)11 Message (com.birbit.android.jobqueue.messaging.Message)2 MessageQueueConsumer (com.birbit.android.jobqueue.messaging.MessageQueueConsumer)2 CommandMessage (com.birbit.android.jobqueue.messaging.message.CommandMessage)2 AddJobMessage (com.birbit.android.jobqueue.messaging.message.AddJobMessage)1 CallbackMessage (com.birbit.android.jobqueue.messaging.message.CallbackMessage)1 CancelMessage (com.birbit.android.jobqueue.messaging.message.CancelMessage)1 CancelResultMessage (com.birbit.android.jobqueue.messaging.message.CancelResultMessage)1 ConstraintChangeMessage (com.birbit.android.jobqueue.messaging.message.ConstraintChangeMessage)1 JobConsumerIdleMessage (com.birbit.android.jobqueue.messaging.message.JobConsumerIdleMessage)1 RunJobResultMessage (com.birbit.android.jobqueue.messaging.message.RunJobResultMessage)1 SchedulerMessage (com.birbit.android.jobqueue.messaging.message.SchedulerMessage)1 SchedulerConstraint (com.birbit.android.jobqueue.scheduling.SchedulerConstraint)1 CountDownLatch (java.util.concurrent.CountDownLatch)1