Package groovyx.gpars.actor

Examples of groovyx.gpars.actor.Actor


     *
     * @param code The code to invoke for each received message
     * @return A new instance of ReactiveEventBasedThread
     */
    public final Actor reactor(@DelegatesTo(Actor.class) final Closure code) {
        final Actor actor = new ReactiveActor(code);
        actor.setParallelGroup(this);
        actor.start();
        return actor;
    }
View Full Code Here


    @Override
    public void execute(RemoteConnection conn) {
        updateRemoteHost(conn);

        Actor actor = conn.getLocalHost().get(Actor.class, actorName);
        conn.getHost().write(new RemoteActorReplyMsg(actorName, actor));
    }
View Full Code Here

        latch = new CountDownLatch(numberOfClients);
        repeatsPerClient = repeat / numberOfClients;
        clients = new ArrayList<Actor>();

        for (int i = 0; i < numberOfClients; i++) {
            final Actor destination = destinationType.getConstructor(new Class<?>[]{DefaultPGroup.class}).newInstance(group).start();
            final Actor w4 = waypointType.getConstructor(new Class<?>[]{Actor.class, DefaultPGroup.class}).newInstance(destination, group).start();
            final Actor w3 = waypointType.getConstructor(new Class<?>[]{Actor.class, DefaultPGroup.class}).newInstance(w4, group).start();
            final Actor w2 = waypointType.getConstructor(new Class<?>[]{Actor.class, DefaultPGroup.class}).newInstance(w3, group).start();
            final Actor w1 = waypointType.getConstructor(new Class<?>[]{Actor.class, DefaultPGroup.class}).newInstance(w2, group).start();
            clients.add(clientType.getConstructor(new Class<?>[]{Actor.class, CountDownLatch.class, long.class, DefaultPGroup.class, BenchmarkCaliper.class}).newInstance(w1, latch, repeatsPerClient, group, this));
        }
    }
View Full Code Here

            @Override
            protected Integer doRun(final Integer integer) {
                return integer * 2;
            }
        };
        final Actor actor = Actors.reactor(messageHandler);

        assertEquals("Result is not matching", 2, actor.sendAndWait(1));
        assertEquals("Result is not matching", 4, actor.sendAndWait(2));
        assertEquals("Result is not matching", 6, actor.sendAndWait(3));
    }
View Full Code Here

*/
@SuppressWarnings({"MagicNumber"})
public class StatefulActorTest {
    @Test
    public void testStatefulActor() throws Exception {
        final Actor actor = new MyActor();
        actor.start();
        actor.send("Hello");
        actor.send("Hello again");
        actor.send(10);

        actor.send("Bye");
        actor.send("Bye again");
        actor.send(10);

        Thread.sleep(2000L);

    }
View Full Code Here

            final long t1 = System.currentTimeMillis();
            // With each message received counter is decreased by the actors
            final int latchCount = ACTORS * MESSAGES;
            final CountDownLatch cdl = new CountDownLatch(latchCount);
            Actor lastActor = null;

            // Create and chain actors (backwards - the lastActor will be first)
            for (int i = 0; i < ACTORS; i++) {
                final Actor actor = new MessagePassingActor(lastActor, cdl);
                actor.setParallelGroup(group);
                lastActor = actor;
                actor.start();
            }

            for (int i = 0; i < MESSAGES; i++) {
                lastActor.send("Hi");
            }
View Full Code Here

TOP

Related Classes of groovyx.gpars.actor.Actor

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.