/** * * @param immediateExec Whether the fiber should be executed in the same thread as the callback. Should generally be set to `false`. */ public FiberAsync(boolean immediateExec) { this.fiber = Fiber.currentFiber(); this.immediateExec = immediateExec; }
@Override public void verifyOwner() { assert owner == Fiber.currentFiber() : "This method has been called by a different strand (thread or fiber) than that owning this object"; // if(owner != Fiber.currentFiber()) // throw new RuntimeException("This method has been called by a different strand (thread or fiber) than that owning this object"); }
private static Fiber verifyCurrent() { final Fiber current = currentFiber(); if (current == null) throw new IllegalStateException("Not called from withing a Fiber"); return current; }
private static Fiber verifyParent() { final Fiber parent = currentFiber(); if (parent == null) throw new IllegalStateException("This constructor may only be used from within a Fiber"); return parent; }
private static Fiber verifyParent() { final Fiber parent = currentFiber(); if (parent == null) throw new IllegalStateException("This constructor may only be used from within a Fiber"); return parent; }
public static long getCurrentRun() { Fiber f = currentFiber(); if (f == null) throw new IllegalStateException("Not in fiber"); return f.getRun(); }
public static Stack getStack() { final Fiber currentFiber = Fiber.currentFiber(); if(currentFiber == null) throw new RuntimeException("Not running in a fiber"); return currentFiber.getStack(); }
public static boolean interrupted() { if (Fiber.currentFiber() != null) return Fiber.interrupted(); else return Thread.interrupted(); }
private static FiberScheduler currentScheduler() { final Fiber currentFiber = Fiber.currentFiber(); if (currentFiber == null) throw new IllegalStateException("Method called not within a fiber"); return currentFiber.getScheduler(); }
public static void yield() throws SuspendExecution { if (Fiber.currentFiber() != null) Fiber.yield(); else Thread.yield(); }
public static void parkNanos(Object blocker, long nanos) throws SuspendExecution, InterruptedException { if (Fiber.currentFiber() != null) Fiber.park(blocker, nanos, TimeUnit.NANOSECONDS); else LockSupport.parkNanos(blocker, nanos); }
public static boolean interrupted() { final Fiber current = currentFiber(); if (current == null) throw new IllegalStateException("Not called on a fiber"); final boolean interrupted = current.isInterrupted(); if (interrupted) current.interrupted = false; return interrupted; }
public static Actor currentActor() { final Fiber currentFiber = Fiber.currentFiber(); if (currentFiber == null) return currentActor.get(); final SuspendableCallable target = currentFiber.getTarget(); if (target == null || !(target instanceof Actor)) return null; return (Actor) target; }
public static void parkNanos(long nanos) throws SuspendExecution, InterruptedException { if (Fiber.currentFiber() != null) Fiber.park(nanos, TimeUnit.NANOSECONDS); else LockSupport.parkNanos(nanos); }
public static ParkableForkJoinTask<?> getCurrent() { ParkableForkJoinTask ct = getCurrent1(); if (ct == null && Thread.currentThread() instanceof ForkJoinWorkerThread) { // false in tests Fiber f = Fiber.currentFiber(); if (f != null) ct = (ParkableForkJoinTask) f.getTask(); } return ct; }
/** * Returns the current fiber, if there is one, or the current thread otherwise. * * @return */ public static Strand currentStrand() { final Fiber fiber = Fiber.currentFiber(); if (fiber != null) return create(fiber); else return create(Thread.currentThread()); }
public static void park() throws SuspendExecution, InterruptedException { if (Fiber.currentFiber() != null) Fiber.park(); else LockSupport.park(); }
private static FiberScheduler defaultScheduler() { final Fiber parent = currentFiber(); if (parent == null) return DefaultFiberScheduler.getInstance(); else return parent.getScheduler(); }
public static void dumpStack() { if (Fiber.currentFiber() != null) Fiber.dumpStack(); else Thread.dumpStack(); }
public static void park(Object blocker) throws SuspendExecution, InterruptedException { if (Fiber.currentFiber() != null) Fiber.park(blocker); else LockSupport.park(blocker); }