Package edu.emory.mathcs.backport.java.util.concurrent.locks

Examples of edu.emory.mathcs.backport.java.util.concurrent.locks.ReentrantLock


        public Object poll(long timeout, TimeUnit unit)
            throws InterruptedException {
            long nanos = unit.toNanos(timeout);
            long deadline = Utils.nanoTime() + nanos;
            final ReentrantLock lock = this.lock;
            lock.lockInterruptibly();
            try {
                for (;;) {
                    RunnableScheduledFuture first = queue[0];
                    if (first == null) {
                        if (nanos <= 0) {
                            return null;
                        } else {
                            available.await(nanos, TimeUnit.NANOSECONDS);
                            nanos = deadline - Utils.nanoTime();
                        }
                    } else {
                        long delay = first.getDelay(TimeUnit.NANOSECONDS);
                        if (delay > 0) {
                            if (nanos <= 0)
                                return null;
                            if (delay > nanos)
                                delay = nanos;
                            available.await(delay, TimeUnit.NANOSECONDS);
                            nanos = deadline - Utils.nanoTime();
                        } else
                            return finishPoll(first);
                    }
                }
            } finally {
                lock.unlock();
            }
        }
View Full Code Here


                lock.unlock();
            }
        }

        public void clear() {
            final ReentrantLock lock = this.lock;
            lock.lock();
            try {
                for (int i = 0; i < size; i++) {
                    RunnableScheduledFuture t = queue[i];
                    if (t != null) {
                        queue[i] = null;
                        setIndex(t, -1);
                    }
                }
                size = 0;
            } finally {
                lock.unlock();
            }
        }
View Full Code Here

        public int drainTo(Collection c) {
            if (c == null)
                throw new NullPointerException();
            if (c == this)
                throw new IllegalArgumentException();
            final ReentrantLock lock = this.lock;
            lock.lock();
            try {
                int n = 0;
                for (;;) {
                    RunnableScheduledFuture first = pollExpired();
                    if (first != null) {
                        c.add(first);
                        ++n;
                    }
                    else
                        break;
                }
                if (n > 0)
                    available.signalAll();
                return n;
            } finally {
                lock.unlock();
            }
        }
View Full Code Here

                throw new NullPointerException();
            if (c == this)
                throw new IllegalArgumentException();
            if (maxElements <= 0)
                return 0;
            final ReentrantLock lock = this.lock;
            lock.lock();
            try {
                int n = 0;
                while (n < maxElements) {
                    RunnableScheduledFuture first = pollExpired();
                    if (first != null) {
                        c.add(first);
                        ++n;
                    }
                    else
                        break;
                }
                if (n > 0)
                    available.signalAll();
                return n;
            } finally {
                lock.unlock();
            }
        }
View Full Code Here

                lock.unlock();
            }
        }

        public Object[] toArray() {
            final ReentrantLock lock = this.lock;
            lock.lock();
            try {
                return Arrays.copyOf(queue, size);
            } finally {
                lock.unlock();
            }
        }
View Full Code Here

                lock.unlock();
            }
        }

        public Object[] toArray(Object[] a) {
            final ReentrantLock lock = this.lock;
            lock.lock();
            try {
                if (a.length < size)
                    return (Object[]) Arrays.copyOf(queue, size, a.getClass());
                System.arraycopy(queue, 0, a, 0, size);
                if (a.length > size)
                    a[size] = null;
                return a;
            } finally {
                lock.unlock();
            }
        }
View Full Code Here

    }

    public synchronized Lock getLock(String key) {
        Lock lock = (Lock)this.locks.get(key);
        if (lock == null) {
            lock = new ReentrantLock(true);
            this.locks.put(key, lock);
        }
        return lock;
    }
View Full Code Here

            IoServiceListenerSupport serviceListeners,
            SocketAddress localAddress, IoHandler handler, VmPipe remoteEntry) {
        this.service = service;
        this.serviceConfig = serviceConfig;
        this.serviceListeners = serviceListeners;
        this.lock = new ReentrantLock();
        this.localAddress = localAddress;
        this.remoteAddress = this.serviceAddress = remoteEntry.getAddress();
        this.handler = handler;
        this.filterChain = new VmPipeFilterChain(this);
        this.pendingDataQueue = new Queue();
View Full Code Here

    private ConcurrentMap locks = new ConcurrentHashMap();
   
    public Lock getLock(String id) {
        Lock lock = (Lock) locks.get(id);
        if (lock == null) {
            lock = new ReentrantLock();
            Lock oldLock = (Lock) locks.putIfAbsent(id, lock);
            if (oldLock != null) {
                lock = oldLock;
            }
        }
View Full Code Here

            return -1;
        }

        public boolean remove(Object x) {
            boolean removed;
            final ReentrantLock lock = this.lock;
            lock.lock();
            try {
                int i;
                if (x instanceof ScheduledFutureTask)
                    i = ((ScheduledFutureTask)x).heapIndex;
                else
                    i = indexOf(x);
                if (removed = (i >= 0 && i < size && queue[i] == x)) {
                    setIndex(x, -1);
                    int s = --size;
                    RunnableScheduledFuture replacement = queue[s];
                    queue[s] = null;
                    if (s != i) {
                        siftDown(i, replacement);
                        if (queue[i] == replacement)
                            siftUp(i, replacement);
                    }
                }
            } finally {
                lock.unlock();
            }
            return removed;
        }
View Full Code Here

TOP

Related Classes of edu.emory.mathcs.backport.java.util.concurrent.locks.ReentrantLock

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.