Examples of Fiber


Examples of co.paralleluniverse.fibers.Fiber

    public void testSelectSendWithClose1() throws Exception {
        final Channel<String> channel1 = newChannel();
        final Channel<String> channel2 = newChannel();
        final Channel<String> channel3 = newChannel();

        Fiber fib = new Fiber("fiber", scheduler, new SuspendableRunnable() {
            @Override
            public void run() throws SuspendExecution, InterruptedException {
                SelectAction<String> sa1 = select(
                        send(channel1, "hi1"),
                        send(channel2, "hi2"),
                        send(channel3, "hi3"));

                SelectAction<String> sa2 = select(
                        send(channel1, "hi1"),
                        send(channel2, "hi2"),
                        send(channel3, "hi3"));

                assertThat(sa1.index(), is(1));
                assertThat(sa2.index(), is(1));
            }
        }).start();

        Thread.sleep(200);

        channel2.close();

        fib.join();
    }
View Full Code Here

Examples of co.paralleluniverse.fibers.Fiber

    public void testSelectSendWithClose2() throws Exception {
        final Channel<String> channel1 = newChannel();
        final Channel<String> channel2 = newChannel();
        final Channel<String> channel3 = newChannel();

        Fiber fib = new Fiber("fiber", scheduler, new SuspendableRunnable() {
            @Override
            public void run() throws SuspendExecution, InterruptedException {
                Strand.sleep(200);
                SelectAction<String> sa1 = select(
                        send(channel1, "hi1"),
                        send(channel2, "hi2"),
                        send(channel3, "hi3"));

                Strand.sleep(200);
                SelectAction<String> sa2 = select(
                        send(channel1, "hi1"),
                        send(channel2, "hi2"),
                        send(channel3, "hi3"));

                assertThat(sa1.index(), is(1));
                assertThat(sa2.index(), is(1));
            }
        }).start();


        channel2.close();

        fib.join();
    }
View Full Code Here

Examples of co.paralleluniverse.fibers.Fiber

    public void testSelectSendTimeout() throws Exception {
        final Channel<String> channel1 = newChannel();
        final Channel<String> channel2 = newChannel();
        final Channel<String> channel3 = newChannel();

        Fiber fib = new Fiber("fiber", scheduler, new SuspendableRunnable() {
            @Override
            public void run() throws SuspendExecution, InterruptedException {
                SelectAction<String> sa1 = select(1, TimeUnit.MILLISECONDS,
                        send(channel1, "hi1"),
                        send(channel2, "hi2"),
                        send(channel3, "hi3"));

                SelectAction<String> sa2 = select(300, TimeUnit.MILLISECONDS,
                        send(channel1, "bye1"),
                        send(channel2, "bye2"),
                        send(channel3, "bye3"));

                assertThat(sa1, is(nullValue()));
                assertThat(sa2.index(), is(2));
            }
        }).start();

        Thread.sleep(200);

        String m1 = channel3.receive();

        assertThat(m1, equalTo("bye3")); // the first send is cancelled

        fib.join();
    }
View Full Code Here

Examples of co.paralleluniverse.fibers.Fiber

    public void testSelectSendWithTimeoutChannel() throws Exception {
        final Channel<String> channel1 = newChannel();
        final Channel<String> channel2 = newChannel();
        final Channel<String> channel3 = newChannel();

        Fiber fib = new Fiber("fiber", scheduler, new SuspendableRunnable() {
            @Override
            public void run() throws SuspendExecution, InterruptedException {
                SelectAction<String> sa1 = select(
                        send(channel1, "hi1"),
                        send(channel2, "hi2"),
                        send(channel3, "hi3"),
                        receive(TimeoutChannel.<String>timeout(1, TimeUnit.MILLISECONDS)));

                SelectAction<String> sa2 = select(
                        send(channel1, "bye1"),
                        send(channel2, "bye2"),
                        send(channel3, "bye3"),
                        receive(TimeoutChannel.<String>timeout(300, TimeUnit.MILLISECONDS)));

                assertThat(sa1.index(), is(3));
                assertThat(sa2.index(), is(2));
            }
        }).start();

        Thread.sleep(200);

        String m1 = channel3.receive();

        assertThat(m1, equalTo("bye3")); // the first send is cancelled

        fib.join();
    }
View Full Code Here

Examples of co.paralleluniverse.fibers.Fiber

        return Channels.newChannel(mailboxSize, policy, singleProducer, singleConsumer);
    }

    void spawn(SuspendableRunnable r) {
        if (fiber)
            new Fiber(scheduler, r).start();
        else
            new Thread(Strand.toRunnable(r)).start();
    }
View Full Code Here

Examples of co.paralleluniverse.fibers.Fiber

            throw new IllegalStateException("A strand can only be cloned after death. " + strand + " isn't dead.");
        if (strand instanceof FiberStrand)
            return clone((Fiber) strand.getUnderlying(), target);

        if (strand instanceof Fiber)
            return new Fiber((Fiber) strand, target);
        else
            return ThreadStrand.get(cloneThread((Thread) strand.getUnderlying(), toRunnable(target)));
    }
View Full Code Here

Examples of co.paralleluniverse.fibers.Fiber

            throw new IllegalStateException("A strand can only be cloned after death. " + strand + " isn't dead.");
        if (strand instanceof FiberStrand)
            return clone((Fiber) strand.getUnderlying(), target);

        if (strand instanceof Fiber)
            return new Fiber((Fiber) strand, target);
        else
            return ThreadStrand.get(cloneThread((Thread) strand.getUnderlying(), toRunnable(target)));
    }
View Full Code Here

Examples of co.paralleluniverse.fibers.Fiber

        int i = 1;

        for (; i < 50; i++)
            sch.send(i);
        Fiber f1 = new Fiber(scheduler, run).start();
        Thread t1 = new Thread(Strand.toRunnable(run));
        t1.start();
        for (; i < 200; i++)
            sch.send(i);
        Fiber f2 = new Fiber(scheduler, run).start();
        Thread t2 = new Thread(Strand.toRunnable(run));
        t2.start();
        for (; i < 600; i++)
            sch.send(i);
        Fiber f3 = new Fiber(scheduler, run).start();
        Thread t3 = new Thread(Strand.toRunnable(run));
        t3.start();
        for (; i < 800; i++)
            sch.send(i);
        Fiber f4 = new Fiber(scheduler, run).start();
        Thread t4 = new Thread(Strand.toRunnable(run));
        t4.start();
        for (; i < 2000; i++)
            sch.send(i);

        sch.close();
        System.out.println("done send");

        Debug.dumpAfter(5000, "ticker.log");
        f1.join();
        System.out.println("f1: " + f1);
        f2.join();
        System.out.println("f2: " + f2);
        f3.join();
        System.out.println("f3: " + f3);
        f4.join();
        System.out.println("f4: " + f4);
        t1.join();
        System.out.println("t1: " + t1);
        t2.join();
        System.out.println("t2: " + t2);
View Full Code Here

Examples of com.sun.xml.internal.ws.api.pipe.Fiber

        configureRequestPacket(packet, requestContext);
        Pool<Tube> pool = tubes;
        if (pool == null)
            throw new WebServiceException("close method has already been invoked"); // TODO: i18n

        Fiber fiber = engine.createFiber();
        // then send it away!
        Tube tube = pool.take();

        try {
            return fiber.runSync(tube, packet);
        } finally {
            // this allows us to capture the packet even when the call failed with an exception.
            // when the call fails with an exception it's no longer a 'reply' but it may provide some information
            // about what went wrong.

            // note that Packet can still be updated after
            // ResponseContext is created.
            Packet reply = (fiber.getPacket() == null) ? packet : fiber.getPacket();
            receiver.setResponseContext(new ResponseContext(reply));

            pool.recycle(tube);
        }
    }
View Full Code Here

Examples of com.sun.xml.internal.ws.api.pipe.Fiber

        final Pool<Tube> pool = tubes;
        if (pool == null)
            throw new WebServiceException("close method has already been invoked"); // TODO: i18n

        Fiber fiber = engine.createFiber();
        // then send it away!
        final Tube tube = pool.take();
        fiber.start(tube, request, new Fiber.CompletionCallback() {
            public void onCompletion(@NotNull Packet response) {
                pool.recycle(tube);
                completionCallback.onCompletion(response);
            }
            public void onCompletion(@NotNull Throwable error) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.