Package jersey.repackaged.jsr166e

Examples of jersey.repackaged.jsr166e.StampedLock


    // Vector-only methods

    /** See {@link Vector#firstElement} */
    public E firstElement() {
        final StampedLock lock = this.lock;
        long stamp = lock.tryOptimisticRead();
        Object[] items;
        if ((items = array) != null && count > 0 && items.length > 0) {
            @SuppressWarnings("unchecked") E e = (E)items[0];
            if (lock.validate(stamp))
                return e;
        }
        return lockedFirstElement();
    }
View Full Code Here


    }

    @SuppressWarnings("unchecked") private E lockedFirstElement() {
        Object e = null;
        boolean oobe = false;
        final StampedLock lock = this.lock;
        long stamp = lock.readLock();
        try {
            Object[] items = array;
            if (items != null && count > 0 && items.length > 0)
                e = items[0];
            else
                oobe = true;
        } finally {
            lock.unlockRead(stamp);
        }
        if (oobe)
            throw new NoSuchElementException();
        return (E) e;
    }
View Full Code Here

        return (E) e;
    }

    /** See {@link Vector#lastElement} */
    public E lastElement() {
        final StampedLock lock = this.lock;
        long stamp = lock.tryOptimisticRead();
        Object[] items;
        int i;
        if ((items = array) != null && (i = count - 1) >= 0 &&
            i < items.length) {
            @SuppressWarnings("unchecked") E e = (E)items[i];
            if (lock.validate(stamp))
                return e;
        }
        return lockedLastElement();
    }
View Full Code Here

                lock.unlockWrite(stamp);
            }
        }

        public boolean remove(Object o) {
            final StampedLock lock = list.lock;
            long stamp = lock.writeLock();
            try {
                if (list.rawRemoveAt(findFirstIndex(list.array, o, offset,
                                                    offset + size))) {
                    --size;
                    return true;
                }
                else
                    return false;
            } finally {
                lock.unlockWrite(stamp);
            }
        }
View Full Code Here

                throw new ArrayIndexOutOfBoundsException(toIndex);
            return new ReadMostlyVectorSublist<E>(list, offset+fromIndex, ssize);
        }

        public Object[] toArray() {
            final StampedLock lock = list.lock;
            long stamp = lock.readLock();
            try {
                return list.internalToArray(offset, offset + size);
            } finally {
                lock.unlockRead(stamp);
            }
        }
View Full Code Here

                lock.unlockRead(stamp);
            }
        }

        public <T> T[] toArray(T[] a) {
            final StampedLock lock = list.lock;
            long stamp = lock.readLock();
            try {
                return list.internalToArray(a, offset, offset + size);
            } finally {
                lock.unlockRead(stamp);
            }
        }
View Full Code Here

                lock.unlockRead(stamp);
            }
        }

        public String toString() {
            final StampedLock lock = list.lock;
            long stamp = lock.readLock();
            try {
                return list.internalToString(offset, offset + size);
            } finally {
                lock.unlockRead(stamp);
            }
        }
View Full Code Here

        int origin;
        int fence;
        int lastRet;

        SubItr(ReadMostlyVectorSublist<E> sublist, int index) {
            final StampedLock lock = sublist.list.lock;
            long stamp = lock.readLock();
            try {
                this.sublist = sublist;
                this.list = sublist.list;
                this.lock = lock;
                this.cursor = index;
                this.origin = sublist.offset;
                this.fence = origin + sublist.size;
                this.lastRet = -1;
            } finally {
                this.seq = lock.tryConvertToOptimisticRead(stamp);
            }
            if (index < 0 || cursor > fence)
                throw new ArrayIndexOutOfBoundsException(index);
        }
View Full Code Here

    }

    @SuppressWarnings("unchecked") private E lockedLastElement() {
        Object e = null;
        boolean oobe = false;
        final StampedLock lock = this.lock;
        long stamp = lock.readLock();
        try {
            Object[] items = array;
            int i = count - 1;
            if (items != null && i >= 0 && i < items.length)
                e = items[i];
            else
                oobe = true;
        } finally {
            lock.unlockRead(stamp);
        }
        if (oobe)
            throw new NoSuchElementException();
        return (E) e;
    }
View Full Code Here

    /** See {@link Vector#indexOf(Object, int)} */
    public int indexOf(Object o, int index) {
        if (index < 0)
            throw new ArrayIndexOutOfBoundsException(index);
        int idx;
        final StampedLock lock = this.lock;
        long stamp = lock.readLock();
        try {
            idx = findFirstIndex(array, o, index, count);
        } finally {
            lock.unlockRead(stamp);
        }
        return idx;
    }
View Full Code Here

TOP

Related Classes of jersey.repackaged.jsr166e.StampedLock

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.