GoroBinderImpl(final Goro goro, final GoroTasksListener listener) { this.goro = goro; this.listener = listener; goro.addTaskListener(listener); }
@Override public void act(final Goro goro) { goro.clear(queueName); } }
protected Goro createGoro() { return delegateExecutor != null ? createWithDelegate(delegateExecutor) : create(); }
@Override public synchronized void act(final Goro goro) { goroFuture = (GoroFuture<T>) goro.schedule(queue, task); if (pendingObservers != null) { pendingObservers.execute(); pendingObservers = null; } notifyAll(); }
@Override public void act(final Goro goro) { goro.getExecutor(queue).execute(command); } }
@Override public void onServiceConnected(final ComponentName name, final IBinder binder) { synchronized (lock) { if (service != null) { throw new GoroException("Already bound and got onServiceConnected from " + name); } service = Goro.from(binder); // delegate listeners if (!scheduledListeners.taskListeners.isEmpty()) { for (GoroListener listener : scheduledListeners.taskListeners) { service.addTaskListener(listener); } scheduledListeners.taskListeners.clear(); } // delegate tasks if (!postponed.isEmpty()) { for (Postponed p : postponed) { p.act(service); } postponed.clear(); } if (oneshot) { doUnbindLocked(); } } }
@Test public void clearShouldBeAppliedAfterBinding() { Callable<?> task1 = mock(Callable.class); goro().schedule("clearedQueue", task1); goro().clear("clearedQueue"); Callable<?> task2 = mock(Callable.class); goro().schedule("clearedQueue", task2); doBinding(); InOrder order = inOrder(serviceInstance); order.verify(serviceInstance).schedule("clearedQueue", task1); order.verify(serviceInstance).clear("clearedQueue"); order.verify(serviceInstance).schedule("clearedQueue", task2); }
@Test public void afterBindingAddRemoveListenerShouldBeDelegated() { doBinding(); GoroListener listener = mock(GoroListener.class); goro().addTaskListener(listener); goro().removeTaskListener(listener); InOrder order = inOrder(serviceInstance); order.verify(serviceInstance).addTaskListener(listener); order.verify(serviceInstance).removeTaskListener(listener); }
@Override public void run() { GoroService.setup(getContext(), Goro.createWithDelegate(executor)); Log.i("GoroTest", "BINDING..."); goro = Goro.from(bindService(new Intent())); assertThat(goro).isNotNull(); bindSyc.countDown(); } });
@Test public void clearShouldNotBePostponedAfterDelegation() { goro = (BoundGoro.BoundGoroImpl) Goro.bindAndAutoReconnectWith(context); goro.bind(); goro.clear("a"); goro.onServiceDisconnected(new ComponentName("any", "any")); verify(serviceInstance).clear("a"); }
@Override public void act(final Goro goro) { goro.removeTaskListener(listener); } });
@Override public void onServiceConnected(final ComponentName name, final IBinder binder) { updateDelegate(Goro.from(binder)); unbindIfRequired(); }
@Provides @Singleton public Goro goro() { return Goro.create(); }
/** * Removes all the pending tasks from a specified queue. * @param queueName queue name, must not be {@code null} */ public final void clear(final String queueName) { if (queueName == null) { throw new IllegalArgumentException("Queue name must not be null"); } removeTasksInQueue(queueName); }
@Provides @Singleton BoundGoro boundGoro() { return Goro.bindAndAutoReconnectWith(context); }
@Override public void run() { GoroService.setup(getContext(), Goro.createWithDelegate(AsyncTask.THREAD_POOL_EXECUTOR)); } });
@Override public <T> ObservableFuture<T> schedule(String queueName, Callable<T> task) { synchronized (lock) { if (service != null) { return service.schedule(queueName, task); } else { BoundFuture<T> future = new BoundFuture<>(queueName, task); postponed.add(future); return future; } } }
@Override public void act(final Goro goro) { goro.getExecutor(queue).execute(command); } }
@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)); if (unbindRequested) { // If unbind is requested before we get a real connection, unbind here, after delegating all buffered calls. unbind(); } }