Remove MessageList.remove(*) , MessageList.set(*) and MessageList.add(i,*)
This commit is contained in:
parent
7234a00f0d
commit
92bd4d2fe0
@ -18,11 +18,10 @@ package io.netty.handler.codec.http.websocketx;
|
|||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelFutureListener;
|
import io.netty.channel.ChannelFutureListener;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
import io.netty.channel.MessageList;
|
|
||||||
import io.netty.handler.codec.http.FullHttpResponse;
|
import io.netty.handler.codec.http.FullHttpResponse;
|
||||||
|
|
||||||
class WebSocketClientProtocolHandshakeHandler extends ChannelInboundHandlerAdapter {
|
class WebSocketClientProtocolHandshakeHandler extends SimpleChannelInboundHandler<FullHttpResponse> {
|
||||||
private final WebSocketClientHandshaker handshaker;
|
private final WebSocketClientHandshaker handshaker;
|
||||||
|
|
||||||
public WebSocketClientProtocolHandshakeHandler(WebSocketClientHandshaker handshaker) {
|
public WebSocketClientProtocolHandshakeHandler(WebSocketClientHandshaker handshaker) {
|
||||||
@ -46,10 +45,10 @@ class WebSocketClientProtocolHandshakeHandler extends ChannelInboundHandlerAdapt
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void messageReceived(ChannelHandlerContext ctx, MessageList<Object> messages) throws Exception {
|
protected void messageReceived(ChannelHandlerContext ctx, FullHttpResponse msg) throws Exception {
|
||||||
if (!handshaker.isHandshakeComplete()) {
|
if (!handshaker.isHandshakeComplete()) {
|
||||||
handshaker.finishHandshake(ctx.channel(), (FullHttpResponse) messages.get(0));
|
handshaker.finishHandshake(ctx.channel(), msg);
|
||||||
messages.remove(0);
|
msg.release();
|
||||||
ctx.fireUserEventTriggered(
|
ctx.fireUserEventTriggered(
|
||||||
WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE);
|
WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE);
|
||||||
ctx.pipeline().remove(this);
|
ctx.pipeline().remove(this);
|
||||||
|
@ -23,6 +23,7 @@ import io.netty.channel.ChannelInboundHandler;
|
|||||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||||
import io.netty.channel.ChannelPipeline;
|
import io.netty.channel.ChannelPipeline;
|
||||||
import io.netty.channel.MessageList;
|
import io.netty.channel.MessageList;
|
||||||
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
||||||
import io.netty.handler.codec.http.FullHttpRequest;
|
import io.netty.handler.codec.http.FullHttpRequest;
|
||||||
import io.netty.handler.codec.http.FullHttpResponse;
|
import io.netty.handler.codec.http.FullHttpResponse;
|
||||||
@ -121,19 +122,13 @@ public class WebSocketServerProtocolHandler extends WebSocketProtocolHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ChannelHandler forbiddenHttpRequestResponder() {
|
static ChannelHandler forbiddenHttpRequestResponder() {
|
||||||
return new ChannelInboundHandlerAdapter() {
|
return new SimpleChannelInboundHandler<FullHttpRequest>() {
|
||||||
@Override
|
@Override
|
||||||
public void messageReceived(final ChannelHandlerContext ctx, MessageList<Object> msgs) throws Exception {
|
protected void messageReceived(ChannelHandlerContext ctx, FullHttpRequest msg) throws Exception {
|
||||||
for (int i = 0; i < msgs.size(); i++) {
|
msg.release();
|
||||||
Object msg = msgs.get(i);
|
FullHttpResponse response =
|
||||||
if (msg instanceof FullHttpRequest) {
|
new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.FORBIDDEN);
|
||||||
FullHttpResponse response =
|
ctx.channel().write(response);
|
||||||
new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.FORBIDDEN);
|
|
||||||
ctx.channel().write(response);
|
|
||||||
msgs.remove(i--);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ctx.fireMessageReceived(msgs);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -684,10 +684,8 @@ public class SpdySessionHandler
|
|||||||
ctx.write(spdyRstStreamFrame);
|
ctx.write(spdyRstStreamFrame);
|
||||||
if (fireMessageReceived) {
|
if (fireMessageReceived) {
|
||||||
in.add(spdyRstStreamFrame);
|
in.add(spdyRstStreamFrame);
|
||||||
ctx.fireMessageReceived(in);
|
ctx.fireMessageReceived(in.copy());
|
||||||
while (!in.isEmpty()) {
|
in.clear();
|
||||||
in.remove(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,111 +137,6 @@ public final class MessageList<T> {
|
|||||||
return elements[index];
|
return elements[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageList<T> set(int index, T value) {
|
|
||||||
checkExclusive(index);
|
|
||||||
if (value == null) {
|
|
||||||
throw new NullPointerException("value");
|
|
||||||
}
|
|
||||||
elements[index] = value;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageList<T> set(int index, T[] src) {
|
|
||||||
if (src == null) {
|
|
||||||
throw new NullPointerException("src");
|
|
||||||
}
|
|
||||||
set(index, src, 0, src.length);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageList<T> set(int index, T[] src, int srcIdx, int srcLen) {
|
|
||||||
checkElements(src, srcIdx, srcLen);
|
|
||||||
|
|
||||||
if (srcLen == 0) {
|
|
||||||
return remove(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (srcLen == 1) {
|
|
||||||
return set(index, src[srcIdx]);
|
|
||||||
}
|
|
||||||
|
|
||||||
checkExclusive(index);
|
|
||||||
|
|
||||||
int oldSize = size;
|
|
||||||
int newSize = oldSize + srcLen - 1;
|
|
||||||
ensureCapacity(newSize);
|
|
||||||
System.arraycopy(elements, index + 1, elements, index + srcLen, oldSize - (index + 1));
|
|
||||||
System.arraycopy(src, srcIdx, elements, index, srcLen);
|
|
||||||
size = newSize;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageList<T> set(int index, int length, T value) {
|
|
||||||
if (length == 0) {
|
|
||||||
return add(index, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (length == 1) {
|
|
||||||
return set(index, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
checkRange(index, length);
|
|
||||||
if (value == null) {
|
|
||||||
throw new NullPointerException("value");
|
|
||||||
}
|
|
||||||
|
|
||||||
elements[index] = value;
|
|
||||||
int nextElemIdx = index + length;
|
|
||||||
int oldSize = size;
|
|
||||||
int newSize = oldSize - length + 1;
|
|
||||||
System.arraycopy(elements, nextElemIdx, elements, index + 1, oldSize - nextElemIdx);
|
|
||||||
Arrays.fill(elements, newSize, oldSize, null);
|
|
||||||
size = newSize;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageList<T> set(int index, int length, T[] src) {
|
|
||||||
if (src == null) {
|
|
||||||
throw new NullPointerException("src");
|
|
||||||
}
|
|
||||||
return set(index, length, src, 0, src.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageList<T> set(int index, int length, T[] src, int srcIdx, int srcLen) {
|
|
||||||
if (length == 0) {
|
|
||||||
return add(index, src, srcIdx, srcLen);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (length == 1) {
|
|
||||||
return set(index, src, srcIdx, srcLen);
|
|
||||||
}
|
|
||||||
|
|
||||||
checkRange(index, length);
|
|
||||||
checkElements(src, srcIdx, srcLen);
|
|
||||||
|
|
||||||
if (srcLen == length) {
|
|
||||||
System.arraycopy(src, srcIdx, elements, index, length);
|
|
||||||
} else if (srcLen < length) {
|
|
||||||
int remainderIdx = index + length;
|
|
||||||
int oldSize = size;
|
|
||||||
int newSize = oldSize - (length - srcLen);
|
|
||||||
System.arraycopy(src, srcIdx, elements, index, srcLen);
|
|
||||||
System.arraycopy(elements, remainderIdx, elements, index + srcLen, oldSize - remainderIdx);
|
|
||||||
Arrays.fill(elements, newSize, oldSize, null);
|
|
||||||
size = newSize;
|
|
||||||
} else {
|
|
||||||
int remainderIdx = index + length;
|
|
||||||
int oldSize = size;
|
|
||||||
int newSize = oldSize + srcLen - length;
|
|
||||||
ensureCapacity(newSize);
|
|
||||||
// 0 [1 2] 3 4 5 -> 0 [1 2 3] 3 4 5
|
|
||||||
System.arraycopy(elements, remainderIdx, elements, index + srcLen, oldSize - remainderIdx);
|
|
||||||
System.arraycopy(src, srcIdx, elements, index, srcLen);
|
|
||||||
size = newSize;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageList<T> add(T value) {
|
public MessageList<T> add(T value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
throw new NullPointerException("value");
|
throw new NullPointerException("value");
|
||||||
@ -272,70 +167,6 @@ public final class MessageList<T> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageList<T> add(int index, T value) {
|
|
||||||
checkInclusive(index);
|
|
||||||
|
|
||||||
if (value == null) {
|
|
||||||
throw new NullPointerException("value");
|
|
||||||
}
|
|
||||||
|
|
||||||
int oldSize = size;
|
|
||||||
int newSize = oldSize + 1;
|
|
||||||
ensureCapacity(newSize);
|
|
||||||
System.arraycopy(elements, index, elements, index + 1, oldSize - index);
|
|
||||||
elements[index] = value;
|
|
||||||
size = newSize;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageList<T> add(int index, T[] src) {
|
|
||||||
if (src == null) {
|
|
||||||
throw new NullPointerException("src");
|
|
||||||
}
|
|
||||||
return add(index, src, 0, src.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageList<T> add(int index, T[] src, int srcIdx, int srcLen) {
|
|
||||||
checkInclusive(index);
|
|
||||||
checkElements(src, srcIdx, srcLen);
|
|
||||||
|
|
||||||
if (srcLen == 0) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
int oldSize = size;
|
|
||||||
int newSize = oldSize + srcLen;
|
|
||||||
ensureCapacity(newSize);
|
|
||||||
System.arraycopy(elements, index, elements, index + srcLen, oldSize - index);
|
|
||||||
System.arraycopy(src, srcIdx, elements, index, srcLen);
|
|
||||||
size = newSize;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageList<T> remove(int index) {
|
|
||||||
checkExclusive(index);
|
|
||||||
int oldSize = size;
|
|
||||||
int newSize = oldSize - 1;
|
|
||||||
System.arraycopy(elements, index + 1, elements, index, newSize - index);
|
|
||||||
elements[newSize] = null;
|
|
||||||
size = newSize;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageList<T> remove(int index, int length) {
|
|
||||||
checkRange(index, length);
|
|
||||||
if (length == 0) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
int oldSize = size;
|
|
||||||
int newSize = oldSize - length;
|
|
||||||
System.arraycopy(elements, index + length, elements, index, newSize - index);
|
|
||||||
Arrays.fill(elements, newSize, oldSize, null);
|
|
||||||
size = newSize;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageList<T> clear() {
|
public MessageList<T> clear() {
|
||||||
Arrays.fill(elements, 0, size, null);
|
Arrays.fill(elements, 0, size, null);
|
||||||
size = 0;
|
size = 0;
|
||||||
@ -449,12 +280,6 @@ public final class MessageList<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkInclusive(int index) {
|
|
||||||
if (index > size) {
|
|
||||||
throw new IndexOutOfBoundsException(String.valueOf(index));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkRange(int index, int length) {
|
private void checkRange(int index, int length) {
|
||||||
if (index + length > size) {
|
if (index + length > size) {
|
||||||
throw new IndexOutOfBoundsException("index: " + index + ", length: " + length + ", size: " + size);
|
throw new IndexOutOfBoundsException("index: " + index + ", length: " + length + ", size: " + size);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user