Overall automated clean up
This commit is contained in:
parent
fae19efd73
commit
b0a2b43379
@ -229,12 +229,12 @@ public class ClientBootstrap extends Bootstrap {
|
||||
// Connect.
|
||||
return ch.connect(remoteAddress);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Attempts to bind a channel with the specified {@code localAddress}. later the channel can be connected
|
||||
* to a remoteAddress by calling {@link Channel#connect(SocketAddress)}.This method is useful where bind and connect
|
||||
* need to be done in separate steps.
|
||||
*
|
||||
* need to be done in separate steps.
|
||||
*
|
||||
* This can also be useful if you want to set an attachment to the {@link Channel} via
|
||||
* {@link Channel#setAttachment(Object)} so you can use it after the {@link #bind(SocketAddress)} was done.
|
||||
* <br>
|
||||
@ -247,7 +247,7 @@ public class ClientBootstrap extends Bootstrap {
|
||||
* bootstrap.connect(new InetSocketAddress("192.168.0.30", 8080));
|
||||
* </pre>
|
||||
* <br>
|
||||
*
|
||||
*
|
||||
* You can use it then in your handlers like this:
|
||||
*
|
||||
* <pre>
|
||||
@ -256,7 +256,7 @@ public class ClientBootstrap extends Bootstrap {
|
||||
* Object dataObject = ctx.getChannel().getAttachment();
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @return a future object which notifies when this bind attempt
|
||||
|
@ -52,7 +52,7 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
|
||||
|
||||
public void writerIndex(int writerIndex) {
|
||||
if (writerIndex < readerIndex || writerIndex > capacity()) {
|
||||
throw new IndexOutOfBoundsException("Invalid readerIndex: "
|
||||
throw new IndexOutOfBoundsException("Invalid readerIndex: "
|
||||
+ readerIndex + " - Maximum is " + writerIndex);
|
||||
}
|
||||
this.writerIndex = writerIndex;
|
||||
@ -60,7 +60,7 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
|
||||
|
||||
public void setIndex(int readerIndex, int writerIndex) {
|
||||
if (readerIndex < 0 || readerIndex > writerIndex || writerIndex > capacity()) {
|
||||
throw new IndexOutOfBoundsException("Invalid writerIndex: "
|
||||
throw new IndexOutOfBoundsException("Invalid writerIndex: "
|
||||
+ writerIndex + " - Maximum is " + readerIndex + " or " + capacity());
|
||||
}
|
||||
this.readerIndex = readerIndex;
|
||||
@ -116,7 +116,7 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
|
||||
|
||||
public void ensureWritableBytes(int writableBytes) {
|
||||
if (writableBytes > writableBytes()) {
|
||||
throw new IndexOutOfBoundsException("Writable bytes exceeded: Got "
|
||||
throw new IndexOutOfBoundsException("Writable bytes exceeded: Got "
|
||||
+ writableBytes + ", maximum is " + writableBytes());
|
||||
}
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ public class ChannelBufferInputStream extends InputStream implements DataInput {
|
||||
lineBuf.setLength(lineBuf.length() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return lineBuf.toString();
|
||||
}
|
||||
@ -227,7 +227,7 @@ public class ChannelBufferInputStream extends InputStream implements DataInput {
|
||||
throw new IndexOutOfBoundsException("fieldSize cannot be a negative number");
|
||||
}
|
||||
if (fieldSize > available()) {
|
||||
throw new EOFException("fieldSize is too long! Length is " + fieldSize
|
||||
throw new EOFException("fieldSize is too long! Length is " + fieldSize
|
||||
+ ", but maximum is " + available());
|
||||
}
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
int componentId = componentId(index);
|
||||
if (index > capacity() - length || dstIndex > dst.length - length) {
|
||||
throw new IndexOutOfBoundsException("Too many bytes to read - Needs "
|
||||
+ (index + length) + ", maximum is " + capacity() + " or "
|
||||
+ (index + length) + ", maximum is " + capacity() + " or "
|
||||
+ dst.length);
|
||||
}
|
||||
|
||||
@ -286,7 +286,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
if (DetectionUtil.javaVersion() >= 7) {
|
||||
return (int) out.write(toByteBuffers(index, length));
|
||||
}
|
||||
|
||||
|
||||
// XXX Gathering write is not supported because of a known issue.
|
||||
// See http://bugs.sun.com/view_bug.do?bug_id=6210541
|
||||
// This issue appeared in 2004 and is still unresolved!?
|
||||
@ -297,7 +297,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
throws IOException {
|
||||
int componentId = componentId(index);
|
||||
if (index > capacity() - length) {
|
||||
throw new IndexOutOfBoundsException("Too many bytes to be read - needs "
|
||||
throw new IndexOutOfBoundsException("Too many bytes to be read - needs "
|
||||
+ (index + length) + ", maximum of " + capacity());
|
||||
}
|
||||
|
||||
@ -647,9 +647,9 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
|
||||
final int bytesToMove = capacity() - localReaderIndex;
|
||||
List<ChannelBuffer> list = decompose(localReaderIndex, bytesToMove);
|
||||
|
||||
|
||||
// If the list is empty we need to assign a new one because
|
||||
// we get a List that is immutable.
|
||||
// we get a List that is immutable.
|
||||
//
|
||||
// See https://github.com/netty/netty/issues/325
|
||||
if (list.isEmpty()) {
|
||||
|
@ -73,8 +73,8 @@ public class DynamicChannelBuffer extends AbstractChannelBuffer {
|
||||
int minNewCapacity = writerIndex() + minWritableBytes;
|
||||
while (newCapacity < minNewCapacity) {
|
||||
newCapacity <<= 1;
|
||||
|
||||
// Check if we exceeded the maximum size of 2gb if this is the case then
|
||||
|
||||
// Check if we exceeded the maximum size of 2gb if this is the case then
|
||||
// newCapacity == 0
|
||||
//
|
||||
// https://github.com/netty/netty/issues/258
|
||||
|
@ -359,11 +359,11 @@ public interface Channel extends Comparable<Channel> {
|
||||
* {@code interestOps} change request succeeds or fails
|
||||
*/
|
||||
ChannelFuture setReadable(boolean readable);
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves an object which is {@link #setAttachment(Object) attached} to
|
||||
* this {@link Channel}.
|
||||
*
|
||||
*
|
||||
* @return {@code null} if no object was attached or {@code null} was
|
||||
* attached
|
||||
*/
|
||||
|
@ -57,7 +57,7 @@ package org.jboss.netty.channel;
|
||||
* You will also find various helper methods in {@link Channels} to be useful
|
||||
* to generate and send an artificial or manipulated event.
|
||||
* <p>
|
||||
* <strong>Caution:</strong>
|
||||
* <strong>Caution:</strong>
|
||||
* <p>
|
||||
* Use the *Later(..) methods of the {@link Channels} class if you want to send an upstream event from a {@link ChannelDownstreamHandler} otherwise you may run into threading issues.
|
||||
*
|
||||
|
@ -460,7 +460,7 @@ public interface ChannelPipeline {
|
||||
* with this pipeline's {@link Channel}.
|
||||
*/
|
||||
ChannelFuture execute(Runnable task);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the {@link Channel} that this pipeline is attached to.
|
||||
*
|
||||
|
@ -38,7 +38,7 @@ public interface ChannelSink {
|
||||
* one of its {@link ChannelHandler}s process a {@link ChannelEvent}.
|
||||
*/
|
||||
void exceptionCaught(ChannelPipeline pipeline, ChannelEvent e, ChannelPipelineException cause) throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* Execute the given {@link Runnable} later in the io-thread.
|
||||
* Some implementation may not support this and just execute it directly.
|
||||
|
@ -304,15 +304,15 @@ public final class Channels {
|
||||
*/
|
||||
public static ChannelFuture fireWriteCompleteLater(final Channel channel, final long amount) {
|
||||
return channel.getPipeline().execute(new Runnable() {
|
||||
|
||||
|
||||
public void run() {
|
||||
fireWriteComplete(channel, amount);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sends a {@code "writeComplete"} event to the first
|
||||
* {@link ChannelUpstreamHandler} in the {@link ChannelPipeline} of
|
||||
@ -336,7 +336,7 @@ public final class Channels {
|
||||
public static void fireWriteComplete(ChannelHandlerContext ctx, long amount) {
|
||||
ctx.sendUpstream(new DefaultWriteCompletionEvent(ctx.getChannel(), amount));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sends a {@code "channelInterestChanged"} event to the first
|
||||
* {@link ChannelUpstreamHandler} in the {@link ChannelPipeline} of
|
||||
@ -344,14 +344,14 @@ public final class Channels {
|
||||
*/
|
||||
public static ChannelFuture fireChannelInterestChangedLater(final Channel channel) {
|
||||
return channel.getPipeline().execute(new Runnable() {
|
||||
|
||||
|
||||
public void run() {
|
||||
fireChannelInterestChanged(channel);
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sends a {@code "channelInterestChanged"} event to the first
|
||||
* {@link ChannelUpstreamHandler} in the {@link ChannelPipeline} of
|
||||
@ -384,7 +384,7 @@ public final class Channels {
|
||||
*/
|
||||
public static ChannelFuture fireChannelDisconnectedLater(final Channel channel) {
|
||||
return channel.getPipeline().execute(new Runnable() {
|
||||
|
||||
|
||||
public void run() {
|
||||
fireChannelDisconnected(channel);
|
||||
}
|
||||
@ -419,14 +419,14 @@ public final class Channels {
|
||||
*/
|
||||
public static ChannelFuture fireChannelUnboundLater(final Channel channel) {
|
||||
return channel.getPipeline().execute(new Runnable() {
|
||||
|
||||
|
||||
public void run() {
|
||||
fireChannelUnbound(channel);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sends a {@code "channelUnbound"} event to the first
|
||||
* {@link ChannelUpstreamHandler} in the {@link ChannelPipeline} of
|
||||
@ -449,8 +449,8 @@ public final class Channels {
|
||||
ctx.getChannel(), ChannelState.BOUND, null));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sends a {@code "channelClosed"} event to the first
|
||||
* {@link ChannelUpstreamHandler} in the {@link ChannelPipeline} of
|
||||
@ -458,15 +458,15 @@ public final class Channels {
|
||||
*/
|
||||
public static ChannelFuture fireChannelClosedLater(final Channel channel) {
|
||||
return channel.getPipeline().execute(new Runnable() {
|
||||
|
||||
|
||||
public void run() {
|
||||
fireChannelClosed(channel);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sends a {@code "channelClosed"} event to the first
|
||||
* {@link ChannelUpstreamHandler} in the {@link ChannelPipeline} of
|
||||
@ -502,7 +502,7 @@ public final class Channels {
|
||||
*/
|
||||
public static ChannelFuture fireExceptionCaughtLater(final Channel channel, final Throwable cause) {
|
||||
return channel.getPipeline().execute(new Runnable() {
|
||||
|
||||
|
||||
public void run() {
|
||||
fireExceptionCaught(channel, cause);
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ import java.net.SocketAddress;
|
||||
* }
|
||||
* }</pre>
|
||||
* <p>
|
||||
* <strong>Caution:</strong>
|
||||
* <strong>Caution:</strong>
|
||||
* <p>
|
||||
* Use the *Later(..) methods of the {@link Channels} class if you want to send an upstream event from a {@link ChannelDownstreamHandler} otherwise you may run into threading issues.
|
||||
*
|
||||
|
@ -146,7 +146,7 @@ public class SimpleChannelUpstreamHandler implements ChannelUpstreamHandler {
|
||||
/**
|
||||
* Invoked when a {@link Channel} is open, but not bound nor connected.
|
||||
* <br/>
|
||||
*
|
||||
*
|
||||
* <strong>Be aware that this event is fired from within the Boss-Thread so you should not execute any heavy operation in there as it will block the dispatching to other workers!</strong>
|
||||
*/
|
||||
public void channelOpen(
|
||||
@ -158,7 +158,7 @@ public class SimpleChannelUpstreamHandler implements ChannelUpstreamHandler {
|
||||
* Invoked when a {@link Channel} is open and bound to a local address,
|
||||
* but not connected.
|
||||
* <br/>
|
||||
*
|
||||
*
|
||||
* <strong>Be aware that this event is fired from within the Boss-Thread so you should not execute any heavy operation in there as it will block the dispatching to other workers!</strong>
|
||||
*/
|
||||
public void channelBound(
|
||||
@ -170,7 +170,7 @@ public class SimpleChannelUpstreamHandler implements ChannelUpstreamHandler {
|
||||
* Invoked when a {@link Channel} is open, bound to a local address, and
|
||||
* connected to a remote address.
|
||||
* <br/>
|
||||
*
|
||||
*
|
||||
* <strong>Be aware that this event is fired from within the Boss-Thread so you should not execute any heavy operation in there as it will block the dispatching to other workers!</strong>
|
||||
*/
|
||||
public void channelConnected(
|
||||
|
@ -22,13 +22,13 @@ public class ChannelRunnableWrapper extends DefaultChannelFuture implements Runn
|
||||
|
||||
private final Runnable task;
|
||||
private boolean started;
|
||||
|
||||
|
||||
public ChannelRunnableWrapper(Channel channel, Runnable task) {
|
||||
super(channel, true);
|
||||
this.task = task;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void run() {
|
||||
synchronized (this) {
|
||||
if (!isCancelled()) {
|
||||
@ -52,7 +52,7 @@ public class ChannelRunnableWrapper extends DefaultChannelFuture implements Runn
|
||||
}
|
||||
return super.cancel();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -18,14 +18,14 @@ package org.jboss.netty.channel.socket;
|
||||
|
||||
/**
|
||||
* A {@link Worker} is responsible to dispatch IO operations
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface Worker extends Runnable {
|
||||
|
||||
/**
|
||||
* Execute the given {@link Runnable} in the IO-Thread. This may be now or
|
||||
* later once the IO-Thread do some other work.
|
||||
*
|
||||
*
|
||||
* @param task
|
||||
* the {@link Runnable} to execute
|
||||
*/
|
||||
|
@ -35,7 +35,7 @@ public abstract class AbstractNioChannelSink extends AbstractChannelSink {
|
||||
return wrapper;
|
||||
}
|
||||
return super.execute(pipeline, task);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -17,18 +17,6 @@ package org.jboss.netty.channel.socket.nio;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelException;
|
||||
import org.jboss.netty.channel.ChannelFuture;
|
||||
import org.jboss.netty.channel.MessageEvent;
|
||||
import org.jboss.netty.channel.socket.Worker;
|
||||
import org.jboss.netty.channel.socket.nio.SocketSendBufferPool.SendBuffer;
|
||||
import org.jboss.netty.logging.InternalLogger;
|
||||
import org.jboss.netty.logging.InternalLoggerFactory;
|
||||
import org.jboss.netty.util.ThreadRenamingRunnable;
|
||||
import org.jboss.netty.util.internal.DeadLockProofWorker;
|
||||
import org.jboss.netty.util.internal.QueueFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.AsynchronousCloseException;
|
||||
import java.nio.channels.CancelledKeyException;
|
||||
@ -47,8 +35,20 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelException;
|
||||
import org.jboss.netty.channel.ChannelFuture;
|
||||
import org.jboss.netty.channel.MessageEvent;
|
||||
import org.jboss.netty.channel.socket.Worker;
|
||||
import org.jboss.netty.channel.socket.nio.SocketSendBufferPool.SendBuffer;
|
||||
import org.jboss.netty.logging.InternalLogger;
|
||||
import org.jboss.netty.logging.InternalLoggerFactory;
|
||||
import org.jboss.netty.util.ThreadRenamingRunnable;
|
||||
import org.jboss.netty.util.internal.DeadLockProofWorker;
|
||||
import org.jboss.netty.util.internal.QueueFactory;
|
||||
|
||||
abstract class AbstractNioWorker implements Worker {
|
||||
|
||||
|
||||
|
||||
private static final AtomicInteger nextId = new AtomicInteger();
|
||||
|
||||
@ -64,7 +64,7 @@ abstract class AbstractNioWorker implements Worker {
|
||||
|
||||
static final int CLEANUP_INTERVAL = 256; // XXX Hard-coded value, but won't need customization.
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Executor used to execute {@link Runnable}s such as channel registration
|
||||
* task.
|
||||
@ -117,7 +117,7 @@ abstract class AbstractNioWorker implements Worker {
|
||||
|
||||
private final Queue<Runnable> eventQueue = QueueFactory.createQueue(Runnable.class);
|
||||
|
||||
|
||||
|
||||
private volatile int cancelledKeys; // should use AtomicInteger but we just need approximation
|
||||
|
||||
protected final SocketSendBufferPool sendBufferPool = new SocketSendBufferPool();
|
||||
@ -132,16 +132,16 @@ abstract class AbstractNioWorker implements Worker {
|
||||
this.executor = executor;
|
||||
this.allowShutdownOnIdle = allowShutdownOnIdle;
|
||||
}
|
||||
|
||||
|
||||
void register(AbstractNioChannel<?> channel, ChannelFuture future) {
|
||||
|
||||
Runnable registerTask = createRegisterTask(channel, future);
|
||||
Selector selector = start();
|
||||
|
||||
|
||||
|
||||
boolean offered = registerTaskQueue.offer(registerTask);
|
||||
assert offered;
|
||||
|
||||
|
||||
if (wakenUp.compareAndSet(false, true)) {
|
||||
selector.wakeup();
|
||||
}
|
||||
@ -149,7 +149,7 @@ abstract class AbstractNioWorker implements Worker {
|
||||
|
||||
/**
|
||||
* Start the {@link AbstractNioWorker} and return the {@link Selector} that will be used for the {@link AbstractNioChannel}'s when they get registered
|
||||
*
|
||||
*
|
||||
* @return selector
|
||||
*/
|
||||
private Selector start() {
|
||||
@ -157,7 +157,7 @@ abstract class AbstractNioWorker implements Worker {
|
||||
if (!started) {
|
||||
// Open a selector if this worker didn't start yet.
|
||||
try {
|
||||
this.selector = Selector.open();
|
||||
selector = Selector.open();
|
||||
} catch (Throwable t) {
|
||||
throw new ChannelException("Failed to create a selector.", t);
|
||||
}
|
||||
@ -175,7 +175,7 @@ abstract class AbstractNioWorker implements Worker {
|
||||
} catch (Throwable t) {
|
||||
logger.warn("Failed to close a selector.", t);
|
||||
}
|
||||
this.selector = null;
|
||||
selector = null;
|
||||
// The method will return to the caller at this point.
|
||||
}
|
||||
}
|
||||
@ -297,10 +297,10 @@ abstract class AbstractNioWorker implements Worker {
|
||||
public void executeInIoThread(Runnable task) {
|
||||
executeInIoThread(task, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute the {@link Runnable} in a IO-Thread
|
||||
*
|
||||
*
|
||||
* @param task
|
||||
* the {@link Runnable} to execute
|
||||
* @param alwaysAsync
|
||||
@ -325,8 +325,8 @@ abstract class AbstractNioWorker implements Worker {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void processRegisterTaskQueue() throws IOException {
|
||||
for (;;) {
|
||||
final Runnable task = registerTaskQueue.poll();
|
||||
@ -350,7 +350,7 @@ abstract class AbstractNioWorker implements Worker {
|
||||
cleanUpCancelledKeys();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void processEventQueue() throws IOException {
|
||||
for (;;) {
|
||||
final Runnable task = eventQueue.poll();
|
||||
@ -361,7 +361,7 @@ abstract class AbstractNioWorker implements Worker {
|
||||
cleanUpCancelledKeys();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void processSelectedKeys(Set<SelectionKey> selectedKeys) throws IOException {
|
||||
for (Iterator<SelectionKey> i = selectedKeys.iterator(); i.hasNext();) {
|
||||
SelectionKey k = i.next();
|
||||
@ -395,9 +395,9 @@ abstract class AbstractNioWorker implements Worker {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void close(SelectionKey k) {
|
||||
AbstractNioChannel<?> ch = (AbstractNioChannel<?>) k.attachment();
|
||||
close(ch, succeededFuture(ch));
|
||||
@ -431,7 +431,7 @@ abstract class AbstractNioWorker implements Worker {
|
||||
write0(ch);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void writeFromSelectorLoop(final SelectionKey k) {
|
||||
AbstractNioChannel<?> ch = (AbstractNioChannel<?>) k.attachment();
|
||||
ch.writeSuspended = false;
|
||||
@ -552,7 +552,7 @@ abstract class AbstractNioWorker implements Worker {
|
||||
static boolean isIoThread(AbstractNioChannel<?> channel) {
|
||||
return Thread.currentThread() == channel.worker.thread;
|
||||
}
|
||||
|
||||
|
||||
protected void setOpWrite(AbstractNioChannel<?> channel) {
|
||||
Selector selector = this.selector;
|
||||
SelectionKey key = channel.channel.keyFor(selector);
|
||||
@ -598,13 +598,13 @@ abstract class AbstractNioWorker implements Worker {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void close(AbstractNioChannel<?> channel, ChannelFuture future) {
|
||||
boolean connected = channel.isConnected();
|
||||
boolean bound = channel.isBound();
|
||||
boolean iothread = isIoThread(channel);
|
||||
|
||||
|
||||
try {
|
||||
channel.channel.close();
|
||||
cancelledKeys ++;
|
||||
@ -688,7 +688,7 @@ abstract class AbstractNioWorker implements Worker {
|
||||
}
|
||||
evt.getFuture().setFailure(cause);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -714,16 +714,16 @@ abstract class AbstractNioWorker implements Worker {
|
||||
// Override OP_WRITE flag - a user cannot change this flag.
|
||||
interestOps &= ~Channel.OP_WRITE;
|
||||
interestOps |= channel.getRawInterestOps() & Channel.OP_WRITE;
|
||||
|
||||
|
||||
if (key == null || selector == null) {
|
||||
if (channel.getRawInterestOps() != interestOps) {
|
||||
changed = true;
|
||||
}
|
||||
|
||||
|
||||
// Not registered to the worker yet.
|
||||
// Set the rawInterestOps immediately; RegisterTask will pick it up.
|
||||
channel.setRawInterestOpsNow(interestOps);
|
||||
|
||||
|
||||
future.setSuccess();
|
||||
if (changed) {
|
||||
if (iothread) {
|
||||
@ -732,7 +732,7 @@ abstract class AbstractNioWorker implements Worker {
|
||||
fireChannelInterestChangedLater(channel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -802,7 +802,7 @@ abstract class AbstractNioWorker implements Worker {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read is called when a Selector has been notified that the underlying channel
|
||||
* was something to be read. The channel would previously have registered its interest
|
||||
@ -814,11 +814,11 @@ abstract class AbstractNioWorker implements Worker {
|
||||
|
||||
/**
|
||||
* Create a new {@link Runnable} which will register the {@link AbstractNioWorker} with the {@link Channel}
|
||||
*
|
||||
*
|
||||
* @param channel
|
||||
* @param future
|
||||
* @return task
|
||||
*/
|
||||
protected abstract Runnable createRegisterTask(AbstractNioChannel<?> channel, ChannelFuture future);
|
||||
|
||||
|
||||
}
|
||||
|
@ -16,14 +16,14 @@
|
||||
|
||||
package org.jboss.netty.channel.socket.nio;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.socket.Worker;
|
||||
import org.jboss.netty.util.ExternalResourceReleasable;
|
||||
import org.jboss.netty.util.internal.ExecutorUtil;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* Abstract base class for {@link WorkerPool} implementations that create the {@link Worker}'s up-front and return them in a "fair" fashion when calling
|
||||
* {@link #nextWorker()}
|
||||
@ -34,10 +34,10 @@ public abstract class AbstractNioWorkerPool<E extends AbstractNioWorker> impleme
|
||||
private final AbstractNioWorker[] workers;
|
||||
private final AtomicInteger workerIndex = new AtomicInteger();
|
||||
private final Executor workerExecutor;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new instance
|
||||
*
|
||||
*
|
||||
* @param workerExecutor the {@link Executor} to use for the {@link Worker}'s
|
||||
* @param allowShutdownOnIdle allow the {@link Worker}'s to shutdown when there is not {@link Channel} is registered with it
|
||||
* @param workerCount the count of {@link Worker}'s to create
|
||||
@ -50,7 +50,7 @@ public abstract class AbstractNioWorkerPool<E extends AbstractNioWorker> impleme
|
||||
throw new IllegalArgumentException(
|
||||
"workerCount (" + workerCount + ") " +
|
||||
"must be a positive integer.");
|
||||
}
|
||||
}
|
||||
workers = new AbstractNioWorker[workerCount];
|
||||
|
||||
for (int i = 0; i < workers.length; i++) {
|
||||
@ -62,11 +62,11 @@ public abstract class AbstractNioWorkerPool<E extends AbstractNioWorker> impleme
|
||||
|
||||
/**
|
||||
* Create a new {@link Worker} which uses the given {@link Executor} to service IO
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param executor the {@link Executor} to use
|
||||
* @param allowShutdownOnIdle allow the {@link Worker} to shutdown when there is not {@link Channel} is registered with it
|
||||
* @return worker the new {@link Worker}
|
||||
* @return worker the new {@link Worker}
|
||||
*/
|
||||
protected abstract E createWorker(Executor executor, boolean allowShutdownOnIdle);
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.jboss.netty.channel.socket.nio;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.fireChannelOpen;
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
import java.nio.channels.SocketChannel;
|
||||
|
||||
@ -38,7 +38,7 @@ final class NioAcceptedSocketChannel extends NioSocketChannel {
|
||||
this.bossThread = bossThread;
|
||||
|
||||
setConnected();
|
||||
|
||||
|
||||
fireChannelOpen(this);
|
||||
}
|
||||
}
|
||||
|
@ -88,14 +88,14 @@ public class NioClientSocketChannelFactory implements ClientSocketChannelFactory
|
||||
private final NioClientSocketPipelineSink sink;
|
||||
|
||||
/**
|
||||
* Creates a new {@link NioClientSocketChannelFactory} which uses {@link Executors#newCachedThreadPool()} for the worker and boss executors.
|
||||
*
|
||||
* Creates a new {@link NioClientSocketChannelFactory} which uses {@link Executors#newCachedThreadPool()} for the worker and boss executors.
|
||||
*
|
||||
* See {@link #NioClientSocketChannelFactory(Executor, Executor)}
|
||||
*/
|
||||
public NioClientSocketChannelFactory() {
|
||||
this(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance. Calling this constructor is same with calling
|
||||
* {@link #NioClientSocketChannelFactory(Executor, Executor, int, int)} with
|
||||
@ -163,7 +163,7 @@ public class NioClientSocketChannelFactory implements ClientSocketChannelFactory
|
||||
"bossCount (" + bossCount + ") " +
|
||||
"must be a positive integer.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
this.bossExecutor = bossExecutor;
|
||||
this.workerPool = workerPool;
|
||||
|
@ -15,18 +15,7 @@
|
||||
*/
|
||||
package org.jboss.netty.channel.socket.nio;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.fireChannelDisconnected;
|
||||
import static org.jboss.netty.channel.Channels.fireChannelDisconnectedLater;
|
||||
import static org.jboss.netty.channel.Channels.fireExceptionCaught;
|
||||
import static org.jboss.netty.channel.Channels.fireExceptionCaughtLater;
|
||||
import static org.jboss.netty.channel.Channels.fireMessageReceived;
|
||||
import static org.jboss.netty.channel.Channels.succeededFuture;
|
||||
import org.jboss.netty.buffer.ChannelBufferFactory;
|
||||
import org.jboss.netty.channel.ChannelException;
|
||||
import org.jboss.netty.channel.ChannelFuture;
|
||||
import org.jboss.netty.channel.Channels;
|
||||
import org.jboss.netty.channel.MessageEvent;
|
||||
import org.jboss.netty.channel.ReceiveBufferSizePredictor;
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.SocketAddress;
|
||||
@ -39,6 +28,13 @@ import java.nio.channels.Selector;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.jboss.netty.buffer.ChannelBufferFactory;
|
||||
import org.jboss.netty.channel.ChannelException;
|
||||
import org.jboss.netty.channel.ChannelFuture;
|
||||
import org.jboss.netty.channel.Channels;
|
||||
import org.jboss.netty.channel.MessageEvent;
|
||||
import org.jboss.netty.channel.ReceiveBufferSizePredictor;
|
||||
|
||||
/**
|
||||
* A class responsible for registering channels with {@link Selector}.
|
||||
* It also implements the {@link Selector} loop.
|
||||
@ -58,7 +54,7 @@ public class NioDatagramWorker extends AbstractNioWorker {
|
||||
NioDatagramWorker(final Executor executor, boolean allowShutdownOnIdle) {
|
||||
super(executor, allowShutdownOnIdle);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean read(final SelectionKey key) {
|
||||
final NioDatagramChannel channel = (NioDatagramChannel) key.attachment();
|
||||
@ -110,7 +106,7 @@ public class NioDatagramWorker extends AbstractNioWorker {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean scheduleWriteIfNecessary(final AbstractNioChannel<?> channel) {
|
||||
@ -163,7 +159,7 @@ public class NioDatagramWorker extends AbstractNioWorker {
|
||||
protected Runnable createRegisterTask(AbstractNioChannel<?> channel, ChannelFuture future) {
|
||||
return new ChannelRegistionTask((NioDatagramChannel) channel, future);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* RegisterTask is a task responsible for registering a channel with a
|
||||
* selector.
|
||||
@ -206,7 +202,7 @@ public class NioDatagramWorker extends AbstractNioWorker {
|
||||
future.setFailure(e);
|
||||
}
|
||||
close(channel, succeededFuture(channel));
|
||||
|
||||
|
||||
if (!(e instanceof ClosedChannelException)) {
|
||||
throw new ChannelException(
|
||||
"Failed to register a socket to the selector.", e);
|
||||
@ -214,7 +210,7 @@ public class NioDatagramWorker extends AbstractNioWorker {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeFromUserCode(final AbstractNioChannel<?> channel) {
|
||||
/*
|
||||
@ -243,7 +239,7 @@ public class NioDatagramWorker extends AbstractNioWorker {
|
||||
|
||||
write0(channel);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void write0(final AbstractNioChannel<?> channel) {
|
||||
|
||||
|
@ -20,7 +20,7 @@ import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* Default implementation which hands of {@link NioDatagramWorker}'s
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class NioDatagramWorkerPool extends AbstractNioWorkerPool<NioDatagramWorker> {
|
||||
|
@ -90,14 +90,14 @@ public class NioServerSocketChannelFactory implements ServerSocketChannelFactory
|
||||
private final ChannelSink sink;
|
||||
|
||||
/**
|
||||
* Create a new {@link NioServerSocketChannelFactory} using {@link Executors#newCachedThreadPool()} for the boss and worker.
|
||||
*
|
||||
* Create a new {@link NioServerSocketChannelFactory} using {@link Executors#newCachedThreadPool()} for the boss and worker.
|
||||
*
|
||||
* See {@link #NioServerSocketChannelFactory(Executor, Executor)}
|
||||
*/
|
||||
public NioServerSocketChannelFactory() {
|
||||
this(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance. Calling this constructor is same with calling
|
||||
* {@link #NioServerSocketChannelFactory(Executor, Executor, int)} with 2 *
|
||||
@ -146,7 +146,7 @@ public class NioServerSocketChannelFactory implements ServerSocketChannelFactory
|
||||
if (workerPool == null) {
|
||||
throw new NullPointerException("workerPool");
|
||||
}
|
||||
|
||||
|
||||
this.bossExecutor = bossExecutor;
|
||||
this.workerPool = workerPool;
|
||||
sink = new NioServerSocketPipelineSink(workerPool);
|
||||
|
@ -15,16 +15,7 @@
|
||||
*/
|
||||
package org.jboss.netty.channel.socket.nio;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.fireChannelBound;
|
||||
import static org.jboss.netty.channel.Channels.fireChannelConnected;
|
||||
import static org.jboss.netty.channel.Channels.fireExceptionCaught;
|
||||
import static org.jboss.netty.channel.Channels.fireMessageReceived;
|
||||
import static org.jboss.netty.channel.Channels.succeededFuture;
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
import org.jboss.netty.buffer.ChannelBufferFactory;
|
||||
import org.jboss.netty.channel.ChannelException;
|
||||
import org.jboss.netty.channel.ChannelFuture;
|
||||
import org.jboss.netty.channel.ReceiveBufferSizePredictor;
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.SocketAddress;
|
||||
@ -35,6 +26,12 @@ import java.nio.channels.Selector;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
import org.jboss.netty.buffer.ChannelBufferFactory;
|
||||
import org.jboss.netty.channel.ChannelException;
|
||||
import org.jboss.netty.channel.ChannelFuture;
|
||||
import org.jboss.netty.channel.ReceiveBufferSizePredictor;
|
||||
|
||||
public class NioWorker extends AbstractNioWorker {
|
||||
|
||||
private final SocketReceiveBufferPool recvBufferPool = new SocketReceiveBufferPool();
|
||||
@ -42,7 +39,7 @@ public class NioWorker extends AbstractNioWorker {
|
||||
public NioWorker(Executor executor) {
|
||||
super(executor);
|
||||
}
|
||||
|
||||
|
||||
public NioWorker(Executor executor, boolean allowShutdownOnIdle) {
|
||||
super(executor, allowShutdownOnIdle);
|
||||
}
|
||||
@ -141,13 +138,13 @@ public class NioWorker extends AbstractNioWorker {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Runnable createRegisterTask(AbstractNioChannel<?> channel, ChannelFuture future) {
|
||||
boolean server = !(channel instanceof NioClientSocketChannel);
|
||||
return new RegisterTask((NioSocketChannel) channel, future, server);
|
||||
}
|
||||
|
||||
|
||||
private final class RegisterTask implements Runnable {
|
||||
private final NioSocketChannel channel;
|
||||
private final ChannelFuture future;
|
||||
@ -186,7 +183,7 @@ public class NioWorker extends AbstractNioWorker {
|
||||
channel.setConnected();
|
||||
future.setSuccess();
|
||||
}
|
||||
|
||||
|
||||
if (server || !((NioClientSocketChannel) channel).boundManually) {
|
||||
fireChannelBound(channel, localAddress);
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* Default implementation which hands of {@link NioWorker}'s
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class NioWorkerPool extends AbstractNioWorkerPool<NioWorker> {
|
||||
|
@ -21,8 +21,8 @@ import org.jboss.netty.util.ExternalResourceReleasable;
|
||||
/**
|
||||
* This implementation of a {@link WorkerPool} should be used if you plan to share a {@link WorkerPool} between different Factories. You will need to call {@link #destroy()} by your own once
|
||||
* you want to release any resources of it.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public final class ShareableWorkerPool<E extends Worker> implements WorkerPool<E> {
|
||||
|
||||
|
@ -72,7 +72,7 @@ final class SocketSendBufferPool {
|
||||
if (src instanceof CompositeChannelBuffer && DetectionUtil.javaVersion() >= 7) {
|
||||
return new GatheringSendBuffer(src.toByteBuffers());
|
||||
}
|
||||
|
||||
|
||||
if (src.isDirect()) {
|
||||
return new UnpooledSendBuffer(src.toByteBuffer());
|
||||
}
|
||||
@ -257,7 +257,7 @@ final class SocketSendBufferPool {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class GatheringSendBuffer implements SendBuffer {
|
||||
|
||||
private final ByteBuffer[] buffers;
|
||||
@ -267,14 +267,14 @@ final class SocketSendBufferPool {
|
||||
|
||||
GatheringSendBuffer(ByteBuffer[] buffers) {
|
||||
this.buffers = buffers;
|
||||
this.last = buffers.length - 1;
|
||||
last = buffers.length - 1;
|
||||
int total = 0;
|
||||
for (ByteBuffer buf: buffers) {
|
||||
total += buf.remaining();
|
||||
}
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
|
||||
public boolean finished() {
|
||||
return !buffers[last].hasRemaining();
|
||||
}
|
||||
@ -329,7 +329,7 @@ final class SocketSendBufferPool {
|
||||
public void release() {
|
||||
// nothing todo
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
final class FileSendBuffer implements SendBuffer {
|
||||
|
@ -26,10 +26,10 @@ public interface WorkerPool<E extends Worker> {
|
||||
|
||||
/**
|
||||
* Return the next {@link Worker} to use
|
||||
*
|
||||
*
|
||||
* @return worker
|
||||
*/
|
||||
E nextWorker();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -37,10 +37,10 @@ public abstract class AbstractOioChannelSink extends AbstractChannelSink {
|
||||
channel.worker.executeInIoThread(wrapper);
|
||||
return wrapper;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return super.execute(pipeline, task);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -16,15 +16,16 @@
|
||||
package org.jboss.netty.channel.socket.oio;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Queue;
|
||||
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelFuture;
|
||||
import org.jboss.netty.channel.Channels;
|
||||
import org.jboss.netty.channel.socket.Worker;
|
||||
import org.jboss.netty.util.internal.QueueFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Queue;
|
||||
|
||||
/**
|
||||
* Abstract base class for Oio-Worker implementations
|
||||
*
|
||||
@ -33,7 +34,7 @@ import java.util.Queue;
|
||||
abstract class AbstractOioWorker<C extends AbstractOioChannel> implements Worker {
|
||||
|
||||
private final Queue<Runnable> eventQueue = QueueFactory.createQueue(Runnable.class);
|
||||
|
||||
|
||||
protected final C channel;
|
||||
|
||||
/**
|
||||
@ -41,15 +42,15 @@ abstract class AbstractOioWorker<C extends AbstractOioChannel> implements Worker
|
||||
* used when starting. i.e. the current thread when the run method is executed.
|
||||
*/
|
||||
protected volatile Thread thread;
|
||||
|
||||
|
||||
private volatile boolean done;
|
||||
|
||||
|
||||
public AbstractOioWorker(C channel) {
|
||||
this.channel = channel;
|
||||
channel.worker = this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void run() {
|
||||
thread = channel.workerThread = Thread.currentThread();
|
||||
|
||||
@ -67,7 +68,7 @@ abstract class AbstractOioWorker<C extends AbstractOioChannel> implements Worker
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boolean cont = false;
|
||||
try {
|
||||
cont = process();
|
||||
@ -77,7 +78,7 @@ abstract class AbstractOioWorker<C extends AbstractOioChannel> implements Worker
|
||||
}
|
||||
} finally {
|
||||
processEventQueue();
|
||||
|
||||
|
||||
if (!cont) {
|
||||
break;
|
||||
}
|
||||
@ -90,37 +91,37 @@ abstract class AbstractOioWorker<C extends AbstractOioChannel> implements Worker
|
||||
|
||||
// Clean up.
|
||||
close(channel, succeededFuture(channel), true);
|
||||
|
||||
|
||||
// Mark the worker event loop as done so we know that we need to run tasks directly and not queue them
|
||||
// See #287
|
||||
done = true;
|
||||
|
||||
|
||||
// just to make we don't have something left
|
||||
processEventQueue();
|
||||
|
||||
}
|
||||
|
||||
|
||||
static boolean isIoThread(AbstractOioChannel channel) {
|
||||
return Thread.currentThread() == channel.workerThread;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void executeInIoThread(Runnable task) {
|
||||
// check if the current thread is the worker thread
|
||||
//
|
||||
// Also check if the event loop of the worker is complete. If so we need to run the task now.
|
||||
// Also check if the event loop of the worker is complete. If so we need to run the task now.
|
||||
// See #287
|
||||
if (Thread.currentThread() == thread || done) {
|
||||
task.run();
|
||||
} else {
|
||||
boolean added = eventQueue.offer(task);
|
||||
|
||||
|
||||
if (added) {
|
||||
// as we set the SO_TIMEOUT to 1 second this task will get picked up in 1 second at latest
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void processEventQueue() {
|
||||
for (;;) {
|
||||
final Runnable task = eventQueue.poll();
|
||||
@ -130,21 +131,21 @@ abstract class AbstractOioWorker<C extends AbstractOioChannel> implements Worker
|
||||
task.run();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Process the incoming messages and also is responsible for call {@link Channels#fireMessageReceived(Channel, Object)} once a message
|
||||
* was processed without errors.
|
||||
*
|
||||
* was processed without errors.
|
||||
*
|
||||
* @return continue returns <code>true</code> as long as this worker should continue to try processing incoming messages
|
||||
* @throws IOException
|
||||
*/
|
||||
abstract boolean process() throws IOException;
|
||||
|
||||
|
||||
static void setInterestOps(
|
||||
AbstractOioChannel channel, ChannelFuture future, int interestOps) {
|
||||
boolean iothread = isIoThread(channel);
|
||||
|
||||
|
||||
// Override OP_WRITE flag - a user cannot change this flag.
|
||||
interestOps &= ~Channel.OP_WRITE;
|
||||
interestOps |= channel.getInterestOps() & Channel.OP_WRITE;
|
||||
@ -187,15 +188,15 @@ abstract class AbstractOioWorker<C extends AbstractOioChannel> implements Worker
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void close(AbstractOioChannel channel, ChannelFuture future) {
|
||||
close(channel, future, isIoThread(channel));
|
||||
}
|
||||
|
||||
|
||||
private static void close(AbstractOioChannel channel, ChannelFuture future, boolean iothread) {
|
||||
boolean connected = channel.isConnected();
|
||||
boolean bound = channel.isBound();
|
||||
|
||||
|
||||
try {
|
||||
channel.closeSocket();
|
||||
if (channel.setClosed()) {
|
||||
|
@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.jboss.netty.channel.socket.oio;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.fireChannelBound;
|
||||
import static org.jboss.netty.channel.Channels.fireChannelOpen;
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
@ -53,7 +52,7 @@ class OioAcceptedSocketChannel extends OioSocketChannel {
|
||||
} catch (IOException e) {
|
||||
throw new ChannelException("Failed to obtain an OutputStream.", e);
|
||||
}
|
||||
|
||||
|
||||
fireChannelOpen(this);
|
||||
fireChannelBound(this, getLocalAddress());
|
||||
}
|
||||
|
@ -78,14 +78,14 @@ public class OioClientSocketChannelFactory implements ClientSocketChannelFactory
|
||||
final OioClientSocketPipelineSink sink;
|
||||
|
||||
/**
|
||||
* Creates a new instance with a {@link Executors#newCachedThreadPool()} as worker executor.
|
||||
*
|
||||
* Creates a new instance with a {@link Executors#newCachedThreadPool()} as worker executor.
|
||||
*
|
||||
* See {@link #OioClientSocketChannelFactory(Executor)}
|
||||
*/
|
||||
public OioClientSocketChannelFactory() {
|
||||
this(Executors.newCachedThreadPool());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
*
|
||||
|
@ -61,7 +61,7 @@ final class OioDatagramChannel extends AbstractOioChannel
|
||||
"Failed to configure the datagram socket timeout.", e);
|
||||
}
|
||||
config = new DefaultDatagramChannelConfig(socket);
|
||||
|
||||
|
||||
fireChannelOpen(this);
|
||||
|
||||
}
|
||||
@ -147,6 +147,6 @@ final class OioDatagramChannel extends AbstractOioChannel
|
||||
boolean isSocketClosed() {
|
||||
return socket.isClosed();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -78,13 +78,13 @@ public class OioDatagramChannelFactory implements DatagramChannelFactory {
|
||||
|
||||
/**
|
||||
* Creates a new instance with a {@link Executors#newCachedThreadPool()}
|
||||
*
|
||||
*
|
||||
* See {@link #OioDatagramChannelFactory(Executor)}
|
||||
*/
|
||||
public OioDatagramChannelFactory() {
|
||||
this(Executors.newCachedThreadPool());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
*
|
||||
|
@ -33,7 +33,7 @@ class OioDatagramWorker extends AbstractOioWorker<OioDatagramChannel> {
|
||||
super(channel);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
boolean process() throws IOException {
|
||||
@ -49,7 +49,7 @@ class OioDatagramWorker extends AbstractOioWorker<OioDatagramChannel> {
|
||||
// Can happen on interruption.
|
||||
// Keep receiving unless the channel is closed.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
fireMessageReceived(
|
||||
channel,
|
||||
@ -64,7 +64,7 @@ class OioDatagramWorker extends AbstractOioWorker<OioDatagramChannel> {
|
||||
OioDatagramChannel channel, ChannelFuture future,
|
||||
Object message, SocketAddress remoteAddress) {
|
||||
boolean iothread = isIoThread(channel);
|
||||
|
||||
|
||||
try {
|
||||
ChannelBuffer buf = (ChannelBuffer) message;
|
||||
int offset = buf.readerIndex();
|
||||
@ -102,11 +102,11 @@ class OioDatagramWorker extends AbstractOioWorker<OioDatagramChannel> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void disconnect(OioDatagramChannel channel, ChannelFuture future) {
|
||||
boolean connected = channel.isConnected();
|
||||
boolean iothread = isIoThread(channel);
|
||||
|
||||
|
||||
try {
|
||||
channel.socket.disconnect();
|
||||
future.setSuccess();
|
||||
|
@ -68,7 +68,7 @@ class OioServerSocketChannel extends AbstractServerChannel
|
||||
logger.warn(
|
||||
"Failed to close a partially initialized socket.", e2);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
throw new ChannelException(
|
||||
"Failed to set the server socket timeout.", e);
|
||||
|
@ -92,13 +92,13 @@ public class OioServerSocketChannelFactory implements ServerSocketChannelFactory
|
||||
|
||||
/**
|
||||
* Create a new {@link OioServerSocketChannelFactory} with a {@link Executors#newCachedThreadPool()} for the boss and worker executor.
|
||||
*
|
||||
*
|
||||
* See {@link #OioServerSocketChannelFactory(Executor, Executor)}
|
||||
*/
|
||||
public OioServerSocketChannelFactory() {
|
||||
this(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
*
|
||||
|
@ -47,7 +47,7 @@ class OioWorker extends AbstractOioWorker<OioSocketChannel> {
|
||||
// Fire the channelConnected event for OioAcceptedSocketChannel.
|
||||
// See #287
|
||||
fireChannelConnected(channel, channel.getRemoteAddress());
|
||||
|
||||
|
||||
}
|
||||
super.run();
|
||||
}
|
||||
@ -70,7 +70,7 @@ class OioWorker extends AbstractOioWorker<OioSocketChannel> {
|
||||
return true;
|
||||
}
|
||||
fireMessageReceived(channel, channel.getConfig().getBufferFactory().getBuffer(buf, 0, readBytes));
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -94,14 +94,14 @@ class OioWorker extends AbstractOioWorker<OioSocketChannel> {
|
||||
try {
|
||||
int length = 0;
|
||||
|
||||
// Add support to write a FileRegion. This in fact will not give any performance gain but at least it not fail and
|
||||
// Add support to write a FileRegion. This in fact will not give any performance gain but at least it not fail and
|
||||
// we did the best to emulate it
|
||||
if (message instanceof FileRegion) {
|
||||
FileRegion fr = (FileRegion) message;
|
||||
try {
|
||||
synchronized (out) {
|
||||
WritableByteChannel bchannel = Channels.newChannel(out);
|
||||
|
||||
|
||||
long i = 0;
|
||||
while ((i = fr.transferTo(bchannel, length)) > 0) {
|
||||
length += i;
|
||||
@ -126,14 +126,14 @@ class OioWorker extends AbstractOioWorker<OioSocketChannel> {
|
||||
a.getBytes(a.readerIndex(), out, length);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
future.setSuccess();
|
||||
if (iothread) {
|
||||
fireWriteComplete(channel, length);
|
||||
} else {
|
||||
fireWriteCompleteLater(channel, length);
|
||||
}
|
||||
|
||||
|
||||
} catch (Throwable t) {
|
||||
// Convert 'SocketException: Socket closed' to
|
||||
// ClosedChannelException.
|
||||
|
@ -34,7 +34,7 @@ public class DiscardServer {
|
||||
public DiscardServer(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
// Configure the server.
|
||||
ServerBootstrap bootstrap = new ServerBootstrap(
|
||||
|
@ -30,11 +30,11 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
public class EchoServer {
|
||||
|
||||
private final int port;
|
||||
|
||||
|
||||
public EchoServer(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
// Configure the server.
|
||||
ServerBootstrap bootstrap = new ServerBootstrap(
|
||||
|
@ -32,7 +32,7 @@ public class FactorialClient {
|
||||
private final String host;
|
||||
private final int port;
|
||||
private final int count;
|
||||
|
||||
|
||||
public FactorialClient(String host, int port, int count) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
|
@ -28,11 +28,11 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
public class FactorialServer {
|
||||
|
||||
private final int port;
|
||||
|
||||
|
||||
public FactorialServer(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
// Configure the server.
|
||||
ServerBootstrap bootstrap = new ServerBootstrap(
|
||||
|
@ -22,13 +22,13 @@ import org.jboss.netty.bootstrap.ServerBootstrap;
|
||||
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
|
||||
public class HttpStaticFileServer {
|
||||
|
||||
|
||||
private final int port;
|
||||
|
||||
|
||||
public HttpStaticFileServer(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
// Configure the server.
|
||||
ServerBootstrap bootstrap = new ServerBootstrap(
|
||||
|
@ -37,7 +37,7 @@ import org.jboss.netty.handler.codec.http.HttpVersion;
|
||||
public class HttpSnoopClient {
|
||||
|
||||
private final URI uri;
|
||||
|
||||
|
||||
public HttpSnoopClient(URI uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
* in a pretty plaintext form.
|
||||
*/
|
||||
public class HttpSnoopServer {
|
||||
|
||||
|
||||
private final int port;
|
||||
|
||||
public HttpSnoopServer(int port) {
|
||||
|
@ -44,7 +44,7 @@ import org.jboss.netty.logging.InternalLogLevel;
|
||||
public class HttpTunnelingClientExample {
|
||||
|
||||
private final URI uri;
|
||||
|
||||
|
||||
public HttpTunnelingClientExample(URI uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
@ -31,27 +31,27 @@ import org.jboss.netty.handler.codec.http.CookieEncoder;
|
||||
import org.jboss.netty.handler.codec.http.DefaultHttpRequest;
|
||||
import org.jboss.netty.handler.codec.http.HttpHeaders;
|
||||
import org.jboss.netty.handler.codec.http.HttpMethod;
|
||||
import org.jboss.netty.handler.codec.http.HttpRequest;
|
||||
import org.jboss.netty.handler.codec.http.HttpVersion;
|
||||
import org.jboss.netty.handler.codec.http.QueryStringEncoder;
|
||||
import org.jboss.netty.handler.codec.http.multipart.DefaultHttpDataFactory;
|
||||
import org.jboss.netty.handler.codec.http.multipart.DiskAttribute;
|
||||
import org.jboss.netty.handler.codec.http.multipart.DiskFileUpload;
|
||||
import org.jboss.netty.handler.codec.http.multipart.HttpDataFactory;
|
||||
import org.jboss.netty.handler.codec.http.multipart.HttpPostRequestEncoder;
|
||||
import org.jboss.netty.handler.codec.http.multipart.InterfaceHttpData;
|
||||
import org.jboss.netty.handler.codec.http.multipart.HttpPostRequestEncoder.ErrorDataEncoderException;
|
||||
import org.jboss.netty.handler.codec.http.HttpRequest;
|
||||
import org.jboss.netty.handler.codec.http.HttpVersion;
|
||||
import org.jboss.netty.handler.codec.http.QueryStringEncoder;
|
||||
import org.jboss.netty.handler.codec.http.multipart.InterfaceHttpData;
|
||||
import org.jboss.netty.logging.InternalLogger;
|
||||
import org.jboss.netty.logging.InternalLoggerFactory;
|
||||
|
||||
public class HttpUploadClient {
|
||||
|
||||
|
||||
private static final InternalLogger logger =
|
||||
InternalLoggerFactory.getInstance(HttpUploadClient.class);
|
||||
|
||||
|
||||
private final String baseUri;
|
||||
private final String filePath;
|
||||
|
||||
|
||||
public HttpUploadClient(String baseUri, String filePath) {
|
||||
this.baseUri = baseUri;
|
||||
this.filePath = filePath;
|
||||
|
@ -27,7 +27,7 @@ import org.jboss.netty.logging.InternalLoggerFactory;
|
||||
import org.jboss.netty.util.CharsetUtil;
|
||||
|
||||
public class HttpUploadClientHandler extends SimpleChannelUpstreamHandler {
|
||||
|
||||
|
||||
private static final InternalLogger logger =
|
||||
InternalLoggerFactory.getInstance(HttpUploadClientHandler.class);
|
||||
|
||||
|
@ -54,7 +54,7 @@ public class HttpUploadClientPipelineFactory implements ChannelPipelineFactory {
|
||||
|
||||
// to be used since huge file transfer
|
||||
pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
|
||||
|
||||
|
||||
pipeline.addLast("handler", new HttpUploadClientHandler());
|
||||
return pipeline;
|
||||
}
|
||||
|
@ -22,13 +22,13 @@ import org.jboss.netty.bootstrap.ServerBootstrap;
|
||||
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
|
||||
public class HttpUploadServer {
|
||||
|
||||
|
||||
private final int port;
|
||||
|
||||
|
||||
public HttpUploadServer(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
// Configure the server.
|
||||
ServerBootstrap bootstrap = new ServerBootstrap(
|
||||
|
@ -44,6 +44,7 @@ import org.jboss.netty.handler.codec.http.HttpRequest;
|
||||
import org.jboss.netty.handler.codec.http.HttpResponse;
|
||||
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
|
||||
import org.jboss.netty.handler.codec.http.HttpVersion;
|
||||
import org.jboss.netty.handler.codec.http.QueryStringDecoder;
|
||||
import org.jboss.netty.handler.codec.http.multipart.Attribute;
|
||||
import org.jboss.netty.handler.codec.http.multipart.DefaultHttpDataFactory;
|
||||
import org.jboss.netty.handler.codec.http.multipart.DiskAttribute;
|
||||
@ -51,13 +52,12 @@ import org.jboss.netty.handler.codec.http.multipart.DiskFileUpload;
|
||||
import org.jboss.netty.handler.codec.http.multipart.FileUpload;
|
||||
import org.jboss.netty.handler.codec.http.multipart.HttpDataFactory;
|
||||
import org.jboss.netty.handler.codec.http.multipart.HttpPostRequestDecoder;
|
||||
import org.jboss.netty.handler.codec.http.multipart.InterfaceHttpData;
|
||||
import org.jboss.netty.handler.codec.http.multipart.HttpPostRequestDecoder.EndOfDataDecoderException;
|
||||
import org.jboss.netty.handler.codec.http.multipart.HttpPostRequestDecoder.ErrorDataDecoderException;
|
||||
import org.jboss.netty.handler.codec.http.multipart.HttpPostRequestDecoder.IncompatibleDataDecoderException;
|
||||
import org.jboss.netty.handler.codec.http.multipart.HttpPostRequestDecoder.NotEnoughDataDecoderException;
|
||||
import org.jboss.netty.handler.codec.http.multipart.InterfaceHttpData;
|
||||
import org.jboss.netty.handler.codec.http.multipart.InterfaceHttpData.HttpDataType;
|
||||
import org.jboss.netty.handler.codec.http.QueryStringDecoder;
|
||||
import org.jboss.netty.logging.InternalLogger;
|
||||
import org.jboss.netty.logging.InternalLoggerFactory;
|
||||
import org.jboss.netty.util.CharsetUtil;
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.jboss.netty.example.http.upload;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.pipeline;
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
import org.jboss.netty.channel.ChannelPipeline;
|
||||
import org.jboss.netty.channel.ChannelPipelineFactory;
|
||||
|
@ -26,13 +26,13 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
* suite
|
||||
*/
|
||||
public class AutobahnServer {
|
||||
|
||||
|
||||
private final int port;
|
||||
|
||||
public AutobahnServer(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
// Configure the server.
|
||||
ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
|
||||
|
@ -15,28 +15,28 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* This package is intended for use with testing against the Python
|
||||
* This package is intended for use with testing against the Python
|
||||
* <a href="http://www.tavendo.de/autobahn/testsuite.html">AutoBahn test suite</a>.
|
||||
*
|
||||
* <h3>How to run the tests on Ubuntu</h3>
|
||||
*
|
||||
*
|
||||
* <p>01. Add <tt>ppa:twisted-dev/ppa</tt> to your system's Software Sources
|
||||
*
|
||||
*
|
||||
* <p>02. Install Twisted V11: <tt>sudo apt-get install python-twisted</tt>
|
||||
*
|
||||
*
|
||||
* <p>03. Intall Python Setup Tools: <tt>sudo apt-get install python-setuptools</tt>
|
||||
*
|
||||
*
|
||||
* <p>04. Install AutoBahn: <tt>sudo easy_install Autobahn</tt>. If you already have Autobahn installed, you may need
|
||||
* to upgrade it: <tt>sudo easy_install --upgrade Autobahn</tt>. Make suer v0.4.10 is installed.
|
||||
*
|
||||
*
|
||||
* <p>05. Get AutoBahn testsuite source code: <tt>git clone git@github.com:tavendo/AutobahnPython.git</tt>
|
||||
*
|
||||
*
|
||||
* <p>06. Go to AutoBahn directory: <tt>cd AutobahnPython</tt>
|
||||
*
|
||||
*
|
||||
* <p>07. Checkout stable version: <tt>git checkout v0.4.10</tt>
|
||||
*
|
||||
*
|
||||
* <p>08. Go to test suite directory: <tt>cd testsuite/websockets</tt>
|
||||
*
|
||||
*
|
||||
* <p>09. Edit <tt>fuzzing_clinet_spec.json</tt> and set the hybi specification version to 10 or 17 (RFC 6455).
|
||||
* <code>
|
||||
* {
|
||||
@ -47,14 +47,14 @@
|
||||
* "exclude-agent-cases": {"FoobarServer*": ["4.*", "1.1.3"]}
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* <p>10. Run our <tt>AutobahnServer</tt> located in this package. If you are in Eclipse IDE, right click on
|
||||
*
|
||||
* <p>10. Run our <tt>AutobahnServer</tt> located in this package. If you are in Eclipse IDE, right click on
|
||||
* <tt>AutobahnServer.java</tt> and select Run As > Java Application.
|
||||
*
|
||||
* <p>11. Run the Autobahn test <tt>python fuzzing_client.py</tt>. Note that the actual test case python code is
|
||||
*
|
||||
* <p>11. Run the Autobahn test <tt>python fuzzing_client.py</tt>. Note that the actual test case python code is
|
||||
* located with the easy_install package (e.g. in <tt>/usr/local/lib/python2.7/dist-packages/
|
||||
* autobahn-0.4.10-py2.7.egg/autobahn/cases</tt>) and not in the checked out git repository.
|
||||
*
|
||||
*
|
||||
* <p>12. See the results in <tt>reports/servers/index.html</tt>
|
||||
*/
|
||||
package org.jboss.netty.example.http.websocketx.autobahn;
|
||||
|
@ -23,14 +23,14 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
|
||||
/**
|
||||
* A HTTP server which serves Web Socket requests at:
|
||||
*
|
||||
*
|
||||
* http://localhost:8080/websocket
|
||||
*
|
||||
*
|
||||
* Open your browser at http://localhost:8080/, then the demo page will be loaded and a Web Socket connection will be
|
||||
* made automatically.
|
||||
*
|
||||
*
|
||||
* This server illustrates support for the different web socket specification versions and will work with:
|
||||
*
|
||||
*
|
||||
* <ul>
|
||||
* <li>Safari 5+ (draft-ietf-hybi-thewebsocketprotocol-00)
|
||||
* <li>Chrome 6-13 (draft-ietf-hybi-thewebsocketprotocol-00)
|
||||
@ -41,13 +41,13 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
* </ul>
|
||||
*/
|
||||
public class WebSocketServer {
|
||||
|
||||
|
||||
private final int port;
|
||||
|
||||
|
||||
public WebSocketServer(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
// Configure the server.
|
||||
ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
|
||||
|
@ -16,12 +16,12 @@
|
||||
|
||||
/**
|
||||
* <p>This package contains an example web socket web server.
|
||||
* <p>The web server only handles text, ping and closing frames. For text frames,
|
||||
* <p>The web server only handles text, ping and closing frames. For text frames,
|
||||
* it echoes the received text in upper case.
|
||||
* <p>Once started, you can test the web server against your browser by navigating
|
||||
* <p>Once started, you can test the web server against your browser by navigating
|
||||
* to http://localhost:8080/
|
||||
* <p>You can also test it with a web socket client. Send web socket traffic to
|
||||
* ws://localhost:8080/websocket.
|
||||
* <p>You can also test it with a web socket client. Send web socket traffic to
|
||||
* ws://localhost:8080/websocket.
|
||||
*/
|
||||
package org.jboss.netty.example.http.websocketx.server;
|
||||
|
||||
|
@ -23,14 +23,14 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
|
||||
/**
|
||||
* A HTTP server which serves Web Socket requests at:
|
||||
*
|
||||
*
|
||||
* https://localhost:8081/websocket
|
||||
*
|
||||
*
|
||||
* Open your browser at https://localhost:8081/, then the demo page will be loaded and a Web Socket connection will be
|
||||
* made automatically.
|
||||
*
|
||||
*
|
||||
* This server illustrates support for the different web socket specification versions and will work with:
|
||||
*
|
||||
*
|
||||
* <ul>
|
||||
* <li>Safari 5+ (draft-ietf-hybi-thewebsocketprotocol-00)
|
||||
* <li>Chrome 6-13 (draft-ietf-hybi-thewebsocketprotocol-00)
|
||||
@ -40,7 +40,7 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
* </ul>
|
||||
*/
|
||||
public class WebSocketSslServer {
|
||||
|
||||
|
||||
private final int port;
|
||||
|
||||
public WebSocketSslServer(int port) {
|
||||
@ -81,7 +81,7 @@ public class WebSocketSslServer {
|
||||
System.out.println("ERROR: System property keystore.file.password not set. Exiting now!");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
|
||||
new WebSocketSslServer(port).run();
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public final class WebSocketSslServerSslContext {
|
||||
/**
|
||||
* SingletonHolder is loaded on the first execution of Singleton.getInstance() or the first access to
|
||||
* SingletonHolder.INSTANCE, not before.
|
||||
*
|
||||
*
|
||||
* See http://en.wikipedia.org/wiki/Singleton_pattern
|
||||
*/
|
||||
private static class SingletonHolder {
|
||||
|
@ -37,7 +37,7 @@ import org.jboss.netty.logging.InternalLogLevel;
|
||||
public class LocalExample {
|
||||
|
||||
private final String port;
|
||||
|
||||
|
||||
public LocalExample(String port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ import org.jboss.netty.logging.InternalLogLevel;
|
||||
public class LocalExampleMultithreaded {
|
||||
|
||||
private final String port;
|
||||
|
||||
|
||||
public LocalExampleMultithreaded(String port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class LocalTimeClient {
|
||||
private final String host;
|
||||
private final int port;
|
||||
private final Collection<String> cities;
|
||||
|
||||
|
||||
public LocalTimeClient(String host, int port, Collection<String> cities) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -38,7 +38,7 @@ public class PortUnificationServer {
|
||||
public PortUnificationServer(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
// Configure the server.
|
||||
ServerBootstrap bootstrap = new ServerBootstrap(
|
||||
|
@ -29,7 +29,7 @@ public class HexDumpProxy {
|
||||
private final int localPort;
|
||||
private final String remoteHost;
|
||||
private final int remotePort;
|
||||
|
||||
|
||||
public HexDumpProxy(int localPort, String remoteHost, int remotePort) {
|
||||
this.localPort = localPort;
|
||||
this.remoteHost = remoteHost;
|
||||
|
@ -34,7 +34,7 @@ public class SecureChatClient {
|
||||
|
||||
private final String host;
|
||||
private final int port;
|
||||
|
||||
|
||||
public SecureChatClient(String host, int port) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
|
@ -33,7 +33,7 @@ public class TelnetClient {
|
||||
|
||||
private final String host;
|
||||
private final int port;
|
||||
|
||||
|
||||
public TelnetClient(String host, int port) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
|
@ -27,11 +27,11 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
public class TelnetServer {
|
||||
|
||||
private final int port;
|
||||
|
||||
|
||||
public TelnetServer(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
// Configure the server.
|
||||
ServerBootstrap bootstrap = new ServerBootstrap(
|
||||
|
@ -16,33 +16,33 @@
|
||||
package org.jboss.netty.handler.codec;
|
||||
|
||||
/**
|
||||
* Exception which should get thrown if a Channel got closed before it is expected
|
||||
* Exception which should get thrown if a Channel got closed before it is expected
|
||||
*/
|
||||
public class PrematureChannelClosureException extends Exception {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 233460005724966593L;
|
||||
|
||||
public PrematureChannelClosureException() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
public PrematureChannelClosureException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public PrematureChannelClosureException(String msg, Throwable t) {
|
||||
super(msg, t);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public PrematureChannelClosureException(Throwable t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -18,9 +18,9 @@ package org.jboss.netty.handler.codec.base64;
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
import org.jboss.netty.buffer.ChannelBuffers;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelHandler.Sharable;
|
||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
import org.jboss.netty.channel.ChannelPipeline;
|
||||
import org.jboss.netty.channel.ChannelHandler.Sharable;
|
||||
import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder;
|
||||
import org.jboss.netty.handler.codec.frame.Delimiters;
|
||||
import org.jboss.netty.handler.codec.frame.FrameDecoder;
|
||||
|
@ -17,9 +17,9 @@ package org.jboss.netty.handler.codec.base64;
|
||||
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelHandler.Sharable;
|
||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
import org.jboss.netty.channel.ChannelPipeline;
|
||||
import org.jboss.netty.channel.ChannelHandler.Sharable;
|
||||
import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder;
|
||||
import org.jboss.netty.handler.codec.frame.Delimiters;
|
||||
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
|
||||
|
@ -192,7 +192,7 @@ public class ZlibEncoder extends OneToOneEncoder implements LifeCycleAwareChanne
|
||||
* and the specified preset dictionary. The wrapper is always
|
||||
* {@link ZlibWrapper#ZLIB} because it is the only format that supports
|
||||
* the preset dictionary.
|
||||
*
|
||||
*
|
||||
* @param compressionLevel
|
||||
* {@code 1} yields the fastest compression and {@code 9} yields the
|
||||
* best compression. {@code 0} means no compression. The default
|
||||
|
@ -187,7 +187,7 @@ public class DelimiterBasedFrameDecoder extends FrameDecoder {
|
||||
this.stripDelimiter = stripDelimiter;
|
||||
this.failFast = failFast;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Object decode(
|
||||
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
|
||||
|
@ -40,21 +40,21 @@ public class FixedLengthFrameDecoder extends FrameDecoder {
|
||||
|
||||
private final int frameLength;
|
||||
private final boolean allocateFullBuffer;
|
||||
|
||||
|
||||
/**
|
||||
* Calls {@link #FixedLengthFrameDecoder(int, boolean)} with <code>false</code>
|
||||
*/
|
||||
public FixedLengthFrameDecoder(int frameLength) {
|
||||
this(frameLength, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
*
|
||||
* @param frameLength the length of the frame
|
||||
* @param allocateFullBuffer <code>true</code> if the cumulative {@link ChannelBuffer} should use the {@link #frameLength} as its initial size
|
||||
*/
|
||||
public FixedLengthFrameDecoder(int frameLength, boolean allocateFullBuffer) {
|
||||
public FixedLengthFrameDecoder(int frameLength, boolean allocateFullBuffer) {
|
||||
if (frameLength <= 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"frameLength must be a positive integer: " + frameLength);
|
||||
@ -72,7 +72,7 @@ public class FixedLengthFrameDecoder extends FrameDecoder {
|
||||
return buffer.readBytes(frameLength);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected ChannelBuffer newCumulationBuffer(ChannelHandlerContext ctx, int minimumCapacity) {
|
||||
ChannelBufferFactory factory = ctx.getChannel().getConfig().getBufferFactory();
|
||||
|
@ -402,14 +402,14 @@ public class LengthFieldBasedFrameDecoder extends FrameDecoder {
|
||||
long tooLongFrameLength = this.tooLongFrameLength;
|
||||
this.tooLongFrameLength = 0;
|
||||
discardingTooLongFrame = false;
|
||||
if ((!failFast) ||
|
||||
(failFast && firstDetectionOfTooLongFrame)) {
|
||||
if (!failFast ||
|
||||
failFast && firstDetectionOfTooLongFrame) {
|
||||
fail(ctx, tooLongFrameLength);
|
||||
}
|
||||
} else {
|
||||
// Keep discarding and notify handlers if necessary.
|
||||
if (failFast && firstDetectionOfTooLongFrame) {
|
||||
fail(ctx, this.tooLongFrameLength);
|
||||
fail(ctx, tooLongFrameLength);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,8 @@ import java.nio.ByteOrder;
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
import org.jboss.netty.buffer.ChannelBufferFactory;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
import org.jboss.netty.channel.ChannelHandler.Sharable;
|
||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
|
||||
|
||||
/**
|
||||
|
@ -36,10 +36,10 @@ import org.jboss.netty.util.internal.QueueFactory;
|
||||
* {@link HttpResponseDecoder} to learn what additional state management needs
|
||||
* to be done for <tt>HEAD</tt> and <tt>CONNECT</tt> and why
|
||||
* {@link HttpResponseDecoder} can not handle it by itself.
|
||||
*
|
||||
*
|
||||
* If the {@link Channel} gets closed and there are requests missing for a response
|
||||
* a {@link PrematureChannelClosureException} is thrown.
|
||||
*
|
||||
*
|
||||
* @see HttpServerCodec
|
||||
*
|
||||
* @apiviz.has org.jboss.netty.handler.codec.http.HttpResponseDecoder
|
||||
@ -64,7 +64,7 @@ public class HttpClientCodec implements ChannelUpstreamHandler,
|
||||
* Creates a new instance with the default decoder options
|
||||
* ({@code maxInitialLineLength (4096}}, {@code maxHeaderSize (8192)}, and
|
||||
* {@code maxChunkSize (8192)}).
|
||||
*
|
||||
*
|
||||
*/
|
||||
public HttpClientCodec() {
|
||||
this(4096, 8192, 8192, false);
|
||||
@ -109,9 +109,9 @@ public class HttpClientCodec implements ChannelUpstreamHandler,
|
||||
if (msg instanceof HttpRequest && !done) {
|
||||
queue.offer(((HttpRequest) msg).getMethod());
|
||||
}
|
||||
|
||||
|
||||
Object obj = super.encode(ctx, channel, msg);
|
||||
|
||||
|
||||
if (failOnMissingResponse) {
|
||||
// check if the request is chunked if so do not increment
|
||||
if (msg instanceof HttpRequest && !((HttpRequest) msg).isChunked()) {
|
||||
@ -149,7 +149,7 @@ public class HttpClientCodec implements ChannelUpstreamHandler,
|
||||
if (msg == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// check if its a HttpMessage and its not chunked
|
||||
if (msg instanceof HttpMessage && !((HttpMessage) msg).isChunked()) {
|
||||
requestResponseCounter.decrementAndGet();
|
||||
@ -212,7 +212,7 @@ public class HttpClientCodec implements ChannelUpstreamHandler,
|
||||
|
||||
return super.isContentAlwaysEmpty(msg);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
|
||||
super.channelClosed(ctx, e);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -79,7 +79,7 @@ public class DefaultHttpDataFactory implements HttpDataFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
* @return the associated list of Files for the request
|
||||
*/
|
||||
@ -91,7 +91,7 @@ public class DefaultHttpDataFactory implements HttpDataFactory {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public Attribute createAttribute(HttpRequest request, String name) {
|
||||
if (useDisk) {
|
||||
Attribute attribute = new DiskAttribute(name);
|
||||
|
@ -28,7 +28,7 @@ import org.jboss.netty.buffer.ChannelBuffer;
|
||||
public interface HttpData extends InterfaceHttpData {
|
||||
/**
|
||||
* Set the content from the ChannelBuffer (erase any previous data)
|
||||
*
|
||||
*
|
||||
* @param buffer
|
||||
* must be not null
|
||||
* @exception IOException
|
||||
@ -37,7 +37,7 @@ public interface HttpData extends InterfaceHttpData {
|
||||
|
||||
/**
|
||||
* Add the content from the ChannelBuffer
|
||||
*
|
||||
*
|
||||
* @param buffer
|
||||
* must be not null except if last is set to False
|
||||
* @param last
|
||||
@ -48,7 +48,7 @@ public interface HttpData extends InterfaceHttpData {
|
||||
|
||||
/**
|
||||
* Set the content from the file (erase any previous data)
|
||||
*
|
||||
*
|
||||
* @param file
|
||||
* must be not null
|
||||
* @exception IOException
|
||||
@ -57,7 +57,7 @@ public interface HttpData extends InterfaceHttpData {
|
||||
|
||||
/**
|
||||
* Set the content from the inputStream (erase any previous data)
|
||||
*
|
||||
*
|
||||
* @param inputStream
|
||||
* must be not null
|
||||
* @exception IOException
|
||||
@ -65,14 +65,14 @@ public interface HttpData extends InterfaceHttpData {
|
||||
void setContent(InputStream inputStream) throws IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return True if the InterfaceHttpData is completed (all data are stored)
|
||||
*/
|
||||
boolean isCompleted();
|
||||
|
||||
/**
|
||||
* Returns the size in byte of the InterfaceHttpData
|
||||
*
|
||||
*
|
||||
* @return the size of the InterfaceHttpData
|
||||
*/
|
||||
long length();
|
||||
@ -85,7 +85,7 @@ public interface HttpData extends InterfaceHttpData {
|
||||
|
||||
/**
|
||||
* Returns the contents of the file item as an array of bytes.
|
||||
*
|
||||
*
|
||||
* @return the contents of the file item as an array of bytes.
|
||||
* @exception IOException
|
||||
*/
|
||||
@ -93,7 +93,7 @@ public interface HttpData extends InterfaceHttpData {
|
||||
|
||||
/**
|
||||
* Returns the content of the file item as a ChannelBuffer
|
||||
*
|
||||
*
|
||||
* @return the content of the file item as a ChannelBuffer
|
||||
* @throws IOException
|
||||
*/
|
||||
@ -104,7 +104,7 @@ public interface HttpData extends InterfaceHttpData {
|
||||
* most length read bytes, increasing the current position of the Bytes
|
||||
* read. Once it arrives at the end, it returns an EMPTY_BUFFER and it
|
||||
* resets the current position to 0.
|
||||
*
|
||||
*
|
||||
* @param length
|
||||
* @return a ChannelBuffer for the content from the current position or an
|
||||
* EMPTY_BUFFER if there is no more data to return
|
||||
@ -115,7 +115,7 @@ public interface HttpData extends InterfaceHttpData {
|
||||
/**
|
||||
* Returns the contents of the file item as a String, using the default
|
||||
* character encoding.
|
||||
*
|
||||
*
|
||||
* @return the contents of the file item as a String, using the default
|
||||
* character encoding.
|
||||
* @exception IOException
|
||||
@ -125,7 +125,7 @@ public interface HttpData extends InterfaceHttpData {
|
||||
/**
|
||||
* Returns the contents of the file item as a String, using the specified
|
||||
* charset.
|
||||
*
|
||||
*
|
||||
* @param encoding
|
||||
* the charset to use
|
||||
* @return the contents of the file item as a String, using the specified
|
||||
@ -136,7 +136,7 @@ public interface HttpData extends InterfaceHttpData {
|
||||
|
||||
/**
|
||||
* Set the Charset passed by the browser if defined
|
||||
*
|
||||
*
|
||||
* @param charset
|
||||
* Charset to set - must be not null
|
||||
*/
|
||||
@ -144,7 +144,7 @@ public interface HttpData extends InterfaceHttpData {
|
||||
|
||||
/**
|
||||
* Returns the Charset passed by the browser or null if not defined.
|
||||
*
|
||||
*
|
||||
* @return the Charset passed by the browser or null if not defined.
|
||||
*/
|
||||
Charset getCharset();
|
||||
@ -154,7 +154,7 @@ public interface HttpData extends InterfaceHttpData {
|
||||
* exists, it will be deleted. Once this method is called, if successful,
|
||||
* the new file will be out of the cleaner of the factory that creates the
|
||||
* original InterfaceHttpData object.
|
||||
*
|
||||
*
|
||||
* @param dest
|
||||
* destination file - must be not null
|
||||
* @return True if the write is successful
|
||||
@ -165,13 +165,13 @@ public interface HttpData extends InterfaceHttpData {
|
||||
/**
|
||||
* Provides a hint as to whether or not the file contents will be read from
|
||||
* memory.
|
||||
*
|
||||
*
|
||||
* @return True if the file contents is in memory.
|
||||
*/
|
||||
boolean isInMemory();
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return the associated File if this data is represented in a file
|
||||
* @exception IOException
|
||||
* if this data is not represented by a file
|
||||
|
@ -147,9 +147,9 @@ final class HttpPostBodyUtil {
|
||||
throw new SeekAheadNoBackArrayException();
|
||||
}
|
||||
this.buffer = buffer;
|
||||
this.bytes = buffer.array();
|
||||
this.pos = this.readerIndex = buffer.readerIndex();
|
||||
this.limit = buffer.writerIndex();
|
||||
bytes = buffer.array();
|
||||
pos = readerIndex = buffer.readerIndex();
|
||||
limit = buffer.writerIndex();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -164,11 +164,11 @@ final class HttpPostBodyUtil {
|
||||
}
|
||||
|
||||
void clear() {
|
||||
this.buffer = null;
|
||||
this.bytes = null;
|
||||
this.limit = 0;
|
||||
this.pos = 0;
|
||||
this.readerIndex = 0;
|
||||
buffer = null;
|
||||
bytes = null;
|
||||
limit = 0;
|
||||
pos = 0;
|
||||
readerIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ public class BinaryWebSocketFrame extends WebSocketFrame {
|
||||
|
||||
/**
|
||||
* Creates a new binary frame with the specified binary data. The final fragment flag is set to true.
|
||||
*
|
||||
*
|
||||
* @param binaryData
|
||||
* the content of the frame.
|
||||
*/
|
||||
@ -42,7 +42,7 @@ public class BinaryWebSocketFrame extends WebSocketFrame {
|
||||
|
||||
/**
|
||||
* Creates a new binary frame with the specified binary data and the final fragment flag.
|
||||
*
|
||||
*
|
||||
* @param finalFragment
|
||||
* flag indicating if this frame is the final fragment
|
||||
* @param rsv
|
||||
|
@ -34,7 +34,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
|
||||
|
||||
/**
|
||||
* Creates a new empty close frame with closing status code and reason text
|
||||
*
|
||||
*
|
||||
* @param statusCode
|
||||
* Integer status code as per <a href="http://tools.ietf.org/html/rfc6455#section-7.4">RFC 6455</a>. For
|
||||
* example, <tt>1000</tt> indicates normal closure.
|
||||
@ -47,7 +47,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
|
||||
|
||||
/**
|
||||
* Creates a new close frame with no losing status code and no reason text
|
||||
*
|
||||
*
|
||||
* @param finalFragment
|
||||
* flag indicating if this frame is the final fragment
|
||||
* @param rsv
|
||||
@ -59,7 +59,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
|
||||
|
||||
/**
|
||||
* Creates a new close frame with closing status code and reason text
|
||||
*
|
||||
*
|
||||
* @param finalFragment
|
||||
* flag indicating if this frame is the final fragment
|
||||
* @param rsv
|
||||
@ -96,7 +96,7 @@ public class CloseWebSocketFrame extends WebSocketFrame {
|
||||
|
||||
/**
|
||||
* Creates a new close frame
|
||||
*
|
||||
*
|
||||
* @param finalFragment
|
||||
* flag indicating if this frame is the final fragment
|
||||
* @param rsv
|
||||
@ -119,7 +119,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;
|
||||
}
|
||||
@ -136,7 +136,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 "";
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
|
||||
|
||||
/**
|
||||
* Creates a new continuation frame with the specified binary data. The final fragment flag is set to true.
|
||||
*
|
||||
*
|
||||
* @param binaryData
|
||||
* the content of the frame.
|
||||
*/
|
||||
@ -46,7 +46,7 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
|
||||
|
||||
/**
|
||||
* Creates a new continuation frame with the specified binary data
|
||||
*
|
||||
*
|
||||
* @param finalFragment
|
||||
* flag indicating if this frame is the final fragment
|
||||
* @param rsv
|
||||
@ -62,7 +62,7 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
|
||||
|
||||
/**
|
||||
* Creates a new continuation frame with the specified binary data
|
||||
*
|
||||
*
|
||||
* @param finalFragment
|
||||
* flag indicating if this frame is the final fragment
|
||||
* @param rsv
|
||||
@ -81,7 +81,7 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
|
||||
|
||||
/**
|
||||
* Creates a new continuation frame with the specified text data
|
||||
*
|
||||
*
|
||||
* @param finalFragment
|
||||
* flag indicating if this frame is the final fragment
|
||||
* @param rsv
|
||||
@ -107,7 +107,7 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
|
||||
|
||||
/**
|
||||
* Sets the string for this frame
|
||||
*
|
||||
*
|
||||
* @param text
|
||||
* text to store
|
||||
*/
|
||||
|
@ -33,7 +33,7 @@ public class PingWebSocketFrame extends WebSocketFrame {
|
||||
|
||||
/**
|
||||
* Creates a new ping frame with the specified binary data.
|
||||
*
|
||||
*
|
||||
* @param binaryData
|
||||
* the content of the frame.
|
||||
*/
|
||||
@ -43,7 +43,7 @@ public class PingWebSocketFrame extends WebSocketFrame {
|
||||
|
||||
/**
|
||||
* Creates a new ping frame with the specified binary data
|
||||
*
|
||||
*
|
||||
* @param finalFragment
|
||||
* flag indicating if this frame is the final fragment
|
||||
* @param rsv
|
||||
|
@ -32,7 +32,7 @@ public class PongWebSocketFrame extends WebSocketFrame {
|
||||
|
||||
/**
|
||||
* Creates a new pong frame with the specified binary data.
|
||||
*
|
||||
*
|
||||
* @param binaryData
|
||||
* the content of the frame.
|
||||
*/
|
||||
@ -42,7 +42,7 @@ public class PongWebSocketFrame extends WebSocketFrame {
|
||||
|
||||
/**
|
||||
* Creates a new pong frame with the specified binary data
|
||||
*
|
||||
*
|
||||
* @param finalFragment
|
||||
* flag indicating if this frame is the final fragment
|
||||
* @param rsv
|
||||
|
@ -33,7 +33,7 @@ public class TextWebSocketFrame extends WebSocketFrame {
|
||||
|
||||
/**
|
||||
* Creates a new text frame with the specified text string. The final fragment flag is set to true.
|
||||
*
|
||||
*
|
||||
* @param text
|
||||
* String to put in the frame
|
||||
*/
|
||||
@ -47,7 +47,7 @@ public class TextWebSocketFrame extends WebSocketFrame {
|
||||
|
||||
/**
|
||||
* Creates a new text frame with the specified binary data. The final fragment flag is set to true.
|
||||
*
|
||||
*
|
||||
* @param binaryData
|
||||
* the content of the frame. Must be UTF-8 encoded
|
||||
*/
|
||||
@ -57,7 +57,7 @@ public class TextWebSocketFrame extends WebSocketFrame {
|
||||
|
||||
/**
|
||||
* Creates a new text frame with the specified text string. The final fragment flag is set to true.
|
||||
*
|
||||
*
|
||||
* @param finalFragment
|
||||
* flag indicating if this frame is the final fragment
|
||||
* @param rsv
|
||||
@ -77,7 +77,7 @@ public class TextWebSocketFrame extends WebSocketFrame {
|
||||
|
||||
/**
|
||||
* Creates a new text frame with the specified binary data. The final fragment flag is set to true.
|
||||
*
|
||||
*
|
||||
* @param finalFragment
|
||||
* flag indicating if this frame is the final fragment
|
||||
* @param rsv
|
||||
@ -103,7 +103,7 @@ public class TextWebSocketFrame extends WebSocketFrame {
|
||||
|
||||
/**
|
||||
* Sets the string for this frame
|
||||
*
|
||||
*
|
||||
* @param text
|
||||
* text to store
|
||||
*/
|
||||
|
@ -18,18 +18,18 @@
|
||||
*
|
||||
* Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.de>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
|
||||
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
package org.jboss.netty.handler.codec.http.websocketx;
|
||||
|
@ -18,18 +18,18 @@
|
||||
*
|
||||
* Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.de>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
|
||||
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||
* of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
package org.jboss.netty.handler.codec.http.websocketx;
|
||||
|
@ -27,7 +27,7 @@ import org.jboss.netty.handler.codec.replay.VoidEnum;
|
||||
* <p>
|
||||
* For the detailed instruction on adding add Web Socket support to your HTTP server, take a look into the
|
||||
* <tt>WebSocketServer</tt> example located in the {@code org.jboss.netty.example.http.websocket} package.
|
||||
*
|
||||
*
|
||||
* @apiviz.landmark
|
||||
* @apiviz.uses org.jboss.netty.handler.codec.http.websocket.WebSocketFrame
|
||||
*/
|
||||
@ -45,7 +45,7 @@ public class WebSocket00FrameDecoder extends ReplayingDecoder<VoidEnum> {
|
||||
/**
|
||||
* Creates a new instance of {@code WebSocketFrameDecoder} with the specified {@code maxFrameSize}. If the client
|
||||
* sends a frame size larger than {@code maxFrameSize}, the channel will be closed.
|
||||
*
|
||||
*
|
||||
* @param maxFrameSize
|
||||
* the maximum frame size to decode
|
||||
* @deprecated
|
||||
@ -54,11 +54,11 @@ public class WebSocket00FrameDecoder extends ReplayingDecoder<VoidEnum> {
|
||||
public WebSocket00FrameDecoder(int maxFrameSize) {
|
||||
this.maxFrameSize = maxFrameSize;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance of {@code WebSocketFrameDecoder} with the specified {@code maxFrameSize}. If the client
|
||||
* sends a frame size larger than {@code maxFrameSize}, the channel will be closed.
|
||||
*
|
||||
*
|
||||
* @param maxFrameSize
|
||||
* the maximum frame size to decode
|
||||
*/
|
||||
|
@ -17,8 +17,8 @@ package org.jboss.netty.handler.codec.http.websocketx;
|
||||
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
import org.jboss.netty.channel.ChannelHandler.Sharable;
|
||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
|
||||
|
||||
/**
|
||||
@ -26,7 +26,7 @@ import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
|
||||
* <p>
|
||||
* For the detailed instruction on adding add Web Socket support to your HTTP server, take a look into the
|
||||
* <tt>WebSocketServer</tt> example located in the {@code org.jboss.netty.example.http.websocket} package.
|
||||
*
|
||||
*
|
||||
* @apiviz.landmark
|
||||
* @apiviz.uses org.jboss.netty.handler.codec.http.websocket.WebSocketFrame
|
||||
*/
|
||||
|
@ -85,7 +85,7 @@ public class WebSocket08FrameEncoder extends OneToOneEncoder {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
*
|
||||
* @param maskPayload
|
||||
* Web socket clients must set this to true to mask payload. Server implementations must set this to
|
||||
* false.
|
||||
|
@ -61,7 +61,7 @@ public class WebSocket13FrameDecoder extends WebSocket08FrameDecoder {
|
||||
|
||||
/**
|
||||
* Constructor with default values
|
||||
*
|
||||
*
|
||||
* @param maskedPayload
|
||||
* Web socket servers must set this to true processed incoming masked payload. Client implementations
|
||||
* must set this to false.
|
||||
@ -74,7 +74,7 @@ public class WebSocket13FrameDecoder extends WebSocket08FrameDecoder {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
*
|
||||
* @param maskedPayload
|
||||
* Web socket servers must set this to true processed incoming
|
||||
* masked payload. Client implementations must set this to false.
|
||||
|
@ -62,7 +62,7 @@ public class WebSocket13FrameEncoder extends WebSocket08FrameEncoder {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
*
|
||||
* @param maskPayload
|
||||
* Web socket clients must set this to true to mask payload. Server implementations must set this to
|
||||
* false.
|
||||
|
@ -58,7 +58,7 @@ public abstract class WebSocketClientHandshaker {
|
||||
Map<String, String> customHeaders) {
|
||||
this(webSocketUrl, version, subprotocol, customHeaders, Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Base constructor
|
||||
*
|
||||
@ -78,7 +78,7 @@ public abstract class WebSocketClientHandshaker {
|
||||
Map<String, String> customHeaders, long maxFramePayloadLength) {
|
||||
this.webSocketUrl = webSocketUrl;
|
||||
this.version = version;
|
||||
this.expectedSubprotocol = subprotocol;
|
||||
expectedSubprotocol = subprotocol;
|
||||
this.customHeaders = customHeaders;
|
||||
this.maxFramePayloadLength = maxFramePayloadLength;
|
||||
}
|
||||
@ -98,12 +98,12 @@ public abstract class WebSocketClientHandshaker {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the max length for any frame's payload
|
||||
* Returns the max length for any frame's payload
|
||||
*/
|
||||
public long getMaxFramePayloadLength() {
|
||||
return maxFramePayloadLength;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Flag to indicate if the opening handshake is complete
|
||||
*/
|
||||
@ -136,7 +136,7 @@ public abstract class WebSocketClientHandshaker {
|
||||
|
||||
/**
|
||||
* Begins the opening handshake
|
||||
*
|
||||
*
|
||||
* @param channel
|
||||
* Channel
|
||||
*/
|
||||
@ -144,7 +144,7 @@ public abstract class WebSocketClientHandshaker {
|
||||
|
||||
/**
|
||||
* Validates and finishes the opening handshake initiated by {@link #handshake}}.
|
||||
*
|
||||
*
|
||||
* @param channel
|
||||
* Channel
|
||||
* @param response
|
||||
|
@ -53,7 +53,7 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker {
|
||||
|
||||
/**
|
||||
* Constructor with default values
|
||||
*
|
||||
*
|
||||
* @param webSocketURL
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
|
||||
* sent to this URL.
|
||||
@ -70,10 +70,10 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker {
|
||||
boolean allowExtensions, Map<String, String> customHeaders) {
|
||||
this(webSocketURL, version, subprotocol, allowExtensions, customHeaders, Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
*
|
||||
* @param webSocketURL
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
|
||||
* sent to this URL.
|
||||
@ -100,7 +100,7 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker {
|
||||
* <p>
|
||||
* Sends the opening request to the server:
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* GET /chat HTTP/1.1
|
||||
* Host: server.example.com
|
||||
@ -111,7 +111,7 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker {
|
||||
* Sec-WebSocket-Protocol: chat, superchat
|
||||
* Sec-WebSocket-Version: 8
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @param channel
|
||||
* Channel into which we can write our request
|
||||
*/
|
||||
@ -151,16 +151,16 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker {
|
||||
// See http://tools.ietf.org/html/rfc6454#section-6.2
|
||||
originValue = originValue + ":" + wsPort;
|
||||
}
|
||||
|
||||
|
||||
// Use Sec-WebSocket-Origin
|
||||
// See https://github.com/netty/netty/issues/264
|
||||
request.addHeader(Names.SEC_WEBSOCKET_ORIGIN, originValue);
|
||||
|
||||
String expectedSubprotocol = this.getExpectedSubprotocol();
|
||||
|
||||
String expectedSubprotocol = getExpectedSubprotocol();
|
||||
if (expectedSubprotocol != null && !expectedSubprotocol.equals("")) {
|
||||
request.addHeader(Names.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol);
|
||||
}
|
||||
|
||||
|
||||
request.addHeader(Names.SEC_WEBSOCKET_VERSION, "8");
|
||||
|
||||
if (customHeaders != null) {
|
||||
@ -180,7 +180,7 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker {
|
||||
* <p>
|
||||
* Process server response:
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* HTTP/1.1 101 Switching Protocols
|
||||
* Upgrade: websocket
|
||||
@ -188,7 +188,7 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker {
|
||||
* Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
|
||||
* Sec-WebSocket-Protocol: chat
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @param channel
|
||||
* Channel
|
||||
* @param response
|
||||
@ -205,14 +205,14 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker {
|
||||
|
||||
String upgrade = response.getHeader(Names.UPGRADE);
|
||||
// Upgrade header should be matched case-insensitive.
|
||||
// See https://github.com/netty/netty/issues/278
|
||||
// See https://github.com/netty/netty/issues/278
|
||||
if (upgrade == null || !upgrade.toLowerCase().equals(Values.WEBSOCKET.toLowerCase())) {
|
||||
throw new WebSocketHandshakeException("Invalid handshake response upgrade: "
|
||||
+ response.getHeader(Names.UPGRADE));
|
||||
}
|
||||
|
||||
// Connection header should be matched case-insensitive.
|
||||
// See https://github.com/netty/netty/issues/278
|
||||
// See https://github.com/netty/netty/issues/278
|
||||
String connection = response.getHeader(Names.CONNECTION);
|
||||
if (connection == null || !connection.toLowerCase().equals(Values.UPGRADE.toLowerCase())) {
|
||||
throw new WebSocketHandshakeException("Invalid handshake response connection: "
|
||||
@ -227,13 +227,13 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker {
|
||||
|
||||
String subprotocol = response.getHeader(Names.SEC_WEBSOCKET_PROTOCOL);
|
||||
setActualSubprotocol(subprotocol);
|
||||
|
||||
|
||||
|
||||
setHandshakeComplete();
|
||||
|
||||
channel.getPipeline().get(HttpResponseDecoder.class).replace("ws-decoder",
|
||||
new WebSocket08FrameDecoder(false, allowExtensions, this.getMaxFramePayloadLength()));
|
||||
|
||||
new WebSocket08FrameDecoder(false, allowExtensions, getMaxFramePayloadLength()));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
|
||||
|
||||
/**
|
||||
* Constructor with default values
|
||||
*
|
||||
*
|
||||
* @param webSocketURL
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
|
||||
* sent to this URL.
|
||||
@ -70,10 +70,10 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
|
||||
boolean allowExtensions, Map<String, String> customHeaders) {
|
||||
this(webSocketURL, version, subprotocol, allowExtensions, customHeaders, Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
*
|
||||
* @param webSocketURL
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
|
||||
* sent to this URL.
|
||||
@ -99,7 +99,7 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
|
||||
* <p>
|
||||
* Sends the opening request to the server:
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* GET /chat HTTP/1.1
|
||||
* Host: server.example.com
|
||||
@ -110,7 +110,7 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
|
||||
* Sec-WebSocket-Protocol: chat, superchat
|
||||
* Sec-WebSocket-Version: 13
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @param channel
|
||||
* Channel into which we can write our request
|
||||
*/
|
||||
@ -152,11 +152,11 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
|
||||
}
|
||||
request.addHeader(Names.ORIGIN, originValue);
|
||||
|
||||
String expectedSubprotocol = this.getExpectedSubprotocol();
|
||||
String expectedSubprotocol = getExpectedSubprotocol();
|
||||
if (expectedSubprotocol != null && !expectedSubprotocol.equals("")) {
|
||||
request.addHeader(Names.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol);
|
||||
}
|
||||
|
||||
|
||||
request.addHeader(Names.SEC_WEBSOCKET_VERSION, "13");
|
||||
|
||||
if (customHeaders != null) {
|
||||
@ -164,7 +164,7 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
|
||||
request.addHeader(header, customHeaders.get(header));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ChannelFuture future = channel.write(request);
|
||||
|
||||
channel.getPipeline().replace(HttpRequestEncoder.class, "ws-encoder", new WebSocket13FrameEncoder(true));
|
||||
@ -176,7 +176,7 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
|
||||
* <p>
|
||||
* Process server response:
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* HTTP/1.1 101 Switching Protocols
|
||||
* Upgrade: websocket
|
||||
@ -184,7 +184,7 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
|
||||
* Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
|
||||
* Sec-WebSocket-Protocol: chat
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @param channel
|
||||
* Channel
|
||||
* @param response
|
||||
@ -201,14 +201,14 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
|
||||
|
||||
String upgrade = response.getHeader(Names.UPGRADE);
|
||||
// Upgrade header should be matched case-insensitive.
|
||||
// See https://github.com/netty/netty/issues/278
|
||||
// See https://github.com/netty/netty/issues/278
|
||||
if (upgrade == null || !upgrade.toLowerCase().equals(Values.WEBSOCKET.toLowerCase())) {
|
||||
throw new WebSocketHandshakeException("Invalid handshake response upgrade: "
|
||||
+ response.getHeader(Names.UPGRADE));
|
||||
}
|
||||
|
||||
// Connection header should be matched case-insensitive.
|
||||
// See https://github.com/netty/netty/issues/278
|
||||
// See https://github.com/netty/netty/issues/278
|
||||
String connection = response.getHeader(Names.CONNECTION);
|
||||
if (connection == null || !connection.toLowerCase().equals(Values.UPGRADE.toLowerCase())) {
|
||||
throw new WebSocketHandshakeException("Invalid handshake response connection: "
|
||||
@ -227,8 +227,8 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
|
||||
setHandshakeComplete();
|
||||
|
||||
channel.getPipeline().get(HttpResponseDecoder.class).replace("ws-decoder",
|
||||
new WebSocket13FrameDecoder(false, allowExtensions, this.getMaxFramePayloadLength()));
|
||||
|
||||
new WebSocket13FrameDecoder(false, allowExtensions, getMaxFramePayloadLength()));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class WebSocketClientHandshakerFactory {
|
||||
|
||||
/**
|
||||
* Instances a new handshaker
|
||||
*
|
||||
*
|
||||
* @param webSocketURL
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
|
||||
* sent to this URL.
|
||||
@ -43,10 +43,10 @@ public class WebSocketClientHandshakerFactory {
|
||||
boolean allowExtensions, Map<String, String> customHeaders) throws WebSocketHandshakeException {
|
||||
return newHandshaker(webSocketURL, version, subprotocol, allowExtensions, customHeaders, Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instances a new handshaker
|
||||
*
|
||||
*
|
||||
* @param webSocketURL
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
|
||||
* sent to this URL.
|
||||
@ -78,5 +78,5 @@ public class WebSocketClientHandshakerFactory {
|
||||
throw new WebSocketHandshakeException("Protocol version " + version.toString() + " not supported.");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ public abstract class WebSocketServerHandshaker {
|
||||
|
||||
/**
|
||||
* Constructor using default values
|
||||
*
|
||||
*
|
||||
* @param version
|
||||
* the protocol version
|
||||
* @param webSocketUrl
|
||||
@ -71,7 +71,7 @@ public abstract class WebSocketServerHandshaker {
|
||||
|
||||
/**
|
||||
* Constructor specifying the destination web socket location
|
||||
*
|
||||
*
|
||||
* @param version
|
||||
* the protocol version
|
||||
* @param webSocketUrl
|
||||
@ -112,7 +112,7 @@ public abstract class WebSocketServerHandshaker {
|
||||
*/
|
||||
public Set<String> getSubprotocols() {
|
||||
Set<String> ret = new LinkedHashSet<String>();
|
||||
for (String p : this.subprotocols) {
|
||||
for (String p : subprotocols) {
|
||||
ret.add(p);
|
||||
}
|
||||
return ret;
|
||||
@ -134,7 +134,7 @@ public abstract class WebSocketServerHandshaker {
|
||||
|
||||
/**
|
||||
* Performs the opening handshake
|
||||
*
|
||||
*
|
||||
* @param channel
|
||||
* Channel
|
||||
* @param req
|
||||
@ -144,7 +144,7 @@ public abstract class WebSocketServerHandshaker {
|
||||
|
||||
/**
|
||||
* Performs the closing handshake
|
||||
*
|
||||
*
|
||||
* @param channel
|
||||
* Channel
|
||||
* @param frame
|
||||
@ -154,7 +154,7 @@ public abstract class WebSocketServerHandshaker {
|
||||
|
||||
/**
|
||||
* Selects the first matching supported sub protocol
|
||||
*
|
||||
*
|
||||
* @param requestedSubprotocols
|
||||
* CSV of protocols to be supported. e.g. "chat, superchat"
|
||||
* @return First matching supported sub protocol. Null if not found.
|
||||
@ -178,9 +178,9 @@ public abstract class WebSocketServerHandshaker {
|
||||
// No match found
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the selected subprotocol. Null if no subprotocol has been selected.
|
||||
* Returns the selected subprotocol. Null if no subprotocol has been selected.
|
||||
* <p>
|
||||
* This is only available AFTER <tt>handshake()</tt> has been called.
|
||||
* </p>
|
||||
@ -188,9 +188,9 @@ public abstract class WebSocketServerHandshaker {
|
||||
public String getSelectedSubprotocol() {
|
||||
return selectedSubprotocol;
|
||||
}
|
||||
|
||||
|
||||
protected void setSelectedSubprotocol(String value) {
|
||||
selectedSubprotocol = value;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
|
||||
|
||||
/**
|
||||
* Constructor with default values
|
||||
*
|
||||
*
|
||||
* @param webSocketURL
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
|
||||
* sent to this URL.
|
||||
@ -62,10 +62,10 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
|
||||
public WebSocketServerHandshaker00(String webSocketURL, String subprotocols) {
|
||||
this(webSocketURL, subprotocols, Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor specifying the destination web socket location
|
||||
*
|
||||
*
|
||||
* @param webSocketURL
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
|
||||
* sent to this URL.
|
||||
@ -86,11 +86,11 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
|
||||
* is really a rehash of <a href="http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76" >hixie-76</a> and
|
||||
* <a href="http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-75" >hixie-75</a>.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* Browser request to the server:
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* GET /demo HTTP/1.1
|
||||
* Upgrade: WebSocket
|
||||
@ -100,14 +100,14 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
|
||||
* Sec-WebSocket-Protocol: chat, sample
|
||||
* Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5
|
||||
* Sec-WebSocket-Key2: 12998 5 Y3 1 .P00
|
||||
*
|
||||
*
|
||||
* ^n:ds[4U
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* Server response:
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* HTTP/1.1 101 WebSocket Protocol Handshake
|
||||
* Upgrade: WebSocket
|
||||
@ -115,10 +115,10 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
|
||||
* Sec-WebSocket-Origin: http://example.com
|
||||
* Sec-WebSocket-Location: ws://example.com/demo
|
||||
* Sec-WebSocket-Protocol: sample
|
||||
*
|
||||
*
|
||||
* 8jKS'y:G*Co,Wxa-
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @param channel
|
||||
* Channel
|
||||
* @param req
|
||||
@ -158,7 +158,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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -190,7 +190,7 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
|
||||
p.remove(HttpChunkAggregator.class);
|
||||
}
|
||||
p.replace(HttpRequestDecoder.class, "wsdecoder",
|
||||
new WebSocket00FrameDecoder(this.getMaxFramePayloadLength()));
|
||||
new WebSocket00FrameDecoder(getMaxFramePayloadLength()));
|
||||
|
||||
ChannelFuture future = channel.write(res);
|
||||
|
||||
@ -201,7 +201,7 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
|
||||
|
||||
/**
|
||||
* Echo back the closing frame
|
||||
*
|
||||
*
|
||||
* @param channel
|
||||
* Channel
|
||||
* @param frame
|
||||
|
@ -54,7 +54,7 @@ public class WebSocketServerHandshaker08 extends WebSocketServerHandshaker {
|
||||
|
||||
/**
|
||||
* Constructor using defaults
|
||||
*
|
||||
*
|
||||
* @param webSocketURL
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
|
||||
* sent to this URL.
|
||||
@ -66,10 +66,10 @@ public class WebSocketServerHandshaker08 extends WebSocketServerHandshaker {
|
||||
public WebSocketServerHandshaker08(String webSocketURL, String subprotocols, boolean allowExtensions) {
|
||||
this(webSocketURL, subprotocols, allowExtensions, Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
*
|
||||
* @param webSocketURL
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
|
||||
* sent to this URL.
|
||||
@ -93,11 +93,11 @@ public class WebSocketServerHandshaker08 extends WebSocketServerHandshaker {
|
||||
* "http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-08">HyBi version 8 to 10</a>. Version 8, 9 and
|
||||
* 10 share the same wire protocol.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* Browser request to the server:
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* GET /chat HTTP/1.1
|
||||
* Host: server.example.com
|
||||
@ -108,11 +108,11 @@ public class WebSocketServerHandshaker08 extends WebSocketServerHandshaker {
|
||||
* Sec-WebSocket-Protocol: chat, superchat
|
||||
* Sec-WebSocket-Version: 8
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* Server response:
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* HTTP/1.1 101 Switching Protocols
|
||||
* Upgrade: websocket
|
||||
@ -120,7 +120,7 @@ public class WebSocketServerHandshaker08 extends WebSocketServerHandshaker {
|
||||
* Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
|
||||
* Sec-WebSocket-Protocol: chat
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @param channel
|
||||
* Channel
|
||||
* @param req
|
||||
@ -163,7 +163,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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,8 +175,8 @@ public class WebSocketServerHandshaker08 extends WebSocketServerHandshaker {
|
||||
p.remove(HttpChunkAggregator.class);
|
||||
}
|
||||
|
||||
p.replace(HttpRequestDecoder.class, "wsdecoder",
|
||||
new WebSocket08FrameDecoder(true, allowExtensions, this.getMaxFramePayloadLength()));
|
||||
p.replace(HttpRequestDecoder.class, "wsdecoder",
|
||||
new WebSocket08FrameDecoder(true, allowExtensions, getMaxFramePayloadLength()));
|
||||
p.replace(HttpResponseEncoder.class, "wsencoder", new WebSocket08FrameEncoder(false));
|
||||
|
||||
return future;
|
||||
@ -184,7 +184,7 @@ public class WebSocketServerHandshaker08 extends WebSocketServerHandshaker {
|
||||
|
||||
/**
|
||||
* Echo back the closing frame and close the connection
|
||||
*
|
||||
*
|
||||
* @param channel
|
||||
* Channel
|
||||
* @param frame
|
||||
|
@ -15,8 +15,8 @@
|
||||
*/
|
||||
package org.jboss.netty.handler.codec.http.websocketx;
|
||||
|
||||
import static org.jboss.netty.handler.codec.http.HttpHeaders.Values.WEBSOCKET;
|
||||
import static org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1;
|
||||
import static org.jboss.netty.handler.codec.http.HttpHeaders.Values.*;
|
||||
import static org.jboss.netty.handler.codec.http.HttpVersion.*;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
@ -25,14 +25,14 @@ import org.jboss.netty.channel.ChannelFuture;
|
||||
import org.jboss.netty.channel.ChannelFutureListener;
|
||||
import org.jboss.netty.channel.ChannelPipeline;
|
||||
import org.jboss.netty.channel.Channels;
|
||||
import org.jboss.netty.handler.codec.http.HttpChunkAggregator;
|
||||
import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
|
||||
import org.jboss.netty.handler.codec.http.HttpChunkAggregator;
|
||||
import org.jboss.netty.handler.codec.http.HttpHeaders.Names;
|
||||
import org.jboss.netty.handler.codec.http.HttpRequest;
|
||||
import org.jboss.netty.handler.codec.http.HttpRequestDecoder;
|
||||
import org.jboss.netty.handler.codec.http.HttpResponse;
|
||||
import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
|
||||
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
|
||||
import org.jboss.netty.handler.codec.http.HttpHeaders.Names;
|
||||
import org.jboss.netty.logging.InternalLogger;
|
||||
import org.jboss.netty.logging.InternalLoggerFactory;
|
||||
import org.jboss.netty.util.CharsetUtil;
|
||||
@ -56,7 +56,7 @@ public class WebSocketServerHandshaker13 extends WebSocketServerHandshaker {
|
||||
|
||||
/**
|
||||
* Constructor using defaults
|
||||
*
|
||||
*
|
||||
* @param webSocketURL
|
||||
* URL for web socket communications. e.g
|
||||
* "ws://myhost.com/mypath". Subsequent web socket frames will be
|
||||
@ -73,7 +73,7 @@ public class WebSocketServerHandshaker13 extends WebSocketServerHandshaker {
|
||||
|
||||
/**
|
||||
* Constructor specifying the destination web socket location
|
||||
*
|
||||
*
|
||||
* @param webSocketURL
|
||||
* URL for web socket communications. e.g
|
||||
* "ws://myhost.com/mypath". Subsequent web socket frames will be
|
||||
@ -100,11 +100,11 @@ public class WebSocketServerHandshaker13 extends WebSocketServerHandshaker {
|
||||
* "http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17">HyBi
|
||||
* versions 13-17</a>. Versions 13-17 share the same wire protocol.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* Browser request to the server:
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* GET /chat HTTP/1.1
|
||||
* Host: server.example.com
|
||||
@ -115,11 +115,11 @@ public class WebSocketServerHandshaker13 extends WebSocketServerHandshaker {
|
||||
* Sec-WebSocket-Protocol: chat, superchat
|
||||
* Sec-WebSocket-Version: 13
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* Server response:
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* HTTP/1.1 101 Switching Protocols
|
||||
* Upgrade: websocket
|
||||
@ -127,7 +127,7 @@ public class WebSocketServerHandshaker13 extends WebSocketServerHandshaker {
|
||||
* Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
|
||||
* Sec-WebSocket-Protocol: chat
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @param channel
|
||||
* Channel
|
||||
* @param req
|
||||
@ -170,7 +170,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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -183,7 +183,7 @@ public class WebSocketServerHandshaker13 extends WebSocketServerHandshaker {
|
||||
}
|
||||
|
||||
p.replace(HttpRequestDecoder.class, "wsdecoder",
|
||||
new WebSocket13FrameDecoder(true, allowExtensions, this.getMaxFramePayloadLength()));
|
||||
new WebSocket13FrameDecoder(true, allowExtensions, getMaxFramePayloadLength()));
|
||||
p.replace(HttpResponseEncoder.class, "wsencoder", new WebSocket13FrameEncoder(false));
|
||||
|
||||
return future;
|
||||
@ -191,7 +191,7 @@ public class WebSocketServerHandshaker13 extends WebSocketServerHandshaker {
|
||||
|
||||
/**
|
||||
* Echo back the closing frame and close the connection
|
||||
*
|
||||
*
|
||||
* @param channel
|
||||
* Channel
|
||||
* @param frame
|
||||
|
@ -17,11 +17,11 @@ package org.jboss.netty.handler.codec.http.websocketx;
|
||||
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
|
||||
import org.jboss.netty.handler.codec.http.HttpHeaders.Names;
|
||||
import org.jboss.netty.handler.codec.http.HttpRequest;
|
||||
import org.jboss.netty.handler.codec.http.HttpResponse;
|
||||
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
|
||||
import org.jboss.netty.handler.codec.http.HttpVersion;
|
||||
import org.jboss.netty.handler.codec.http.HttpHeaders.Names;
|
||||
|
||||
/**
|
||||
* Instances the appropriate handshake class to use for servers
|
||||
@ -35,10 +35,10 @@ public class WebSocketServerHandshakerFactory {
|
||||
private final boolean allowExtensions;
|
||||
|
||||
private final long maxFramePayloadLength;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
||||
|
||||
* @param subprotocols
|
||||
* CSV of supported protocols. Null if sub protocols not supported.
|
||||
* @param allowExtensions
|
||||
@ -50,7 +50,7 @@ public class WebSocketServerHandshakerFactory {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
*
|
||||
* @param webSocketURL
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
|
||||
* sent to this URL.
|
||||
@ -62,17 +62,17 @@ public class WebSocketServerHandshakerFactory {
|
||||
* Maximum allowable frame payload length. Setting this value to your application's requirement may
|
||||
* reduce denial of service attacks using long data frames.
|
||||
*/
|
||||
public WebSocketServerHandshakerFactory(String webSocketURL, String subprotocols, boolean allowExtensions,
|
||||
public WebSocketServerHandshakerFactory(String webSocketURL, String subprotocols, boolean allowExtensions,
|
||||
long maxFramePayloadLength) {
|
||||
this.webSocketURL = webSocketURL;
|
||||
this.subprotocols = subprotocols;
|
||||
this.allowExtensions = allowExtensions;
|
||||
this.maxFramePayloadLength = maxFramePayloadLength;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instances a new handshaker
|
||||
*
|
||||
*
|
||||
* @return A new WebSocketServerHandshaker for the requested web socket version. Null if web socket version is not
|
||||
* supported.
|
||||
*/
|
||||
@ -97,7 +97,7 @@ public class WebSocketServerHandshakerFactory {
|
||||
|
||||
/**
|
||||
* Return that we need cannot not support the web socket version
|
||||
*
|
||||
*
|
||||
* @param channel
|
||||
* Channel
|
||||
*/
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user