/** * Add <code>{@link DispatchTask}</code> to the queue */ public void dispatchAsync(DispatchTask task, long delayMillis) { task.setScheduled(true); dispatch(task, delayMillis); }
/** * Handles request synchronously */ void dispatchRequest(final HttpRequest request) { networkQueue.dispatchAsync(new DispatchTask() { @Override protected void execute() { request.dispatchSync(networkQueue); } }); }
/** * Add <code>{@link DispatchTask}</code> to the queue if it's not already on the queue (this * way you can ensure only one instance of the task is scheduled at a time). After the task is * executed you can schedule it again. * * @return true if task was scheduled */ public boolean dispatchAsyncOnce(DispatchTask task) { return dispatchAsyncOnce(task, 0L); }
@Test public void testSchedulingTasks() { DispatchTask task = new DispatchTask() { @Override protected void execute() { addResult("executed"); } }; DispatchQueue.mainQueue().dispatchAsync(task); DispatchQueue.mainQueue().dispatchAsync(task); dispatchTasks(); assertResult("executed", "executed"); }
private static void notifyFailure(final LoginCallback callback, final String errorMessage) { if (callback != null) { DispatchQueue.mainQueue().dispatchAsync(new DispatchTask() { @Override protected void execute() { callback.onLoginFail(errorMessage); } }); } }
/** * Add <code>{@link DispatchTask}</code> to the queue if it's not already on the queue (this * way you can ensure only one instance of the task is scheduled at a time). After the task is * executed you can schedule it again. * * @return true if task was scheduled */ public boolean dispatchAsyncOnce(DispatchTask task, long delayMillis) { if (!task.isScheduled()) { dispatchAsync(task, delayMillis); return true; } return false; }
/** * Creates a background queue with specified <code>name</code> and dispatch type. */ public static DispatchQueue createBackgroundQueue(String name, DispatchQueueType type) { if (type == DispatchQueueType.Serial) { return new SerialDispatchQueue(name); } if (type == DispatchQueueType.Concurrent) { return new ConcurrentDispatchQueue(name); } throw new IllegalArgumentException("Unexpected queue type: " + type); }
public static MockDispatchQueue overrideMainQueue(boolean runImmediately) { MockDispatchQueue queue = new MockDispatchQueue(runImmediately); overrideMainQueue(queue); return queue; }
private static DispatchQueue createConversationDataQueue() { try { return DispatchQueue.createBackgroundQueue("Apptentive Conversation Data Queue", DispatchQueueType.Serial); } catch (Exception e) { return null; // let unit test handle this } } }
/** * Returns <code>true</code> if code is executing on the main queue */ public static boolean isMainQueue() { return MAIN_QUEUE_CHECKER.isMainQueue(); }
private static DispatchQueue createBackgroundQueue() { return new ConcurrentDispatchQueue("Apptentive Background Queue"); } }
private static DispatchQueue createMainQueue() { try { // this call will fail when running a unit test // we would allow that and make test responsible for setting the implementation return new SerialDispatchQueue(Looper.getMainLooper(), "Main"); } catch (Exception e) { return null; } }
protected void overrideMainQueue(boolean runImmediately) { dispatchQueue = MockDispatchQueue.overrideMainQueue(runImmediately); }
MockAsyncLogWriter(File destDir, int logHistorySize) { super(destDir, new MockDispatchQueue(true), logHistorySize); }
protected void dispatchTasks() { dispatchQueue.dispatchTasks(); }
protected void dispatchOnMainQueue(DispatchTask task) { DispatchQueue.mainQueue().dispatchAsync(task); }
/** * Add <code>{@link DispatchTask}</code> to the queue */ public void dispatchAsync(DispatchTask task) { dispatchAsync(task, 0L); }
private static DispatchQueue createConversationQueue() { try { return DispatchQueue.createBackgroundQueue("Apptentive Queue", DispatchQueueType.Serial); } catch (Exception e) { return null; // let unit test handle this } }
protected void dispatchOnMainQueue(DispatchTask task) { DispatchQueue.mainQueue().dispatchAsync(task); }
public AsyncLogWriter(File destDir, int logHistorySize) { this(destDir, DispatchQueue.createBackgroundQueue("Apptentive Log Queue", DispatchQueueType.Serial), logHistorySize); }