jstrachan 01/05/06 09:50:24
Modified: threading/src/java/org/apache/commons/threading
FIFONotifier.java FIFOQueue.java LIFOQueue.java
Notifier.java Queue.java
Log:
Used more JCF based names for methods in the Queue and Notifier interfaces and
implementations. Now using add(), remove() and size(). Also added a simple
removeNoWait() helper method which does not throw any exceptions but just returns null
if there is no available object.
Revision Changes Path
1.2 +7 -7
jakarta-commons-sandbox/threading/src/java/org/apache/commons/threading/FIFONotifier.java
Index: FIFONotifier.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/threading/src/java/org/apache/commons/threading/FIFONotifier.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FIFONotifier.java 2001/04/15 00:50:58 1.1
+++ FIFONotifier.java 2001/05/06 16:50:22 1.2
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons-sandbox/threading/src/java/org/apache/commons/threading/FIFONotifier.java,v
1.1 2001/04/15 00:50:58 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2001/04/15 00:50:58 $
+ * $Header:
/home/cvs/jakarta-commons-sandbox/threading/src/java/org/apache/commons/threading/FIFONotifier.java,v
1.2 2001/05/06 16:50:22 jstrachan Exp $
+ * $Revision: 1.2 $
+ * $Date: 2001/05/06 16:50:22 $
*
* ====================================================================
*
@@ -73,7 +73,7 @@
* in JavaWorld (09/1998 - 04/1999) by Allen Holub.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2001/04/15 00:50:58 $
+ * @version $Revision: 1.2 $ $Date: 2001/05/06 16:50:22 $
* @see Notifier
*/
@@ -150,9 +150,9 @@
/**
* Return the number of deliveries that are queued, but not yet completed.
*/
- public int getCount() {
+ public int size() {
- return (entries.getCount());
+ return (entries.size());
}
@@ -225,7 +225,7 @@
*/
public void send(Subscriber subscriber, Object published) {
- entries.enqueue(new FIFONotifierEntry(subscriber, published));
+ entries.add(new FIFONotifierEntry(subscriber, published));
}
@@ -253,7 +253,7 @@
FIFONotifierEntry entry = null;
try {
- entry = (FIFONotifierEntry) entries.dequeue();
+ entry = (FIFONotifierEntry) entries.remove();
} catch (InterruptedException e) {
break; // stop() was called
}
1.2 +22 -8
jakarta-commons-sandbox/threading/src/java/org/apache/commons/threading/FIFOQueue.java
Index: FIFOQueue.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/threading/src/java/org/apache/commons/threading/FIFOQueue.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FIFOQueue.java 2001/04/15 00:50:57 1.1
+++ FIFOQueue.java 2001/05/06 16:50:22 1.2
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons-sandbox/threading/src/java/org/apache/commons/threading/FIFOQueue.java,v
1.1 2001/04/15 00:50:57 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2001/04/15 00:50:57 $
+ * $Header:
/home/cvs/jakarta-commons-sandbox/threading/src/java/org/apache/commons/threading/FIFOQueue.java,v
1.2 2001/05/06 16:50:22 jstrachan Exp $
+ * $Revision: 1.2 $
+ * $Date: 2001/05/06 16:50:22 $
*
* ====================================================================
*
@@ -73,7 +73,7 @@
* in JavaWorld (09/1998 - 04/1999) by Allen Holub.</p>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2001/04/15 00:50:57 $
+ * @version $Revision: 1.2 $ $Date: 2001/05/06 16:50:22 $
* @see Queue
*/
@@ -109,7 +109,7 @@
/**
* Return the number of objects currently available in the queue.
*/
- public int getCount() {
+ public int size() {
return (queue.size());
@@ -135,10 +135,10 @@
*
* @exception InterruptedException if the waiting thread is interrupted
*/
- public Object dequeue() throws InterruptedException {
+ public Object remove() throws InterruptedException {
try {
- return (dequeue(Long.MAX_VALUE));
+ return (remove(Long.MAX_VALUE));
} catch (TimeoutException e) {
return (null); // Cannot happen
}
@@ -158,7 +158,7 @@
* @exception TimeoutException if a timeout occurs before an object
* becomes available
*/
- public Object dequeue(long timeout)
+ public Object remove(long timeout)
throws InterruptedException, TimeoutException {
counter.acquire(timeout);
@@ -170,6 +170,20 @@
}
+ /**
+ * Return the "next" available object from the queue without waiting or
+ * returning null if there is no object available.
+ */
+ public Object removeNoWait() {
+ Object value = null;
+ synchronized (queue) {
+ if ( ! queue.isEmpty() ) {
+ value = queue.removeFirst();
+ }
+ }
+ return value;
+ }
+
/**
* Add a new available object to the queue, making it available to any
@@ -177,7 +191,7 @@
*
* @param object The new object to be added
*/
- public void enqueue(Object object) {
+ public void add(Object object) {
synchronized (queue) {
queue.addLast(object);
1.2 +22 -8
jakarta-commons-sandbox/threading/src/java/org/apache/commons/threading/LIFOQueue.java
Index: LIFOQueue.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/threading/src/java/org/apache/commons/threading/LIFOQueue.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LIFOQueue.java 2001/04/15 00:50:58 1.1
+++ LIFOQueue.java 2001/05/06 16:50:23 1.2
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons-sandbox/threading/src/java/org/apache/commons/threading/LIFOQueue.java,v
1.1 2001/04/15 00:50:58 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2001/04/15 00:50:58 $
+ * $Header:
/home/cvs/jakarta-commons-sandbox/threading/src/java/org/apache/commons/threading/LIFOQueue.java,v
1.2 2001/05/06 16:50:23 jstrachan Exp $
+ * $Revision: 1.2 $
+ * $Date: 2001/05/06 16:50:23 $
*
* ====================================================================
*
@@ -73,7 +73,7 @@
* in JavaWorld (09/1998 - 04/1999) by Allen Holub.</p>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2001/04/15 00:50:58 $
+ * @version $Revision: 1.2 $ $Date: 2001/05/06 16:50:23 $
* @see Queue
*/
@@ -109,7 +109,7 @@
/**
* Return the number of objects currently available in the queue.
*/
- public int getCount() {
+ public int size() {
return (queue.size());
@@ -135,10 +135,10 @@
*
* @exception InterruptedException if the waiting thread is interrupted
*/
- public Object dequeue() throws InterruptedException {
+ public Object remove() throws InterruptedException {
try {
- return (dequeue(Long.MAX_VALUE));
+ return (remove(Long.MAX_VALUE));
} catch (TimeoutException e) {
return (null); // Cannot happen
}
@@ -158,7 +158,7 @@
* @exception TimeoutException if a timeout occurs before an object
* becomes available
*/
- public Object dequeue(long timeout)
+ public Object remove(long timeout)
throws InterruptedException, TimeoutException {
counter.acquire(timeout);
@@ -170,6 +170,20 @@
}
+ /**
+ * Return the "next" available object from the queue without waiting or
+ * returning null if there is no object available.
+ */
+ public Object removeNoWait() {
+ Object value = null;
+ synchronized (queue) {
+ if ( ! queue.isEmpty() ) {
+ value = queue.removeLast();
+ }
+ }
+ return value;
+ }
+
/**
* Add a new available object to the queue, making it available to any
@@ -177,7 +191,7 @@
*
* @param object The new object to be added
*/
- public void enqueue(Object object) {
+ public void add(Object object) {
synchronized (queue) {
queue.addLast(object);
1.2 +4 -4
jakarta-commons-sandbox/threading/src/java/org/apache/commons/threading/Notifier.java
Index: Notifier.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/threading/src/java/org/apache/commons/threading/Notifier.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Notifier.java 2001/04/15 00:50:58 1.1
+++ Notifier.java 2001/05/06 16:50:23 1.2
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons-sandbox/threading/src/java/org/apache/commons/threading/Notifier.java,v
1.1 2001/04/15 00:50:58 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2001/04/15 00:50:58 $
+ * $Header:
/home/cvs/jakarta-commons-sandbox/threading/src/java/org/apache/commons/threading/Notifier.java,v
1.2 2001/05/06 16:50:23 jstrachan Exp $
+ * $Revision: 1.2 $
+ * $Date: 2001/05/06 16:50:23 $
*
* ====================================================================
*
@@ -72,7 +72,7 @@
* in JavaWorld (09/1998 - 04/1999) by Allen Holub.</p>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2001/04/15 00:50:58 $
+ * @version $Revision: 1.2 $ $Date: 2001/05/06 16:50:23 $
* @see Publisher
* @see Subscriber
*/
@@ -86,7 +86,7 @@
/**
* Return the number of deliveries that are queued, but not yet completed.
*/
- public int getCount();
+ public int size();
/**
1.2 +15 -8
jakarta-commons-sandbox/threading/src/java/org/apache/commons/threading/Queue.java
Index: Queue.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/threading/src/java/org/apache/commons/threading/Queue.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Queue.java 2001/04/15 00:50:58 1.1
+++ Queue.java 2001/05/06 16:50:23 1.2
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons-sandbox/threading/src/java/org/apache/commons/threading/Queue.java,v
1.1 2001/04/15 00:50:58 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2001/04/15 00:50:58 $
+ * $Header:
/home/cvs/jakarta-commons-sandbox/threading/src/java/org/apache/commons/threading/Queue.java,v
1.2 2001/05/06 16:50:23 jstrachan Exp $
+ * $Revision: 1.2 $
+ * $Date: 2001/05/06 16:50:23 $
*
* ====================================================================
*
@@ -68,11 +68,12 @@
* ordering are characteristics of specific implementations of this
* interface.</p>
*
- * <p>This code was inspired by the "Java Threads in the Real Wrold" series
+ * <p>This code was inspired by the "Java Threads in the Real World" series
* in JavaWord (09/1998 - 04/1999) by Allen Holub.</p>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2001/04/15 00:50:58 $
+ * @author James Strachan
+ * @version $Revision: 1.2 $ $Date: 2001/05/06 16:50:23 $
*/
public interface Queue {
@@ -84,7 +85,7 @@
/**
* Return the number of objects currently available in the queue.
*/
- public int getCount();
+ public int size();
/**
@@ -102,7 +103,7 @@
*
* @exception InterruptedException if the waiting thread is interrupted
*/
- public Object dequeue() throws InterruptedException;
+ public Object remove() throws InterruptedException;
/**
@@ -117,9 +118,15 @@
* @exception TimeoutException if a timeout occurs before an object
* becomes available
*/
- public Object dequeue(long timeout)
+ public Object remove(long timeout)
throws InterruptedException, TimeoutException;
+ /**
+ * Return the "next" available object from the queue without waiting or
+ * returning null if there is no object available.
+ */
+ public Object removeNoWait();
+
/**
* Add a new available object to the queue, making it available to any
@@ -127,7 +134,7 @@
*
* @param object The new object to be added
*/
- public void enqueue(Object object);
+ public void add(Object object);
/**