You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by tr...@apache.org on 2008/05/22 10:59:40 UTC
svn commit: r659051 - in
/mina/branches/buffer/core/src/main/java/org/apache/mina/queue:
AbstractIoQueue.java CircularIoQueue.java
Author: trustin
Date: Thu May 22 01:59:40 2008
New Revision: 659051
URL: http://svn.apache.org/viewvc?rev=659051&view=rev
Log:
Removed IoQueue.element(int) which doesn't work very well with other queue implementations
Modified:
mina/branches/buffer/core/src/main/java/org/apache/mina/queue/AbstractIoQueue.java
mina/branches/buffer/core/src/main/java/org/apache/mina/queue/CircularIoQueue.java
Modified: mina/branches/buffer/core/src/main/java/org/apache/mina/queue/AbstractIoQueue.java
URL: http://svn.apache.org/viewvc/mina/branches/buffer/core/src/main/java/org/apache/mina/queue/AbstractIoQueue.java?rev=659051&r1=659050&r2=659051&view=diff
==============================================================================
--- mina/branches/buffer/core/src/main/java/org/apache/mina/queue/AbstractIoQueue.java (original)
+++ mina/branches/buffer/core/src/main/java/org/apache/mina/queue/AbstractIoQueue.java Thu May 22 01:59:40 2008
@@ -20,9 +20,6 @@
package org.apache.mina.queue;
import java.util.AbstractQueue;
-import java.util.ConcurrentModificationException;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,7 +37,6 @@
private static final Logger LOG = LoggerFactory.getLogger(AbstractIoQueue.class);
private volatile IoQueueListener<? super E>[] listeners = newListenerArray(0);
- private int modCount;
/**
* {@inheritDoc}
@@ -122,8 +118,6 @@
}
doOffer(e);
-
- modCount ++;
offered(e);
return true;
}
@@ -137,43 +131,10 @@
return null;
}
- modCount ++;
polled(e);
return e;
}
- @Override
- public Iterator<E> iterator() {
- final int expectedModCount = modCount;
- return new Iterator<E>() {
- private int index = 0;
-
- public boolean hasNext() {
- return index != size();
- }
-
- public E next() {
- try {
- E next = element(index++);
- return next;
- } catch (IndexOutOfBoundsException e) {
- checkForComodification();
- throw new NoSuchElementException();
- }
- }
-
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- private void checkForComodification() {
- if (modCount != expectedModCount) {
- throw new ConcurrentModificationException();
- }
- }
- };
- }
-
/**
* Performs the actual insertion operation.
*
Modified: mina/branches/buffer/core/src/main/java/org/apache/mina/queue/CircularIoQueue.java
URL: http://svn.apache.org/viewvc/mina/branches/buffer/core/src/main/java/org/apache/mina/queue/CircularIoQueue.java?rev=659051&r1=659050&r2=659051&view=diff
==============================================================================
--- mina/branches/buffer/core/src/main/java/org/apache/mina/queue/CircularIoQueue.java (original)
+++ mina/branches/buffer/core/src/main/java/org/apache/mina/queue/CircularIoQueue.java Thu May 22 01:59:40 2008
@@ -19,6 +19,8 @@
*/
package org.apache.mina.queue;
+import java.util.ConcurrentModificationException;
+import java.util.Iterator;
import java.util.NoSuchElementException;
/**
@@ -50,6 +52,7 @@
private int last;
private boolean full;
private int shrinkThreshold;
+ private int modCount;
/**
* Creates a new empty queue.
@@ -83,13 +86,10 @@
@Override
protected final void doOffer(E e) {
- if (e == null) {
- throw new NullPointerException("element");
- }
-
expandIfNeeded();
items[last] = e;
increaseSize();
+ modCount ++;
}
@Override
@@ -101,11 +101,7 @@
E ret = items[first];
items[first] = null;
decreaseSize();
-
- if (first == last) {
- first = last = 0;
- }
-
+ modCount ++;
shrinkIfNeeded();
return ret;
}
@@ -136,6 +132,38 @@
return items[first];
}
+ @Override
+ public Iterator<E> iterator() {
+ final int expectedModCount = modCount;
+ return new Iterator<E>() {
+ private int index = 0;
+
+ public boolean hasNext() {
+ return index != size();
+ }
+
+ public E next() {
+ try {
+ E next = element(index++);
+ return next;
+ } catch (IndexOutOfBoundsException e) {
+ checkForComodification();
+ throw new NoSuchElementException();
+ }
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ private void checkForComodification() {
+ if (modCount != expectedModCount) {
+ throw new ConcurrentModificationException();
+ }
+ }
+ };
+ }
+
private void checkIndex(int idx) {
if (idx < 0 || idx >= size()) {
throw new NoSuchElementException(String.valueOf(idx));
@@ -154,6 +182,10 @@
private void decreaseSize() {
first = first + 1 & mask;
full = false;
+
+ if (first == last) {
+ first = last = 0;
+ }
}
private void expandIfNeeded() {