Search in sources :

Example 1 with CancelResultMessage

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

the class CallbackManager method start.

private void start() {
    Thread callbackThread = new Thread(new Runnable() {

        @Override
        public void run() {
            messageQueue.consume(new MessageQueueConsumer() {

                long lastDelivery = Long.MIN_VALUE;

                @Override
                public void onStart() {
                }

                @Override
                public void handleMessage(Message message) {
                    if (message.type == Type.CALLBACK) {
                        CallbackMessage cm = (CallbackMessage) message;
                        deliverMessage(cm);
                        lastDelivery = timer.nanoTime();
                    } else if (message.type == Type.CANCEL_RESULT_CALLBACK) {
                        deliverCancelResult((CancelResultMessage) message);
                        lastDelivery = timer.nanoTime();
                    } else if (message.type == Type.COMMAND) {
                        CommandMessage command = (CommandMessage) message;
                        final int what = command.getWhat();
                        if (what == CommandMessage.QUIT) {
                            messageQueue.stop();
                            started.set(false);
                        } else if (what == CommandMessage.RUNNABLE) {
                            command.getRunnable().run();
                        }
                    } else if (message.type == Type.PUBLIC_QUERY) {
                        ((PublicQueryMessage) message).getCallback().onResult(0);
                    }
                }

                @Override
                public void onIdle() {
                }
            });
        }
    }, "job-manager-callbacks");
    try {
        callbackThread.start();
    } catch (InternalError error) {
        // process is already dying, no reason to crash for this (and hide the real crash)
        JqLog.e(error, "Cannot start a thread. Looks like app is shutting down." + "See issue #294 for details.");
    }
}
Also used : CancelResultMessage(com.birbit.android.jobqueue.messaging.message.CancelResultMessage) CommandMessage(com.birbit.android.jobqueue.messaging.message.CommandMessage) PublicQueryMessage(com.birbit.android.jobqueue.messaging.message.PublicQueryMessage) CallbackMessage(com.birbit.android.jobqueue.messaging.message.CallbackMessage) Message(com.birbit.android.jobqueue.messaging.Message) CallbackMessage(com.birbit.android.jobqueue.messaging.message.CallbackMessage) PublicQueryMessage(com.birbit.android.jobqueue.messaging.message.PublicQueryMessage) CancelResultMessage(com.birbit.android.jobqueue.messaging.message.CancelResultMessage) MessageQueueConsumer(com.birbit.android.jobqueue.messaging.MessageQueueConsumer) CommandMessage(com.birbit.android.jobqueue.messaging.message.CommandMessage)

Example 2 with CancelResultMessage

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

the class CallbackManager method notifyCancelResult.

public void notifyCancelResult(@NonNull CancelResult result, @NonNull CancelResult.AsyncCancelCallback callback) {
    CancelResultMessage message = factory.obtain(CancelResultMessage.class);
    message.set(callback, result);
    messageQueue.post(message);
    startIfNeeded();
}
Also used : CancelResultMessage(com.birbit.android.jobqueue.messaging.message.CancelResultMessage)

Aggregations

CancelResultMessage (com.birbit.android.jobqueue.messaging.message.CancelResultMessage)2 Message (com.birbit.android.jobqueue.messaging.Message)1 MessageQueueConsumer (com.birbit.android.jobqueue.messaging.MessageQueueConsumer)1 CallbackMessage (com.birbit.android.jobqueue.messaging.message.CallbackMessage)1 CommandMessage (com.birbit.android.jobqueue.messaging.message.CommandMessage)1 PublicQueryMessage (com.birbit.android.jobqueue.messaging.message.PublicQueryMessage)1