Package co.paralleluniverse.strands

Examples of co.paralleluniverse.strands.SimpleConditionSynchronizer


     */
    @Override
    @Suspendable
    public V get(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException {
        try {
            final SimpleConditionSynchronizer s = sync;
            if (s != null) {
                Object token = s.register();
                try {
                    final long start = System.nanoTime();
                    long left = unit.toNanos(timeout);
                    final long deadline = start + left;
                    for (int i = 0; sync != null; i++) {
                        s.awaitNanos(i, left);
                        left = deadline - System.nanoTime();
                        if (left <= 0)
                            throw new TimeoutException();
                    }
                } finally {
                    s.unregister(token);
                }
            }
            return value;
        } catch (SuspendExecution e) {
            throw new AssertionError(e);
View Full Code Here


    public final void set(V value) {
        if (sync == null)
            throw new IllegalStateException("Value has already been set (and can only be set once)");
        this.value = value;
        final SimpleConditionSynchronizer s = sync;
        sync = null; // must be done before signal
        s.signalAll();
    }
View Full Code Here

        return value;
    }

    @Override
    public V get() throws InterruptedException, SuspendExecution {
        final SimpleConditionSynchronizer s = sync;
        if (s != null) {
            s.register();
            try {
                for (int i = 0; sync != null; i++)
                    s.await(i);
            } finally {
                s.unregister();
            }
        }
        return value;
    }
View Full Code Here

        return value;
    }

    @Override
    public V get(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException, SuspendExecution {
        final SimpleConditionSynchronizer s = sync;
        if (s != null) {
            s.register();
            try {
                long left = unit.toNanos(timeout);
                for (int i=0; sync != null; i++) {
                    left = s.awaitNanos(i, left);
                    if (left <= 0)
                        throw new TimeoutException();
                }
            } finally {
                s.unregister();
            }
        }
        return value;
    }
View Full Code Here

    private boolean receiveClosed;

    protected QueueChannel(BasicQueue<Message> queue, OverflowPolicy overflowPolicy, boolean singleConsumer) {
        this.queue = queue;
        if (!singleConsumer || queue instanceof CircularBuffer)
            this.sync = new SimpleConditionSynchronizer();
        else
            this.sync = new OwnedSynchronizer();

        this.overflowPolicy = overflowPolicy;
        this.sendersSync = overflowPolicy == OverflowPolicy.BLOCK ? new SimpleConditionSynchronizer() : null;
    }
View Full Code Here

    private boolean receiveClosed;

    protected QueueChannel(BasicQueue<Message> queue, OverflowPolicy overflowPolicy, boolean singleConsumer) {
        this.queue = queue;
        if (!singleConsumer || queue instanceof CircularBuffer)
            this.sync = new SimpleConditionSynchronizer(this);
        else
            this.sync = new OwnedSynchronizer(this);

        this.overflowPolicy = overflowPolicy;
        this.sendersSync = overflowPolicy == OverflowPolicy.BLOCK ? new SimpleConditionSynchronizer(this) : null;
    }
View Full Code Here

    public final void set(V value) {
        if (sync == null)
            throw new IllegalStateException("Value has already been set (and can only be set once)");
        this.value = value;
        final SimpleConditionSynchronizer s = sync;
        sync = null; // must be done before signal
        s.signalAll();
    }
View Full Code Here

    @Override
    @Suspendable
    public V get() throws InterruptedException {
        try {
            final SimpleConditionSynchronizer s = sync;
            if (s != null) {
                s.register();
                try {
                    for (int i = 0; sync != null; i++)
                        s.await(i);
                } finally {
                    s.unregister();
                }
            }
            return value;
        } catch (SuspendExecution e) {
            throw new AssertionError(e);
View Full Code Here

    @Override
    @Suspendable
    public V get(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException {
        try {
            final SimpleConditionSynchronizer s = sync;
            if (s != null) {
                s.register();
                try {
                    final long start = System.nanoTime();
                    long left = unit.toNanos(timeout);
                    final long deadline = start + left;
                    for (int i = 0; sync != null; i++) {
                        s.awaitNanos(i, left);
                        left = deadline - System.nanoTime();
                        if (left <= 0)
                            throw new TimeoutException();
                    }
                } finally {
                    s.unregister();
                }
            }
            return value;
        } catch (SuspendExecution e) {
            throw new AssertionError(e);
View Full Code Here

    private boolean receiveClosed;

    protected QueueChannel(BasicQueue<Message> queue, OverflowPolicy overflowPolicy, boolean singleConsumer) {
        this.queue = queue;
        if (!singleConsumer || queue instanceof CircularBuffer)
            this.sync = new SimpleConditionSynchronizer(this);
        else
            this.sync = new OwnedSynchronizer(this);

        this.overflowPolicy = overflowPolicy;
        this.sendersSync = overflowPolicy == OverflowPolicy.BLOCK ? new SimpleConditionSynchronizer(this) : null;
    }
View Full Code Here

TOP

Related Classes of co.paralleluniverse.strands.SimpleConditionSynchronizer

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.