Package co.paralleluniverse.actors

Examples of co.paralleluniverse.actors.ActorRef


        return getActor0(name, 0, null);
    }

    @Override
    public <Message> ActorRef<Message> getOrRegisterActor(String name, Callable<ActorRef<Message>> actorFactory) throws SuspendExecution {
        ActorRef cacheValue = rootCache.get(name);
        if (cacheValue != null)
            return cacheValue;
        cacheValue = rootCache.get(name);
        if (cacheValue != null)
            return cacheValue;
View Full Code Here


            } catch (Exception e) {
                replyError(req, e);
            }
        } else if (m1 instanceof ExitMessage) {
            final ExitMessage death = (ExitMessage) m1;
            final ActorRef actor = death.actor;
            final ChildEntry child = findEntry(actor);

            if (child != null) {
                log().info("Detected child death: " + child + ". cause: ", death.cause);
                if (!restartStrategy.onChildDeath(this, child, death.cause)) {
View Full Code Here

        }
    }

    private ChildEntry addChild1(ChildSpec spec) {
        log().debug("Adding child {}", spec);
        ActorRef actor = null;
        if (spec.builder instanceof ActorRef) {
            actor = (ActorRef) spec.builder;
            if (findEntry(actor) != null)
                throw new SupervisorException("Supervisor " + this + " already supervises actor " + actor);
        }

        Object id = spec.getId();
        if (id == null && actor != null)
            id = actor.getName();
        if (id != null && findEntryById(id) != null)
            throw new SupervisorException("Supervisor " + this + " already supervises an actor by the name " + id);
        final ChildEntry child = new ChildEntry(spec, actor);
        children.add(child);
        if (id != null)
View Full Code Here

                    return true;
                }
            // fall through
            case PERMANENT:
                log().info("Supervisor trying to restart child {}. (cause: {})", child, cause);
                final ActorRef actor = child.actor;
                shutdownChild(child, true);
                child.restartHistory.addRestart(now);
                final int numRestarts = child.restartHistory.numRestarts(now - child.spec.unit.toMillis(child.spec.duration));
                if (log().isDebugEnabled())
                    log().debug("Child {} has been restarted {} times in the last {} {}s", child, numRestarts, child.spec.duration, child.spec.unit);
View Full Code Here

                throw new AssertionError();
        }
    }

    private ActorRef<?> start(ChildEntry child) throws SuspendExecution {
        final ActorRef old = child.actor;
        if (old != null && !LocalActor.isDone(old))
            throw new IllegalStateException("Actor " + child.actor + " cannot be restarted because it is not dead");

        final Actor actor = child.spec.builder.build();
        if (actor.getName() == null && child.spec.id != null)
View Full Code Here

            child.actor = null;
        }
    }

    private boolean joinChild(ChildEntry child) throws SuspendExecution, InterruptedException {
        final ActorRef actor = child.actor;

        log().debug("Joining child {}", child);
        if (child.actor != null) {
            try {
                LocalActor.join(actor, child.spec.shutdownDeadline, TimeUnit.MILLISECONDS);
View Full Code Here

    public static void replyError(RequestMessage<?> req, Throwable e) throws SuspendExecution {
        req.getFrom().send(new ErrorResponseMessage(req.getId(), e));
    }

    private static ActorRef getCurrentActor() {
        ActorRef actorRef = LocalActor.self();
        if (actorRef == null) {
            Actor actor = new TempActor(); // create a "dummy actor" on the current strand
            actorRef = actor.ref();
        }
        return actorRef;
View Full Code Here

            ActorRegistry.hasGlobalRegistry();
            ActorRef<Message> ping = new BasicActor<Message, Void>() {
                @Override
                protected Void doRun() throws InterruptedException, SuspendExecution {
                    ActorRef pong;
                    System.out.println("Finding pong...");
                    pong = ActorRegistry.getActor("pong");
                    System.out.println("pong is " + pong);

                    for (int i = 0; i < 3; i++) {
                        pong.send(new Message(self(), PING));
                        Message msg = receive();
                        System.out.println("ping received " + msg.type);
                    }

                    pong.send(new Message(null, FINISHED));
                    return null;
                }
            }.spawn();
            LocalActor.join(ping);
            System.out.println("finished ping");
View Full Code Here

    public static void replyError(RequestMessage<?> req, Throwable e) throws SuspendExecution {
        req.getFrom().send(new ErrorResponseMessage(req.getId(), e));
    }

    private static ActorRef getCurrentActor() {
        ActorRef actorRef = LocalActor.self();
        if (actorRef == null) {
            Actor actor = new TempActor(); // create a "dummy actor" on the current strand
            actorRef = actor.ref();
        }
        return actorRef;
View Full Code Here

        }
    }

    private ChildEntry addChild1(ChildSpec spec) {
        log().debug("Adding child {}", spec);
        ActorRef actor = null;
        if (spec.builder instanceof ActorRef) {
            actor = (ActorRef) spec.builder;
            if (findEntry(actor) != null)
                throw new SupervisorException("Supervisor " + this + " already supervises actor " + actor);
        }

        Object id = spec.getId();
        if (id == null && actor != null)
            id = actor.getName();
        if (id != null && findEntryById(id) != null)
            throw new SupervisorException("Supervisor " + this + " already supervises an actor by the name " + id);
        final ChildEntry child = new ChildEntry(spec, actor);
        children.add(child);
        if (id != null)
View Full Code Here

TOP

Related Classes of co.paralleluniverse.actors.ActorRef

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.