/** * Returns a {@link ByteArraySerializer} capable of serializing an object graph containing fibers. * * @param includeThreadLocals if true, thread/fiber local storage slots will also be serialised. * You may want to set this to false if you are using frameworks that put * things that cannot be properly serialised into TLS slots, or if the feature * causes other issues. */ public static ByteArraySerializer getFiberSerializer(boolean includeThreadLocals) { return Fiber.getFiberSerializer(includeThreadLocals); }
/** * Returns a {@link ByteArraySerializer} capable of serializing an object graph containing fibers. */ public static ByteArraySerializer getFiberSerializer() { return getFiberSerializer(true); }
/** * Returns a {@link ByteArraySerializer} capable of serializing an object graph containing fibers. */ public static ByteArraySerializer getFiberSerializer() { return Fiber.getFiberSerializer(); }
@Override public void run(Fiber f) { f.record(1, "Fiber", "parkAndSerialize", "Serializing fiber %s", f); writer.write(f, getFiberSerializer()); } }));
/** * Deserializes a fiber from the given byte array and unparks it. * * @param serFiber The byte array containing a fiber's serialized form. * @param scheduler The {@link FiberScheduler} to use for scheduling the fiber. * @return The deserialized, running fiber. */ public static <V> Fiber<V> unparkSerialized(byte[] serFiber, FiberScheduler scheduler) { final Fiber<V> f = (Fiber<V>) getFiberSerializer().read(serFiber); return unparkDeserialized(f, scheduler); }
/** * Hires and resumes/restarts a migrated actor. * * @param ref the {@link ActorRef} of the migrated actor. * @param scheduler the {@link FiberScheduler} on which to schedule this actor, * or {@code null} to schedule the actor on a thread. * @return the ref */ public static <M> ActorRef<M> hire(ActorRef<M> ref, FiberScheduler scheduler) throws SuspendExecution { Actor actor = MigrationService.hire(ref, Fiber.getFiberSerializer()); final Fiber<?> fiber = actor.runner != null ? (Fiber) actor.getStrand() : null; actor.setRef(ref); if (fiber == null) actor.runner = new ActorRunner<>(ref); // actor.runner = fiber != null ? (ActorRunner) fiber.getTarget() : new ActorRunner<>(ref); actor.ref.setImpl(actor); assert ref == actor.ref : ref + " - " + actor.ref; if (fiber != null) Fiber.unparkDeserialized(fiber, scheduler); else { if (scheduler != null) { final FiberFactory ff = scheduler; actor.spawn(ff); } else actor.spawnThread(); } return ref; } //</editor-fold>