You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by bs...@apache.org on 2015/08/21 23:23:00 UTC
[36/51] [partial] incubator-geode git commit: GEODE-77 removing the
old jgroups subproject
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8b2ea77d/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/ReentrantWriterPreferenceReadWriteLock.java
----------------------------------------------------------------------
diff --git a/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/ReentrantWriterPreferenceReadWriteLock.java b/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/ReentrantWriterPreferenceReadWriteLock.java
deleted file mode 100644
index 6b7bf48..0000000
--- a/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/ReentrantWriterPreferenceReadWriteLock.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/** Notice of modification as required by the LGPL
- * This file was modified by Gemstone Systems Inc. on
- * $Date$
- **/
-/*
- File: ReentrantWriterPreferenceReadWriteLock.java
-
- Originally written by Doug Lea and released into the public domain.
- This may be used for any purposes whatsoever without acknowledgment.
- Thanks for the assistance and support of Sun Microsystems Labs,
- and everyone contributing, testing, and using this code.
-
- History:
- Date Who What
- 26aug1998 dl Create public version
- 7sep2000 dl Readers are now also reentrant
- 19jan2001 dl Allow read->write upgrades if the only reader
- 10dec2002 dl Throw IllegalStateException on extra release
-*/
-
-package com.gemstone.org.jgroups.oswego.concurrent;
-import java.util.*;
-
-/**
- * A writer-preference ReadWriteLock that allows both readers and
- * writers to reacquire
- * read or write locks in the style of a ReentrantLock.
- * Readers are not allowed until all write locks held by
- * the writing thread have been released.
- * Among other applications, reentrancy can be useful when
- * write locks are held during calls or callbacks to methods that perform
- * reads under read locks.
- * <p>
- * <b>Sample usage</b>. Here is a code sketch showing how to exploit
- * reentrancy to perform lock downgrading after updating a cache:
- * <pre>
- * class CachedData {
- * Object data;
- * volatile boolean cacheValid;
- * ReentrantWriterPreferenceReadWriteLock rwl = ...
- *
- * void processCachedData() {
- * rwl.readLock().acquire();
- * if (!cacheValid) {
- *
- * // upgrade lock:
- * rwl.readLock().release(); // must release first to obtain writelock
- * rwl.writeLock().acquire();
- * if (!cacheValid) { // recheck
- * data = ...
- * cacheValid = true;
- * }
- * // downgrade lock
- * rwl.readLock().acquire(); // reacquire read without giving up lock
- * rwl.writeLock().release(); // release write, still hold read
- * }
- *
- * use(data);
- * rwl.readLock().release();
- * }
- * }
- * </pre>
- *
- *
- * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>]
- * @see ReentrantLock
- **/
-
-public class ReentrantWriterPreferenceReadWriteLock extends WriterPreferenceReadWriteLock {
-
- /** Number of acquires on write lock by activeWriter_ thread **/
- protected long writeHolds_ = 0;
-
- /** Number of acquires on read lock by any reader thread **/
- protected HashMap readers_ = new HashMap();
-
- /** cache/reuse the special Integer value one to speed up readlocks **/
- protected static final Integer IONE = Integer.valueOf(1);
-
-
- @Override // GemStoneAddition
- protected boolean allowReader() {
- return (activeWriter_ == null && waitingWriters_ == 0) ||
- activeWriter_ == Thread.currentThread();
- }
-
- @Override
- protected synchronized boolean startRead() {
- Thread t = Thread.currentThread();
- Object c = readers_.get(t);
- if (c != null) { // already held -- just increment hold count
- readers_.put(t, Integer.valueOf(((Integer)(c)).intValue()+1));
- ++activeReaders_;
- return true;
- }
- else if (allowReader()) {
- readers_.put(t, IONE);
- ++activeReaders_;
- return true;
- }
- else
- return false;
- }
-
- @Override
- protected synchronized boolean startWrite() {
- if (activeWriter_ == Thread.currentThread()) { // already held; re-acquire
- ++writeHolds_;
- return true;
- }
- else if (writeHolds_ == 0) {
- if (activeReaders_ == 0 ||
- (readers_.size() == 1 &&
- readers_.get(Thread.currentThread()) != null)) {
- activeWriter_ = Thread.currentThread();
- writeHolds_ = 1;
- return true;
- }
- else
- return false;
- }
- else
- return false;
- }
-
-
- @Override
- protected synchronized Signaller endRead() {
- Thread t = Thread.currentThread();
- Object c = readers_.get(t);
- if (c == null)
- throw new IllegalStateException();
- --activeReaders_;
- if (c != IONE) { // more than one hold; decrement count
- int h = ((Integer)(c)).intValue()-1;
- Integer ih = (h == 1)? IONE : Integer.valueOf(h);
- readers_.put(t, ih);
- return null;
- }
- else {
- readers_.remove(t);
-
- if (writeHolds_ > 0) // a write lock is still held by current thread
- return null;
- else if (activeReaders_ == 0 && waitingWriters_ > 0)
- return writerLock_;
- else
- return null;
- }
- }
-
- @Override
- protected synchronized Signaller endWrite() {
- --writeHolds_;
- if (writeHolds_ > 0) // still being held
- return null;
- else {
- activeWriter_ = null;
- if (waitingReaders_ > 0 && allowReader())
- return readerLock_;
- else if (waitingWriters_ > 0)
- return writerLock_;
- else
- return null;
- }
- }
-
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8b2ea77d/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/Rendezvous.java
----------------------------------------------------------------------
diff --git a/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/Rendezvous.java b/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/Rendezvous.java
deleted file mode 100644
index e44c25c..0000000
--- a/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/Rendezvous.java
+++ /dev/null
@@ -1,422 +0,0 @@
-/** Notice of modification as required by the LGPL
- * This file was modified by Gemstone Systems Inc. on
- * $Date$
- **/
-/*
- File: Rendezvous.java
-
- Originally written by Doug Lea and released into the public domain.
- This may be used for any purposes whatsoever without acknowledgment.
- Thanks for the assistance and support of Sun Microsystems Labs,
- and everyone contributing, testing, and using this code.
-
- History:
- Date Who What
- 11Jun1998 dl Create public version
- 30Jul1998 dl Minor code simplifications
-*/
-
-package com.gemstone.org.jgroups.oswego.concurrent;
-
-/**
- * A rendezvous is a barrier that:
- * <ul>
- * <li> Unlike a CyclicBarrier, is not restricted to use
- * with fixed-sized groups of threads.
- * Any number of threads can attempt to enter a rendezvous,
- * but only the predetermined number of parties enter
- * and later become released from the rendezvous at any give time.
- * <li> Enables each participating thread to exchange information
- * with others at the rendezvous point. Each entering thread
- * presents some object on entry to the rendezvous, and
- * returns some object on release. The object returned is
- * the result of a RendezvousFunction that is run once per
- * rendezvous, (it is run by the last-entering thread). By
- * default, the function applied is a rotation, so each
- * thread returns the object given by the next (modulo parties)
- * entering thread. This default function faciliates simple
- * application of a common use of rendezvous, as exchangers.
- * </ul>
- * <p>
- * Rendezvous use an all-or-none breakage model
- * for failed synchronization attempts: If threads
- * leave a rendezvous point prematurely because of timeout
- * or interruption, others will also leave abnormally
- * (via BrokenBarrierException), until
- * the rendezvous is <code>restart</code>ed. This is usually
- * the simplest and best strategy for sharing knowledge
- * about failures among cooperating threads in the most
- * common usages contexts of Rendezvous.
- * <p>
- * While any positive number (including 1) of parties can
- * be handled, the most common case is to have two parties.
- * <p>
- * <b>Sample Usage</b><p>
- * Here are the highlights of a class that uses a Rendezvous to
- * swap buffers between threads so that the thread filling the
- * buffer gets a freshly
- * emptied one when it needs it, handing off the filled one to
- * the thread emptying the buffer.
- * <pre>
- * class FillAndEmpty {
- * Rendezvous exchanger = new Rendezvous(2);
- * Buffer initialEmptyBuffer = ... a made-up type
- * Buffer initialFullBuffer = ...
- *
- * class FillingLoop implements Runnable {
- * public void run() {
- * Buffer currentBuffer = initialEmptyBuffer;
- * try {
- * while (currentBuffer != null) {
- * addToBuffer(currentBuffer);
- * if (currentBuffer.full())
- * currentBuffer = (Buffer)(exchanger.rendezvous(currentBuffer));
- * }
- * }
- * catch (BrokenBarrierException ex) {
- * return;
- * }
- * catch (InterruptedException ex) {
- * Thread.currentThread().interrupt();
- * }
- * }
- * }
- *
- * class EmptyingLoop implements Runnable {
- * public void run() {
- * Buffer currentBuffer = initialFullBuffer;
- * try {
- * while (currentBuffer != null) {
- * takeFromBuffer(currentBuffer);
- * if (currentBuffer.empty())
- * currentBuffer = (Buffer)(exchanger.rendezvous(currentBuffer));
- * }
- * }
- * catch (BrokenBarrierException ex) {
- * return;
- * }
- * catch (InterruptedException ex) {
- * Thread.currentThread().interrupt();
- * }
- * }
- * }
- *
- * void start() {
- * new Thread(new FillingLoop()).start();
- * new Thread(new EmptyingLoop()).start();
- * }
- * }
- * </pre>
- * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>]
-
- **/
-
-public class Rendezvous implements Barrier {
-
- /**
- * Interface for functions run at rendezvous points
- **/
- public interface RendezvousFunction {
- /**
- * Perform some function on the objects presented at
- * a rendezvous. The objects array holds all presented
- * items; one per thread. Its length is the number of parties.
- * The array is ordered by arrival into the rendezvous.
- * So, the last element (at objects[objects.length-1])
- * is guaranteed to have been presented by the thread performing
- * this function. No identifying information is
- * otherwise kept about which thread presented which item.
- * If you need to
- * trace origins, you will need to use an item type for rendezvous
- * that includes identifying information. After return of this
- * function, other threads are released, and each returns with
- * the item with the same index as the one it presented.
- **/
- public void rendezvousFunction(Object[] objects);
- }
-
- /**
- * The default rendezvous function. Rotates the array
- * so that each thread returns an item presented by some
- * other thread (or itself, if parties is 1).
- **/
- public static class Rotator implements RendezvousFunction {
- /** Rotate the array **/
- public void rendezvousFunction(Object[] objects) {
- int lastIdx = objects.length - 1;
- Object first = objects[0];
- for (int i = 0; i < lastIdx; ++i) objects[i] = objects[i+1];
- objects[lastIdx] = first;
- }
- }
-
-
- protected final int parties_;
-
-
- protected boolean broken_ = false;
-
- /**
- * Number of threads that have entered rendezvous
- **/
- protected int entries_ = 0;
-
- /**
- * Number of threads that are permitted to depart rendezvous
- **/
- protected long departures_ = 0;
-
- /**
- * Incoming threads pile up on entry until last set done.
- **/
- protected final Semaphore entryGate_;
-
- /**
- * Temporary holder for items in exchange
- **/
- protected final Object[] slots_;
-
- /**
- * The function to run at rendezvous point
- **/
-
- protected RendezvousFunction rendezvousFunction_;
-
- /**
- * Create a Barrier for the indicated number of parties,
- * and the default Rotator function to run at each barrier point.
- * @exception IllegalArgumentException if parties less than or equal to zero.
- **/
-
- public Rendezvous(int parties) {
- this(parties, new Rotator());
- }
-
- /**
- * Create a Barrier for the indicated number of parties.
- * and the given function to run at each barrier point.
- * @exception IllegalArgumentException if parties less than or equal to zero.
- **/
-
- public Rendezvous(int parties, RendezvousFunction function) {
- if (parties <= 0) throw new IllegalArgumentException();
- parties_ = parties;
- rendezvousFunction_ = function;
- entryGate_ = new WaiterPreferenceSemaphore(parties);
- slots_ = new Object[parties];
- }
-
- /**
- * Set the function to call at the point at which all threads reach the
- * rendezvous. This function is run exactly once, by the thread
- * that trips the barrier. The function is not run if the barrier is
- * broken.
- * @param function the function to run. If null, no function is run.
- * @return the previous function
- **/
-
-
- public synchronized RendezvousFunction setRendezvousFunction(RendezvousFunction function) {
- RendezvousFunction old = rendezvousFunction_;
- rendezvousFunction_ = function;
- return old;
- }
-
- public int parties() { return parties_; }
-
- public synchronized boolean broken() { return broken_; }
-
- /**
- * Reset to initial state. Clears both the broken status
- * and any record of waiting threads, and releases all
- * currently waiting threads with indeterminate return status.
- * This method is intended only for use in recovery actions
- * in which it is somehow known
- * that no thread could possibly be relying on the
- * the synchronization properties of this barrier.
- **/
-
- public void restart() {
- // This is not very good, but probably the best that can be done
- for (;;) {
- synchronized(this) {
- if (entries_ != 0) {
- notifyAll();
- }
- else {
- broken_ = false;
- return;
- }
- }
- Thread.yield();
- }
- }
-
-
- /**
- * Enter a rendezvous; returning after all other parties arrive.
- * @param x the item to present at rendezvous point.
- * By default, this item is exchanged with another.
- * @return an item x given by some thread, and/or processed
- * by the rendezvousFunction.
- * @exception BrokenBarrierException
- * if any other thread
- * in any previous or current barrier
- * since either creation or the last <code>restart</code>
- * operation left the barrier
- * prematurely due to interruption or time-out. (If so,
- * the <code>broken</code> status is also set.)
- * Also returns as
- * broken if the RendezvousFunction encountered a run-time exception.
- * Threads that are noticed to have been
- * interrupted <em>after</em> being released are not considered
- * to have broken the barrier.
- * In all cases, the interruption
- * status of the current thread is preserved, so can be tested
- * by checking <code>Thread.interrupted</code>.
- * @exception InterruptedException if this thread was interrupted
- * during the exchange. If so, <code>broken</code> status is also set.
- **/
-
-
- public Object rendezvous(Object x) throws InterruptedException, BrokenBarrierException {
-// if (Thread.interrupted()) throw new InterruptedException(); // GemStoneAddition not necessary checked in doRendezvous
- return doRendezvous(x, false, 0);
- }
-
- /**
- * Wait msecs to complete a rendezvous.
- * @param x the item to present at rendezvous point.
- * By default, this item is exchanged with another.
- * @param msecs The maximum time to wait.
- * @return an item x given by some thread, and/or processed
- * by the rendezvousFunction.
- * @exception BrokenBarrierException
- * if any other thread
- * in any previous or current barrier
- * since either creation or the last <code>restart</code>
- * operation left the barrier
- * prematurely due to interruption or time-out. (If so,
- * the <code>broken</code> status is also set.)
- * Also returns as
- * broken if the RendezvousFunction encountered a run-time exception.
- * Threads that are noticed to have been
- * interrupted <em>after</em> being released are not considered
- * to have broken the barrier.
- * In all cases, the interruption
- * status of the current thread is preserved, so can be tested
- * by checking <code>Thread.interrupted</code>.
- * @exception InterruptedException if this thread was interrupted
- * during the exchange. If so, <code>broken</code> status is also set.
- * @exception TimeoutException if this thread timed out waiting for
- * the exchange. If the timeout occured while already in the
- * exchange, <code>broken</code> status is also set.
- **/
-
-
- public Object attemptRendezvous(Object x, long msecs)
- throws InterruptedException, TimeoutException, BrokenBarrierException {
-// if (Thread.interrupted()) throw new InterruptedException(); // GemStoneAddition not necessary checked in doRendezvous
- return doRendezvous(x, true, msecs);
- }
-
- protected Object doRendezvous(Object x, boolean timed, long msecs)
- throws InterruptedException, TimeoutException, BrokenBarrierException {
- if (Thread.interrupted()) throw new InterruptedException(); // GemStoneAddition
-
- // rely on semaphore to throw interrupt on entry
-
- long startTime;
-
- if (timed) {
- startTime = System.currentTimeMillis();
- if (!entryGate_.attempt(msecs)) {
- throw new TimeoutException(msecs);
- }
- }
- else {
- startTime = 0;
- entryGate_.acquire();
- }
-
- synchronized(this) {
-
- Object y = null;
-
- int index = entries_++;
- slots_[index] = x;
-
- try {
- // last one in runs function and releases
- if (entries_ == parties_) {
-
- departures_ = entries_;
- notifyAll();
-
- try {
- if (!broken_ && rendezvousFunction_ != null)
- rendezvousFunction_.rendezvousFunction(slots_);
- }
- catch (RuntimeException ex) {
- broken_ = true;
- }
-
- }
-
- else {
-
- while (!broken_ && departures_ < 1) {
- long timeLeft = 0;
- if (timed) {
- timeLeft = msecs - (System.currentTimeMillis() - startTime);
- if (timeLeft <= 0) {
- broken_ = true;
- departures_ = entries_;
- notifyAll();
- throw new TimeoutException(msecs);
- }
- }
-
- try {
- wait(timeLeft);
- }
- catch (InterruptedException ex) {
- if (broken_ || departures_ > 0) { // interrupted after release
- Thread.currentThread().interrupt();
- break;
- }
- else {
- broken_ = true;
- departures_ = entries_;
- notifyAll();
- throw ex;
- }
- }
- }
- }
-
- }
-
- finally {
-
- y = slots_[index];
-
- // Last one out cleans up and allows next set of threads in
- if (--departures_ <= 0) {
- for (int i = 0; i < slots_.length; ++i) slots_[i] = null;
- entryGate_.release(entries_);
- entries_ = 0;
- }
- }
-
- // continue if no IE/TO throw
- if (broken_)
- throw new BrokenBarrierException(index);
- else
- return y;
- }
- }
-
-}
-
-
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8b2ea77d/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/Semaphore.java
----------------------------------------------------------------------
diff --git a/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/Semaphore.java b/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/Semaphore.java
deleted file mode 100644
index 0555376..0000000
--- a/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/Semaphore.java
+++ /dev/null
@@ -1,193 +0,0 @@
-/** Notice of modification as required by the LGPL
- * This file was modified by Gemstone Systems Inc. on
- * $Date$
- **/
-/*
- File: Semaphore.java
-
- Originally written by Doug Lea and released into the public domain.
- This may be used for any purposes whatsoever without acknowledgment.
- Thanks for the assistance and support of Sun Microsystems Labs,
- and everyone contributing, testing, and using this code.
-
- History:
- Date Who What
- 11Jun1998 dl Create public version
- 5Aug1998 dl replaced int counters with longs
- 24Aug1999 dl release(n): screen arguments
-*/
-
-package com.gemstone.org.jgroups.oswego.concurrent;
-
-/**
- * Base class for counting semaphores.
- * Conceptually, a semaphore maintains a set of permits.
- * Each acquire() blocks if necessary
- * until a permit is available, and then takes it.
- * Each release adds a permit. However, no actual permit objects
- * are used; the Semaphore just keeps a count of the number
- * available and acts accordingly.
- * <p>
- * A semaphore initialized to 1 can serve as a mutual exclusion
- * lock.
- * <p>
- * Different implementation subclasses may provide different
- * ordering guarantees (or lack thereof) surrounding which
- * threads will be resumed upon a signal.
- * <p>
- * The default implementation makes NO
- * guarantees about the order in which threads will
- * acquire permits. It is often faster than other implementations.
- * <p>
- * <b>Sample usage.</b> Here is a class that uses a semaphore to
- * help manage access to a pool of items.
- * <pre>
- * class Pool {
- * static final MAX_AVAILABLE = 100;
- * private final Semaphore available = new Semaphore(MAX_AVAILABLE);
- *
- * public Object getItem() throws InterruptedException { // no synch
- * available.acquire();
- * return getNextAvailableItem();
- * }
- *
- * public void putItem(Object x) { // no synch
- * if (markAsUnused(x))
- * available.release();
- * }
- *
- * // Not a particularly efficient data structure; just for demo
- *
- * protected Object[] items = ... whatever kinds of items being managed
- * protected boolean[] used = new boolean[MAX_AVAILABLE];
- *
- * protected synchronized Object getNextAvailableItem() {
- * for (int i = 0; i < MAX_AVAILABLE; ++i) {
- * if (!used[i]) {
- * used[i] = true;
- * return items[i];
- * }
- * }
- * return null; // not reached
- * }
- *
- * protected synchronized boolean markAsUnused(Object item) {
- * for (int i = 0; i < MAX_AVAILABLE; ++i) {
- * if (item == items[i]) {
- * if (used[i]) {
- * used[i] = false;
- * return true;
- * }
- * else
- * return false;
- * }
- * }
- * return false;
- * }
- *
- * }
- *</pre>
- * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>]
-**/
-
-
-public class Semaphore implements Sync {
- /** current number of available permits **/
- protected long permits_;
-
- /**
- * Create a Semaphore with the given initial number of permits.
- * Using a seed of one makes the semaphore act as a mutual exclusion lock.
- * Negative seeds are also allowed, in which case no acquires will proceed
- * until the number of releases has pushed the number of permits past 0.
- **/
- public Semaphore(long initialPermits) { permits_ = initialPermits; }
-
-
- /** Wait until a permit is available, and take one **/
- public void acquire() throws InterruptedException {
- if (Thread.interrupted()) throw new InterruptedException();
- synchronized(this) {
- try {
- while (permits_ <= 0) wait();
- --permits_;
- }
- catch (InterruptedException ex) {
- notify();
- throw ex;
- }
- }
- }
-
- /** Wait at most msecs millisconds for a permit. **/
- public boolean attempt(long msecs) throws InterruptedException {
- if (Thread.interrupted()) throw new InterruptedException();
-
- synchronized(this) {
- if (permits_ > 0) {
- --permits_;
- return true;
- }
- else if (msecs <= 0)
- return false;
- else {
- try {
- long startTime = System.currentTimeMillis();
- long waitTime = msecs;
-
- for (;;) {
- wait(waitTime);
- if (permits_ > 0) {
- --permits_;
- return true;
- }
- else {
- waitTime = msecs - (System.currentTimeMillis() - startTime);
- if (waitTime <= 0)
- return false;
- }
- }
- }
- catch(InterruptedException ex) {
- notify();
- throw ex;
- }
- }
- }
- }
-
- /** Release a permit **/
- public synchronized void release() {
- ++permits_;
- notify();
- }
-
-
- /**
- * Release N permits. <code>release(n)</code> is
- * equivalent in effect to:
- * <pre>
- * for (int i = 0; i < n; ++i) release();
- * </pre>
- * <p>
- * But may be more efficient in some semaphore implementations.
- * @exception IllegalArgumentException if n is negative.
- **/
- public synchronized void release(long n) {
- if (n < 0) throw new IllegalArgumentException("Negative argument");
-
- permits_ += n;
- for (long i = 0; i < n; ++i) notify();
- }
-
- /**
- * Return the current number of available permits.
- * Returns an accurate, but possibly unstable value,
- * that may change immediately after returning.
- **/
- public synchronized long permits() {
- return permits_;
- }
-
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8b2ea77d/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/SemaphoreControlledChannel.java
----------------------------------------------------------------------
diff --git a/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/SemaphoreControlledChannel.java b/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/SemaphoreControlledChannel.java
deleted file mode 100644
index 634594b..0000000
--- a/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/SemaphoreControlledChannel.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/** Notice of modification as required by the LGPL
- * This file was modified by Gemstone Systems Inc. on
- * $Date$
- **/
-/*
- File: SemaphoreControlledChannel.java
-
- Originally written by Doug Lea and released into the public domain.
- This may be used for any purposes whatsoever without acknowledgment.
- Thanks for the assistance and support of Sun Microsystems Labs,
- and everyone contributing, testing, and using this code.
-
- History:
- Date Who What
- 16Jun1998 dl Create public version
- 5Aug1998 dl replaced int counters with longs
- 08dec2001 dl reflective constructor now uses longs too.
-*/
-
-package com.gemstone.org.jgroups.oswego.concurrent;
-import java.lang.reflect.*;
-
-/**
- * Abstract class for channels that use Semaphores to
- * control puts and takes.
- * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>]
- **/
-
-public abstract class SemaphoreControlledChannel implements BoundedChannel {
- protected final Semaphore putGuard_;
- protected final Semaphore takeGuard_;
- protected int capacity_;
-
- /**
- * Create a channel with the given capacity and default
- * semaphore implementation
- * @exception IllegalArgumentException if capacity less or equal to zero
- **/
-
- public SemaphoreControlledChannel(int capacity)
- throws IllegalArgumentException {
- if (capacity <= 0) throw new IllegalArgumentException();
- capacity_ = capacity;
- putGuard_ = new Semaphore(capacity);
- takeGuard_ = new Semaphore(0);
- }
-
-
- /**
- * Create a channel with the given capacity and
- * semaphore implementations instantiated from the supplied class
- * @exception IllegalArgumentException if capacity less or equal to zero.
- * @exception NoSuchMethodException If class does not have constructor
- * that intializes permits
- * @exception SecurityException if constructor information
- * not accessible
- * @exception InstantiationException if semaphore class is abstract
- * @exception IllegalAccessException if constructor cannot be called
- * @exception InvocationTargetException if semaphore constructor throws an
- * exception
- **/
- public SemaphoreControlledChannel(int capacity, Class semaphoreClass)
- throws IllegalArgumentException,
- NoSuchMethodException,
- SecurityException,
- InstantiationException,
- IllegalAccessException,
- InvocationTargetException {
- if (capacity <= 0) throw new IllegalArgumentException();
- capacity_ = capacity;
- Class[] longarg = { Long.TYPE };
- Constructor ctor = semaphoreClass.getDeclaredConstructor(longarg);
- Object[] cap = { Long.valueOf(capacity) };
- putGuard_ = (Semaphore)(ctor.newInstance(/*(Object[]) GemStoneAddition*/cap));
- Object[] zero = { Long.valueOf(0) };
- takeGuard_ = (Semaphore)(ctor.newInstance(/*(Object[]) GemStoneAddition*/zero));
- }
-
-
-
- public int capacity() { return capacity_; }
-
- /**
- * Return the number of elements in the buffer.
- * This is only a snapshot value, that may change
- * immediately after returning.
- **/
-
- public int size() { return (int)(takeGuard_.permits()); }
-
- /**
- * Internal mechanics of put.
- **/
- protected abstract void insert(Object x);
-
- /**
- * Internal mechanics of take.
- **/
- protected abstract Object extract();
-
- public void put(Object x) throws InterruptedException {
- if (x == null) throw new IllegalArgumentException();
- if (Thread.interrupted()) throw new InterruptedException();
- putGuard_.acquire();
- try {
- insert(x);
- takeGuard_.release();
- }
- catch (ClassCastException ex) {
- putGuard_.release();
- throw ex;
- }
- }
-
- public boolean offer(Object x, long msecs) throws InterruptedException {
- if (x == null) throw new IllegalArgumentException();
- if (Thread.interrupted()) throw new InterruptedException();
- if (!putGuard_.attempt(msecs))
- return false;
- else {
- try {
- insert(x);
- takeGuard_.release();
- return true;
- }
- catch (ClassCastException ex) {
- putGuard_.release();
- throw ex;
- }
- }
- }
-
- public Object take() throws InterruptedException {
- if (Thread.interrupted()) throw new InterruptedException();
- takeGuard_.acquire();
- try {
- Object x = extract();
- putGuard_.release();
- return x;
- }
- catch (ClassCastException ex) {
- takeGuard_.release();
- throw ex;
- }
- }
-
- public Object poll(long msecs) throws InterruptedException {
- if (Thread.interrupted()) throw new InterruptedException();
- if (!takeGuard_.attempt(msecs))
- return null;
- else {
- try {
- Object x = extract();
- putGuard_.release();
- return x;
- }
- catch (ClassCastException ex) {
- takeGuard_.release();
- throw ex;
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8b2ea77d/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/Slot.java
----------------------------------------------------------------------
diff --git a/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/Slot.java b/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/Slot.java
deleted file mode 100644
index 75526e3..0000000
--- a/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/Slot.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/** Notice of modification as required by the LGPL
- * This file was modified by Gemstone Systems Inc. on
- * $Date$
- **/
-/*
- File: Slot.java
-
- Originally written by Doug Lea and released into the public domain.
- This may be used for any purposes whatsoever without acknowledgment.
- Thanks for the assistance and support of Sun Microsystems Labs,
- and everyone contributing, testing, and using this code.
-
- History:
- Date Who What
- 11Jun1998 dl Create public version
- 25aug1998 dl added peek
-*/
-
-package com.gemstone.org.jgroups.oswego.concurrent;
-import java.lang.reflect.*;
-
-/**
- * A one-slot buffer, using semaphores to control access.
- * Slots are usually more efficient and controllable than using other
- * bounded buffers implementations with capacity of 1.
- * <p>
- * Among other applications, Slots can be convenient in token-passing
- * designs: Here. the Slot holds a some object serving as a token,
- * that can be obtained
- * and returned by various threads.
- *
- * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>]
-**/
-
-public class Slot extends SemaphoreControlledChannel {
-
- /**
- * Create a buffer with the given capacity, using
- * the supplied Semaphore class for semaphores.
- * @exception NoSuchMethodException If class does not have constructor
- * that intializes permits
- * @exception SecurityException if constructor information
- * not accessible
- * @exception InstantiationException if semaphore class is abstract
- * @exception IllegalAccessException if constructor cannot be called
- * @exception InvocationTargetException if semaphore constructor throws an
- * exception
- **/
-
- public Slot(Class semaphoreClass)
- throws NoSuchMethodException,
- SecurityException,
- InstantiationException,
- IllegalAccessException,
- InvocationTargetException {
- super(1, semaphoreClass);
- }
-
- /**
- * Create a new Slot using default Semaphore implementations
- **/
- public Slot() {
- super(1);
- }
-
- /** The slot **/
- protected Object item_ = null;
-
-
- /** Set the item in preparation for a take **/
- @Override // GemStoneAddition
- protected synchronized void insert(Object x) {
- item_ = x;
- }
-
- /** Take item known to exist **/
- @Override // GemStoneAddition
- protected synchronized Object extract() {
- Object x = item_;
- item_ = null;
- return x;
- }
-
- public synchronized Object peek() {
- return item_;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8b2ea77d/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/Sync.java
----------------------------------------------------------------------
diff --git a/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/Sync.java b/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/Sync.java
deleted file mode 100644
index ac8cb03..0000000
--- a/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/Sync.java
+++ /dev/null
@@ -1,344 +0,0 @@
-/** Notice of modification as required by the LGPL
- * This file was modified by Gemstone Systems Inc. on
- * $Date$
- **/
-/*
- File: Sync.java
-
- Originally written by Doug Lea and released into the public domain.
- This may be used for any purposes whatsoever without acknowledgment.
- Thanks for the assistance and support of Sun Microsystems Labs,
- and everyone contributing, testing, and using this code.
-
- History:
- Date Who What
- 11Jun1998 dl Create public version
- 5Aug1998 dl Added some convenient time constants
-*/
-
-package com.gemstone.org.jgroups.oswego.concurrent;
-
-/**
- * Main interface for locks, gates, and conditions.
- * <p>
- * Sync objects isolate waiting and notification for particular
- * logical states, resource availability, events, and the like that are
- * shared across multiple threads. Use of Syncs sometimes
- * (but by no means always) adds flexibility and efficiency
- * compared to the use of plain java monitor methods
- * and locking, and are sometimes (but by no means always)
- * simpler to program with.
- * <p>
- *
- * Most Syncs are intended to be used primarily (although
- * not exclusively) in before/after constructions such as:
- * <pre>
- * class X {
- * Sync gate;
- * // ...
- *
- * public void m() {
- * try {
- * gate.acquire(); // block until condition holds
- * try {
- * // ... method body
- * }
- * finally {
- * gate.release()
- * }
- * }
- * catch (InterruptedException ex) {
- * // ... evasive action
- * }
- * }
- *
- * public void m2(Sync cond) { // use supplied condition
- * try {
- * if (cond.attempt(10)) { // try the condition for 10 ms
- * try {
- * // ... method body
- * }
- * finally {
- * cond.release()
- * }
- * }
- * }
- * catch (InterruptedException ex) {
- * // ... evasive action
- * }
- * }
- * }
- * </pre>
- * Syncs may be used in somewhat tedious but more flexible replacements
- * for built-in Java synchronized blocks. For example:
- * <pre>
- * class HandSynched {
- * private double state_ = 0.0;
- * private final Sync lock; // use lock type supplied in constructor
- * public HandSynched(Sync l) { lock = l; }
- *
- * public void changeState(double d) {
- * try {
- * lock.acquire();
- * try { state_ = updateFunction(d); }
- * finally { lock.release(); }
- * }
- * catch(InterruptedException ex) { }
- * }
- *
- * public double getState() {
- * double d = 0.0;
- * try {
- * lock.acquire();
- * try { d = accessFunction(state_); }
- * finally { lock.release(); }
- * }
- * catch(InterruptedException ex){}
- * return d;
- * }
- * private double updateFunction(double d) { ... }
- * private double accessFunction(double d) { ... }
- * }
- * </pre>
- * If you have a lot of such methods, and they take a common
- * form, you can standardize this using wrappers. Some of these
- * wrappers are standardized in LockedExecutor, but you can make others.
- * For example:
- * <pre>
- * class HandSynchedV2 {
- * private double state_ = 0.0;
- * private final Sync lock; // use lock type supplied in constructor
- * public HandSynchedV2(Sync l) { lock = l; }
- *
- * protected void runSafely(Runnable r) {
- * try {
- * lock.acquire();
- * try { r.run(); }
- * finally { lock.release(); }
- * }
- * catch (InterruptedException ex) { // propagate without throwing
- * Thread.currentThread().interrupt();
- * }
- * }
- *
- * public void changeState(double d) {
- * runSafely(new Runnable() {
- * public void run() { state_ = updateFunction(d); }
- * });
- * }
- * // ...
- * }
- * </pre>
- * <p>
- * One reason to bother with such constructions is to use deadlock-
- * avoiding back-offs when dealing with locks involving multiple objects.
- * For example, here is a Cell class that uses attempt to back-off
- * and retry if two Cells are trying to swap values with each other
- * at the same time.
- * <pre>
- * class Cell {
- * long value;
- * Sync lock = ... // some sync implementation class
- * void swapValue(Cell other) {
- * for (;;) {
- * try {
- * lock.acquire();
- * try {
- * if (other.lock.attempt(100)) {
- * try {
- * long t = value;
- * value = other.value;
- * other.value = t;
- * return;
- * }
- * finally { other.lock.release(); }
- * }
- * }
- * finally { lock.release(); }
- * }
- * catch (InterruptedException ex) { return; }
- * }
- * }
- * }
- *</pre>
- * <p>
- * Here is an even fancier version, that uses lock re-ordering
- * upon conflict:
- * <pre>
- * class Cell {
- * long value;
- * Sync lock = ...;
- * private static boolean trySwap(Cell a, Cell b) {
- * a.lock.acquire();
- * try {
- * if (!b.lock.attempt(0))
- * return false;
- * try {
- * long t = a.value;
- * a.value = b.value;
- * b.value = t;
- * return true;
- * }
- * finally { other.lock.release(); }
- * }
- * finally { lock.release(); }
- * return false;
- * }
- *
- * void swapValue(Cell other) {
- * try {
- * while (!trySwap(this, other) &&
- * !tryswap(other, this))
- * Thread.sleep(1);
- * }
- * catch (InterruptedException ex) { return; }
- * }
- *}
- *</pre>
- * <p>
- * Interruptions are in general handled as early as possible.
- * Normally, InterruptionExceptions are thrown
- * in acquire and attempt(msec) if interruption
- * is detected upon entry to the method, as well as in any
- * later context surrounding waits.
- * However, interruption status is ignored in release();
- * <p>
- * Timed versions of attempt report failure via return value.
- * If so desired, you can transform such constructions to use exception
- * throws via
- * <pre>
- * if (!c.attempt(timeval)) throw new TimeoutException(timeval);
- * </pre>
- * <p>
- * The TimoutSync wrapper class can be used to automate such usages.
- * <p>
- * All time values are expressed in milliseconds as longs, which have a maximum
- * value of Long.MAX_VALUE, or almost 300,000 centuries. It is not
- * known whether JVMs actually deal correctly with such extreme values.
- * For convenience, some useful time values are defined as static constants.
- * <p>
- * All implementations of the three Sync methods guarantee to
- * somehow employ Java <code>synchronized</code> methods or blocks,
- * and so entail the memory operations described in JLS
- * chapter 17 which ensure that variables are loaded and flushed
- * within before/after constructions.
- * <p>
- * Syncs may also be used in spinlock constructions. Although
- * it is normally best to just use acquire(), various forms
- * of busy waits can be implemented. For a simple example
- * (but one that would probably never be preferable to using acquire()):
- * <pre>
- * class X {
- * Sync lock = ...
- * void spinUntilAcquired() throws InterruptedException {
- * // Two phase.
- * // First spin without pausing.
- * int purespins = 10;
- * for (int i = 0; i < purespins; ++i) {
- * if (lock.attempt(0))
- * return true;
- * }
- * // Second phase - use timed waits
- * long waitTime = 1; // 1 millisecond
- * for (;;) {
- * if (lock.attempt(waitTime))
- * return true;
- * else
- * waitTime = waitTime * 3 / 2 + 1; // increase 50%
- * }
- * }
- * }
- * </pre>
- * <p>
- * In addition pure synchronization control, Syncs
- * may be useful in any context requiring before/after methods.
- * For example, you can use an ObservableSync
- * (perhaps as part of a LayeredSync) in order to obtain callbacks
- * before and after each method invocation for a given class.
- * <p>
-
- * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>]
-**/
-
-
-public interface Sync {
-
- /**
- * Wait (possibly forever) until successful passage.
- * Fail only upon interuption. Interruptions always result in
- * `clean' failures. On failure, you can be sure that it has not
- * been acquired, and that no
- * corresponding release should be performed. Conversely,
- * a normal return guarantees that the acquire was successful.
- **/
-
- public void acquire() throws InterruptedException;
-
- /**
- * Wait at most msecs to pass; report whether passed.
- * <p>
- * The method has best-effort semantics:
- * The msecs bound cannot
- * be guaranteed to be a precise upper bound on wait time in Java.
- * Implementations generally can only attempt to return as soon as possible
- * after the specified bound. Also, timers in Java do not stop during garbage
- * collection, so timeouts can occur just because a GC intervened.
- * So, msecs arguments should be used in
- * a coarse-grained manner. Further,
- * implementations cannot always guarantee that this method
- * will return at all without blocking indefinitely when used in
- * unintended ways. For example, deadlocks may be encountered
- * when called in an unintended context.
- * <p>
- * @param msecs the number of milleseconds to wait.
- * An argument less than or equal to zero means not to wait at all.
- * However, this may still require
- * access to a synchronization lock, which can impose unbounded
- * delay if there is a lot of contention among threads.
- * @return true if acquired
- **/
-
- public boolean attempt(long msecs) throws InterruptedException;
-
- /**
- * Potentially enable others to pass.
- * <p>
- * Because release does not raise exceptions,
- * it can be used in `finally' clauses without requiring extra
- * embedded try/catch blocks. But keep in mind that
- * as with any java method, implementations may
- * still throw unchecked exceptions such as Error or NullPointerException
- * when faced with uncontinuable errors. However, these should normally
- * only be caught by higher-level error handlers.
- **/
-
- public void release();
-
- /** One second, in milliseconds; convenient as a time-out value **/
- public static final long ONE_SECOND = 1000;
-
- /** One minute, in milliseconds; convenient as a time-out value **/
- public static final long ONE_MINUTE = 60 * ONE_SECOND;
-
- /** One hour, in milliseconds; convenient as a time-out value **/
- public static final long ONE_HOUR = 60 * ONE_MINUTE;
-
- /** One day, in milliseconds; convenient as a time-out value **/
- public static final long ONE_DAY = 24 * ONE_HOUR;
-
- /** One week, in milliseconds; convenient as a time-out value **/
- public static final long ONE_WEEK = 7 * ONE_DAY;
-
- /** One year in milliseconds; convenient as a time-out value **/
- // Not that it matters, but there is some variation across
- // standard sources about value at msec precision.
- // The value used is the same as in java.util.GregorianCalendar
- public static final long ONE_YEAR = (long)(365.2425 * ONE_DAY);
-
- /** One century in milliseconds; convenient as a time-out value **/
- public static final long ONE_CENTURY = 100 * ONE_YEAR;
-
-
-}
-
-
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8b2ea77d/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/SyncCollection.java
----------------------------------------------------------------------
diff --git a/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/SyncCollection.java b/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/SyncCollection.java
deleted file mode 100644
index 40a426f..0000000
--- a/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/SyncCollection.java
+++ /dev/null
@@ -1,514 +0,0 @@
-/** Notice of modification as required by the LGPL
- * This file was modified by Gemstone Systems Inc. on
- * $Date$
- **/
-/*
- File: SyncCollection.java
-
- Originally written by Doug Lea and released into the public domain.
- This may be used for any purposes whatsoever without acknowledgment.
- Thanks for the assistance and support of Sun Microsystems Labs,
- and everyone contributing, testing, and using this code.
-
- History:
- Date Who What
- 1Aug1998 dl Create public version
-*/
-
-package com.gemstone.org.jgroups.oswego.concurrent;
-import java.util.*;
-
-/**
- * SyncCollections wrap Sync-based control around java.util.Collections.
- * They are similar in operation to those provided
- * by java.util.Collection.synchronizedCollection, but have
- * several extended capabilities.
- * <p>
- * The Collection interface is conceptually broken into two
- * parts for purposes of synchronization control. The purely inspective
- * reader operations are:
- * <ul>
- * <li> size
- * <li> isEmpty
- * <li> toArray
- * <li> contains
- * <li> containsAll
- * <li> iterator
- * </ul>
- * The possibly mutative writer operations (which are also
- * the set of operations that are allowed to throw
- * UnsupportedOperationException) are:
- * <ul>
- * <li> add
- * <li> addAll
- * <li> remove
- * <li> clear
- * <li> removeAll
- * <li> retainAll
- * </ul>
- *
- * <p>
- * SyncCollections can be used with either Syncs or ReadWriteLocks.
- * When used with
- * single Syncs, the same lock is used as both the reader and writer lock.
- * The SyncCollection class cannot itself guarantee that using
- * a pair of read/write locks will always correctly protect objects, since
- * Collection implementations are not precluded from internally
- * performing hidden unprotected state changes within conceptually read-only
- * operations. However, they do work with current java.util implementations.
- * (Hopefully, implementations that do not provide this natural
- * guarantee will be clearly documentented as such.)
- * <p>
- * This class provides a straight implementation of Collections interface.
- * In order to conform to this interface, sync failures
- * due to interruption do NOT result in InterruptedExceptions.
- * Instead, upon detection of interruption,
- * <ul>
- * <li> All mutative operations convert the interruption to
- * an UnsupportedOperationException, while also propagating
- * the interrupt status of the thread. Thus, unlike normal
- * java.util.Collections, SyncCollections can <em>transiently</em>
- * behave as if mutative operations are not supported.
- * <li> All read-only operations
- * attempt to return a result even upon interruption. In some contexts,
- * such results will be meaningless due to interference, but
- * provide best-effort status indications that can be useful during
- * recovery. The cumulative number of synchronization failures encountered
- * during such operations is accessible using method
- * <code>synchronizationFailures()</code>.
- * Non-zero values may indicate serious program errors.
- * </ul>
- * <p>
- * The iterator() method returns a SyncCollectionIterator with
- * properties and methods that are analogous to those of SyncCollection
- * itself: hasNext and next are read-only, and remove is mutative.
- * These methods allow fine-grained controlled access, but do <em>NOT</em>
- * preclude concurrent modifications from being interleaved with traversals,
- * which may lead to ConcurrentModificationExceptions.
- * However, the class also supports method <code>unprotectedIterator</code>
- * that can be used in conjunction with the <code>readerSync</code> or
- * <code>writerSync</code> methods to perform locked traversals. For example,
- * to protect a block of reads:
- * <pre>
- * Sync lock = coll.readerSync();
- * try {
- * lock.acquire();
- * try {
- * Iterator it = coll.unprotectedIterator();
- * while (it.hasNext())
- * System.out.println(it.next());
- * }
- * finally {
- * lock.release();
- * }
- * }
- * catch (InterruptedException ex) { ... }
- * </pre>
- * If you need to protect blocks of writes, you must use some
- * form of <em>reentrant</em> lock (for example <code>ReentrantLock</code>
- * or <code>ReentrantWriterPreferenceReadWriteLock</code>) as the Sync
- * for the collection in order to allow mutative methods to proceed
- * while the current thread holds the lock. For example, you might
- * need to hold a write lock during an initialization sequence:
- * <pre>
- * Collection c = new SyncCollection(new ArrayList(),
- * new ReentrantWriterPreferenceReadWriteLock());
- * // ...
- * c.writeLock().acquire();
- * try {
- * for (...) {
- * Object x = someStream.readObject();
- * c.add(x); // would block if writeLock not reentrant
- * }
- * }
- * catch (IOException iox) {
- * ...
- * }
- * finally {
- * c.writeLock().release();
- * }
- * catch (InterruptedException ex) { ... }
- * </pre>
- * <p>
- * (It would normally be better practice here to not make the
- * collection accessible until initialization is complete.)
- * <p>
- * This class does not specifically support use of
- * timed synchronization through the attempt method. However,
- * you can obtain this effect via
- * the TimeoutSync class. For example:
- * <pre>
- * Mutex lock = new Mutex();
- * TimeoutSync timedLock = new TimeoutSync(lock, 1000); // 1 sec timeouts
- * Collection c = new SyncCollection(new HashSet(), timedlock);
- * </pre>
- * <p>
- * The same can be done with read-write locks:
- * <pre>
- * ReadWriteLock rwl = new WriterPreferenceReadWriteLock();
- * Sync rlock = new TimeoutSync(rwl.readLock(), 100);
- * Sync wlock = new TimeoutSync(rwl.writeLock(), 100);
- * Collection c = new SyncCollection(new HashSet(), rlock, wlock);
- * </pre>
- * <p>
- * In addition to synchronization control, SyncCollections
- * may be useful in any context requiring before/after methods
- * surrounding collections. For example, you can use ObservableSync
- * to arrange notifications on method calls to collections, as in:
- * <pre>
- * class X {
- * Collection c;
- *
- * static class CollectionObserver implements ObservableSync.SyncObserver {
- * public void onAcquire(Object arg) {
- * Collection coll = (Collection) arg;
- * System.out.println("Starting operation on" + coll);
- * // Other plausible responses include performing integrity
- * // checks on the collection, updating displays, etc
- * }
- * public void onRelease(Object arg) {
- * Collection coll = (Collection) arg;
- * System.out.println("Finished operation on" + coll);
- * }
- * }
- *
- * X() {
- * ObservableSync s = new ObservableSync();
- * c = new SyncCollection(new HashSet(), s);
- * s.setNotificationArgument(c);
- * CollectionObserver obs = new CollectionObserver();
- * s.attach(obs);
- * }
- * ...
- * }
- * </pre>
- *
- * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>]
- * @see LayeredSync
- * @see TimeoutSync
-**/
-
-
-public class SyncCollection implements Collection {
- protected final Collection c_; // Backing Collection
- protected final Sync rd_; // sync for read-only methods
- protected final Sync wr_; // sync for mutative methods
-
- protected final SynchronizedLong syncFailures_ = new SynchronizedLong(0);
-
- /**
- * Create a new SyncCollection protecting the given collection,
- * and using the given sync to control both reader and writer methods.
- * Common, reasonable choices for the sync argument include
- * Mutex, ReentrantLock, and Semaphores initialized to 1.
- * <p>
- * <b>Sample Usage</b>
- * <pre>
- * Collection c = new SyncCollection(new ArrayList(), new Mutex());
- * </pre>
- **/
- public SyncCollection(Collection collection, Sync sync) {
- this (collection, sync, sync);
- }
-
-
- /**
- * Create a new SyncCollection protecting the given collection,
- * and using the given ReadWriteLock to control reader and writer methods.
- * <p>
- * <b>Sample Usage</b>
- * <pre>
- * Collection c = new SyncCollection(new HashSet(),
- * new WriterPreferenceReadWriteLock());
- * </pre>
- **/
- public SyncCollection(Collection collection, ReadWriteLock rwl) {
- this (collection, rwl.readLock(), rwl.writeLock());
- }
-
- /**
- * Create a new SyncCollection protecting the given collection,
- * and using the given pair of locks to control reader and writer methods.
- **/
- public SyncCollection(Collection collection, Sync readLock, Sync writeLock) {
- c_ = collection;
- rd_ = readLock;
- wr_ = writeLock;
- }
-
- /**
- * Return the Sync object managing read-only operations
- **/
-
- public Sync readerSync() {
- return rd_;
- }
-
- /**
- * Return the Sync object managing mutative operations
- **/
-
- public Sync writerSync() {
- return wr_;
- }
-
- /**
- * Return the number of synchronization failures for read-only operations
- **/
- public long syncFailures() {
- return syncFailures_.get();
- }
-
-
- /** Try to acquire sync before a reader operation; record failure **/
- protected boolean beforeRead() {
- try {
- rd_.acquire();
- return false;
- }
- catch (InterruptedException ex) {
- Thread.currentThread().interrupt(); // GemStoneAddition
- syncFailures_.increment();
- return true;
- }
- }
-
- /** Clean up after a reader operation **/
- protected void afterRead(boolean wasInterrupted) {
- if (wasInterrupted) {
- Thread.currentThread().interrupt();
- }
- else
- rd_.release();
- }
-
-
-
- public int size() {
- boolean wasInterrupted = beforeRead();
- try {
- return c_.size();
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public boolean isEmpty() {
- boolean wasInterrupted = beforeRead();
- try {
- return c_.isEmpty();
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public boolean contains(Object o) {
- boolean wasInterrupted = beforeRead();
- try {
- return c_.contains(o);
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public Object[] toArray() {
- boolean wasInterrupted = beforeRead();
- try {
- return c_.toArray();
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public Object[] toArray(Object[] a) {
- boolean wasInterrupted = beforeRead();
- try {
- return c_.toArray(a);
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public boolean containsAll(Collection coll) {
- boolean wasInterrupted = beforeRead();
- try {
- return c_.containsAll(coll);
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
-
- public boolean add(Object o) {
- try {
- wr_.acquire();
- try {
- return c_.add(o);
- }
- finally {
- wr_.release();
- }
- }
- catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
- throw new UnsupportedOperationException();
- }
- }
-
- public boolean remove(Object o) {
- try {
- wr_.acquire();
- try {
- return c_.remove(o);
- }
- finally {
- wr_.release();
- }
- }
- catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
- throw new UnsupportedOperationException();
- }
- }
-
- public boolean addAll(Collection coll) {
- try {
- wr_.acquire();
- try {
- return c_.addAll(coll);
- }
- finally {
- wr_.release();
- }
- }
- catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
- throw new UnsupportedOperationException();
- }
- }
-
- public boolean removeAll(Collection coll) {
- try {
- wr_.acquire();
- try {
- return c_.removeAll(coll);
- }
- finally {
- wr_.release();
- }
- }
- catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
- throw new UnsupportedOperationException();
- }
- }
-
-
- public boolean retainAll(Collection coll) {
- try {
- wr_.acquire();
- try {
- return c_.retainAll(coll);
- }
- finally {
- wr_.release();
- }
- }
- catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
- throw new UnsupportedOperationException();
- }
- }
-
-
- public void clear() {
- try {
- wr_.acquire();
- try {
- c_.clear();
- }
- finally {
- wr_.release();
- }
- }
- catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
- throw new UnsupportedOperationException();
- }
- }
-
-
- /** Return the base iterator of the underlying collection **/
- public Iterator unprotectedIterator() {
- boolean wasInterrupted = beforeRead();
- try {
- return c_.iterator();
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public Iterator iterator() {
- boolean wasInterrupted = beforeRead();
- try {
- return new SyncCollectionIterator(c_.iterator());
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public class SyncCollectionIterator implements Iterator {
- protected final Iterator baseIterator_;
-
- SyncCollectionIterator(Iterator baseIterator) {
- baseIterator_ = baseIterator;
- }
-
- public boolean hasNext() {
- boolean wasInterrupted = beforeRead();
- try {
- return baseIterator_.hasNext();
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public Object next() {
- boolean wasInterrupted = beforeRead();
- try {
- return baseIterator_.next();
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public void remove() {
- try {
- wr_.acquire();
- try {
- baseIterator_.remove();
- }
- finally {
- wr_.release();
- }
- }
- catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
- throw new UnsupportedOperationException();
- }
- }
-
- }
-}
-
-
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8b2ea77d/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/SyncList.java
----------------------------------------------------------------------
diff --git a/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/SyncList.java b/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/SyncList.java
deleted file mode 100644
index 3611b7a..0000000
--- a/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/SyncList.java
+++ /dev/null
@@ -1,327 +0,0 @@
-/** Notice of modification as required by the LGPL
- * This file was modified by Gemstone Systems Inc. on
- * $Date$
- **/
-/*
- File: SyncList.java
-
- Originally written by Doug Lea and released into the public domain.
- This may be used for any purposes whatsoever without acknowledgment.
- Thanks for the assistance and support of Sun Microsystems Labs,
- and everyone contributing, testing, and using this code.
-
- History:
- Date Who What
- 1Aug1998 dl Create public version
-*/
-
-package com.gemstone.org.jgroups.oswego.concurrent;
-import java.util.*;
-
-/**
- * SyncLists wrap Sync-based control around java.util.Lists.
- * They support the following additional reader operations over
- * SyncCollection: hashCode, equals, get, indexOf, lastIndexOf,
- * subList. They support additional writer operations remove(int),
- * set(int), add(int), addAll(int). The corresponding listIterators
- * and are similarly extended.
- * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>]
- * @see SyncCollection
-**/
-
-
-public class SyncList extends SyncCollection implements List {
-
- /**
- * Create a new SyncList protecting the given collection,
- * and using the given sync to control both reader and writer methods.
- * Common, reasonable choices for the sync argument include
- * Mutex, ReentrantLock, and Semaphores initialized to 1.
- **/
- public SyncList(List list, Sync sync) {
- super (list, sync);
- }
-
- /**
- * Create a new SyncList protecting the given list,
- * and using the given ReadWriteLock to control reader and writer methods.
- **/
- public SyncList(List list, ReadWriteLock rwl) {
- super (list, rwl.readLock(), rwl.writeLock());
- }
-
- /**
- * Create a new SyncList protecting the given list,
- * and using the given pair of locks to control reader and writer methods.
- **/
- public SyncList(List list, Sync readLock, Sync writeLock) {
- super(list, readLock, writeLock);
- }
-
-
- protected List baseList() {
- return (List)c_;
- }
-
-
- @Override // GemStoneAddition
- public int hashCode() {
- boolean wasInterrupted = beforeRead();
- try {
- return c_.hashCode();
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- @Override // GemStoneAddition
- public boolean equals(Object o) {
- boolean wasInterrupted = beforeRead();
- try {
- return c_.equals(o);
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public Object get(int index) {
- boolean wasInterrupted = beforeRead();
- try {
- return baseList().get(index);
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public int indexOf(Object o) {
- boolean wasInterrupted = beforeRead();
- try {
- return baseList().indexOf(o);
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
-
- public int lastIndexOf(Object o) {
- boolean wasInterrupted = beforeRead();
- try {
- return baseList().lastIndexOf(o);
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
-
-
- public List subList(int fromIndex, int toIndex) {
- boolean wasInterrupted = beforeRead();
- try {
- return new SyncList(baseList().subList(fromIndex, toIndex), rd_, wr_);
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public Object set(int index, Object o) {
- try {
- wr_.acquire();
- try {
- return baseList().set(index, o);
- }
- finally {
- wr_.release();
- }
- }
- catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
- throw new UnsupportedOperationException();
- }
- }
-
-
- public Object remove(int index) {
- try {
- wr_.acquire();
- try {
- return baseList().remove(index);
- }
- finally {
- wr_.release();
- }
- }
- catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
- throw new UnsupportedOperationException();
- }
- }
-
- public void add(int index, Object o) {
- try {
- wr_.acquire();
- try {
- baseList().add(index, o);
- }
- finally {
- wr_.release();
- }
- }
- catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
- throw new UnsupportedOperationException();
- }
- }
-
- public boolean addAll(int index, Collection coll) {
- try {
- wr_.acquire();
- try {
- return baseList().addAll(index, coll);
- }
- finally {
- wr_.release();
- }
- }
- catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
- throw new UnsupportedOperationException();
- }
- }
-
- public ListIterator unprotectedListIterator() {
- boolean wasInterrupted = beforeRead();
- try {
- return baseList().listIterator();
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public ListIterator listIterator() {
- boolean wasInterrupted = beforeRead();
- try {
- return new SyncCollectionListIterator(baseList().listIterator());
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public ListIterator unprotectedListIterator(int index) {
- boolean wasInterrupted = beforeRead();
- try {
- return baseList().listIterator(index);
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public ListIterator listIterator(int index) {
- boolean wasInterrupted = beforeRead();
- try {
- return new SyncCollectionListIterator(baseList().listIterator(index));
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
-
- public class SyncCollectionListIterator extends SyncCollectionIterator implements ListIterator {
-
- SyncCollectionListIterator(Iterator baseIterator) {
- super(baseIterator);
- }
-
- protected ListIterator baseListIterator() {
- return (ListIterator)(baseIterator_);
- }
-
- public boolean hasPrevious() {
- boolean wasInterrupted = beforeRead();
- try {
- return baseListIterator().hasPrevious();
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public Object previous() {
- boolean wasInterrupted = beforeRead();
- try {
- return baseListIterator().previous();
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public int nextIndex() {
- boolean wasInterrupted = beforeRead();
- try {
- return baseListIterator().nextIndex();
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
-
- public int previousIndex() {
- boolean wasInterrupted = beforeRead();
- try {
- return baseListIterator().previousIndex();
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
-
- public void set(Object o) {
- try {
- wr_.acquire();
- try {
- baseListIterator().set(o);
- }
- finally {
- wr_.release();
- }
- }
- catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
- throw new UnsupportedOperationException();
- }
- }
-
- public void add(Object o) {
- try {
- wr_.acquire();
- try {
- baseListIterator().add(o);
- }
- finally {
- wr_.release();
- }
- }
- catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
- throw new UnsupportedOperationException();
- }
- }
-
-
- }
-
-}
-
-
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8b2ea77d/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/SyncMap.java
----------------------------------------------------------------------
diff --git a/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/SyncMap.java b/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/SyncMap.java
deleted file mode 100644
index fc6813d..0000000
--- a/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/SyncMap.java
+++ /dev/null
@@ -1,314 +0,0 @@
-/** Notice of modification as required by the LGPL
- * This file was modified by Gemstone Systems Inc. on
- * $Date$
- **/
-/*
- File: SyncMap.java
-
- Originally written by Doug Lea and released into the public domain.
- This may be used for any purposes whatsoever without acknowledgment.
- Thanks for the assistance and support of Sun Microsystems Labs,
- and everyone contributing, testing, and using this code.
-
- History:
- Date Who What
- 1Aug1998 dl Create public version
-*/
-
-package com.gemstone.org.jgroups.oswego.concurrent;
-import java.util.*;
-
-/**
- * SyncMaps wrap Sync-based control around java.util.Maps.
- * They operate in the same way as SyncCollection.
- * <p>
- * Reader operations are
- * <ul>
- * <li> size
- * <li> isEmpty
- * <li> get
- * <li> containsKey
- * <li> containsValue
- * <li> keySet
- * <li> entrySet
- * <li> values
- * </ul>
- * Writer operations are:
- * <ul>
- * <li> put
- * <li> putAll
- * <li> remove
- * <li> clear
- * </ul>
- *
- * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>]
- * @see SyncCollection
-**/
-
-
-public class SyncMap implements Map {
- protected final Map c_; // Backing Map
- protected final Sync rd_; // sync for read-only methods
- protected final Sync wr_; // sync for mutative methods
-
- protected final SynchronizedLong syncFailures_ = new SynchronizedLong(0);
-
- /**
- * Create a new SyncMap protecting the given map,
- * and using the given sync to control both reader and writer methods.
- * Common, reasonable choices for the sync argument include
- * Mutex, ReentrantLock, and Semaphores initialized to 1.
- **/
- public SyncMap(Map map, Sync sync) {
- this (map, sync, sync);
- }
-
-
- /**
- * Create a new SyncMap protecting the given map,
- * and using the given ReadWriteLock to control reader and writer methods.
- **/
- public SyncMap(Map map, ReadWriteLock rwl) {
- this (map, rwl.readLock(), rwl.writeLock());
- }
-
- /**
- * Create a new SyncMap protecting the given map,
- * and using the given pair of locks to control reader and writer methods.
- **/
- public SyncMap(Map map, Sync readLock, Sync writeLock) {
- c_ = map;
- rd_ = readLock;
- wr_ = writeLock;
- }
-
- /**
- * Return the Sync object managing read-only operations
- **/
-
- public Sync readerSync() {
- return rd_;
- }
-
- /**
- * Return the Sync object managing mutative operations
- **/
-
- public Sync writerSync() {
- return wr_;
- }
-
- /**
- * Return the number of synchronization failures for read-only operations
- **/
- public long syncFailures() {
- return syncFailures_.get();
- }
-
-
- /** Try to acquire sync before a reader operation; record failure **/
- protected boolean beforeRead() {
- try {
- rd_.acquire();
- return false;
- }
- catch (InterruptedException ex) {
- Thread.currentThread().interrupt(); // GemStoneAddition
- syncFailures_.increment();
- return true;
- }
- }
-
- /** Clean up after a reader operation **/
- protected void afterRead(boolean wasInterrupted) {
- if (wasInterrupted) {
- Thread.currentThread().interrupt();
- }
- else
- rd_.release();
- }
-
-
-
- @Override // GemStoneAddition
- public int hashCode() {
- boolean wasInterrupted = beforeRead();
- try {
- return c_.hashCode();
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- @Override // GemStoneAddition
- public boolean equals(Object o) {
- boolean wasInterrupted = beforeRead();
- try {
- return c_.equals(o);
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public int size() {
- boolean wasInterrupted = beforeRead();
- try {
- return c_.size();
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public boolean isEmpty() {
- boolean wasInterrupted = beforeRead();
- try {
- return c_.isEmpty();
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public boolean containsKey(Object o) {
- boolean wasInterrupted = beforeRead();
- try {
- return c_.containsKey(o);
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public boolean containsValue(Object o) {
- boolean wasInterrupted = beforeRead();
- try {
- return c_.containsValue(o);
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public Object get(Object key) {
- boolean wasInterrupted = beforeRead();
- try {
- return c_.get(key);
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
-
- public Object put(Object key, Object value) {
- try {
- wr_.acquire();
- try {
- return c_.put(key, value);
- }
- finally {
- wr_.release();
- }
- }
- catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
- throw new UnsupportedOperationException();
- }
- }
-
- public Object remove(Object key) {
- try {
- wr_.acquire();
- try {
- return c_.remove(key);
- }
- finally {
- wr_.release();
- }
- }
- catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
- throw new UnsupportedOperationException();
- }
- }
-
- public void putAll(Map coll) {
- try {
- wr_.acquire();
- try {
- c_.putAll(coll);
- }
- finally {
- wr_.release();
- }
- }
- catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
- throw new UnsupportedOperationException();
- }
- }
-
-
- public void clear() {
- try {
- wr_.acquire();
- try {
- c_.clear();
- }
- finally {
- wr_.release();
- }
- }
- catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
- throw new UnsupportedOperationException();
- }
- }
-
- private transient Set keySet_ = null;
- private transient Set entrySet_ = null;
- private transient Collection values_ = null;
-
- public Set keySet() {
- boolean wasInterrupted = beforeRead();
- try {
- if (keySet_ == null)
- keySet_ = new SyncSet(c_.keySet(), rd_, wr_);
- return keySet_;
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public Set entrySet() {
- boolean wasInterrupted = beforeRead();
- try {
- if (entrySet_ == null)
- entrySet_ = new SyncSet(c_.entrySet(), rd_, wr_);
- return entrySet_;
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
-
- public Collection values() {
- boolean wasInterrupted = beforeRead();
- try {
- if (values_ == null)
- values_ = new SyncCollection(c_.values(), rd_, wr_);
- return values_;
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
-}
-
-
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8b2ea77d/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/SyncSet.java
----------------------------------------------------------------------
diff --git a/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/SyncSet.java b/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/SyncSet.java
deleted file mode 100644
index 83a1baf..0000000
--- a/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/SyncSet.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/** Notice of modification as required by the LGPL
- * This file was modified by Gemstone Systems Inc. on
- * $Date$
- **/
-/*
- File: SyncSet.java
-
- Originally written by Doug Lea and released into the public domain.
- This may be used for any purposes whatsoever without acknowledgment.
- Thanks for the assistance and support of Sun Microsystems Labs,
- and everyone contributing, testing, and using this code.
-
- History:
- Date Who What
- 1Aug1998 dl Create public version
-*/
-
-package com.gemstone.org.jgroups.oswego.concurrent;
-import java.util.*;
-
-/**
- * SyncSets wrap Sync-based control around java.util.Sets.
- * They support two additional reader operations than do
- * SyncCollection: hashCode and equals.
- * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>]
- * @see SyncCollection
-**/
-
-
-public class SyncSet extends SyncCollection implements Set {
-
- /**
- * Create a new SyncSet protecting the given collection,
- * and using the given sync to control both reader and writer methods.
- * Common, reasonable choices for the sync argument include
- * Mutex, ReentrantLock, and Semaphores initialized to 1.
- **/
- public SyncSet(Set set, Sync sync) {
- super (set, sync);
- }
-
- /**
- * Create a new SyncSet protecting the given set,
- * and using the given ReadWriteLock to control reader and writer methods.
- **/
- public SyncSet(Set set, ReadWriteLock rwl) {
- super (set, rwl.readLock(), rwl.writeLock());
- }
-
- /**
- * Create a new SyncSet protecting the given set,
- * and using the given pair of locks to control reader and writer methods.
- **/
- public SyncSet(Set set, Sync readLock, Sync writeLock) {
- super(set, readLock, writeLock);
- }
-
- @Override // GemStoneAddition
- public int hashCode() {
- boolean wasInterrupted = beforeRead();
- try {
- return c_.hashCode();
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- @Override // GemStoneAddition
- public boolean equals(Object o) {
- boolean wasInterrupted = beforeRead();
- try {
- return c_.equals(o);
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
-}
-
-
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8b2ea77d/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/SyncSortedMap.java
----------------------------------------------------------------------
diff --git a/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/SyncSortedMap.java b/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/SyncSortedMap.java
deleted file mode 100644
index 729c19f..0000000
--- a/gemfire-jgroups/src/main/java/com/gemstone/org/jgroups/oswego/concurrent/SyncSortedMap.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/** Notice of modification as required by the LGPL
- * This file was modified by Gemstone Systems Inc. on
- * $Date$
- **/
-/*
- File: SyncSortedMap.java
-
- Originally written by Doug Lea and released into the public domain.
- This may be used for any purposes whatsoever without acknowledgment.
- Thanks for the assistance and support of Sun Microsystems Labs,
- and everyone contributing, testing, and using this code.
-
- History:
- Date Who What
- 1Aug1998 dl Create public version
-*/
-
-package com.gemstone.org.jgroups.oswego.concurrent;
-import java.util.*;
-
-/**
- * SyncSortedMaps wrap Sync-based control around java.util.SortedMaps.
- * They support the following additional reader operations over
- * SyncMap: comparator, subMap, headMap, tailMap, firstKey, lastKey.
- * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>]
- * @see SyncCollection
-**/
-
-
-public class SyncSortedMap extends SyncMap implements SortedMap {
-
- /**
- * Create a new SyncSortedMap protecting the given map,
- * and using the given sync to control both reader and writer methods.
- * Common, reasonable choices for the sync argument include
- * Mutex, ReentrantLock, and Semaphores initialized to 1.
- **/
- public SyncSortedMap(SortedMap map, Sync sync) {
- this (map, sync, sync);
- }
-
- /**
- * Create a new SyncSortedMap protecting the given map,
- * and using the given ReadWriteLock to control reader and writer methods.
- **/
- public SyncSortedMap(SortedMap map, ReadWriteLock rwl) {
- super (map, rwl.readLock(), rwl.writeLock());
- }
-
- /**
- * Create a new SyncSortedMap protecting the given map,
- * and using the given pair of locks to control reader and writer methods.
- **/
- public SyncSortedMap(SortedMap map, Sync readLock, Sync writeLock) {
- super(map, readLock, writeLock);
- }
-
-
- protected SortedMap baseSortedMap() {
- return (SortedMap)c_;
- }
-
- public Comparator comparator() {
- boolean wasInterrupted = beforeRead();
- try {
- return baseSortedMap().comparator();
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public Object firstKey() {
- boolean wasInterrupted = beforeRead();
- try {
- return baseSortedMap().firstKey();
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public Object lastKey() {
- boolean wasInterrupted = beforeRead();
- try {
- return baseSortedMap().lastKey();
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
-
- public SortedMap subMap(Object fromElement, Object toElement) {
- boolean wasInterrupted = beforeRead();
- try {
- return new SyncSortedMap(baseSortedMap().subMap(fromElement, toElement),
- rd_, wr_);
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public SortedMap headMap(Object toElement) {
- boolean wasInterrupted = beforeRead();
- try {
- return new SyncSortedMap(baseSortedMap().headMap(toElement),
- rd_, wr_);
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
- public SortedMap tailMap(Object fromElement) {
- boolean wasInterrupted = beforeRead();
- try {
- return new SyncSortedMap(baseSortedMap().tailMap(fromElement),
- rd_, wr_);
- }
- finally {
- afterRead(wasInterrupted);
- }
- }
-
-}
-
-