private GoroBinderImpl getBinder() { if (binder == null) { binder = new GoroBinderImpl(createGoro(), new GoroTasksListener()); } return binder; }
/** * Creates a new Goro instance which uses the specified executor to delegate tasks. * @param delegateExecutor executor Goro delegates tasks to * @return instance of Goro */ public static Goro createWithDelegate(final Executor delegateExecutor) { GoroImpl goro = new GoroImpl(); goro.queues.setDelegateExecutor(delegateExecutor); return goro; }
@Override public void addTaskListener(final GoroListener listener) { // main thread => no sync Goro service = this.service; if (service != null) { service.addTaskListener(listener); } else { scheduledListeners.addTaskListener(listener); } }
public void postError(final Callable<?> task, Throwable error) { Message msg = h.obtainMessage(MSG_ERROR); msg.obj = new MessageData(task, error, null); h.sendMessage(msg); }
@Override public void run() { GoroService.setup(getContext(), Goro.createWithDelegate(AsyncTask.THREAD_POOL_EXECUTOR)); } });
@Override public void removeTaskListener(final GoroListener listener) { // main thread => no sync Goro service = this.service; if (service != null) { service.removeTaskListener(listener); } else { scheduledListeners.removeTaskListener(listener); } }
@Override public void onServiceConnected(final ComponentName name, final IBinder binder) { updateDelegate(Goro.from(binder)); unbindIfRequired(); }
private static void checkThread() { if (!checkMainThread()) { throw new GoroException("Listeners cannot be modified outside the main thread"); } }
@Override public Executor getExecutor(final String queueName) { synchronized (lock) { if (service != null) { return service.getExecutor(queueName); } return new PostponeExecutor(queueName); } }
@Override public Executor getExecutor(final String queueName) { synchronized (lock) { if (delegate != null) { return delegate.getExecutor(queueName); } return new PostponeExecutor(queueName); } }
private synchronized void unbindIfRequired() { if (bindRequested && updateDelegate(null)) { bindRequested = false; GoroService.unbind(context, this); } }
@Override public final void addTaskListener(final GoroListener listener) { super.addTaskListener(listener); bindIfRequired(); }
public void postSchedule(final Callable<?> task, final String queue) { Message msg = h.obtainMessage(MSG_SCHEDULE); msg.obj = new MessageData(task, null, queue); h.sendMessage(msg); }
/** * Creates a new Goro instance which uses the specified executor to delegate tasks. * @param delegateExecutor executor Goro delegates tasks to * @return instance of Goro */ public static Goro createWithDelegate(final Executor delegateExecutor) { GoroImpl goro = new GoroImpl(); goro.queues.setDelegateExecutor(delegateExecutor); return goro; }
private static void checkThread() { if (!checkMainThread()) { throw new GoroException("Listeners cannot be modified outside the main thread"); } }
public void postSchedule(final Callable<?> task, final String queue) { Message msg = h.obtainMessage(MSG_SCHEDULE); msg.obj = new MessageData(task, null, queue); h.sendMessage(msg); }
public void postFinish(final Callable<?> task, Object result) { Message msg = h.obtainMessage(MSG_FINISH); msg.obj = new MessageData(task, result, null); h.sendMessage(msg); }
public void postError(final Callable<?> task, Throwable error) { Message msg = h.obtainMessage(MSG_ERROR); msg.obj = new MessageData(task, error, null); h.sendMessage(msg); }
public void postStart(final Callable<?> task) { Message msg = h.obtainMessage(MSG_START); msg.obj = new MessageData(task, null, null); h.sendMessage(msg); }