Package co.paralleluniverse.actors

Examples of co.paralleluniverse.actors.LocalActor


        return getCurrentActor(); // new TempActor<Message>(getCurrentActor());
    }

    public static GenResponseMessage call(final Actor actor, GenRequestMessage m, long timeout, TimeUnit unit) throws TimeoutException, InterruptedException, SuspendExecution {

        final LocalActor currentActor;
        if (m.getFrom() instanceof TempActor)
            currentActor = (LocalActor) ((TempActor) m.getFrom()).actor.get();
        else
            currentActor = LocalActor.self();

        assert currentActor != null;

        final Object watch = currentActor.watch(actor);

        if (m.getId() == null)
            m.setId(watch);

        final Object id = m.getId();

        final SelectiveReceiveHelper<Object> helper = new SelectiveReceiveHelper<Object>(currentActor) {
            @Override
            protected void handleLifecycleMessage(LifecycleMessage m) {
                if (m instanceof ExitMessage) {
                    final ExitMessage exit = (ExitMessage) m;
                    if (Objects.equals(exit.getActor(), actor) && exit.getWatch() == watch)
                        throw Exceptions.rethrow(exit.getCause());
                }
                super.handleLifecycleMessage(m);
            }
        };
        try {
            actor.sendSync(m);
            final GenResponseMessage response = (GenResponseMessage) helper.receive(timeout, unit, new MessageProcessor<Object>() {
                @Override
                public boolean process(Object m) throws SuspendExecution, InterruptedException {
                    return (m instanceof GenResponseMessage && id.equals(((GenResponseMessage) m).getId()));
                }
            });
            currentActor.unwatch(actor, watch); // no need to unwatch in case of receiver death, so not doen in finally block

            if (response instanceof GenErrorResponseMessage)
                throw Exceptions.rethrow(((GenErrorResponseMessage) response).getError());
            return response;
        } finally {
View Full Code Here


    private static Actor getCurrentActor() {
        Actor actor = LocalActor.self();
        if (actor == null) {
            // create a "dummy actor" on the current strand
            actor = new LocalActor(Strand.currentStrand(), null, new MailboxConfig(5, OverflowPolicy.THROW)) {
                @Override
                protected Object doRun() throws InterruptedException, SuspendExecution {
                    throw new AssertionError();
                }
            };
View Full Code Here

        }
    }

    private ChildEntry addChild1(ChildSpec spec) {
        LOG.debug("Adding child {}", spec);
        LocalActor actor = null;
        if (spec.builder instanceof LocalActor) {
            actor = (LocalActor) 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

    @Override
    public final Actor addChild(ChildSpec spec) throws SuspendExecution, InterruptedException {
        if (isInActor()) {
            final ChildEntry child = addChild1(spec);

            final LocalActor actor = spec.builder instanceof LocalActor ? (LocalActor) spec.builder : null;
            if (actor == null)
                start(child);
            else
                start(child, actor);
View Full Code Here

        boolean handled = false;
        try {
            if (m instanceof ExitMessage) {
                final ExitMessage death = (ExitMessage) m;
                if (death.getWatch() != null && death.actor instanceof LocalActor) {
                    final LocalActor actor = (LocalActor) 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

                throw new AssertionError();
        }
    }

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

        final LocalActor actor = child.info.builder.build();
        if (actor.getName() == null && child.info.id != null)
            actor.setName(child.info.id);

        LOG.info("{} starting child {}", this, actor);

        if (old != null && actor.getMonitor() == null && old.getMonitor() != null)
            actor.setMonitor(old.getMonitor());
        if (actor.getMonitor() != null)
            actor.getMonitor().addRestart();

        return start(child, actor);
    }
View Full Code Here

TOP

Related Classes of co.paralleluniverse.actors.LocalActor

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.