Package co.paralleluniverse.strands.channels

Examples of co.paralleluniverse.strands.channels.IntChannel


    }

    void run() throws ExecutionException, InterruptedException {
        final long start = System.nanoTime();

        final IntChannel managerChannel = Channels.newIntChannel(mailboxSize);
        IntChannel a = managerChannel;
        for (int i = 0; i < N - 1; i++)
            a = createRelayActor(a);
        final IntChannel lastChannel = a;

        Fiber<Integer> manager = new Fiber<Integer>() {
            @Override
            protected Integer run() throws InterruptedException, SuspendExecution {
                lastChannel.send(1); // start things off

                int msg = 0;
                try {
                    for (int i = 0; i < M; i++) {
                        msg = managerChannel.receiveInt();
                        lastChannel.send(msg + 1);
                    }
                    return msg;
                } catch (ReceivePort.EOFException e) {
                    return null;
                }
View Full Code Here


        final long time = TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS);
        System.out.println("Messages: " + totalCount + " Time (ms): " + time);
    }

    private IntChannel createRelayActor(final IntChannel prev) {
        final IntChannel channel = Channels.newIntChannel(mailboxSize);
        Fiber<Void> fiber = new Fiber<Void>() {
            @Override
            protected Void run() throws InterruptedException, SuspendExecution {
                try {
                    for (;;)
                        prev.send(channel.receiveInt() + 1);
                } catch (ReceivePort.EOFException e) {
                    return null;
                }
            }
        };
View Full Code Here

TOP

Related Classes of co.paralleluniverse.strands.channels.IntChannel

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.