use of com.birbit.android.jobqueue.messaging.message.CallbackMessage 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.");
}
}
use of com.birbit.android.jobqueue.messaging.message.CallbackMessage in project android-priority-jobqueue by yigit.
the class CallbackManager method notifyOnRun.
public void notifyOnRun(@NonNull Job job, int result) {
if (!hasAnyCallbacks()) {
return;
}
CallbackMessage callback = factory.obtain(CallbackMessage.class);
callback.set(job, CallbackMessage.ON_RUN, result);
messageQueue.post(callback);
}
use of com.birbit.android.jobqueue.messaging.message.CallbackMessage in project android-priority-jobqueue by yigit.
the class CallbackManager method notifyOnCancel.
public void notifyOnCancel(@NonNull Job job, boolean byCancelRequest, @Nullable Throwable throwable) {
if (!hasAnyCallbacks()) {
return;
}
CallbackMessage callback = factory.obtain(CallbackMessage.class);
callback.set(job, CallbackMessage.ON_CANCEL, byCancelRequest, throwable);
messageQueue.post(callback);
}
use of com.birbit.android.jobqueue.messaging.message.CallbackMessage in project android-priority-jobqueue by yigit.
the class CallbackManager method notifyOnAdded.
public void notifyOnAdded(@NonNull Job job) {
if (!hasAnyCallbacks()) {
return;
}
CallbackMessage callback = factory.obtain(CallbackMessage.class);
callback.set(job, CallbackMessage.ON_ADDED);
messageQueue.post(callback);
}
use of com.birbit.android.jobqueue.messaging.message.CallbackMessage in project android-priority-jobqueue by yigit.
the class CallbackManager method notifyOnDone.
public void notifyOnDone(@NonNull Job job) {
if (!hasAnyCallbacks()) {
return;
}
CallbackMessage callback = factory.obtain(CallbackMessage.class);
callback.set(job, CallbackMessage.ON_DONE);
messageQueue.post(callback);
}
Aggregations