Package groovyx.gpars.group

Examples of groovyx.gpars.group.PGroup


            return all;
        }
    }

    public static InternalActor create(final Object groupId) {
        final PGroup group;
        if ("".equals(groupId)) group = Actors.defaultActorPGroup;
        else {
            group = ActiveObjectRegistry.getInstance().findGroupById((String) groupId);
        }
        if (group == null)
View Full Code Here


        for (int index = 0; index <= 3; index++) {
            final int concurrencyLevel = 20;

            // All actors in this group share the same thread pool
            final PGroup group = new DefaultPGroup(new DefaultPool(true, concurrencyLevel));

            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");
            }

            cdl.await(1000, TimeUnit.SECONDS);

            group.shutdown();
            final long t2 = System.currentTimeMillis();
            System.out.println("Time to process " + latchCount + " messages: " + (t2 - t1) + " ms");
            assertEquals("Latch has not been decreased to 0", 0, cdl.getCount());
        }

View Full Code Here

        final StatefulDynamicDispatchActor downloader = new WriteStatefulDynamicDispatchActor();

        downloader.follower = indexer;
        indexer.follower = writer;

        final PGroup group = new DefaultPGroup(new DefaultPool(false, 4));

        writer.setParallelGroup(group);
        indexer.setParallelGroup(group);
        downloader.setParallelGroup(group);
        downloader.follower = indexer;
        indexer.follower = writer;
        writer.silentStart();
        indexer.silentStart();
        downloader.silentStart();

        final long t1 = System.currentTimeMillis();

        long i = 0;
        while (i < 1000000L) {
            downloader.send("Requested " + i);
            i++;
        }

        downloader.send(new StopMessage());
        downloader.join();
        indexer.join();
        writer.join();
        final long t2 = System.currentTimeMillis();

        System.out.println(t2 - t1);
        group.shutdown();
    }
View Full Code Here

     * Retrieves the thread-local value of the active PGroup or the default DataflowGroup
     *
     * @return The PGroup to use for DF within the current thread
     */
    public static PGroup retrieveCurrentDFPGroup() {
        PGroup pGroup = activeParallelGroup.get();
        if (pGroup == null) {
            pGroup = Dataflow.DATA_FLOW_GROUP;
        }
        return pGroup;
    }
View Full Code Here

     * @param group The group to make the default inside the block
     * @param code  The code to run with overriden default
     * @return The value returned from the supplied code block
     */
    public static Object usingGroup(final PGroup group, final Closure code) {
        final PGroup original = activeParallelGroup.get();
        try {
            activeParallelGroup.set(group);
            return code.call();
        } finally {
            activeParallelGroup.set(original);
View Full Code Here

     *
     * @param code The task body to run
     * @return A LazyDataflowVariable, which gets assigned the value returned from the supplied code
     */
    public static <T> Promise<T> lazyTask(final Closure<T> code) {
        final PGroup group = retrieveCurrentDFPGroup();
        return group.lazyTask(code);
    }
View Full Code Here

        numberOfChannels = channels.size();
        disabledDFVs = new boolean[numberOfChannels];
        Arrays.fill(disabledDFVs, false);
        for (int i = 0; i < numberOfChannels; i++) {
            final SelectableChannel<? extends T> channel = channels.get(i);
            final PGroup originalGroup = Dataflow.retrieveCurrentDFPGroup();
            try {
                Dataflow.activeParallelGroup.set(pGroup);
                //noinspection ThisEscapedInObjectConstruction
                channel.wheneverBound(new SelectCallback<T>(this, i, channel));
            } finally {
View Full Code Here

TOP

Related Classes of groovyx.gpars.group.PGroup

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.