Automated code clean-up
This commit is contained in:
parent
734d452be2
commit
77274ae743
@ -17,6 +17,7 @@ package io.netty.buffer;
|
||||
|
||||
import static io.netty.buffer.ChannelBuffers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import io.netty.util.CharsetUtil;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -26,7 +27,6 @@ import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import io.netty.util.CharsetUtil;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -16,8 +16,8 @@
|
||||
package io.netty.buffer;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import io.netty.util.CharsetUtil;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
|
@ -15,8 +15,8 @@
|
||||
*/
|
||||
package io.netty.buffer;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static io.netty.buffer.ChannelBuffers.*;
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -15,13 +15,13 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
|
||||
/**
|
||||
* The default {@link HttpChunkTrailer} implementation.
|
||||
*/
|
||||
|
@ -15,14 +15,14 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* The default {@link HttpMessage} implementation.
|
||||
*/
|
||||
|
@ -15,15 +15,15 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
|
||||
/**
|
||||
* An HTTP chunk which is used for HTTP chunked transfer-encoding.
|
||||
* {@link HttpMessageDecoder} generates {@link HttpChunk} after
|
||||
|
@ -15,15 +15,15 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
|
||||
/**
|
||||
* An HTTP message which provides common properties for {@link HttpRequest} and
|
||||
* {@link HttpResponse}.
|
||||
|
@ -37,9 +37,9 @@ public class DefaultHttpDataFactory implements HttpDataFactory {
|
||||
*/
|
||||
public static long MINSIZE = 0x4000;
|
||||
|
||||
private boolean useDisk;
|
||||
private final boolean useDisk;
|
||||
|
||||
private boolean checkSize;
|
||||
private final boolean checkSize;
|
||||
|
||||
private long minSize;
|
||||
|
||||
@ -55,7 +55,7 @@ public class DefaultHttpDataFactory implements HttpDataFactory {
|
||||
public DefaultHttpDataFactory() {
|
||||
useDisk = false;
|
||||
checkSize = true;
|
||||
this.minSize = MINSIZE;
|
||||
minSize = MINSIZE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -15,13 +15,13 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http.multipart;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
|
||||
/**
|
||||
* Extended interface for InterfaceHttpData
|
||||
*/
|
||||
|
@ -113,7 +113,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
|
||||
* a status code is set, -1 is returned.
|
||||
*/
|
||||
public int getStatusCode() {
|
||||
ChannelBuffer binaryData = this.getBinaryData();
|
||||
ChannelBuffer binaryData = getBinaryData();
|
||||
if (binaryData == null || binaryData.capacity() == 0) {
|
||||
return -1;
|
||||
}
|
||||
@ -130,7 +130,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
|
||||
* text is not supplied, an empty string is returned.
|
||||
*/
|
||||
public String getReasonText() {
|
||||
ChannelBuffer binaryData = this.getBinaryData();
|
||||
ChannelBuffer binaryData = getBinaryData();
|
||||
if (binaryData == null || binaryData.capacity() <= 2) {
|
||||
return "";
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
|
||||
throw new WebSocketHandshakeException("Requested subprotocol(s) not supported: " + subprotocols);
|
||||
} else {
|
||||
res.addHeader(Names.SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol);
|
||||
this.setSelectedSubprotocol(selectedSubprotocol);
|
||||
setSelectedSubprotocol(selectedSubprotocol);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -138,7 +138,7 @@ public class WebSocketServerHandshaker08 extends WebSocketServerHandshaker {
|
||||
throw new WebSocketHandshakeException("Requested subprotocol(s) not supported: " + subprotocols);
|
||||
} else {
|
||||
res.addHeader(Names.SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol);
|
||||
this.setSelectedSubprotocol(selectedSubprotocol);
|
||||
setSelectedSubprotocol(selectedSubprotocol);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@ public class WebSocketServerHandshaker13 extends WebSocketServerHandshaker {
|
||||
throw new WebSocketHandshakeException("Requested subprotocol(s) not supported: " + subprotocols);
|
||||
} else {
|
||||
res.addHeader(Names.SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol);
|
||||
this.setSelectedSubprotocol(selectedSubprotocol);
|
||||
setSelectedSubprotocol(selectedSubprotocol);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,14 +15,14 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http.websocketx;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
import io.netty.handler.codec.base64.Base64;
|
||||
import io.netty.util.CharsetUtil;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* TODO Document me.
|
||||
*/
|
||||
|
@ -15,11 +15,11 @@
|
||||
*/
|
||||
package io.netty.handler.codec.rtsp;
|
||||
|
||||
import io.netty.handler.codec.http.HttpMethod;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import io.netty.handler.codec.http.HttpMethod;
|
||||
|
||||
/**
|
||||
* The request method of RTSP.
|
||||
* @apiviz.exclude
|
||||
|
@ -16,7 +16,6 @@
|
||||
package io.netty.handler.codec.spdy;
|
||||
|
||||
import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.handler.codec.compression.CompressionException;
|
||||
import io.netty.util.internal.jzlib.JZlib;
|
||||
|
@ -15,11 +15,10 @@
|
||||
*/
|
||||
package io.netty.handler.codec.spdy;
|
||||
|
||||
import java.util.zip.Deflater;
|
||||
|
||||
import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
|
||||
import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
|
||||
import java.util.zip.Deflater;
|
||||
|
||||
class SpdyHeaderBlockZlibCompressor extends SpdyHeaderBlockCompressor {
|
||||
|
||||
|
@ -15,12 +15,11 @@
|
||||
*/
|
||||
package io.netty.handler.codec.spdy;
|
||||
|
||||
import java.util.zip.DataFormatException;
|
||||
import java.util.zip.Inflater;
|
||||
|
||||
import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
|
||||
import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
|
||||
import java.util.zip.DataFormatException;
|
||||
import java.util.zip.Inflater;
|
||||
|
||||
class SpdyHeaderBlockZlibDecompressor extends SpdyHeaderBlockDecompressor {
|
||||
|
||||
|
@ -15,12 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
|
@ -15,9 +15,7 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
|
@ -15,13 +15,14 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http;
|
||||
|
||||
import io.netty.util.CharsetUtil;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import io.netty.util.CharsetUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -15,10 +15,10 @@
|
||||
*/
|
||||
package io.netty.handler.codec.embedder;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* A helper that wraps an encoder or a decoder (codec) so that they can be used
|
||||
* without doing actual I/O in unit tests or higher level codecs. Please refer
|
||||
|
@ -15,9 +15,10 @@
|
||||
*/
|
||||
package io.netty.handler.codec.marshalling;
|
||||
|
||||
import org.jboss.marshalling.Unmarshaller;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
import org.jboss.marshalling.Unmarshaller;
|
||||
|
||||
/**
|
||||
* This provider is responsible to get an {@link Unmarshaller} for a {@link ChannelHandlerContext}
|
||||
*
|
||||
|
@ -98,7 +98,7 @@ public class ObjectDecoderInputStream extends InputStream implements
|
||||
} else {
|
||||
this.in = new DataInputStream(in);
|
||||
}
|
||||
this.classResolver = ClassResolvers.weakCachingResolver(classLoader);
|
||||
classResolver = ClassResolvers.weakCachingResolver(classLoader);
|
||||
this.maxObjectSize = maxObjectSize;
|
||||
}
|
||||
|
||||
|
@ -15,16 +15,16 @@
|
||||
*/
|
||||
package io.netty.handler.codec.serialization;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ChannelBufferOutputStream;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutput;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.buffer.ChannelBufferOutputStream;
|
||||
import io.netty.buffer.ChannelBuffers;
|
||||
|
||||
/**
|
||||
* An {@link ObjectOutput} which is interoperable with {@link ObjectDecoder}
|
||||
* and {@link ObjectDecoderInputStream}.
|
||||
|
@ -15,13 +15,13 @@
|
||||
*/
|
||||
package io.netty.handler.codec.protobuf;
|
||||
|
||||
import static io.netty.buffer.ChannelBuffers.*;
|
||||
import static org.hamcrest.core.Is.*;
|
||||
import static org.hamcrest.core.IsNull.*;
|
||||
import static io.netty.buffer.ChannelBuffers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.handler.codec.embedder.DecoderEmbedder;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -15,12 +15,12 @@
|
||||
*/
|
||||
package io.netty.handler.codec.protobuf;
|
||||
|
||||
import static org.hamcrest.core.Is.*;
|
||||
import static io.netty.buffer.ChannelBuffers.*;
|
||||
import static org.hamcrest.core.Is.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import io.netty.buffer.ChannelBuffer;
|
||||
import io.netty.handler.codec.embedder.EncoderEmbedder;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -29,6 +29,9 @@ public class UniqueName implements Comparable<UniqueName> {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args arguments to validate
|
||||
*/
|
||||
protected void validateArgs(Object... args) {
|
||||
// Subclasses will override.
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ public final class ConcurrentIdentityWeakKeyHashMap<K, V> extends AbstractMap<K,
|
||||
return segments[hash >>> segmentShift & segmentMask];
|
||||
}
|
||||
|
||||
private int hashOf(Object key) {
|
||||
private static int hashOf(Object key) {
|
||||
return hash(System.identityHashCode(key));
|
||||
}
|
||||
|
||||
@ -315,7 +315,7 @@ public final class ConcurrentIdentityWeakKeyHashMap<K, V> extends AbstractMap<K,
|
||||
return new Segment[i];
|
||||
}
|
||||
|
||||
private boolean keyEq(Object src, Object dest) {
|
||||
private static boolean keyEq(Object src, Object dest) {
|
||||
return src == dest;
|
||||
}
|
||||
|
||||
|
@ -672,7 +672,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
|
||||
@ -1351,7 +1351,7 @@ public class LegacyLinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
throws java.io.IOException, ClassNotFoundException {
|
||||
s.defaultReadObject();
|
||||
for (;;) {
|
||||
@SuppressWarnings("unchecked") E item = (E) s.readObject();
|
||||
E item = (E) s.readObject();
|
||||
if (item == null) {
|
||||
break;
|
||||
} else {
|
||||
|
@ -496,7 +496,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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -514,7 +514,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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -598,8 +598,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 +609,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 +622,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 +665,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) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
@ -703,28 +715,32 @@ 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
|
||||
}
|
||||
else if (timed) {
|
||||
long now = System.nanoTime();
|
||||
if ((nanos -= now - lastTime) > 0)
|
||||
if ((nanos -= now - lastTime) > 0) {
|
||||
LockSupport.parkNanos(this, nanos);
|
||||
}
|
||||
lastTime = now;
|
||||
}
|
||||
else {
|
||||
@ -739,13 +755,16 @@ 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;
|
||||
}
|
||||
|
||||
@ -758,7 +777,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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -767,8 +786,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;
|
||||
}
|
||||
@ -781,12 +801,14 @@ 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;
|
||||
}
|
||||
|
||||
@ -798,15 +820,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;
|
||||
}
|
||||
@ -835,25 +859,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;
|
||||
}
|
||||
@ -865,18 +890,20 @@ 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;
|
||||
}
|
||||
@ -885,27 +912,34 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
advance(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean hasNext() {
|
||||
return nextNode != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------- Removal methods -------------- */
|
||||
|
||||
@ -929,26 +963,34 @@ 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();
|
||||
break;
|
||||
@ -965,18 +1007,19 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Main implementation of remove(Object)
|
||||
@ -992,8 +1035,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;
|
||||
@ -1031,6 +1075,7 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
*
|
||||
* @throws NullPointerException if the specified element is null
|
||||
*/
|
||||
@Override
|
||||
public void put(E e) {
|
||||
xfer(e, true, ASYNC, 0);
|
||||
}
|
||||
@ -1045,6 +1090,7 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
* BlockingQueue.offer})
|
||||
* @throws NullPointerException if the specified element is null
|
||||
*/
|
||||
@Override
|
||||
public boolean offer(E e, long timeout, TimeUnit unit) {
|
||||
xfer(e, true, ASYNC, 0);
|
||||
return true;
|
||||
@ -1057,6 +1103,7 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
* @return {@code true} (as specified by {@link Queue#offer})
|
||||
* @throws NullPointerException if the specified element is null
|
||||
*/
|
||||
@Override
|
||||
public boolean offer(E e) {
|
||||
xfer(e, true, ASYNC, 0);
|
||||
return true;
|
||||
@ -1070,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;
|
||||
@ -1123,28 +1171,35 @@ 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();
|
||||
}
|
||||
|
||||
@Override
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public E poll() {
|
||||
return xfer(null, false, NOW, 0);
|
||||
}
|
||||
@ -1153,11 +1208,14 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
* @throws NullPointerException {@inheritDoc}
|
||||
* @throws IllegalArgumentException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
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);
|
||||
@ -1170,11 +1228,14 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
* @throws NullPointerException {@inheritDoc}
|
||||
* @throws IllegalArgumentException {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
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);
|
||||
@ -1196,10 +1257,12 @@ 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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public E peek() {
|
||||
return firstDataItem();
|
||||
}
|
||||
@ -1209,11 +1272,13 @@ 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;
|
||||
}
|
||||
|
||||
@ -1233,6 +1298,7 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
*
|
||||
* @return the number of elements in this queue
|
||||
*/
|
||||
@Override
|
||||
public int size() {
|
||||
return countOfMode(true);
|
||||
}
|
||||
@ -1252,6 +1318,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);
|
||||
}
|
||||
@ -1264,17 +1331,22 @@ 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;
|
||||
}
|
||||
|
||||
@ -1286,6 +1358,7 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
* {@link java.util.concurrent.BlockingQueue#remainingCapacity()
|
||||
* BlockingQueue.remainingCapacity})
|
||||
*/
|
||||
@Override
|
||||
public int remainingCapacity() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
@ -1300,8 +1373,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);
|
||||
}
|
||||
@ -1316,14 +1390,14 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
throws java.io.IOException, ClassNotFoundException {
|
||||
s.defaultReadObject();
|
||||
for (;;) {
|
||||
@SuppressWarnings("unchecked")
|
||||
E item = (E) s.readObject();
|
||||
if (item == null)
|
||||
if (item == null) {
|
||||
break;
|
||||
else
|
||||
} else {
|
||||
offer(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Unsafe mechanics
|
||||
|
||||
@ -1361,6 +1435,7 @@ public class LinkedTransferQueue<E> extends AbstractQueue<E>
|
||||
return java.security.AccessController.doPrivileged
|
||||
(new java.security
|
||||
.PrivilegedExceptionAction<sun.misc.Unsafe>() {
|
||||
@Override
|
||||
public sun.misc.Unsafe run() throws Exception {
|
||||
java.lang.reflect.Field f = sun.misc
|
||||
.Unsafe.class.getDeclaredField("theUnsafe");
|
||||
|
@ -15,12 +15,12 @@
|
||||
*/
|
||||
package io.netty.util.internal;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/**
|
||||
* Warn when user creates too many instances to avoid {@link OutOfMemoryError}.
|
||||
*/
|
||||
|
@ -456,7 +456,7 @@ final class InfCodes {
|
||||
// at least ten. The ten bytes are six bytes for the longest length/
|
||||
// distance pair plus four bytes for overloading the bit buffer.
|
||||
|
||||
int inflate_fast(int bl, int bd, int[] tl, int tl_index, int[] td,
|
||||
static int inflate_fast(int bl, int bd, int[] tl, int tl_index, int[] td,
|
||||
int td_index, InfBlocks s, ZStream z) {
|
||||
int t; // temporary pointer
|
||||
int[] tp; // temporary pointer
|
||||
|
@ -562,7 +562,7 @@ final class Inflate {
|
||||
}
|
||||
}
|
||||
|
||||
int inflateSetDictionary(ZStream z, byte[] dictionary, int dictLength) {
|
||||
static int inflateSetDictionary(ZStream z, byte[] dictionary, int dictLength) {
|
||||
int index = 0;
|
||||
int length = dictLength;
|
||||
if (z == null || z.istate == null || z.istate.mode != DICT0) {
|
||||
|
@ -114,7 +114,7 @@ public final class ZStream {
|
||||
if (istate == null) {
|
||||
return JZlib.Z_STREAM_ERROR;
|
||||
}
|
||||
return istate.inflateSetDictionary(this, dictionary, dictLength);
|
||||
return Inflate.inflateSetDictionary(this, dictionary, dictLength);
|
||||
}
|
||||
|
||||
public int deflateInit(int level) {
|
||||
|
@ -66,7 +66,7 @@ public class StringUtilTest {
|
||||
}
|
||||
}
|
||||
|
||||
private void assertStripped(final char controlCode) {
|
||||
private static void assertStripped(final char controlCode) {
|
||||
final Object object = "aaa" + controlCode + "bbb";
|
||||
final String stripped = StringUtil.stripControlCharacters(object);
|
||||
assertEquals("aaa bbb", stripped);
|
||||
|
Loading…
x
Reference in New Issue
Block a user