Search in sources :

Example 11 with PublicQueryMessage

use of com.birbit.android.jobqueue.messaging.message.PublicQueryMessage in project android-priority-jobqueue by yigit.

the class JobManager method waitUntilConsumersAreFinished.

private void waitUntilConsumersAreFinished(boolean stop) {
    assertNotInMainThread();
    final CountDownLatch latch = new CountDownLatch(1);
    JqLog.v("adding no consumers listener.");
    jobManagerThread.consumerManager.addNoConsumersListener(new Runnable() {

        @Override
        public void run() {
            JqLog.v("received no consumers callback");
            latch.countDown();
            jobManagerThread.consumerManager.removeNoConsumersListener(this);
        }
    });
    if (stop) {
        stop();
    }
    if (jobManagerThread.consumerManager.getWorkerCount() == 0) {
        return;
    }
    try {
        latch.await();
    } catch (InterruptedException ignored) {
    }
    PublicQueryMessage pm = messageFactory.obtain(PublicQueryMessage.class);
    pm.set(PublicQueryMessage.CLEAR, null);
    new IntQueryFuture<>(jobManagerThread.callbackManager.messageQueue, pm).getSafe();
}
Also used : PublicQueryMessage(com.birbit.android.jobqueue.messaging.message.PublicQueryMessage) CountDownLatch(java.util.concurrent.CountDownLatch)

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