Search in sources :

Example 1 with FiberWriter

use of co.paralleluniverse.fibers.FiberWriter in project quasar by puniverse.

the class Actor method migrate.

/**
 * Suspends and migrate the actor.
 * This method suspends the fiber the actor is running in (and is therefore available only for actors running in fibers),
 * so that when the actor is hired, it will continue execution from the point this method was called.
 * This method must be called on a fiber.
 */
public void migrate() throws SuspendExecution {
    record(1, "Actor", "migrate", "Actor %s is migrating.", this);
    verifyOnActorStrand();
    migrating = true;
    preMigrate();
    Fiber.parkAndSerialize(new FiberWriter() {

        @Override
        public void write(Fiber fiber, ByteArraySerializer ser) {
            final byte[] buf = ser.write(Actor.this);
            new Fiber<Void>() {

                @Override
                protected Void run() throws SuspendExecution, InterruptedException {
                    MigrationService.migrate(getGlobalId(), Actor.this, buf);
                    postMigrate();
                    return null;
                }
            }.start();
        }
    });
    migrating = false;
}
Also used : Fiber(co.paralleluniverse.fibers.Fiber) FiberWriter(co.paralleluniverse.fibers.FiberWriter) ByteArraySerializer(co.paralleluniverse.io.serialization.ByteArraySerializer)

Aggregations

Fiber (co.paralleluniverse.fibers.Fiber)1 FiberWriter (co.paralleluniverse.fibers.FiberWriter)1 ByteArraySerializer (co.paralleluniverse.io.serialization.ByteArraySerializer)1