Package co.paralleluniverse.fibers

Examples of co.paralleluniverse.fibers.Fiber


        topic.subscribe(channel1);
        topic.subscribe(channel2);
        topic.subscribe(channel3);

        Fiber f1 = new Fiber(scheduler, new SuspendableRunnable() {
            @Override
            public void run() throws SuspendExecution, InterruptedException {
                assertThat(channel1.receive(), equalTo("hello"));
                assertThat(channel1.receive(), equalTo("world!"));
            }
        }).start();

        Fiber f2 = new Fiber(scheduler, new SuspendableRunnable() {
            @Override
            public void run() throws SuspendExecution, InterruptedException {
                assertThat(channel2.receive(), equalTo("hello"));
                assertThat(channel2.receive(), equalTo("world!"));
            }
        }).start();

        Fiber f3 = new Fiber(scheduler, new SuspendableRunnable() {
            @Override
            public void run() throws SuspendExecution, InterruptedException {
                assertThat(channel3.receive(), equalTo("hello"));
                assertThat(channel3.receive(), equalTo("world!"));
            }
        }).start();

        Thread.sleep(100);
        topic.send("hello");
        Thread.sleep(100);
        topic.send("world!");

        f1.join();
        f2.join();
        f3.join();
    }
View Full Code Here


        final Channel<String> channel2 = newChannel();
        final Channel<String> channel3 = newChannel();

        final ReceivePortGroup<String> group = new ReceivePortGroup<String>(channel1, channel2, channel3);

        Fiber fib = new Fiber("fiber", scheduler, new SuspendableRunnable() {
            @Override
            public void run() throws SuspendExecution, InterruptedException {
                String m1 = group.receive();
                String m2 = channel2.receive();

                assertThat(m1, equalTo("hello"));
                assertThat(m2, equalTo("world!"));
            }
        }).start();

        Thread.sleep(100);
        channel3.send("hello");
        Thread.sleep(100);
        if (policy != OverflowPolicy.BLOCK) {
            channel1.send("goodbye"); // TransferChannel will block here
            Thread.sleep(100);
        }
        channel2.send("world!");
        fib.join();
    }
View Full Code Here

        final Channel<String> channel2 = newChannel();
        final Channel<String> channel3 = newChannel();

        final ReceivePortGroup<String> group = new ReceivePortGroup<String>(channel1, channel2, channel3);

        Fiber fib = new Fiber("fiber", scheduler, new SuspendableRunnable() {
            @Override
            public void run() throws SuspendExecution, InterruptedException {
                String m1 = group.receive();
                String m2 = channel2.receive();
                String m3 = group.receive(10, TimeUnit.MILLISECONDS);
                String m4 = group.receive(200, TimeUnit.MILLISECONDS);

                assertThat(m1, equalTo("hello"));
                assertThat(m2, equalTo("world!"));
                assertThat(m3, nullValue());
                assertThat(m4, equalTo("foo"));
            }
        }).start();

        Thread.sleep(100);
        channel3.send("hello");
        Thread.sleep(100);
        channel2.send("world!");
        Thread.sleep(100);
        channel1.send("foo");
        fib.join();
    }
View Full Code Here

    }

    public static ParkableForkJoinTask<?> getCurrent() {
        ParkableForkJoinTask ct = getCurrent1();
        if (ct == null && Thread.currentThread() instanceof ForkJoinWorkerThread) { // false in tests
            Fiber f = Fiber.currentFiber();
            if (f != null)
                ct = (ParkableForkJoinTask) f.getTask();
        }
        return ct;
    }
View Full Code Here

    private Strand createStrandForActor(Strand oldStrand, Actor actor) {
        final Strand strand;
        if (oldStrand != null)
            strand = Strand.clone(oldStrand, actor);
        else
            strand = new Fiber(actor);
        actor.setStrand(strand);
        return strand;
    }
View Full Code Here

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        System.setProperty("galaxy.nodeId", Integer.toString(nodeId));
        System.setProperty("galaxy.port", Integer.toString(7050 + nodeId));
        System.setProperty("galaxy.slave_port", Integer.toString(8050 + nodeId));

        new Fiber(new ServerActor(new AbstractServerHandler<SumRequest, Integer, SumRequest>() {
            @Override
            public void init() throws SuspendExecution {
                super.init();
                Actor.currentActor().register("myServer");
                System.out.println(this.toString() + " is ready");
View Full Code Here

        }
    }

    @Test
    public void testMerge() {
        Fiber c = new Fiber((String)null, null, new MergeTest());
        TestsHelper.exec(c);
    }
View Full Code Here

    public void test3() {
        testWithSize(3);
    }
   
    private void testWithSize(int stackSize) {
        Fiber c = new Fiber(null, null, stackSize, this);
        assertEquals(getStackSize(c), stackSize);
        boolean res = TestsHelper.exec(c);
        assertEquals(res, false);
        res = TestsHelper.exec(c);
        assertEquals(res, true);
View Full Code Here

    double result;

    @Test
    public void testDouble() {
        Fiber co = new Fiber((String)null, null, this);
        TestsHelper.exec(co);
        assertEquals(0, result, 1e-8);
        boolean res = TestsHelper.exec(co);
        assertEquals(1, result, 1e-8);
        assertEquals(res, true);
View Full Code Here

    @Test
    public void testThrow() {
        results.clear();
       
        Fiber co = new Fiber((String)null, null, this);
        try {
            exec(co);
            results.add("B");
            exec(co);
            results.add("D");
View Full Code Here

TOP

Related Classes of co.paralleluniverse.fibers.Fiber

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.