Code cleanup
This commit is contained in:
parent
9788ea7291
commit
6cdd9ac711
9
pom.xml
9
pom.xml
@ -90,6 +90,15 @@
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- Example dependencies - completely optional -->
|
||||
<dependency>
|
||||
<groupId>javax.activation</groupId>
|
||||
<artifactId>activation</artifactId>
|
||||
<version>1.1.1</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- IoC/DI containers - completely optional -->
|
||||
<dependency>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
|
@ -24,6 +24,7 @@ import org.jboss.netty.channel.ChannelPipelineFactory;
|
||||
import org.jboss.netty.channel.Channels;
|
||||
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
||||
import org.jboss.netty.example.echo.EchoClient;
|
||||
import org.jboss.netty.handler.codec.serialization.ClassResolvers;
|
||||
import org.jboss.netty.handler.codec.serialization.ObjectDecoder;
|
||||
import org.jboss.netty.handler.codec.serialization.ObjectEncoder;
|
||||
|
||||
@ -54,7 +55,8 @@ public class ObjectEchoClient {
|
||||
public ChannelPipeline getPipeline() throws Exception {
|
||||
return Channels.pipeline(
|
||||
new ObjectEncoder(),
|
||||
new ObjectDecoder(),
|
||||
new ObjectDecoder(
|
||||
ClassResolvers.cacheDisabled(getClass().getClassLoader())),
|
||||
new ObjectEchoClientHandler(firstMessageSize));
|
||||
}
|
||||
});
|
||||
|
@ -51,7 +51,8 @@ public class ObjectEchoServer {
|
||||
public ChannelPipeline getPipeline() throws Exception {
|
||||
return Channels.pipeline(
|
||||
new ObjectEncoder(),
|
||||
new ObjectDecoder(),
|
||||
new ObjectDecoder(
|
||||
ClassResolvers.cacheDisabled(getClass().getClassLoader())),
|
||||
new ObjectEchoServerHandler());
|
||||
}
|
||||
});
|
||||
|
@ -49,7 +49,7 @@ public class RedisEncoder extends SimpleChannelDownstreamHandler {
|
||||
ChannelFuture future = e.getFuture();
|
||||
|
||||
// Useful for transactions and database select
|
||||
for (Object i : (Iterable) o) {
|
||||
for (Object i : (Iterable<?>) o) {
|
||||
if (i instanceof Command) {
|
||||
Command command = (Command) i;
|
||||
command.write(cb);
|
||||
|
@ -19,7 +19,6 @@ import java.io.IOException;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectStreamClass;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
class CompactObjectOutputStream extends ObjectOutputStream {
|
||||
|
||||
|
@ -22,6 +22,8 @@ package org.jboss.netty.handler.codec.spdy;
|
||||
*/
|
||||
public class SpdyProtocolException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 7870000537743847264L;
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
*/
|
||||
|
@ -655,7 +655,7 @@ public class LegacyLinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
}
|
||||
LockSupport.unpark(p.waiter);
|
||||
// Explicit cast, see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6302954
|
||||
return (E) LegacyLinkedTransferQueue.cast(item);
|
||||
return LegacyLinkedTransferQueue.cast(item);
|
||||
}
|
||||
}
|
||||
Node n = p.next;
|
||||
@ -671,7 +671,7 @@ public class LegacyLinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
continue retry; // lost race vs opposite mode
|
||||
}
|
||||
if (how != ASYNC) {
|
||||
return awaitMatch(s, pred, e, (how == TIMED), nanos);
|
||||
return awaitMatch(s, pred, e, how == TIMED, nanos);
|
||||
}
|
||||
}
|
||||
return e; // not waiting
|
||||
@ -739,8 +739,7 @@ public class LegacyLinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
if (item != e) { // matched
|
||||
// assert item != s;
|
||||
s.forgetContents(); // avoid garbage
|
||||
// Explicit cast, see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6302954
|
||||
return (E) LegacyLinkedTransferQueue.cast(item);
|
||||
return LegacyLinkedTransferQueue.cast(item);
|
||||
}
|
||||
if ((w.isInterrupted() || timed && nanos <= 0) &&
|
||||
s.casItem(e, s)) { // cancel
|
||||
@ -828,8 +827,7 @@ public class LegacyLinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
Object item = p.item;
|
||||
if (p.isData) {
|
||||
if (item != null && item != p) {
|
||||
// Explicit cast, see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6302954
|
||||
return (E) LegacyLinkedTransferQueue.cast(item);
|
||||
return LegacyLinkedTransferQueue.cast(item);
|
||||
}
|
||||
}
|
||||
else if (item == null) {
|
||||
@ -882,8 +880,7 @@ public class LegacyLinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
Object item = p.item;
|
||||
if (p.isData) {
|
||||
if (item != null && item != p) {
|
||||
// Explicit cast, see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6302954
|
||||
nextItem = (E) LegacyLinkedTransferQueue.cast(item);
|
||||
nextItem = LegacyLinkedTransferQueue.cast(item);
|
||||
nextNode = p;
|
||||
return;
|
||||
}
|
||||
|
@ -494,7 +494,7 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
*/
|
||||
final boolean isMatched() {
|
||||
Object x = item;
|
||||
return (x == this) || ((x == null) == isData);
|
||||
return x == this || x == null == isData;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -512,7 +512,7 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
final boolean cannotPrecede(boolean haveData) {
|
||||
boolean d = isData;
|
||||
Object x;
|
||||
return d != haveData && (x = item) != this && (x != null) == d;
|
||||
return d != haveData && (x = item) != this && x != null == d;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -528,8 +528,6 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
return false;
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = -3375979862319811754L;
|
||||
|
||||
// Unsafe mechanics
|
||||
private static final sun.misc.Unsafe UNSAFE;
|
||||
private static final long itemOffset;
|
||||
@ -598,8 +596,9 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
* @throws NullPointerException if haveData mode but e is null
|
||||
*/
|
||||
private E xfer(E e, boolean haveData, int how, long nanos) {
|
||||
if (haveData && (e == null))
|
||||
if (haveData && e == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
Node s = null; // the node to append, if needed
|
||||
|
||||
retry:
|
||||
@ -608,9 +607,10 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
for (Node h = head, p = h; p != null;) { // find & match first node
|
||||
boolean isData = p.isData;
|
||||
Object item = p.item;
|
||||
if (item != p && (item != null) == isData) { // unmatched
|
||||
if (isData == haveData) // can't match
|
||||
if (item != p && item != null == isData) { // unmatched
|
||||
if (isData == haveData) {
|
||||
break;
|
||||
}
|
||||
if (p.casItem(item, e)) { // match
|
||||
for (Node q = p; q != h;) {
|
||||
Node n = q.next; // update by 2 unless singleton
|
||||
@ -620,24 +620,30 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
} // advance and retry
|
||||
if ((h = head) == null ||
|
||||
(q = h.next) == null || !q.isMatched())
|
||||
{
|
||||
break; // unless slack < 2
|
||||
}
|
||||
}
|
||||
LockSupport.unpark(p.waiter);
|
||||
return LinkedTransferQueue.<E>cast(item);
|
||||
}
|
||||
}
|
||||
Node n = p.next;
|
||||
p = (p != n) ? n : (h = head); // Use head if p offlist
|
||||
p = p != n ? n : (h = head); // Use head if p offlist
|
||||
}
|
||||
|
||||
if (how != NOW) { // No matches available
|
||||
if (s == null)
|
||||
if (s == null) {
|
||||
s = new Node(e, haveData);
|
||||
}
|
||||
Node pred = tryAppend(s, haveData);
|
||||
if (pred == null)
|
||||
{
|
||||
continue retry; // lost race vs opposite mode
|
||||
if (how != ASYNC)
|
||||
return awaitMatch(s, pred, e, (how == TIMED), nanos);
|
||||
}
|
||||
if (how != ASYNC) {
|
||||
return awaitMatch(s, pred, e, how == TIMED, nanos);
|
||||
}
|
||||
}
|
||||
return e; // not waiting
|
||||
}
|
||||
@ -657,21 +663,25 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
Node n, u; // temps for reads of next & tail
|
||||
if (p == null && (p = head) == null) {
|
||||
if (casHead(null, s))
|
||||
{
|
||||
return s; // initialize
|
||||
}
|
||||
}
|
||||
else if (p.cannotPrecede(haveData))
|
||||
else if (p.cannotPrecede(haveData)) {
|
||||
return null; // lost race vs opposite mode
|
||||
else if ((n = p.next) != null) // not last; keep traversing
|
||||
} else if ((n = p.next) != null) {
|
||||
p = p != t && t != (u = tail) ? (t = u) : // stale tail
|
||||
(p != n) ? n : null; // restart if off list
|
||||
else if (!p.casNext(null, s))
|
||||
p != n ? n : null; // restart if off list
|
||||
} else if (!p.casNext(null, s)) {
|
||||
p = p.next; // re-read on CAS failure
|
||||
else {
|
||||
} else {
|
||||
if (p != t) { // update if slack now >= 2
|
||||
while ((tail != t || !casTail(t, s)) &&
|
||||
(t = tail) != null &&
|
||||
(s = t.next) != null && // advance and retry
|
||||
(s = s.next) != null && s != t);
|
||||
(s = s.next) != null && s != t) {
|
||||
;
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
@ -703,20 +713,23 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
s.forgetContents(); // avoid garbage
|
||||
return LinkedTransferQueue.<E>cast(item);
|
||||
}
|
||||
if ((w.isInterrupted() || (timed && nanos <= 0)) &&
|
||||
if ((w.isInterrupted() || timed && nanos <= 0) &&
|
||||
s.casItem(e, s)) { // cancel
|
||||
unsplice(pred, s);
|
||||
return e;
|
||||
}
|
||||
|
||||
if (spins < 0) { // establish spins at/near front
|
||||
if ((spins = spinsFor(pred, s.isData)) > 0)
|
||||
if ((spins = spinsFor(pred, s.isData)) > 0) {
|
||||
randomYields = ThreadLocalRandom.current();
|
||||
}
|
||||
}
|
||||
else if (spins > 0) { // spin
|
||||
--spins;
|
||||
if (randomYields.nextInt(CHAINED_SPINS) == 0)
|
||||
{
|
||||
Thread.yield(); // occasionally yield
|
||||
}
|
||||
}
|
||||
else if (s.waiter == null) {
|
||||
s.waiter = w; // request unpark then recheck
|
||||
@ -748,12 +761,15 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
*/
|
||||
private static int spinsFor(Node pred, boolean haveData) {
|
||||
if (MP && pred != null) {
|
||||
if (pred.isData != haveData) // phase change
|
||||
if (pred.isData != haveData) {
|
||||
return FRONT_SPINS + CHAINED_SPINS;
|
||||
if (pred.isMatched()) // probably at front
|
||||
}
|
||||
if (pred.isMatched()) {
|
||||
return FRONT_SPINS;
|
||||
if (pred.waiter == null) // pred apparently spinning
|
||||
}
|
||||
if (pred.waiter == null) {
|
||||
return CHAINED_SPINS;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -767,7 +783,7 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
*/
|
||||
final Node succ(Node p) {
|
||||
Node next = p.next;
|
||||
return (p == next) ? head : next;
|
||||
return p == next ? head : next;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -776,8 +792,9 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
*/
|
||||
private Node firstOfMode(boolean isData) {
|
||||
for (Node p = head; p != null; p = succ(p)) {
|
||||
if (!p.isMatched())
|
||||
return (p.isData == isData) ? p : null;
|
||||
if (!p.isMatched()) {
|
||||
return p.isData == isData ? p : null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -790,11 +807,13 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
for (Node p = head; p != null; p = succ(p)) {
|
||||
Object item = p.item;
|
||||
if (p.isData) {
|
||||
if (item != null && item != p)
|
||||
if (item != null && item != p) {
|
||||
return LinkedTransferQueue.<E>cast(item);
|
||||
}
|
||||
}
|
||||
else if (item == null)
|
||||
else if (item == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -807,15 +826,17 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
int count = 0;
|
||||
for (Node p = head; p != null; ) {
|
||||
if (!p.isMatched()) {
|
||||
if (p.isData != data)
|
||||
if (p.isData != data) {
|
||||
return 0;
|
||||
if (++count == Integer.MAX_VALUE) // saturated
|
||||
}
|
||||
if (++count == Integer.MAX_VALUE) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Node n = p.next;
|
||||
if (n != p)
|
||||
if (n != p) {
|
||||
p = n;
|
||||
else {
|
||||
} else {
|
||||
count = 0;
|
||||
p = head;
|
||||
}
|
||||
@ -844,25 +865,26 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
*/
|
||||
|
||||
Node r, b; // reset lastPred upon possible deletion of lastRet
|
||||
if ((r = lastRet) != null && !r.isMatched())
|
||||
if ((r = lastRet) != null && !r.isMatched()) {
|
||||
lastPred = r; // next lastPred is old lastRet
|
||||
else if ((b = lastPred) == null || b.isMatched())
|
||||
} else if ((b = lastPred) == null || b.isMatched()) {
|
||||
lastPred = null; // at start of list
|
||||
else {
|
||||
} else {
|
||||
Node s, n; // help with removal of lastPred.next
|
||||
while ((s = b.next) != null &&
|
||||
s != b && s.isMatched() &&
|
||||
(n = s.next) != null && n != s)
|
||||
(n = s.next) != null && n != s) {
|
||||
b.casNext(s, n);
|
||||
}
|
||||
}
|
||||
|
||||
this.lastRet = prev;
|
||||
|
||||
for (Node p = prev, s, n;;) {
|
||||
s = (p == null) ? head : p.next;
|
||||
if (s == null)
|
||||
s = p == null ? head : p.next;
|
||||
if (s == null) {
|
||||
break;
|
||||
else if (s == p) {
|
||||
} else if (s == p) {
|
||||
p = null;
|
||||
continue;
|
||||
}
|
||||
@ -874,17 +896,19 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (item == null)
|
||||
else if (item == null) {
|
||||
break;
|
||||
}
|
||||
// assert s.isMatched();
|
||||
if (p == null)
|
||||
if (p == null) {
|
||||
p = s;
|
||||
else if ((n = s.next) == null)
|
||||
} else if ((n = s.next) == null) {
|
||||
break;
|
||||
else if (s == n)
|
||||
} else if (s == n) {
|
||||
p = null;
|
||||
else
|
||||
} else {
|
||||
p.casNext(s, n);
|
||||
}
|
||||
}
|
||||
nextNode = null;
|
||||
nextItem = null;
|
||||
@ -900,7 +924,9 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
|
||||
public final E next() {
|
||||
Node p = nextNode;
|
||||
if (p == null) throw new NoSuchElementException();
|
||||
if (p == null) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
E e = nextItem;
|
||||
advance(p);
|
||||
return e;
|
||||
@ -908,11 +934,13 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
|
||||
public final void remove() {
|
||||
final Node lastRet = this.lastRet;
|
||||
if (lastRet == null)
|
||||
if (lastRet == null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
this.lastRet = null;
|
||||
if (lastRet.tryMatchData())
|
||||
if (lastRet.tryMatchData()) {
|
||||
unsplice(lastPred, lastRet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -938,25 +966,33 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
if (pred != null && pred != s && pred.next == s) {
|
||||
Node n = s.next;
|
||||
if (n == null ||
|
||||
(n != s && pred.casNext(s, n) && pred.isMatched())) {
|
||||
n != s && pred.casNext(s, n) && pred.isMatched()) {
|
||||
for (;;) { // check if at, or could be, head
|
||||
Node h = head;
|
||||
if (h == pred || h == s || h == null)
|
||||
{
|
||||
return; // at head or list empty
|
||||
if (!h.isMatched())
|
||||
}
|
||||
if (!h.isMatched()) {
|
||||
break;
|
||||
}
|
||||
Node hn = h.next;
|
||||
if (hn == null)
|
||||
{
|
||||
return; // now empty
|
||||
}
|
||||
if (hn != h && casHead(h, hn))
|
||||
{
|
||||
h.forgetNext(); // advance head
|
||||
}
|
||||
}
|
||||
if (pred.next != pred && s.next != s) { // recheck if offlist
|
||||
for (;;) { // sweep now if enough votes
|
||||
int v = sweepVotes;
|
||||
if (v < SWEEP_THRESHOLD) {
|
||||
if (casSweepVotes(v, v + 1))
|
||||
if (casSweepVotes(v, v + 1)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (casSweepVotes(v, 0)) {
|
||||
sweep();
|
||||
@ -974,16 +1010,17 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
*/
|
||||
private void sweep() {
|
||||
for (Node p = head, s, n; p != null && (s = p.next) != null; ) {
|
||||
if (!s.isMatched())
|
||||
if (!s.isMatched()) {
|
||||
// Unmatched nodes are never self-linked
|
||||
p = s;
|
||||
else if ((n = s.next) == null) // trailing node is pinned
|
||||
} else if ((n = s.next) == null) {
|
||||
break;
|
||||
else if (s == n) // stale
|
||||
} else if (s == n) {
|
||||
// No need to also check for p == s, since that implies s == n
|
||||
p = head;
|
||||
else
|
||||
} else {
|
||||
p.casNext(s, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1001,8 +1038,9 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (item == null)
|
||||
else if (item == null) {
|
||||
break;
|
||||
}
|
||||
pred = p;
|
||||
if ((p = p.next) == pred) { // stale
|
||||
pred = null;
|
||||
@ -1079,6 +1117,7 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
* @return {@code true} (as specified by {@link Collection#add})
|
||||
* @throws NullPointerException if the specified element is null
|
||||
*/
|
||||
@Override
|
||||
public boolean add(E e) {
|
||||
xfer(e, true, ASYNC, 0);
|
||||
return true;
|
||||
@ -1132,25 +1171,29 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
*/
|
||||
public boolean tryTransfer(E e, long timeout, TimeUnit unit)
|
||||
throws InterruptedException {
|
||||
if (xfer(e, true, TIMED, unit.toNanos(timeout)) == null)
|
||||
if (xfer(e, true, TIMED, unit.toNanos(timeout)) == null) {
|
||||
return true;
|
||||
if (!Thread.interrupted())
|
||||
}
|
||||
if (!Thread.interrupted()) {
|
||||
return false;
|
||||
}
|
||||
throw new InterruptedException();
|
||||
}
|
||||
|
||||
public E take() throws InterruptedException {
|
||||
E e = xfer(null, false, SYNC, 0);
|
||||
if (e != null)
|
||||
if (e != null) {
|
||||
return e;
|
||||
}
|
||||
Thread.interrupted();
|
||||
throw new InterruptedException();
|
||||
}
|
||||
|
||||
public E poll(long timeout, TimeUnit unit) throws InterruptedException {
|
||||
E e = xfer(null, false, TIMED, unit.toNanos(timeout));
|
||||
if (e != null || !Thread.interrupted())
|
||||
if (e != null || !Thread.interrupted()) {
|
||||
return e;
|
||||
}
|
||||
throw new InterruptedException();
|
||||
}
|
||||
|
||||
@ -1163,10 +1206,12 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
* @throws IllegalArgumentException {@inheritDoc}
|
||||
*/
|
||||
public int drainTo(Collection<? super E> c) {
|
||||
if (c == null)
|
||||
if (c == null) {
|
||||
throw new NullPointerException();
|
||||
if (c == this)
|
||||
}
|
||||
if (c == this) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
int n = 0;
|
||||
for (E e; (e = poll()) != null;) {
|
||||
c.add(e);
|
||||
@ -1180,10 +1225,12 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
* @throws IllegalArgumentException {@inheritDoc}
|
||||
*/
|
||||
public int drainTo(Collection<? super E> c, int maxElements) {
|
||||
if (c == null)
|
||||
if (c == null) {
|
||||
throw new NullPointerException();
|
||||
if (c == this)
|
||||
}
|
||||
if (c == this) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
int n = 0;
|
||||
for (E e; n < maxElements && (e = poll()) != null;) {
|
||||
c.add(e);
|
||||
@ -1205,6 +1252,7 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
*
|
||||
* @return an iterator over the elements in this queue in proper sequence
|
||||
*/
|
||||
@Override
|
||||
public Iterator<E> iterator() {
|
||||
return new Itr();
|
||||
}
|
||||
@ -1218,10 +1266,12 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
*
|
||||
* @return {@code true} if this queue contains no elements
|
||||
*/
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
for (Node p = head; p != null; p = succ(p)) {
|
||||
if (!p.isMatched())
|
||||
if (!p.isMatched()) {
|
||||
return !p.isData;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -1242,6 +1292,7 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
*
|
||||
* @return the number of elements in this queue
|
||||
*/
|
||||
@Override
|
||||
public int size() {
|
||||
return countOfMode(true);
|
||||
}
|
||||
@ -1261,6 +1312,7 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
* @param o element to be removed from this queue, if present
|
||||
* @return {@code true} if this queue changed as a result of the call
|
||||
*/
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
return findAndRemove(o);
|
||||
}
|
||||
@ -1273,16 +1325,21 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
* @param o object to be checked for containment in this queue
|
||||
* @return {@code true} if this queue contains the specified element
|
||||
*/
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
if (o == null) return false;
|
||||
if (o == null) {
|
||||
return false;
|
||||
}
|
||||
for (Node p = head; p != null; p = succ(p)) {
|
||||
Object item = p.item;
|
||||
if (p.isData) {
|
||||
if (item != null && item != p && o.equals(item))
|
||||
if (item != null && item != p && o.equals(item)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (item == null)
|
||||
else if (item == null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -1309,8 +1366,9 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
private void writeObject(java.io.ObjectOutputStream s)
|
||||
throws java.io.IOException {
|
||||
s.defaultWriteObject();
|
||||
for (E e : this)
|
||||
for (E e : this) {
|
||||
s.writeObject(e);
|
||||
}
|
||||
// Use trailing null as sentinel
|
||||
s.writeObject(null);
|
||||
}
|
||||
@ -1327,10 +1385,11 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
for (;;) {
|
||||
@SuppressWarnings("unchecked")
|
||||
E item = (E) s.readObject();
|
||||
if (item == null)
|
||||
if (item == null) {
|
||||
break;
|
||||
else
|
||||
} else {
|
||||
offer(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,9 +19,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.jboss.netty.channel.DefaultChannelPipeline;
|
||||
import org.jboss.netty.channel.ChannelPipeline;
|
||||
import org.jboss.netty.channel.SimpleChannelHandler;
|
||||
import org.jboss.netty.channel.StaticChannelPipeline;
|
||||
import org.jboss.netty.util.DebugUtil;
|
||||
import org.jboss.netty.util.ThreadRenamingRunnable;
|
||||
|
||||
@ -42,8 +41,8 @@ public final class StackTraceSimplifier {
|
||||
/**
|
||||
* Removes unnecessary {@link StackTraceElement}s from the specified
|
||||
* exception. {@link ThreadRenamingRunnable}, {@link SimpleChannelHandler},
|
||||
* {@link DefaultChannelPipeline}, and {@link StaticChannelPipeline}
|
||||
* will be dropped from the trace.
|
||||
* and {@link ChannelPipeline} implementations will be dropped from the
|
||||
* trace.
|
||||
*/
|
||||
public static void simplify(Throwable e) {
|
||||
if (!SIMPLIFY_STACK_TRACE) {
|
||||
|
@ -27,7 +27,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.easymock.classextension.EasyMock;
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -21,6 +21,7 @@ import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class StaticChannelPipelineTest {
|
||||
|
||||
@Test
|
||||
|
@ -81,11 +81,13 @@ public abstract class AbstractSocketObjectStreamEchoTest {
|
||||
EchoHandler sh = new EchoHandler();
|
||||
EchoHandler ch = new EchoHandler();
|
||||
|
||||
sb.getPipeline().addLast("decoder", new ObjectDecoder());
|
||||
sb.getPipeline().addLast("decoder", new ObjectDecoder(
|
||||
ClassResolvers.cacheDisabled(String.class.getClassLoader())));
|
||||
sb.getPipeline().addLast("encoder", new ObjectEncoder());
|
||||
sb.getPipeline().addLast("handler", sh);
|
||||
|
||||
cb.getPipeline().addLast("decoder", new ObjectDecoder());
|
||||
cb.getPipeline().addLast("decoder", new ObjectDecoder(
|
||||
ClassResolvers.cacheDisabled(String.class.getClassLoader())));
|
||||
cb.getPipeline().addLast("encoder", new ObjectEncoder());
|
||||
cb.getPipeline().addLast("handler", ch);
|
||||
|
||||
|
@ -16,7 +16,6 @@
|
||||
package org.jboss.netty.handler.codec.serialization;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.easymock.classextension.EasyMock.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
@ -16,7 +16,6 @@
|
||||
package org.jboss.netty.logging;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.easymock.classextension.EasyMock.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.After;
|
||||
|
@ -16,7 +16,6 @@
|
||||
package org.jboss.netty.logging;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.easymock.classextension.EasyMock.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
@ -16,7 +16,6 @@
|
||||
package org.jboss.netty.logging;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.easymock.classextension.EasyMock.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
@ -16,7 +16,6 @@
|
||||
package org.jboss.netty.logging;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.easymock.classextension.EasyMock.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
@ -16,7 +16,6 @@
|
||||
package org.jboss.netty.util.internal;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.easymock.classextension.EasyMock.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
|
Loading…
Reference in New Issue
Block a user