private static void checkThread() { if (!checkMainThread()) { throw new GoroException("Listeners cannot be modified outside the main thread"); } }
private static void checkThread() { if (!checkMainThread()) { throw new GoroException("Listeners cannot be modified outside the main thread"); } }
/*** * Initialize GoroService which will allow you to use {@code Goro.bindXXX} methods. * @param context context instance used to enable GoroService component * @param goro instance of Goro that should be used by the service */ public static void setup(final Context context, final Goro goro) { if (goro == null) { throw new IllegalArgumentException("Goro instance cannot be null"); } if (!Util.checkMainThread()) { throw new IllegalStateException("GoroService.setup must be called on the main thread"); } GoroService.goro = goro; context.getPackageManager().setComponentEnabledSetting( new ComponentName(context, GoroService.class), COMPONENT_ENABLED_STATE_ENABLED, DONT_KILL_APP ); }
private GoroBinderImpl getBinder() { if (binder == null) { if (!Util.checkMainThread()) { throw new IllegalStateException( "Goro binder is being created not in the main thread. " + "This might happen if you invoke GoroService.getGoro() not from the main thread." ); } if (goro == null) { throw new IllegalStateException("GoroService is not initialized. Call GoroService.setup"); } binder = new GoroBinderImpl(goro, new GoroTasksListener()); } return binder; }
@Override public synchronized T get(final long timeout, @SuppressWarnings("NullableProblems") final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { // delegate if (goroFuture != null) { return goroFuture.get(timeout, unit); } if (checkMainThread()) { throw new GoroException("Blocking main thread here will lead to a deadlock"); } if (canceled) { throw new CancellationException("Task was canceled"); } // wait for act() or cancel() wait(unit.toMillis(timeout)); // either we got a delegate if (goroFuture != null) { return goroFuture.get(); } // or we are canceled if (canceled) { throw new CancellationException("Task was canceled"); } // otherwise it's a timeout throw new TimeoutException(); }
@Override public synchronized T get(final long timeout, @SuppressWarnings("NullableProblems") final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { // delegate if (goroFuture != null) { return goroFuture.get(timeout, unit); } if (checkMainThread()) { throw new GoroException("Blocking main thread here will lead to a deadlock"); } if (canceled) { throw new CancellationException("Task was canceled"); } // wait for act() or cancel() wait(unit.toMillis(timeout)); // either we got a delegate if (goroFuture != null) { return goroFuture.get(); } // or we are canceled if (canceled) { throw new CancellationException("Task was canceled"); } // otherwise it's a timeout throw new TimeoutException(); }
@Override public synchronized T get() throws InterruptedException, ExecutionException { // delegate if (goroFuture != null) { return goroFuture.get(); } if (checkMainThread()) { throw new GoroException("Blocking main thread here will lead to a deadlock"); } if (canceled) { throw new CancellationException("Task was canceled"); } // wait for act() or cancel() wait(); // either we got a delegate if (goroFuture != null) { return goroFuture.get(); } // or we are canceled if (canceled) { throw new CancellationException("Task was canceled"); } // wtf? throw new IllegalStateException("get() is unblocked but there is neither result" + " nor cancellation"); }
@Override public synchronized T get() throws InterruptedException, ExecutionException { // delegate if (goroFuture != null) { return goroFuture.get(); } if (checkMainThread()) { throw new GoroException("Blocking main thread here will lead to a deadlock"); } if (canceled) { throw new CancellationException("Task was canceled"); } // wait for act() or cancel() wait(); // either we got a delegate if (goroFuture != null) { return goroFuture.get(); } // or we are canceled if (canceled) { throw new CancellationException("Task was canceled"); } // wtf? throw new IllegalStateException("get() is unblocked but there is neither result" + " nor cancellation"); }