Sorry.. bad revert "Revert "Merge branch '3' of ssh://github.com/netty/netty into 3""
This reverts commit 91accdc5e41ce4669df94296e625e6098b082d68.
This commit is contained in:
parent
91accdc5e4
commit
4776e6ae9f
10
pom.xml
10
pom.xml
@ -26,7 +26,7 @@
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty</artifactId>
|
||||
<packaging>bundle</packaging>
|
||||
<version>3.5.0.Final-SNAPSHOT</version>
|
||||
<version>3.5.1.Final-SNAPSHOT</version>
|
||||
|
||||
<name>The Netty Project</name>
|
||||
<url>http://netty.io/</url>
|
||||
@ -577,10 +577,10 @@
|
||||
<doctitle>${project.name} API Reference (${project.version})</doctitle>
|
||||
<windowtitle>${project.name} API Reference (${project.version})</windowtitle>
|
||||
<additionalparam>
|
||||
-link http://java.sun.com/javase/6/docs/api/
|
||||
-link http://docs.oracle.com/javase/7/docs/api/
|
||||
-link http://code.google.com/apis/protocolbuffers/docs/reference/java/
|
||||
-link http://java.sun.com/products/servlet/2.5/docs/servlet-2_5-mr2/
|
||||
-link http://www.osgi.org/javadoc/r4v41/
|
||||
-link http://docs.oracle.com/javaee/6/api/
|
||||
-link http://www.osgi.org/javadoc/r4v43/core/
|
||||
-link http://www.slf4j.org/apidocs/
|
||||
-link http://commons.apache.org/logging/commons-logging-1.1.1/apidocs/
|
||||
-link http://logging.apache.org/log4j/1.2/apidocs/
|
||||
@ -665,7 +665,7 @@
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>netty-build</artifactId>
|
||||
<version>7</version>
|
||||
<version>9</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
|
@ -34,6 +34,7 @@
|
||||
<include>**/src/**</include>
|
||||
</includes>
|
||||
<excludes>
|
||||
<exclude>**/bin/**</exclude>
|
||||
<exclude>**/target/**</exclude>
|
||||
<exclude>**/.*/**</exclude>
|
||||
</excludes>
|
||||
|
@ -231,12 +231,13 @@ public class ClientBootstrap extends Bootstrap {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
* {@link Channel#setAttachment(Object)} so you can use it after the {@link #bind(SocketAddress)}
|
||||
* was done.
|
||||
* <br>
|
||||
* For example:
|
||||
*
|
||||
|
@ -39,11 +39,10 @@ import java.nio.charset.UnsupportedCharsetException;
|
||||
* <h3>Random Access Indexing</h3>
|
||||
*
|
||||
* Just like an ordinary primitive byte array, {@link ChannelBuffer} uses
|
||||
* <a href="http://en.wikipedia.org/wiki/Index_(information_technology)#Array_element_identifier">zero-based indexing</a>.
|
||||
* It means the index of the first byte is always {@code 0} and the index of
|
||||
* the last byte is always {@link #capacity() capacity - 1}. For example, to
|
||||
* iterate all bytes of a buffer, you can do the following, regardless of
|
||||
* its internal implementation:
|
||||
* <a href="http://en.wikipedia.org/wiki/Zero-based_numbering">zero-based indexing</a>.
|
||||
* It means the index of the first byte is always {@code 0} and the index of the last byte is
|
||||
* always {@link #capacity() capacity - 1}. For example, to iterate all bytes of a buffer, you
|
||||
* can do the following, regardless of its internal implementation:
|
||||
*
|
||||
* <pre>
|
||||
* {@link ChannelBuffer} buffer = ...;
|
||||
@ -1724,13 +1723,15 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
||||
String charsetName, ChannelBufferIndexFinder terminatorFinder);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #bytesBefore(int, int, ChannelBufferIndexFinder)} and {@link #toString(int, int, Charset)} instead.
|
||||
* @deprecated Use {@link #bytesBefore(int, int, ChannelBufferIndexFinder)} and
|
||||
* {@link #toString(int, int, Charset)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
String toString(int index, int length, String charsetName);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #bytesBefore(int, int, ChannelBufferIndexFinder)} and {@link #toString(int, int, Charset)} instead.
|
||||
* @deprecated Use {@link #bytesBefore(int, int, ChannelBufferIndexFinder)} and
|
||||
* {@link #toString(int, int, Charset)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
String toString(
|
||||
|
@ -227,7 +227,8 @@ public final class ChannelBuffers {
|
||||
* More accurate estimation yields less unexpected reallocation overhead.
|
||||
* The new buffer's {@code readerIndex} and {@code writerIndex} are {@code 0}.
|
||||
*/
|
||||
public static ChannelBuffer dynamicBuffer(ByteOrder endianness, int estimatedLength, ChannelBufferFactory factory) {
|
||||
public static ChannelBuffer dynamicBuffer(
|
||||
ByteOrder endianness, int estimatedLength, ChannelBufferFactory factory) {
|
||||
return new DynamicChannelBuffer(endianness, estimatedLength, factory);
|
||||
}
|
||||
|
||||
@ -308,7 +309,8 @@ public final class ChannelBuffers {
|
||||
return EMPTY_BUFFER;
|
||||
}
|
||||
if (buffer.hasArray()) {
|
||||
return wrappedBuffer(buffer.order(), buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
|
||||
return wrappedBuffer(
|
||||
buffer.order(), buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
|
||||
} else {
|
||||
return new ByteBufferBackedChannelBuffer(buffer);
|
||||
}
|
||||
@ -1050,7 +1052,8 @@ public final class ChannelBuffers {
|
||||
* The default implementation of {@link ChannelBuffer#indexOf(int, int, ChannelBufferIndexFinder)}.
|
||||
* This method is useful when implementing a new buffer type.
|
||||
*/
|
||||
public static int indexOf(ChannelBuffer buffer, int fromIndex, int toIndex, ChannelBufferIndexFinder indexFinder) {
|
||||
public static int indexOf(
|
||||
ChannelBuffer buffer, int fromIndex, int toIndex, ChannelBufferIndexFinder indexFinder) {
|
||||
if (fromIndex <= toIndex) {
|
||||
return firstIndexOf(buffer, fromIndex, toIndex, indexFinder);
|
||||
} else {
|
||||
@ -1118,7 +1121,8 @@ public final class ChannelBuffers {
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static int firstIndexOf(ChannelBuffer buffer, int fromIndex, int toIndex, ChannelBufferIndexFinder indexFinder) {
|
||||
private static int firstIndexOf(
|
||||
ChannelBuffer buffer, int fromIndex, int toIndex, ChannelBufferIndexFinder indexFinder) {
|
||||
fromIndex = Math.max(fromIndex, 0);
|
||||
if (fromIndex >= toIndex || buffer.capacity() == 0) {
|
||||
return -1;
|
||||
@ -1133,7 +1137,8 @@ public final class ChannelBuffers {
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static int lastIndexOf(ChannelBuffer buffer, int fromIndex, int toIndex, ChannelBufferIndexFinder indexFinder) {
|
||||
private static int lastIndexOf(
|
||||
ChannelBuffer buffer, int fromIndex, int toIndex, ChannelBufferIndexFinder indexFinder) {
|
||||
fromIndex = Math.min(fromIndex, buffer.capacity());
|
||||
if (fromIndex < 0 || buffer.capacity() == 0) {
|
||||
return -1;
|
||||
|
@ -140,7 +140,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
|
||||
private CompositeChannelBuffer(CompositeChannelBuffer buffer) {
|
||||
order = buffer.order;
|
||||
this.gathering = buffer.gathering;
|
||||
gathering = buffer.gathering;
|
||||
components = buffer.components.clone();
|
||||
indices = buffer.indices.clone();
|
||||
setIndex(buffer.readerIndex(), buffer.writerIndex());
|
||||
|
@ -56,11 +56,11 @@ public class DirectChannelBufferFactory extends AbstractChannelBufferFactory {
|
||||
|
||||
private final Object bigEndianLock = new Object();
|
||||
private final Object littleEndianLock = new Object();
|
||||
private final int preallocatedBufferCapacity;
|
||||
private ChannelBuffer preallocatedBigEndianBuffer;
|
||||
private int preallocatedBigEndianBufferPosition;
|
||||
private ChannelBuffer preallocatedLittleEndianBuffer;
|
||||
private int preallocatedLittleEndianBufferPosition;
|
||||
private final int preallocatedBufCapacity;
|
||||
private ChannelBuffer preallocatedBEBuf;
|
||||
private int preallocatedBEBufPos;
|
||||
private ChannelBuffer preallocatedLEBuf;
|
||||
private int preallocatedLEBufPos;
|
||||
|
||||
/**
|
||||
* Creates a new factory whose default {@link ByteOrder} is
|
||||
@ -96,10 +96,10 @@ public class DirectChannelBufferFactory extends AbstractChannelBufferFactory {
|
||||
super(defaultOrder);
|
||||
if (preallocatedBufferCapacity <= 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"preallocatedBufferCapacity must be greater than 0: " + preallocatedBufferCapacity);
|
||||
"preallocatedBufCapacity must be greater than 0: " + preallocatedBufferCapacity);
|
||||
}
|
||||
|
||||
this.preallocatedBufferCapacity = preallocatedBufferCapacity;
|
||||
this.preallocatedBufCapacity = preallocatedBufferCapacity;
|
||||
}
|
||||
|
||||
public ChannelBuffer getBuffer(ByteOrder order, int capacity) {
|
||||
@ -112,7 +112,7 @@ public class DirectChannelBufferFactory extends AbstractChannelBufferFactory {
|
||||
if (capacity == 0) {
|
||||
return ChannelBuffers.EMPTY_BUFFER;
|
||||
}
|
||||
if (capacity >= preallocatedBufferCapacity) {
|
||||
if (capacity >= preallocatedBufCapacity) {
|
||||
return ChannelBuffers.directBuffer(order, capacity);
|
||||
}
|
||||
|
||||
@ -160,17 +160,17 @@ public class DirectChannelBufferFactory extends AbstractChannelBufferFactory {
|
||||
private ChannelBuffer allocateBigEndianBuffer(int capacity) {
|
||||
ChannelBuffer slice;
|
||||
synchronized (bigEndianLock) {
|
||||
if (preallocatedBigEndianBuffer == null) {
|
||||
preallocatedBigEndianBuffer = ChannelBuffers.directBuffer(ByteOrder.BIG_ENDIAN, preallocatedBufferCapacity);
|
||||
slice = preallocatedBigEndianBuffer.slice(0, capacity);
|
||||
preallocatedBigEndianBufferPosition = capacity;
|
||||
} else if (preallocatedBigEndianBuffer.capacity() - preallocatedBigEndianBufferPosition >= capacity) {
|
||||
slice = preallocatedBigEndianBuffer.slice(preallocatedBigEndianBufferPosition, capacity);
|
||||
preallocatedBigEndianBufferPosition += capacity;
|
||||
if (preallocatedBEBuf == null) {
|
||||
preallocatedBEBuf = ChannelBuffers.directBuffer(ByteOrder.BIG_ENDIAN, preallocatedBufCapacity);
|
||||
slice = preallocatedBEBuf.slice(0, capacity);
|
||||
preallocatedBEBufPos = capacity;
|
||||
} else if (preallocatedBEBuf.capacity() - preallocatedBEBufPos >= capacity) {
|
||||
slice = preallocatedBEBuf.slice(preallocatedBEBufPos, capacity);
|
||||
preallocatedBEBufPos += capacity;
|
||||
} else {
|
||||
preallocatedBigEndianBuffer = ChannelBuffers.directBuffer(ByteOrder.BIG_ENDIAN, preallocatedBufferCapacity);
|
||||
slice = preallocatedBigEndianBuffer.slice(0, capacity);
|
||||
preallocatedBigEndianBufferPosition = capacity;
|
||||
preallocatedBEBuf = ChannelBuffers.directBuffer(ByteOrder.BIG_ENDIAN, preallocatedBufCapacity);
|
||||
slice = preallocatedBEBuf.slice(0, capacity);
|
||||
preallocatedBEBufPos = capacity;
|
||||
}
|
||||
}
|
||||
return slice;
|
||||
@ -179,17 +179,17 @@ public class DirectChannelBufferFactory extends AbstractChannelBufferFactory {
|
||||
private ChannelBuffer allocateLittleEndianBuffer(int capacity) {
|
||||
ChannelBuffer slice;
|
||||
synchronized (littleEndianLock) {
|
||||
if (preallocatedLittleEndianBuffer == null) {
|
||||
preallocatedLittleEndianBuffer = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, preallocatedBufferCapacity);
|
||||
slice = preallocatedLittleEndianBuffer.slice(0, capacity);
|
||||
preallocatedLittleEndianBufferPosition = capacity;
|
||||
} else if (preallocatedLittleEndianBuffer.capacity() - preallocatedLittleEndianBufferPosition >= capacity) {
|
||||
slice = preallocatedLittleEndianBuffer.slice(preallocatedLittleEndianBufferPosition, capacity);
|
||||
preallocatedLittleEndianBufferPosition += capacity;
|
||||
if (preallocatedLEBuf == null) {
|
||||
preallocatedLEBuf = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, preallocatedBufCapacity);
|
||||
slice = preallocatedLEBuf.slice(0, capacity);
|
||||
preallocatedLEBufPos = capacity;
|
||||
} else if (preallocatedLEBuf.capacity() - preallocatedLEBufPos >= capacity) {
|
||||
slice = preallocatedLEBuf.slice(preallocatedLEBufPos, capacity);
|
||||
preallocatedLEBufPos += capacity;
|
||||
} else {
|
||||
preallocatedLittleEndianBuffer = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, preallocatedBufferCapacity);
|
||||
slice = preallocatedLittleEndianBuffer.slice(0, capacity);
|
||||
preallocatedLittleEndianBufferPosition = capacity;
|
||||
preallocatedLEBuf = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, preallocatedBufCapacity);
|
||||
slice = preallocatedLEBuf.slice(0, capacity);
|
||||
preallocatedLEBufPos = capacity;
|
||||
}
|
||||
}
|
||||
return slice;
|
||||
|
@ -59,7 +59,8 @@ package org.jboss.netty.channel;
|
||||
* <p>
|
||||
* <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.
|
||||
* 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.
|
||||
*
|
||||
* <h3>State management</h3>
|
||||
*
|
||||
|
@ -71,7 +71,8 @@ import org.jboss.netty.channel.socket.ServerSocketChannel;
|
||||
* <td>{@code "channelOpen"}</td>
|
||||
* <td>{@link ChannelStateEvent}<br/>(state = {@link ChannelState#OPEN OPEN}, value = {@code true})</td>
|
||||
* <td>a {@link Channel} is open, but not bound nor connected</td>
|
||||
* <td><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></td>
|
||||
* <td><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></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@code "channelClosed"}</td>
|
||||
@ -82,7 +83,8 @@ import org.jboss.netty.channel.socket.ServerSocketChannel;
|
||||
* <td>{@code "channelBound"}</td>
|
||||
* <td>{@link ChannelStateEvent}<br/>(state = {@link ChannelState#BOUND BOUND}, value = {@link SocketAddress})</td>
|
||||
* <td>a {@link Channel} is open and bound to a local address, but not connected.</td>
|
||||
* <td><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></td>
|
||||
* <td><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></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@code "channelUnbound"}</td>
|
||||
@ -91,9 +93,11 @@ import org.jboss.netty.channel.socket.ServerSocketChannel;
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@code "channelConnected"}</td>
|
||||
* <td>{@link ChannelStateEvent}<br/>(state = {@link ChannelState#CONNECTED CONNECTED}, value = {@link SocketAddress})</td>
|
||||
* <td>{@link ChannelStateEvent}<br/>(state = {@link ChannelState#CONNECTED CONNECTED}, value =
|
||||
* {@link SocketAddress})</td>
|
||||
* <td>a {@link Channel} is open, bound to a local address, and connected to a remote address</td>
|
||||
* <td><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></td>
|
||||
* <td><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></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@code "writeComplete"}</td>
|
||||
@ -153,7 +157,8 @@ import org.jboss.netty.channel.socket.ServerSocketChannel;
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@code "connect"}</td>
|
||||
* <td>{@link ChannelStateEvent}<br/>(state = {@link ChannelState#CONNECTED CONNECTED}, value = {@link SocketAddress})</td>
|
||||
* <td>{@link ChannelStateEvent}<br/>(state = {@link ChannelState#CONNECTED CONNECTED}, value =
|
||||
* {@link SocketAddress})</td>
|
||||
* <td>Connect the {@link Channel} to the specified remote address.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
|
@ -142,7 +142,7 @@ import org.jboss.netty.channel.group.ChannelGroup;
|
||||
* <pre>
|
||||
* public final class DataServerState {
|
||||
*
|
||||
* <b>public static final {@link ChannelLocal}<Boolean> loggedIn = new {@link ChannelLocal}<Boolean>() {
|
||||
* <b>public static final {@link ChannelLocal}<Boolean> loggedIn = new {@link ChannelLocal}<>() {
|
||||
* protected Boolean initialValue(Channel channel) {
|
||||
* return false;
|
||||
* }
|
||||
|
@ -48,7 +48,8 @@ public class ChannelLocal<T> implements Iterable<Entry<Channel, T>> {
|
||||
private final boolean removeOnClose;
|
||||
|
||||
/**
|
||||
* Creates a {@link Channel} local variable by calling {@link #ChannelLocal(boolean)} with <code>false</code> as parameter
|
||||
* Creates a {@link Channel} local variable by calling {@link #ChannelLocal(boolean)} with
|
||||
* <code>false</code> as parameter
|
||||
*/
|
||||
public ChannelLocal() {
|
||||
this(false);
|
||||
@ -57,7 +58,8 @@ public class ChannelLocal<T> implements Iterable<Entry<Channel, T>> {
|
||||
/**
|
||||
* Creates a {@link Channel} local variable.
|
||||
*
|
||||
* @param removeOnClose if <code>true</code> the {@link ChannelLocal} will remove a {@link Channel} from it own once the {@link Channel} was closed.
|
||||
* @param removeOnClose if <code>true</code> the {@link ChannelLocal} will remove a
|
||||
* {@link Channel} from it own once the {@link Channel} was closed.
|
||||
*/
|
||||
public ChannelLocal(boolean removeOnClose) {
|
||||
this.removeOnClose = removeOnClose;
|
||||
|
@ -168,7 +168,8 @@ import org.jboss.netty.handler.ssl.SslHandler;
|
||||
* {@link ChannelPipeline} pipeline = {@link Channels#pipeline() Channels.pipeline()};
|
||||
* pipeline.addLast("decoder", new MyProtocolDecoder());
|
||||
* pipeline.addLast("encoder", new MyProtocolEncoder());
|
||||
* pipeline.addLast("executor", new {@link ExecutionHandler}(new {@link OrderedMemoryAwareThreadPoolExecutor}(16, 1048576, 1048576)));
|
||||
* pipeline.addLast("executor", new {@link ExecutionHandler}(
|
||||
* new {@link OrderedMemoryAwareThreadPoolExecutor}(16, 1048576, 1048576)));
|
||||
* pipeline.addLast("handler", new MyBusinessLogicHandler());
|
||||
* </pre>
|
||||
*
|
||||
|
@ -29,46 +29,60 @@ import java.net.SocketAddress;
|
||||
* <th>Direction</th><th>State</th><th>Value</th><th>Meaning</th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Upstream</td><td>{@link #OPEN}</td><td>{@code true}</td><td>The channel is open.</td>
|
||||
* <td>Upstream</td><td>{@link #OPEN}</td>
|
||||
* <td>{@code true}</td><td>The channel is open.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Upstream</td><td>{@link #OPEN}</td><td>{@code false}</td><td>The channel is closed.</td>
|
||||
* <td>Upstream</td><td>{@link #OPEN}</td>
|
||||
* <td>{@code false}</td><td>The channel is closed.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Upstream</td><td>{@link #BOUND}</td><td>{@link SocketAddress}</td><td>The channel is bound to a local address.</td>
|
||||
* <td>Upstream</td><td>{@link #BOUND}</td>
|
||||
* <td>{@link SocketAddress}</td><td>The channel is bound to a local address.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Upstream</td><td>{@link #BOUND}</td><td>{@code null}</td><td>The channel is unbound to a local address.</td>
|
||||
* <td>Upstream</td><td>{@link #BOUND}</td>
|
||||
* <td>{@code null}</td><td>The channel is unbound to a local address.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Upstream</td><td>{@link #CONNECTED}</td><td>{@link SocketAddress}</td><td>The channel is connected to a remote address.</td>
|
||||
* <td>Upstream</td><td>{@link #CONNECTED}</td>
|
||||
* <td>{@link SocketAddress}</td><td>The channel is connected to a remote address.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Upstream</td><td>{@link #CONNECTED}</td><td>{@code null}</td><td>The channel is disconnected from a remote address.</td>
|
||||
* <td>Upstream</td><td>{@link #CONNECTED}</td>
|
||||
* <td>{@code null}</td><td>The channel is disconnected from a remote address.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Upstream</td><td>{@link #INTEREST_OPS}</td><td>an integer</td><td>The channel interestOps has been changed.</td>
|
||||
* <td>Upstream</td><td>{@link #INTEREST_OPS}</td>
|
||||
* <td>an integer</td><td>The channel interestOps has been changed.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Downstream</td><td>{@link #OPEN}</td><td>{@code true}</td><td>N/A</td>
|
||||
* <td>Downstream</td><td>{@link #OPEN}</td>
|
||||
* <td>{@code true}</td><td>N/A</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Downstream</td><td>{@link #OPEN}</td><td>{@code false}</td><td>Close the channel.</td>
|
||||
* <td>Downstream</td><td>{@link #OPEN}</td>
|
||||
* <td>{@code false}</td><td>Close the channel.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Downstream</td><td>{@link #BOUND}</td><td>{@link SocketAddress}</td><td>Bind the channel to the specified local address.</td>
|
||||
* <td>Downstream</td><td>{@link #BOUND}</td>
|
||||
* <td>{@link SocketAddress}</td><td>Bind the channel to the specified local address.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Downstream</td><td>{@link #BOUND}</td><td>{@code null}</td><td>Unbind the channel from the current local address.</td>
|
||||
* <td>Downstream</td><td>{@link #BOUND}</td>
|
||||
* <td>{@code null}</td><td>Unbind the channel from the current local address.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Downstream</td><td>{@link #CONNECTED}</td><td>{@link SocketAddress}</td><td>Connect the channel to the specified remote address.</td>
|
||||
* <td>Downstream</td><td>{@link #CONNECTED}</td>
|
||||
* <td>{@link SocketAddress}</td><td>Connect the channel to the specified remote address.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Downstream</td><td>{@link #CONNECTED}</td><td>{@code null}</td><td>Disconnect the channel from the current remote address.</td>
|
||||
* <td>Downstream</td><td>{@link #CONNECTED}</td>
|
||||
* <td>{@code null}</td><td>Disconnect the channel from the current remote address.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Downstream</td><td>{@link #INTEREST_OPS}</td><td>an integer</td><td>Change the interestOps of the channel.</td>
|
||||
* <td>Downstream</td><td>{@link #INTEREST_OPS}</td>
|
||||
* <td>an integer</td><td>Change the interestOps of the channel.</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
* <p>
|
||||
|
@ -52,7 +52,8 @@ import java.net.SocketAddress;
|
||||
* <p>
|
||||
* <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.
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
public class SimpleChannelDownstreamHandler implements ChannelDownstreamHandler {
|
||||
|
@ -147,7 +147,8 @@ 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>
|
||||
* <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(
|
||||
ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
|
||||
@ -159,7 +160,8 @@ public class SimpleChannelUpstreamHandler implements ChannelUpstreamHandler {
|
||||
* 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>
|
||||
* <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(
|
||||
ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
|
||||
@ -171,7 +173,8 @@ public class SimpleChannelUpstreamHandler implements ChannelUpstreamHandler {
|
||||
* 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>
|
||||
* <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(
|
||||
ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
|
||||
|
@ -55,7 +55,9 @@ final class DefaultLocalChannel extends AbstractChannel implements LocalChannel
|
||||
volatile LocalAddress localAddress;
|
||||
volatile LocalAddress remoteAddress;
|
||||
|
||||
DefaultLocalChannel(LocalServerChannel parent, ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink, DefaultLocalChannel pairedChannel) {
|
||||
DefaultLocalChannel(
|
||||
LocalServerChannel parent, ChannelFactory factory, ChannelPipeline pipeline,
|
||||
ChannelSink sink, DefaultLocalChannel pairedChannel) {
|
||||
super(parent, factory, pipeline, sink);
|
||||
this.pairedChannel = pairedChannel;
|
||||
config = new DefaultChannelConfig();
|
||||
|
@ -43,8 +43,8 @@ public class DefaultLocalServerChannelFactory implements LocalServerChannelFacto
|
||||
|
||||
|
||||
/**
|
||||
* Release all the previous created channels. This takes care of calling {@link LocalChannelRegistry#unregister(LocalAddress)}
|
||||
* for each if them.
|
||||
* Release all the previous created channels.
|
||||
* This takes care of calling {@link LocalChannelRegistry#unregister(LocalAddress)} for each of them.
|
||||
*/
|
||||
public void releaseExternalResources() {
|
||||
group.close().awaitUninterruptibly();
|
||||
|
@ -15,9 +15,9 @@
|
||||
*/
|
||||
package org.jboss.netty.channel.socket;
|
||||
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.StandardSocketOptions;
|
||||
|
||||
import org.jboss.netty.channel.ChannelConfig;
|
||||
import org.jboss.netty.channel.FixedReceiveBufferSizePredictor;
|
||||
@ -49,9 +49,11 @@ import org.jboss.netty.channel.ReceiveBufferSizePredictorFactory;
|
||||
* </tr><tr>
|
||||
* <td>{@code "receiveBufferSize"}</td><td>{@link #setReceiveBufferSize(int)}</td>
|
||||
* </tr><tr>
|
||||
* <td>{@code "receiveBufferSizePredictor"}</td><td>{@link #setReceiveBufferSizePredictor(ReceiveBufferSizePredictor)}</td>
|
||||
* <td>{@code "receiveBufferSizePredictor"}</td>
|
||||
* <td>{@link #setReceiveBufferSizePredictor(ReceiveBufferSizePredictor)}</td>
|
||||
* </tr><tr>
|
||||
* <td>{@code "receiveBufferSizePredictorFactory"}</td><td>{@link #setReceiveBufferSizePredictorFactory(ReceiveBufferSizePredictorFactory)}</td>
|
||||
* <td>{@code "receiveBufferSizePredictorFactory"}</td>
|
||||
* <td>{@link #setReceiveBufferSizePredictorFactory(ReceiveBufferSizePredictorFactory)}</td>
|
||||
* </tr><tr>
|
||||
* <td>{@code "sendBufferSize"}</td><td>{@link #setSendBufferSize(int)}</td>
|
||||
* </tr><tr>
|
||||
@ -64,64 +66,62 @@ import org.jboss.netty.channel.ReceiveBufferSizePredictorFactory;
|
||||
public interface DatagramChannelConfig extends ChannelConfig {
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_SNDBUF}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#SO_SNDBUF} option.
|
||||
*/
|
||||
int getSendBufferSize();
|
||||
|
||||
/**
|
||||
* Sets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_SNDBUF}</a> option.
|
||||
* Sets the {@link StandardSocketOptions#SO_SNDBUF} option.
|
||||
*/
|
||||
void setSendBufferSize(int sendBufferSize);
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_RCVBUF}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#SO_RCVBUF} option.
|
||||
*/
|
||||
int getReceiveBufferSize();
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_RCVBUF}</a> option.
|
||||
* Sets the {@link StandardSocketOptions#SO_RCVBUF} option.
|
||||
*/
|
||||
void setReceiveBufferSize(int receiveBufferSize);
|
||||
|
||||
/**
|
||||
* Gets the traffic class.
|
||||
* Gets the {@link StandardSocketOptions#IP_TOS} option.
|
||||
*/
|
||||
int getTrafficClass();
|
||||
|
||||
/**
|
||||
* Sets the traffic class as specified in {@link DatagramSocket#setTrafficClass(int)}.
|
||||
* Gets the {@link StandardSocketOptions#IP_TOS} option.
|
||||
*/
|
||||
void setTrafficClass(int trafficClass);
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_REUSEADDR}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#SO_REUSEADDR} option.
|
||||
*/
|
||||
boolean isReuseAddress();
|
||||
|
||||
/**
|
||||
* Sets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_REUSEADDR}</a> option.
|
||||
* Sets the {@link StandardSocketOptions#SO_REUSEADDR} option.
|
||||
*/
|
||||
void setReuseAddress(boolean reuseAddress);
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_BROADCAST}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#SO_BROADCAST} option.
|
||||
*/
|
||||
boolean isBroadcast();
|
||||
|
||||
/**
|
||||
* Sets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_BROADCAST}</a> option.
|
||||
* Sets the {@link StandardSocketOptions#SO_BROADCAST} option.
|
||||
*/
|
||||
void setBroadcast(boolean broadcast);
|
||||
|
||||
/**
|
||||
* Gets the setting for local loopback of multicast datagrams.
|
||||
*
|
||||
* @return {@code true} if and only if the loopback mode has been disabled
|
||||
* Gets the {@link StandardSocketOptions#IP_MULTICAST_LOOP} option.
|
||||
*/
|
||||
boolean isLoopbackModeDisabled();
|
||||
|
||||
/**
|
||||
* Sets the setting for local loopback of multicast datagrams.
|
||||
* Sets the {@link StandardSocketOptions#IP_MULTICAST_LOOP} option.
|
||||
*
|
||||
* @param loopbackModeDisabled
|
||||
* {@code true} if and only if the loopback mode has been disabled
|
||||
@ -129,14 +129,12 @@ public interface DatagramChannelConfig extends ChannelConfig {
|
||||
void setLoopbackModeDisabled(boolean loopbackModeDisabled);
|
||||
|
||||
/**
|
||||
* Gets the default time-to-live for multicast packets sent out on the
|
||||
* socket.
|
||||
* Gets the {@link StandardSocketOptions#IP_MULTICAST_TTL} option.
|
||||
*/
|
||||
int getTimeToLive();
|
||||
|
||||
/**
|
||||
* Sets the default time-to-live for multicast packets sent out on the
|
||||
* {@link DatagramChannel} in order to control the scope of the multicasts.
|
||||
* Sets the {@link StandardSocketOptions#IP_MULTICAST_TTL} option.
|
||||
*/
|
||||
void setTimeToLive(int ttl);
|
||||
|
||||
@ -151,14 +149,12 @@ public interface DatagramChannelConfig extends ChannelConfig {
|
||||
void setInterface(InetAddress interfaceAddress);
|
||||
|
||||
/**
|
||||
* Gets the network interface for outgoing multicast datagrams sent on
|
||||
* the {@link DatagramChannel}.
|
||||
* Gets the {@link StandardSocketOptions#IP_MULTICAST_IF} option.
|
||||
*/
|
||||
NetworkInterface getNetworkInterface();
|
||||
|
||||
/**
|
||||
* Sets the network interface for outgoing multicast datagrams sent on
|
||||
* the {@link DatagramChannel}.
|
||||
* Sets the {@link StandardSocketOptions#IP_MULTICAST_IF} option.
|
||||
*/
|
||||
void setNetworkInterface(NetworkInterface networkInterface);
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
package org.jboss.netty.channel.socket;
|
||||
|
||||
import java.net.ServerSocket;
|
||||
import java.net.StandardSocketOptions;
|
||||
|
||||
import org.jboss.netty.channel.ChannelConfig;
|
||||
|
||||
@ -55,22 +56,22 @@ public interface ServerSocketChannelConfig extends ChannelConfig {
|
||||
void setBacklog(int backlog);
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_REUSEADDR}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#SO_REUSEADDR} option.
|
||||
*/
|
||||
boolean isReuseAddress();
|
||||
|
||||
/**
|
||||
* Sets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_REUSEADDR}</a> option.
|
||||
* Sets the {@link StandardSocketOptions#SO_REUSEADDR} option.
|
||||
*/
|
||||
void setReuseAddress(boolean reuseAddress);
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_RCVBUF}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#SO_RCVBUF} option.
|
||||
*/
|
||||
int getReceiveBufferSize();
|
||||
|
||||
/**
|
||||
* Sets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_RCVBUF}</a> option.
|
||||
* Sets the {@link StandardSocketOptions#SO_RCVBUF} option.
|
||||
*/
|
||||
void setReceiveBufferSize(int receiveBufferSize);
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
package org.jboss.netty.channel.socket;
|
||||
|
||||
import java.net.Socket;
|
||||
import java.net.StandardSocketOptions;
|
||||
|
||||
import org.jboss.netty.channel.ChannelConfig;
|
||||
|
||||
@ -50,72 +51,72 @@ import org.jboss.netty.channel.ChannelConfig;
|
||||
public interface SocketChannelConfig extends ChannelConfig {
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_TCPNODELAY}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#TCP_NODELAY} option.
|
||||
*/
|
||||
boolean isTcpNoDelay();
|
||||
|
||||
/**
|
||||
* Sets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_TCPNODELAY}</a> option.
|
||||
* Sets the {@link StandardSocketOptions#TCP_NODELAY} option.
|
||||
*/
|
||||
void setTcpNoDelay(boolean tcpNoDelay);
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_LINGER}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#SO_LINGER} option.
|
||||
*/
|
||||
int getSoLinger();
|
||||
|
||||
/**
|
||||
* Sets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_LINGER}</a> option.
|
||||
* Sets the {@link StandardSocketOptions#SO_LINGER} option.
|
||||
*/
|
||||
void setSoLinger(int soLinger);
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_SNDBUF}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#SO_SNDBUF} option.
|
||||
*/
|
||||
int getSendBufferSize();
|
||||
|
||||
/**
|
||||
* Sets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_SNDBUF}</a> option.
|
||||
* Sets the {@link StandardSocketOptions#SO_SNDBUF} option.
|
||||
*/
|
||||
void setSendBufferSize(int sendBufferSize);
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_RCVBUF}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#SO_RCVBUF} option.
|
||||
*/
|
||||
int getReceiveBufferSize();
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_RCVBUF}</a> option.
|
||||
* Sets the {@link StandardSocketOptions#SO_RCVBUF} option.
|
||||
*/
|
||||
void setReceiveBufferSize(int receiveBufferSize);
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_KEEPALIVE}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#SO_KEEPALIVE} option.
|
||||
*/
|
||||
boolean isKeepAlive();
|
||||
|
||||
/**
|
||||
* Sets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_KEEPALIVE}</a> option.
|
||||
* Sets the {@link StandardSocketOptions#SO_KEEPALIVE} option.
|
||||
*/
|
||||
void setKeepAlive(boolean keepAlive);
|
||||
|
||||
/**
|
||||
* Gets the traffic class.
|
||||
* Gets the {@link StandardSocketOptions#IP_TOS} option.
|
||||
*/
|
||||
int getTrafficClass();
|
||||
|
||||
/**
|
||||
* Sets the traffic class as specified in {@link Socket#setTrafficClass(int)}.
|
||||
* Sets the {@link StandardSocketOptions#IP_TOS} option.
|
||||
*/
|
||||
void setTrafficClass(int trafficClass);
|
||||
|
||||
/**
|
||||
* Gets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_REUSEADDR}</a> option.
|
||||
* Gets the {@link StandardSocketOptions#SO_REUSEADDR} option.
|
||||
*/
|
||||
boolean isReuseAddress();
|
||||
|
||||
/**
|
||||
* Sets the <a href="http://java.sun.com/javase/6/docs/technotes/guides/net/socketOpt.html">{@code SO_REUSEADDR}</a> option.
|
||||
* Sets the {@link StandardSocketOptions#SO_REUSEADDR} option.
|
||||
*/
|
||||
void setReuseAddress(boolean reuseAddress);
|
||||
|
||||
|
@ -100,7 +100,9 @@ abstract class AbstractNioChannel<C extends SelectableChannel & WritableByteChan
|
||||
|
||||
final C channel;
|
||||
|
||||
protected AbstractNioChannel(Integer id, Channel parent, ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink, AbstractNioWorker worker, C ch) {
|
||||
protected AbstractNioChannel(
|
||||
Integer id, Channel parent, ChannelFactory factory, ChannelPipeline pipeline,
|
||||
ChannelSink sink, AbstractNioWorker worker, C ch) {
|
||||
super(id, parent, factory, pipeline, sink);
|
||||
this.worker = worker;
|
||||
this.channel = ch;
|
||||
|
@ -148,7 +148,8 @@ 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
|
||||
* Start the {@link AbstractNioWorker} and return the {@link Selector} that will be used for
|
||||
* the {@link AbstractNioChannel}'s when they get registered
|
||||
*
|
||||
* @return selector
|
||||
*/
|
||||
|
@ -25,11 +25,11 @@ import org.jboss.netty.util.ExternalResourceReleasable;
|
||||
import org.jboss.netty.util.internal.ExecutorUtil;
|
||||
|
||||
/**
|
||||
* 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()}
|
||||
*
|
||||
* 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()}
|
||||
*/
|
||||
public abstract class AbstractNioWorkerPool<E extends AbstractNioWorker> implements WorkerPool<E> , ExternalResourceReleasable {
|
||||
public abstract class AbstractNioWorkerPool<E extends AbstractNioWorker>
|
||||
implements WorkerPool<E>, ExternalResourceReleasable {
|
||||
|
||||
private final AbstractNioWorker[] workers;
|
||||
private final AtomicInteger workerIndex = new AtomicInteger();
|
||||
@ -39,7 +39,8 @@ public abstract class AbstractNioWorkerPool<E extends AbstractNioWorker> impleme
|
||||
* 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 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
|
||||
*/
|
||||
AbstractNioWorkerPool(Executor workerExecutor, int workerCount, boolean allowShutDownOnIdle) {
|
||||
@ -65,7 +66,8 @@ public abstract class AbstractNioWorkerPool<E extends AbstractNioWorker> impleme
|
||||
*
|
||||
*
|
||||
* @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
|
||||
* @param allowShutdownOnIdle allow the {@link Worker} to shutdown when there is not
|
||||
* {@link Channel} is registered with it
|
||||
* @return worker the new {@link Worker}
|
||||
*/
|
||||
protected abstract E createWorker(Executor executor, boolean allowShutdownOnIdle);
|
||||
|
@ -88,7 +88,8 @@ 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)}
|
||||
*/
|
||||
|
@ -130,7 +130,8 @@ public final class NioDatagramChannel extends AbstractNioChannel<DatagramChannel
|
||||
|
||||
public ChannelFuture joinGroup(InetAddress multicastAddress) {
|
||||
try {
|
||||
return joinGroup(multicastAddress, NetworkInterface.getByInetAddress(getLocalAddress().getAddress()), null);
|
||||
return joinGroup(
|
||||
multicastAddress, NetworkInterface.getByInetAddress(getLocalAddress().getAddress()), null);
|
||||
} catch (SocketException e) {
|
||||
return Channels.failedFuture(this, e);
|
||||
}
|
||||
@ -144,7 +145,8 @@ public final class NioDatagramChannel extends AbstractNioChannel<DatagramChannel
|
||||
/**
|
||||
* Joins the specified multicast group at the specified interface using the specified source.
|
||||
*/
|
||||
public ChannelFuture joinGroup(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source) {
|
||||
public ChannelFuture joinGroup(
|
||||
InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source) {
|
||||
if (DetectionUtil.javaVersion() < 7) {
|
||||
throw new UnsupportedOperationException();
|
||||
} else {
|
||||
@ -185,7 +187,8 @@ public final class NioDatagramChannel extends AbstractNioChannel<DatagramChannel
|
||||
|
||||
public ChannelFuture leaveGroup(InetAddress multicastAddress) {
|
||||
try {
|
||||
return leaveGroup(multicastAddress, NetworkInterface.getByInetAddress(getLocalAddress().getAddress()), null);
|
||||
return leaveGroup(
|
||||
multicastAddress, NetworkInterface.getByInetAddress(getLocalAddress().getAddress()), null);
|
||||
} catch (SocketException e) {
|
||||
return Channels.failedFuture(this, e);
|
||||
}
|
||||
@ -222,7 +225,8 @@ public final class NioDatagramChannel extends AbstractNioChannel<DatagramChannel
|
||||
while (keyIt.hasNext()) {
|
||||
MembershipKey key = keyIt.next();
|
||||
if (networkInterface.equals(key.networkInterface())) {
|
||||
if (source == null && key.sourceAddress() == null || source != null && source.equals(key.sourceAddress())) {
|
||||
if (source == null && key.sourceAddress() == null ||
|
||||
source != null && source.equals(key.sourceAddress())) {
|
||||
key.drop();
|
||||
keyIt.remove();
|
||||
}
|
||||
|
@ -144,7 +144,8 @@ public class NioDatagramChannelFactory implements DatagramChannelFactory {
|
||||
* Use {@link #NioDatagramChannelFactory(WorkerPool, InternetProtocolFamily)} if unsure.
|
||||
*
|
||||
* @param workerPool
|
||||
* the {@link WorkerPool} which will be used to obtain the {@link NioDatagramWorker} that execute the I/O worker threads
|
||||
* the {@link WorkerPool} which will be used to obtain the {@link NioDatagramWorker} that execute
|
||||
* the I/O worker threads
|
||||
*/
|
||||
public NioDatagramChannelFactory(WorkerPool<NioDatagramWorker> workerPool) {
|
||||
this(workerPool, null);
|
||||
@ -186,7 +187,8 @@ public class NioDatagramChannelFactory implements DatagramChannelFactory {
|
||||
* Creates a new instance.
|
||||
*
|
||||
* @param workerPool
|
||||
* the {@link WorkerPool} which will be used to obtain the {@link Worker} that execute the I/O worker threads
|
||||
* the {@link WorkerPool} which will be used to obtain the {@link Worker} that execute
|
||||
* the I/O worker threads
|
||||
* @param family
|
||||
* the {@link InternetProtocolFamily} to use. This should be used for UDP multicast.
|
||||
* <strong>Be aware that this option is only considered when running on java7+</strong>
|
||||
|
@ -38,8 +38,9 @@ class NioDatagramPipelineSink extends AbstractNioChannelSink {
|
||||
private final WorkerPool<NioDatagramWorker> workerPool;
|
||||
|
||||
/**
|
||||
* Creates a new {@link NioDatagramPipelineSink} with a the number of {@link NioDatagramWorker}s specified in workerCount.
|
||||
* The {@link NioDatagramWorker}s take care of reading and writing for the {@link NioDatagramChannel}.
|
||||
* Creates a new {@link NioDatagramPipelineSink} with a the number of {@link NioDatagramWorker}s
|
||||
* specified in workerCount. The {@link NioDatagramWorker}s take care of reading and writing
|
||||
* for the {@link NioDatagramChannel}.
|
||||
*
|
||||
* @param workerExecutor
|
||||
* the {@link Executor} that will run the {@link NioDatagramWorker}s
|
||||
|
@ -90,7 +90,8 @@ 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)}
|
||||
*/
|
||||
@ -136,7 +137,8 @@ public class NioServerSocketChannelFactory implements ServerSocketChannelFactory
|
||||
* @param bossExecutor
|
||||
* the {@link Executor} which will execute the boss threads
|
||||
* @param workerPool
|
||||
* the {@link WorkerPool} which will be used to obtain the {@link NioWorker} that execute the I/O worker threads
|
||||
* the {@link WorkerPool} which will be used to obtain the {@link NioWorker} that execute
|
||||
* the I/O worker threads
|
||||
*/
|
||||
public NioServerSocketChannelFactory(
|
||||
Executor bossExecutor, WorkerPool<NioWorker> workerPool) {
|
||||
|
@ -42,9 +42,11 @@ import org.jboss.netty.channel.socket.SocketChannelConfig;
|
||||
* </tr><tr>
|
||||
* <td>{@code "writeSpinCount"}</td><td>{@link #setWriteSpinCount(int)}</td>
|
||||
* </tr><tr>
|
||||
* <td>{@code "receiveBufferSizePredictor"}</td><td>{@link #setReceiveBufferSizePredictor(ReceiveBufferSizePredictor)}</td>
|
||||
* <td>{@code "receiveBufferSizePredictor"}</td>
|
||||
* <td>{@link #setReceiveBufferSizePredictor(ReceiveBufferSizePredictor)}</td>
|
||||
* </tr><tr>
|
||||
* <td>{@code "receiveBufferSizePredictorFactory"}</td><td>{@link #setReceiveBufferSizePredictorFactory(ReceiveBufferSizePredictorFactory)}</td>
|
||||
* <td>{@code "receiveBufferSizePredictorFactory"}</td>
|
||||
* <td>{@link #setReceiveBufferSizePredictorFactory(ReceiveBufferSizePredictorFactory)}</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*/
|
||||
|
@ -19,8 +19,9 @@ import org.jboss.netty.channel.socket.Worker;
|
||||
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.
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
@ -27,7 +27,6 @@ import org.jboss.netty.buffer.ChannelBuffer;
|
||||
import org.jboss.netty.buffer.CompositeChannelBuffer;
|
||||
import org.jboss.netty.channel.DefaultFileRegion;
|
||||
import org.jboss.netty.channel.FileRegion;
|
||||
import org.jboss.netty.util.internal.DetectionUtil;
|
||||
|
||||
final class SocketSendBufferPool {
|
||||
|
||||
@ -368,7 +367,8 @@ final class SocketSendBufferPool {
|
||||
public void release() {
|
||||
if (file instanceof DefaultFileRegion) {
|
||||
if (((DefaultFileRegion) file).releaseAfterTransfer()) {
|
||||
// Make sure the FileRegion resource are released otherwise it may cause a FD leak or something similar
|
||||
// Make sure the FileRegion resource are released otherwise it may cause a FD
|
||||
// leak or something similar
|
||||
file.releaseExternalResources();
|
||||
}
|
||||
}
|
||||
|
@ -134,10 +134,12 @@ abstract class AbstractOioWorker<C extends AbstractOioChannel> implements Worker
|
||||
|
||||
|
||||
/**
|
||||
* Process the incoming messages and also is responsible for call {@link Channels#fireMessageReceived(Channel, Object)} once a message
|
||||
* was processed without errors.
|
||||
* Process the incoming messages and also is responsible for call
|
||||
* {@link Channels#fireMessageReceived(Channel, Object)} once a message was processed without
|
||||
* errors.
|
||||
*
|
||||
* @return continue returns <code>true</code> as long as this worker should continue to try processing incoming messages
|
||||
* @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;
|
||||
|
@ -91,7 +91,8 @@ public class OioServerSocketChannelFactory implements ServerSocketChannelFactory
|
||||
private final ChannelSink sink;
|
||||
|
||||
/**
|
||||
* Create a new {@link OioServerSocketChannelFactory} with a {@link Executors#newCachedThreadPool()} for the boss and worker executor.
|
||||
* Create a new {@link OioServerSocketChannelFactory} with a {@link Executors#newCachedThreadPool()}
|
||||
* for the boss and worker executor.
|
||||
*
|
||||
* See {@link #OioServerSocketChannelFactory(Executor, Executor)}
|
||||
*/
|
||||
|
@ -94,8 +94,8 @@ 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
|
||||
// we did the best to emulate it
|
||||
// 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 {
|
||||
|
@ -138,7 +138,8 @@ public class HttpStaticFileServerHandler extends SimpleChannelUpstreamHandler {
|
||||
SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US);
|
||||
Date ifModifiedSinceDate = dateFormatter.parse(ifModifiedSince);
|
||||
|
||||
// Only compare up to the second because the datetime format we send to the client does not have milliseconds
|
||||
// Only compare up to the second because the datetime format we send to the client does
|
||||
// not have milliseconds
|
||||
long ifModifiedSinceDateSeconds = ifModifiedSinceDate.getTime() / 1000;
|
||||
long fileLastModifiedSeconds = file.lastModified() / 1000;
|
||||
if (ifModifiedSinceDateSeconds == fileLastModifiedSeconds) {
|
||||
@ -297,7 +298,8 @@ public class HttpStaticFileServerHandler extends SimpleChannelUpstreamHandler {
|
||||
time.add(Calendar.SECOND, HTTP_CACHE_SECONDS);
|
||||
response.setHeader(HttpHeaders.Names.EXPIRES, dateFormatter.format(time.getTime()));
|
||||
response.setHeader(HttpHeaders.Names.CACHE_CONTROL, "private, max-age=" + HTTP_CACHE_SECONDS);
|
||||
response.setHeader(HttpHeaders.Names.LAST_MODIFIED, dateFormatter.format(new Date(fileToCache.lastModified())));
|
||||
response.setHeader(
|
||||
HttpHeaders.Names.LAST_MODIFIED, dateFormatter.format(new Date(fileToCache.lastModified())));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -132,7 +132,8 @@ public class HttpSnoopServerHandler extends SimpleChannelUpstreamHandler {
|
||||
if (keepAlive) {
|
||||
// Add 'Content-Length' header only for a keep-alive connection.
|
||||
response.setHeader(CONTENT_LENGTH, response.getContent().readableBytes());
|
||||
// Add keep alive header as per http://www.w3.org/Protocols/HTTP/1.1/draft-ietf-http-v11-spec-01.html#Connection
|
||||
// Add keep alive header as per:
|
||||
// - http://www.w3.org/Protocols/HTTP/1.1/draft-ietf-http-v11-spec-01.html#Connection
|
||||
response.setHeader(CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
|
||||
}
|
||||
|
||||
|
@ -430,7 +430,8 @@ public class HttpUploadServerHandler extends SimpleChannelUpstreamHandler {
|
||||
responseContent
|
||||
.append("<tr><td>Fill with value: <br> <textarea name=\"thirdinfo\" cols=40 rows=10></textarea>");
|
||||
responseContent
|
||||
.append("<tr><td>Fill with file (only file name will be transmitted): <br> <input type=file name=\"myfile\">");
|
||||
.append("<tr><td>Fill with file (only file name will be transmitted): <br> " +
|
||||
"<input type=file name=\"myfile\">");
|
||||
responseContent.append("</td></tr>");
|
||||
responseContent
|
||||
.append("<tr><td><INPUT TYPE=\"submit\" NAME=\"Send\" VALUE=\"Send\"></INPUT></td>");
|
||||
|
@ -27,67 +27,50 @@ public final class WebSocketServerIndexPage {
|
||||
private static final String NEWLINE = "\r\n";
|
||||
|
||||
public static ChannelBuffer getContent(String webSocketLocation) {
|
||||
return ChannelBuffers
|
||||
.copiedBuffer(
|
||||
"<html><head><title>Web Socket Test</title></head>"
|
||||
+ NEWLINE
|
||||
+ "<body>"
|
||||
+ NEWLINE
|
||||
+ "<script type=\"text/javascript\">"
|
||||
+ NEWLINE
|
||||
+ "var socket;"
|
||||
+ NEWLINE
|
||||
+ "if (!window.WebSocket) {"
|
||||
+ NEWLINE
|
||||
+ " window.WebSocket = window.MozWebSocket;"
|
||||
+ NEWLINE
|
||||
+ "}"
|
||||
+ NEWLINE
|
||||
+ "if (window.WebSocket) {"
|
||||
+ NEWLINE
|
||||
+ " socket = new WebSocket(\""
|
||||
+ webSocketLocation
|
||||
+ "\");"
|
||||
+ NEWLINE
|
||||
+ " socket.onmessage = function(event) { var ta = document.getElementById('responseText'); ta.value = ta.value + '\\n' + event.data };"
|
||||
+ NEWLINE
|
||||
+ " socket.onopen = function(event) { var ta = document.getElementById('responseText'); ta.value = \"Web Socket opened!\"; };"
|
||||
+ NEWLINE
|
||||
+ " socket.onclose = function(event) { var ta = document.getElementById('responseText'); ta.value = ta.value + \"Web Socket closed\"; };"
|
||||
+ NEWLINE
|
||||
+ "} else {"
|
||||
+ NEWLINE
|
||||
+ " alert(\"Your browser does not support Web Socket.\");"
|
||||
+ NEWLINE
|
||||
+ "}"
|
||||
+ NEWLINE
|
||||
+ NEWLINE
|
||||
+ "function send(message) {"
|
||||
+ NEWLINE
|
||||
+ " if (!window.WebSocket) { return; }"
|
||||
+ NEWLINE
|
||||
+ " if (socket.readyState == WebSocket.OPEN) {"
|
||||
+ NEWLINE
|
||||
+ " socket.send(message);"
|
||||
+ NEWLINE
|
||||
+ " } else {"
|
||||
+ NEWLINE
|
||||
+ " alert(\"The socket is not open.\");"
|
||||
+ NEWLINE
|
||||
+ " }"
|
||||
+ NEWLINE
|
||||
+ "}"
|
||||
+ NEWLINE
|
||||
+ "</script>"
|
||||
+ NEWLINE
|
||||
+ "<form onsubmit=\"return false;\">"
|
||||
+ NEWLINE
|
||||
+ "<input type=\"text\" name=\"message\" value=\"Hello, World!\"/>"
|
||||
+ "<input type=\"button\" value=\"Send Web Socket Data\" onclick=\"send(this.form.message.value)\" />"
|
||||
+ NEWLINE + "<h3>Output</h3>" + NEWLINE
|
||||
+ "<textarea id=\"responseText\" style=\"width: 500px; height:300px;\"></textarea>"
|
||||
+ NEWLINE + "</form>" + NEWLINE + "</body>" + NEWLINE + "</html>" + NEWLINE,
|
||||
CharsetUtil.US_ASCII);
|
||||
return ChannelBuffers.copiedBuffer(
|
||||
"<html><head><title>Web Socket Test</title></head>" + NEWLINE +
|
||||
"<body>" + NEWLINE +
|
||||
"<script type=\"text/javascript\">" + NEWLINE +
|
||||
"var socket;" + NEWLINE +
|
||||
"if (!window.WebSocket) {" + NEWLINE +
|
||||
" window.WebSocket = window.MozWebSocket;" + NEWLINE +
|
||||
"}" + NEWLINE +
|
||||
"if (window.WebSocket) {" + NEWLINE +
|
||||
" socket = new WebSocket(\"" + webSocketLocation + "\");" + NEWLINE +
|
||||
" socket.onmessage = function(event) {" + NEWLINE +
|
||||
" var ta = document.getElementById('responseText');" + NEWLINE +
|
||||
" ta.value = ta.value + '\\n' + event.data" + NEWLINE +
|
||||
" };" + NEWLINE +
|
||||
" socket.onopen = function(event) {" + NEWLINE +
|
||||
" var ta = document.getElementById('responseText');" + NEWLINE +
|
||||
" ta.value = \"Web Socket opened!\";" + NEWLINE +
|
||||
" };" + NEWLINE +
|
||||
" socket.onclose = function(event) {" + NEWLINE +
|
||||
" var ta = document.getElementById('responseText');" + NEWLINE +
|
||||
" ta.value = ta.value + \"Web Socket closed\"; " + NEWLINE +
|
||||
" };" + NEWLINE +
|
||||
"} else {" + NEWLINE +
|
||||
" alert(\"Your browser does not support Web Socket.\");" + NEWLINE +
|
||||
"}" + NEWLINE +
|
||||
NEWLINE +
|
||||
"function send(message) {" + NEWLINE +
|
||||
" if (!window.WebSocket) { return; }" + NEWLINE +
|
||||
" if (socket.readyState == WebSocket.OPEN) {" + NEWLINE +
|
||||
" socket.send(message);" + NEWLINE +
|
||||
" } else {" + NEWLINE +
|
||||
" alert(\"The socket is not open.\");" + NEWLINE +
|
||||
" }" + NEWLINE +
|
||||
"}" + NEWLINE +
|
||||
"</script>" + NEWLINE +
|
||||
"<form onsubmit=\"return false;\">" + NEWLINE +
|
||||
"<input type=\"text\" name=\"message\" value=\"Hello, World!\"/>" +
|
||||
"<input type=\"button\" value=\"Send Web Socket Data\"" + NEWLINE +
|
||||
" onclick=\"send(this.form.message.value)\" />" + NEWLINE +
|
||||
"<h3>Output</h3>" + NEWLINE +
|
||||
"<textarea id=\"responseText\" style=\"width:500px;height:300px;\"></textarea>" + NEWLINE +
|
||||
"</form>" + NEWLINE +
|
||||
"</body>" + NEWLINE +
|
||||
"</html>" + NEWLINE, CharsetUtil.US_ASCII);
|
||||
}
|
||||
|
||||
private WebSocketServerIndexPage() {
|
||||
|
@ -29,6 +29,7 @@ import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
import org.jboss.netty.channel.ExceptionEvent;
|
||||
import org.jboss.netty.channel.MessageEvent;
|
||||
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
|
||||
import org.jboss.netty.example.http.websocketx.server.WebSocketServerIndexPage;
|
||||
import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
|
||||
import org.jboss.netty.handler.codec.http.HttpHeaders;
|
||||
import org.jboss.netty.handler.codec.http.HttpRequest;
|
||||
@ -75,7 +76,7 @@ public class WebSocketSslServerHandler extends SimpleChannelUpstreamHandler {
|
||||
if (req.getUri().equals("/")) {
|
||||
HttpResponse res = new DefaultHttpResponse(HTTP_1_1, OK);
|
||||
|
||||
ChannelBuffer content = WebSocketSslServerIndexPage.getContent(getWebSocketLocation(req));
|
||||
ChannelBuffer content = WebSocketServerIndexPage.getContent(getWebSocketLocation(req));
|
||||
|
||||
res.setHeader(CONTENT_TYPE, "text/html; charset=UTF-8");
|
||||
setContentLength(res, content.readableBytes());
|
||||
|
@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 The Netty Project
|
||||
*
|
||||
* The Netty Project licenses this file to you under the Apache License,
|
||||
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jboss.netty.example.http.websocketx.sslserver;
|
||||
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
import org.jboss.netty.buffer.ChannelBuffers;
|
||||
import org.jboss.netty.util.CharsetUtil;
|
||||
|
||||
/**
|
||||
* Generates the demo HTML page which is served at http://localhost:8080/
|
||||
*/
|
||||
public final class WebSocketSslServerIndexPage {
|
||||
|
||||
private static final String NEWLINE = "\r\n";
|
||||
|
||||
public static ChannelBuffer getContent(String webSocketLocation) {
|
||||
return ChannelBuffers
|
||||
.copiedBuffer(
|
||||
"<html><head><title>Web Socket Test</title></head>"
|
||||
+ NEWLINE
|
||||
+ "<body>"
|
||||
+ NEWLINE
|
||||
+ "<script type=\"text/javascript\">"
|
||||
+ NEWLINE
|
||||
+ "var socket;"
|
||||
+ NEWLINE
|
||||
+ "if (!window.WebSocket) {"
|
||||
+ NEWLINE
|
||||
+ " window.WebSocket = window.MozWebSocket;"
|
||||
+ NEWLINE
|
||||
+ "}"
|
||||
+ NEWLINE
|
||||
+ "if (window.WebSocket) {"
|
||||
+ NEWLINE
|
||||
+ " socket = new WebSocket(\""
|
||||
+ webSocketLocation
|
||||
+ "\");"
|
||||
+ NEWLINE
|
||||
+ " socket.onmessage = function(event) { var ta = document.getElementById('responseText'); ta.value = ta.value + '\\n' + event.data };"
|
||||
+ NEWLINE
|
||||
+ " socket.onopen = function(event) { var ta = document.getElementById('responseText'); ta.value = \"Web Socket opened!\"; };"
|
||||
+ NEWLINE
|
||||
+ " socket.onclose = function(event) { var ta = document.getElementById('responseText'); ta.value = ta.value + \"Web Socket closed\"; };"
|
||||
+ NEWLINE
|
||||
+ "} else {"
|
||||
+ NEWLINE
|
||||
+ " alert(\"Your browser does not support Web Socket.\");"
|
||||
+ NEWLINE
|
||||
+ "}"
|
||||
+ NEWLINE
|
||||
+ NEWLINE
|
||||
+ "function send(message) {"
|
||||
+ NEWLINE
|
||||
+ " if (!window.WebSocket) { return; }"
|
||||
+ NEWLINE
|
||||
+ " if (socket.readyState == WebSocket.OPEN) {"
|
||||
+ NEWLINE
|
||||
+ " socket.send(message);"
|
||||
+ NEWLINE
|
||||
+ " } else {"
|
||||
+ NEWLINE
|
||||
+ " alert(\"The socket is not open.\");"
|
||||
+ NEWLINE
|
||||
+ " }"
|
||||
+ NEWLINE
|
||||
+ "}"
|
||||
+ NEWLINE
|
||||
+ "</script>"
|
||||
+ NEWLINE
|
||||
+ "<form onsubmit=\"return false;\">"
|
||||
+ NEWLINE
|
||||
+ "<input type=\"text\" name=\"message\" value=\"Hello, World!\"/>"
|
||||
+ "<input type=\"button\" value=\"Send Web Socket Data\" onclick=\"send(this.form.message.value)\" />"
|
||||
+ NEWLINE + "<h3>Output</h3>" + NEWLINE
|
||||
+ "<textarea id=\"responseText\" style=\"width: 500px; height:300px;\"></textarea>"
|
||||
+ NEWLINE + "</form>" + NEWLINE + "</body>" + NEWLINE + "</html>" + NEWLINE,
|
||||
CharsetUtil.US_ASCII);
|
||||
}
|
||||
|
||||
private WebSocketSslServerIndexPage() {
|
||||
// Unused
|
||||
}
|
||||
}
|
@ -34,7 +34,7 @@ import org.jboss.netty.util.CharsetUtil;
|
||||
* A UDP broadcast client that asks for a quote of the moment (QOTM) to
|
||||
* {@link QuoteOfTheMomentServer}.
|
||||
*
|
||||
* Inspired by <a href="http://java.sun.com/docs/books/tutorial/networking/datagrams/clientServer.html">the official Java tutorial</a>.
|
||||
* Inspired by <a href="http://goo.gl/BsXVR">the official Java tutorial</a>.
|
||||
*/
|
||||
public class QuoteOfTheMomentClient {
|
||||
|
||||
|
@ -32,7 +32,7 @@ import org.jboss.netty.util.CharsetUtil;
|
||||
* A UDP server that responds to the QOTM (quote of the moment) request to a
|
||||
* {@link QuoteOfTheMomentClient}.
|
||||
*
|
||||
* Inspired by <a href="http://java.sun.com/docs/books/tutorial/networking/datagrams/clientServer.html">the official Java tutorial</a>.
|
||||
* Inspired by <a href="http://goo.gl/BsXVR">the official Java tutorial</a>.
|
||||
*/
|
||||
public class QuoteOfTheMomentServer {
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
package org.jboss.netty.example.securechat;
|
||||
|
||||
import java.security.KeyStore;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.Security;
|
||||
|
||||
import javax.net.ssl.KeyManager;
|
||||
@ -42,10 +43,10 @@ import org.jboss.netty.handler.ssl.SslHandler;
|
||||
* {@link SslHandler}.</li>
|
||||
* <li>When initializing an {@link SSLContext} on the client side,
|
||||
* specify the {@link KeyManager} that contains the client certificate as
|
||||
* the first argument of {@link SSLContext#init(KeyManager[], javax.net.ssl.TrustManager[], java.security.SecureRandom)}.</li>
|
||||
* the first argument of {@link SSLContext#init(KeyManager[], TrustManager[], SecureRandom)}.</li>
|
||||
* <li>When initializing an {@link SSLContext} on the server side,
|
||||
* specify the proper {@link TrustManager} as the second argument of
|
||||
* {@link SSLContext#init(KeyManager[], javax.net.ssl.TrustManager[], java.security.SecureRandom)}
|
||||
* {@link SSLContext#init(KeyManager[], TrustManager[], SecureRandom)}
|
||||
* to validate the client certificate.</li>
|
||||
* </ul>
|
||||
*/
|
||||
|
@ -28,7 +28,9 @@ import org.jboss.netty.buffer.HeapChannelBufferFactory;
|
||||
* <a href="http://en.wikipedia.org/wiki/Base64">Base64</a> notation.
|
||||
* <p>
|
||||
* The encoding and decoding algorithm in this class has been derived from
|
||||
* <a href="http://iharder.sourceforge.net/current/java/base64/">Robert Harder's Public Domain Base64 Encoder/Decoder</a>.
|
||||
* <a href="http://iharder.sourceforge.net/current/java/base64/">Robert Harder's Public Domain
|
||||
* Base64 Encoder/Decoder</a>.
|
||||
*
|
||||
* @apiviz.landmark
|
||||
* @apiviz.uses org.jboss.netty.handler.codec.base64.Base64Dialect
|
||||
*/
|
||||
@ -125,7 +127,8 @@ public final class Base64 {
|
||||
return encode(src, off, len, Base64Dialect.STANDARD, bufferFactory);
|
||||
}
|
||||
|
||||
public static ChannelBuffer encode(ChannelBuffer src, int off, int len, Base64Dialect dialect, ChannelBufferFactory bufferFactory) {
|
||||
public static ChannelBuffer encode(
|
||||
ChannelBuffer src, int off, int len, Base64Dialect dialect, ChannelBufferFactory bufferFactory) {
|
||||
return encode(src, off, len, breakLines(dialect), dialect, bufferFactory);
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,8 @@ package org.jboss.netty.handler.codec.base64;
|
||||
* Enumeration of supported Base64 dialects.
|
||||
* <p>
|
||||
* The internal lookup tables in this class has been derived from
|
||||
* <a href="http://iharder.sourceforge.net/current/java/base64/">Robert Harder's Public Domain Base64 Encoder/Decoder</a>.
|
||||
* <a href="http://iharder.sourceforge.net/current/java/base64/">Robert Harder's Public Domain
|
||||
* Base64 Encoder/Decoder</a>.
|
||||
*/
|
||||
public enum Base64Dialect {
|
||||
/**
|
||||
|
@ -25,7 +25,8 @@ import org.jboss.netty.channel.DefaultChannelConfig;
|
||||
|
||||
/**
|
||||
* TODO Make EmbeddedChannel implement ChannelConfig and ChannelSink to reduce overhead.
|
||||
* TODO Do not extend AbstractChannel to reduce overhead and remove the internal-use-only constructor in AbstractChannel.
|
||||
* TODO Do not extend AbstractChannel to reduce overhead and remove the internal-use-only
|
||||
* constructor in AbstractChannel.
|
||||
*/
|
||||
class EmbeddedChannel extends AbstractChannel {
|
||||
|
||||
|
@ -34,7 +34,7 @@ import org.jboss.netty.util.CharsetUtil;
|
||||
* <pre>
|
||||
* String data = "foobar";
|
||||
*
|
||||
* {@link EncoderEmbedder}<{@link ChannelBuffer}> embedder = new {@link EncoderEmbedder}<{@link ChannelBuffer}>(
|
||||
* {@link EncoderEmbedder}<{@link ChannelBuffer}> embedder = new {@link EncoderEmbedder}<>(
|
||||
* new {@link Base64Encoder}(), new {@link StringEncoder}());
|
||||
*
|
||||
* embedder.offer(data);
|
||||
|
@ -51,8 +51,11 @@ public class FixedLengthFrameDecoder extends FrameDecoder {
|
||||
/**
|
||||
* 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
|
||||
* @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) {
|
||||
if (frameLength <= 0) {
|
||||
|
@ -214,7 +214,8 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler implemen
|
||||
callDecode(ctx, e.getChannel(), input, e.getRemoteAddress());
|
||||
} finally {
|
||||
if (input.readable()) {
|
||||
// seems like there is something readable left in the input buffer. So create the cumulation buffer and copy the input into it
|
||||
// seems like there is something readable left in the input buffer. So create
|
||||
// the cumulation buffer and copy the input into it
|
||||
(cumulation = newCumulationBuffer(ctx, input.readableBytes())).writeBytes(input);
|
||||
}
|
||||
}
|
||||
@ -350,7 +351,8 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler implemen
|
||||
}
|
||||
}
|
||||
|
||||
protected final void unfoldAndFireMessageReceived(ChannelHandlerContext context, SocketAddress remoteAddress, Object result) {
|
||||
protected final void unfoldAndFireMessageReceived(
|
||||
ChannelHandlerContext context, SocketAddress remoteAddress, Object result) {
|
||||
if (unfold) {
|
||||
if (result instanceof Object[]) {
|
||||
for (Object r: (Object[]) result) {
|
||||
@ -369,8 +371,8 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler implemen
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets called on {@link #channelDisconnected(ChannelHandlerContext, ChannelStateEvent)} and {@link #channelClosed(ChannelHandlerContext, ChannelStateEvent)}
|
||||
*
|
||||
* Gets called on {@link #channelDisconnected(ChannelHandlerContext, ChannelStateEvent)} and
|
||||
* {@link #channelClosed(ChannelHandlerContext, ChannelStateEvent)}
|
||||
*/
|
||||
protected void cleanup(ChannelHandlerContext ctx, ChannelStateEvent e)
|
||||
throws Exception {
|
||||
@ -420,7 +422,8 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler implemen
|
||||
*/
|
||||
public void replace(String handlerName, ChannelHandler handler) {
|
||||
if (ctx == null) {
|
||||
throw new IllegalStateException("Replace cann only be called once the FrameDecoder is added to the ChannelPipeline");
|
||||
throw new IllegalStateException(
|
||||
"Replace cann only be called once the FrameDecoder is added to the ChannelPipeline");
|
||||
}
|
||||
ChannelPipeline pipeline = ctx.getPipeline();
|
||||
pipeline.addAfter(ctx.getName(), handlerName, handler);
|
||||
|
@ -41,8 +41,8 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public class CookieDecoder {
|
||||
|
||||
private static final Pattern PATTERN =
|
||||
Pattern.compile("(?:\\s|[;,])*\\$*([^;=]+)(?:=(?:[\"']((?:\\\\.|[^\"])*)[\"']|([^;,]*)))?(\\s*(?:[;,]+\\s*|$))");
|
||||
private static final Pattern PATTERN = Pattern.compile(
|
||||
"(?:\\s|[;,])*\\$*([^;=]+)(?:=(?:[\"']((?:\\\\.|[^\"])*)[\"']|([^;,]*)))?(\\s*(?:[;,]+\\s*|$))");
|
||||
|
||||
private static final String COMMA = ",";
|
||||
|
||||
|
@ -219,7 +219,8 @@ public class HttpClientCodec implements ChannelUpstreamHandler,
|
||||
if (failOnMissingResponse) {
|
||||
long missingResponses = requestResponseCounter.get();
|
||||
if (missingResponses > 0) {
|
||||
throw new PrematureChannelClosureException("Channel closed but still missing " + missingResponses + " response(s)");
|
||||
throw new PrematureChannelClosureException(
|
||||
"Channel closed but still missing " + missingResponses + " response(s)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -150,7 +150,8 @@ public abstract class HttpContentEncoder extends SimpleChannelHandler {
|
||||
// the last product on closure,
|
||||
if (lastProduct.readable()) {
|
||||
Channels.write(
|
||||
ctx, Channels.succeededFuture(e.getChannel()), new DefaultHttpChunk(lastProduct), e.getRemoteAddress());
|
||||
ctx, Channels.succeededFuture(e.getChannel()),
|
||||
new DefaultHttpChunk(lastProduct), e.getRemoteAddress());
|
||||
}
|
||||
|
||||
// Emit the last chunk.
|
||||
|
@ -167,7 +167,8 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<HttpMessageDec
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer, State state) throws Exception {
|
||||
protected Object decode(
|
||||
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer, State state) throws Exception {
|
||||
switch (state) {
|
||||
case SKIP_CONTROL_CHARS: {
|
||||
try {
|
||||
@ -270,7 +271,7 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<HttpMessageDec
|
||||
return readFixedLengthContent(buffer);
|
||||
}
|
||||
case READ_FIXED_LENGTH_CONTENT_AS_CHUNKS: {
|
||||
assert this.chunkSize <= Integer.MAX_VALUE;
|
||||
assert chunkSize <= Integer.MAX_VALUE;
|
||||
int chunkSize = (int) this.chunkSize;
|
||||
int readLimit = actualReadableBytes();
|
||||
int toRead = chunkSize;
|
||||
@ -323,7 +324,7 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<HttpMessageDec
|
||||
return chunk;
|
||||
}
|
||||
case READ_CHUNKED_CONTENT_AS_CHUNKS: {
|
||||
assert this.chunkSize <= Integer.MAX_VALUE;
|
||||
assert chunkSize <= Integer.MAX_VALUE;
|
||||
int chunkSize = (int) this.chunkSize;
|
||||
int readLimit = actualReadableBytes();
|
||||
int toRead = chunkSize;
|
||||
|
@ -26,28 +26,32 @@ import java.util.Map;
|
||||
*/
|
||||
public class HttpMethod implements Comparable<HttpMethod> {
|
||||
/**
|
||||
* The OPTIONS method represents a request for information about the communication options available on the request/response
|
||||
* chain identified by the Request-URI. This method allows the client to determine the options and/or requirements
|
||||
* associated with a resource, or the capabilities of a server, without implying a resource action or initiating a
|
||||
* resource retrieval.
|
||||
* The OPTIONS method represents a request for information about the communication options
|
||||
* available on the request/response chain identified by the Request-URI. This method allows
|
||||
* the client to determine the options and/or requirements associated with a resource, or the
|
||||
* capabilities of a server, without implying a resource action or initiating a resource
|
||||
* retrieval.
|
||||
*/
|
||||
public static final HttpMethod OPTIONS = new HttpMethod("OPTIONS");
|
||||
|
||||
/**
|
||||
* The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI.
|
||||
* If the Request-URI refers to a data-producing process, it is the produced data which shall be returned as the entity
|
||||
* in the response and not the source text of the process, unless that text happens to be the output of the process.
|
||||
* The GET method means retrieve whatever information (in the form of an entity) is identified
|
||||
* by the Request-URI. If the Request-URI refers to a data-producing process, it is the
|
||||
* produced data which shall be returned as the entity in the response and not the source text
|
||||
* of the process, unless that text happens to be the output of the process.
|
||||
*/
|
||||
public static final HttpMethod GET = new HttpMethod("GET");
|
||||
|
||||
/**
|
||||
* The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response.
|
||||
* The HEAD method is identical to GET except that the server MUST NOT return a message-body in
|
||||
* the response.
|
||||
*/
|
||||
public static final HttpMethod HEAD = new HttpMethod("HEAD");
|
||||
|
||||
/**
|
||||
* The POST method is used to request that the origin server accept the entity enclosed in the request as a new
|
||||
* subordinate of the resource identified by the Request-URI in the Request-Line.
|
||||
* The POST method is used to request that the origin server accept the entity enclosed in the
|
||||
* request as a new subordinate of the resource identified by the Request-URI in the
|
||||
* Request-Line.
|
||||
*/
|
||||
public static final HttpMethod POST = new HttpMethod("POST");
|
||||
|
||||
@ -63,17 +67,20 @@ public class HttpMethod implements Comparable<HttpMethod> {
|
||||
public static final HttpMethod PATCH = new HttpMethod("PATCH");
|
||||
|
||||
/**
|
||||
* The DELETE method requests that the origin server delete the resource identified by the Request-URI.
|
||||
* The DELETE method requests that the origin server delete the resource identified by the
|
||||
* Request-URI.
|
||||
*/
|
||||
public static final HttpMethod DELETE = new HttpMethod("DELETE");
|
||||
|
||||
/**
|
||||
* The TRACE method is used to invoke a remote, application-layer loop- back of the request message.
|
||||
* The TRACE method is used to invoke a remote, application-layer loop- back of the request
|
||||
* message.
|
||||
*/
|
||||
public static final HttpMethod TRACE = new HttpMethod("TRACE");
|
||||
|
||||
/**
|
||||
* This specification reserves the method name CONNECT for use with a proxy that can dynamically switch to being a tunnel
|
||||
* This specification reserves the method name CONNECT for use with a proxy that can
|
||||
* dynamically switch to being a tunnel
|
||||
*/
|
||||
public static final HttpMethod CONNECT = new HttpMethod("CONNECT");
|
||||
|
||||
|
@ -102,7 +102,9 @@ public class HttpResponseDecoder extends HttpMessageDecoder {
|
||||
|
||||
@Override
|
||||
protected HttpMessage createMessage(String[] initialLine) {
|
||||
return new DefaultHttpResponse(HttpVersion.valueOf(initialLine[0]), new HttpResponseStatus(Integer.valueOf(initialLine[1]), initialLine[2]));
|
||||
return new DefaultHttpResponse(
|
||||
HttpVersion.valueOf(initialLine[0]),
|
||||
new HttpResponseStatus(Integer.valueOf(initialLine[1]), initialLine[2]));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -56,7 +56,8 @@ public class HttpResponseStatus implements Comparable<HttpResponseStatus> {
|
||||
/**
|
||||
* 203 Non-Authoritative Information (since HTTP/1.1)
|
||||
*/
|
||||
public static final HttpResponseStatus NON_AUTHORITATIVE_INFORMATION = new HttpResponseStatus(203, "Non-Authoritative Information");
|
||||
public static final HttpResponseStatus NON_AUTHORITATIVE_INFORMATION =
|
||||
new HttpResponseStatus(203, "Non-Authoritative Information");
|
||||
|
||||
/**
|
||||
* 204 No Content
|
||||
@ -151,7 +152,8 @@ public class HttpResponseStatus implements Comparable<HttpResponseStatus> {
|
||||
/**
|
||||
* 407 Proxy Authentication Required
|
||||
*/
|
||||
public static final HttpResponseStatus PROXY_AUTHENTICATION_REQUIRED = new HttpResponseStatus(407, "Proxy Authentication Required");
|
||||
public static final HttpResponseStatus PROXY_AUTHENTICATION_REQUIRED =
|
||||
new HttpResponseStatus(407, "Proxy Authentication Required");
|
||||
|
||||
/**
|
||||
* 408 Request Timeout
|
||||
@ -181,7 +183,8 @@ public class HttpResponseStatus implements Comparable<HttpResponseStatus> {
|
||||
/**
|
||||
* 413 Request Entity Too Large
|
||||
*/
|
||||
public static final HttpResponseStatus REQUEST_ENTITY_TOO_LARGE = new HttpResponseStatus(413, "Request Entity Too Large");
|
||||
public static final HttpResponseStatus REQUEST_ENTITY_TOO_LARGE =
|
||||
new HttpResponseStatus(413, "Request Entity Too Large");
|
||||
|
||||
/**
|
||||
* 414 Request-URI Too Long
|
||||
@ -191,12 +194,14 @@ public class HttpResponseStatus implements Comparable<HttpResponseStatus> {
|
||||
/**
|
||||
* 415 Unsupported Media Type
|
||||
*/
|
||||
public static final HttpResponseStatus UNSUPPORTED_MEDIA_TYPE = new HttpResponseStatus(415, "Unsupported Media Type");
|
||||
public static final HttpResponseStatus UNSUPPORTED_MEDIA_TYPE =
|
||||
new HttpResponseStatus(415, "Unsupported Media Type");
|
||||
|
||||
/**
|
||||
* 416 Requested Range Not Satisfiable
|
||||
*/
|
||||
public static final HttpResponseStatus REQUESTED_RANGE_NOT_SATISFIABLE = new HttpResponseStatus(416, "Requested Range Not Satisfiable");
|
||||
public static final HttpResponseStatus REQUESTED_RANGE_NOT_SATISFIABLE =
|
||||
new HttpResponseStatus(416, "Requested Range Not Satisfiable");
|
||||
|
||||
/**
|
||||
* 417 Expectation Failed
|
||||
@ -231,7 +236,8 @@ public class HttpResponseStatus implements Comparable<HttpResponseStatus> {
|
||||
/**
|
||||
* 500 Internal Server Error
|
||||
*/
|
||||
public static final HttpResponseStatus INTERNAL_SERVER_ERROR = new HttpResponseStatus(500, "Internal Server Error");
|
||||
public static final HttpResponseStatus INTERNAL_SERVER_ERROR =
|
||||
new HttpResponseStatus(500, "Internal Server Error");
|
||||
|
||||
/**
|
||||
* 501 Not Implemented
|
||||
@ -256,12 +262,14 @@ public class HttpResponseStatus implements Comparable<HttpResponseStatus> {
|
||||
/**
|
||||
* 505 HTTP Version Not Supported
|
||||
*/
|
||||
public static final HttpResponseStatus HTTP_VERSION_NOT_SUPPORTED = new HttpResponseStatus(505, "HTTP Version Not Supported");
|
||||
public static final HttpResponseStatus HTTP_VERSION_NOT_SUPPORTED =
|
||||
new HttpResponseStatus(505, "HTTP Version Not Supported");
|
||||
|
||||
/**
|
||||
* 506 Variant Also Negotiates (RFC2295)
|
||||
*/
|
||||
public static final HttpResponseStatus VARIANT_ALSO_NEGOTIATES = new HttpResponseStatus(506, "Variant Also Negotiates");
|
||||
public static final HttpResponseStatus VARIANT_ALSO_NEGOTIATES =
|
||||
new HttpResponseStatus(506, "Variant Also Negotiates");
|
||||
|
||||
/**
|
||||
* 507 Insufficient Storage (WebDAV, RFC4918)
|
||||
|
@ -47,10 +47,10 @@ import org.jboss.netty.util.CharsetUtil;
|
||||
*
|
||||
* <h3>HashDOS vulnerability fix</h3>
|
||||
*
|
||||
* As a workaround to the <a href="http://events.ccc.de/congress/2011/Fahrplan/attachments/2007_28C3_Effective_DoS_on_web_application_platforms.pdf">HashDOS</a>
|
||||
* vulnerability, the decoder limits the maximum number of decoded key-value
|
||||
* parameter pairs, up to {@literal 1024} by default, and you can configure it
|
||||
* when you construct the decoder by passing an additional integer parameter.
|
||||
* As a workaround to the <a href="http://goo.gl/I4Nky">HashDOS</a> vulnerability, the decoder
|
||||
* limits the maximum number of decoded key-value parameter pairs, up to {@literal 1024} by
|
||||
* default, and you can configure it when you construct the decoder by passing an additional
|
||||
* integer parameter.
|
||||
*
|
||||
* @see QueryStringEncoder
|
||||
*
|
||||
|
@ -461,7 +461,8 @@ public class HttpPostRequestDecoder {
|
||||
} else if (read == '&') { // special empty FIELD
|
||||
currentStatus = MultiPartStatus.DISPOSITION;
|
||||
ampersandpos = currentpos - 1;
|
||||
String key = decodeAttribute(undecodedChunk.toString(firstpos, ampersandpos - firstpos, charset), charset);
|
||||
String key = decodeAttribute(
|
||||
undecodedChunk.toString(firstpos, ampersandpos - firstpos, charset), charset);
|
||||
currentAttribute = factory.createAttribute(request, key);
|
||||
currentAttribute.setValue(""); // empty
|
||||
addHttpData(currentAttribute);
|
||||
@ -587,7 +588,8 @@ public class HttpPostRequestDecoder {
|
||||
} else if (read == '&') { // special empty FIELD
|
||||
currentStatus = MultiPartStatus.DISPOSITION;
|
||||
ampersandpos = currentpos - 1;
|
||||
String key = decodeAttribute(undecodedChunk.toString(firstpos, ampersandpos - firstpos, charset), charset);
|
||||
String key = decodeAttribute(
|
||||
undecodedChunk.toString(firstpos, ampersandpos - firstpos, charset), charset);
|
||||
currentAttribute = factory.createAttribute(request, key);
|
||||
currentAttribute.setValue(""); // empty
|
||||
addHttpData(currentAttribute);
|
||||
|
@ -20,8 +20,8 @@ import org.jboss.netty.buffer.ChannelBuffers;
|
||||
import org.jboss.netty.util.CharsetUtil;
|
||||
|
||||
/**
|
||||
* Web Socket continuation frame containing continuation text or binary data. This is used for fragmented messages where
|
||||
* the contents of a messages is contained more than 1 frame.
|
||||
* Web Socket continuation frame containing continuation text or binary data. This is used for
|
||||
* fragmented messages where the contents of a messages is contained more than 1 frame.
|
||||
*/
|
||||
public class ContinuationWebSocketFrame extends WebSocketFrame {
|
||||
|
||||
@ -35,7 +35,8 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new continuation frame with the specified binary data. The final fragment flag is set to true.
|
||||
* 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.
|
||||
@ -72,7 +73,8 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
|
||||
* @param aggregatedText
|
||||
* Aggregated text set by decoder on the final continuation frame of a fragmented text message
|
||||
*/
|
||||
public ContinuationWebSocketFrame(boolean finalFragment, int rsv, ChannelBuffer binaryData, String aggregatedText) {
|
||||
public ContinuationWebSocketFrame(
|
||||
boolean finalFragment, int rsv, ChannelBuffer binaryData, String aggregatedText) {
|
||||
setFinalFragment(finalFragment);
|
||||
setRsv(rsv);
|
||||
setBinaryData(binaryData);
|
||||
|
@ -18,19 +18,20 @@
|
||||
*
|
||||
* 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
|
||||
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
* 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
|
||||
* of the Software.
|
||||
* 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
|
||||
* IN 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 IN THE SOFTWARE.
|
||||
*/
|
||||
package org.jboss.netty.handler.codec.http.websocketx;
|
||||
|
||||
|
@ -18,19 +18,20 @@
|
||||
*
|
||||
* 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
|
||||
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
* 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
|
||||
* of the Software.
|
||||
* 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
|
||||
* IN 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 IN THE SOFTWARE.
|
||||
*/
|
||||
package org.jboss.netty.handler.codec.http.websocketx;
|
||||
|
||||
@ -41,20 +42,23 @@ final class UTF8Output {
|
||||
private static final int UTF8_ACCEPT = 0;
|
||||
private static final int UTF8_REJECT = 12;
|
||||
|
||||
private static final byte[] TYPES = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 11,
|
||||
6, 6, 6, 5, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 };
|
||||
private static final byte[] TYPES = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8,
|
||||
8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 11, 6, 6, 6, 5, 8, 8, 8, 8, 8,
|
||||
8, 8, 8, 8, 8, 8 };
|
||||
|
||||
private static final byte[] STATES = { 0, 12, 24, 36, 60, 96, 84, 12, 12, 12, 48, 72, 12, 12, 12, 12, 12, 12, 12,
|
||||
12, 12, 12, 12, 12, 12, 0, 12, 12, 12, 12, 12, 0, 12, 0, 12, 12, 12, 24, 12, 12, 12, 12, 12, 24, 12, 24,
|
||||
12, 12, 12, 12, 12, 12, 12, 12, 12, 24, 12, 12, 12, 12, 12, 24, 12, 12, 12, 12, 12, 12, 12, 24, 12, 12, 12,
|
||||
12, 12, 12, 12, 12, 12, 36, 12, 36, 12, 12, 12, 36, 12, 12, 12, 12, 12, 36, 12, 36, 12, 12, 12, 36, 12, 12,
|
||||
12, 12, 12, 12, 12, 12, 12, 12 };
|
||||
private static final byte[] STATES = { 0, 12, 24, 36, 60, 96, 84, 12, 12, 12, 48, 72, 12, 12,
|
||||
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 0, 12, 12, 12, 12, 12, 0, 12, 0, 12, 12,
|
||||
12, 24, 12, 12, 12, 12, 12, 24, 12, 24, 12, 12, 12, 12, 12, 12, 12, 12, 12, 24, 12, 12,
|
||||
12, 12, 12, 24, 12, 12, 12, 12, 12, 12, 12, 24, 12, 12, 12, 12, 12, 12, 12, 12, 12, 36,
|
||||
12, 36, 12, 12, 12, 36, 12, 12, 12, 12, 12, 36, 12, 36, 12, 12, 12, 36, 12, 12, 12, 12,
|
||||
12, 12, 12, 12, 12, 12 };
|
||||
|
||||
private int state = UTF8_ACCEPT;
|
||||
private int codep;
|
||||
|
@ -27,8 +27,8 @@ 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.
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath".
|
||||
* Subsequent web socket frames will be sent to this URL.
|
||||
* @param version
|
||||
* Version of web socket specification to use to connect to the server
|
||||
* @param subprotocol
|
||||
@ -48,8 +48,8 @@ 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.
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath".
|
||||
* Subsequent web socket frames will be sent to this URL.
|
||||
* @param version
|
||||
* Version of web socket specification to use to connect to the server
|
||||
* @param subprotocol
|
||||
@ -59,20 +59,24 @@ public class WebSocketClientHandshakerFactory {
|
||||
* @param customHeaders
|
||||
* Custom HTTP headers to send during the handshake
|
||||
* @param maxFramePayloadLength
|
||||
* Maximum allowable frame payload length. Setting this value to your application's requirement may
|
||||
* reduce denial of service attacks using long data frames.
|
||||
* @throws WebSocketHandshakeException
|
||||
* Maximum allowable frame payload length. Setting this value to your application's
|
||||
* requirement may reduce denial of service attacks using long data frames.
|
||||
*/
|
||||
public WebSocketClientHandshaker newHandshaker(URI webSocketURL, WebSocketVersion version, String subprotocol,
|
||||
boolean allowExtensions, Map<String, String> customHeaders, long maxFramePayloadLength) throws WebSocketHandshakeException {
|
||||
public WebSocketClientHandshaker newHandshaker(
|
||||
URI webSocketURL, WebSocketVersion version, String subprotocol,
|
||||
boolean allowExtensions, Map<String, String> customHeaders, long maxFramePayloadLength)
|
||||
throws WebSocketHandshakeException {
|
||||
if (version == WebSocketVersion.V13) {
|
||||
return new WebSocketClientHandshaker13(webSocketURL, version, subprotocol, allowExtensions, customHeaders, maxFramePayloadLength);
|
||||
return new WebSocketClientHandshaker13(
|
||||
webSocketURL, version, subprotocol, allowExtensions, customHeaders, maxFramePayloadLength);
|
||||
}
|
||||
if (version == WebSocketVersion.V08) {
|
||||
return new WebSocketClientHandshaker08(webSocketURL, version, subprotocol, allowExtensions, customHeaders, maxFramePayloadLength);
|
||||
return new WebSocketClientHandshaker08(
|
||||
webSocketURL, version, subprotocol, allowExtensions, customHeaders, maxFramePayloadLength);
|
||||
}
|
||||
if (version == WebSocketVersion.V00) {
|
||||
return new WebSocketClientHandshaker00(webSocketURL, version, subprotocol, customHeaders, maxFramePayloadLength);
|
||||
return new WebSocketClientHandshaker00(
|
||||
webSocketURL, version, subprotocol, customHeaders, maxFramePayloadLength);
|
||||
}
|
||||
|
||||
throw new WebSocketHandshakeException("Protocol version " + version.toString() + " not supported.");
|
||||
|
@ -67,8 +67,8 @@ public class WebSocketServerHandshaker00 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
|
||||
* sent to this URL.
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath".
|
||||
* Subsequent web socket frames will be sent to this URL.
|
||||
* @param subprotocols
|
||||
* CSV of supported protocols
|
||||
* @param maxFramePayloadLength
|
||||
|
@ -52,15 +52,15 @@ 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.
|
||||
* URL for web socket communications. e.g "ws://myhost.com/mypath".
|
||||
* Subsequent web socket frames will be sent to this URL.
|
||||
* @param subprotocols
|
||||
* CSV of supported protocols. Null if sub protocols not supported.
|
||||
* @param allowExtensions
|
||||
* Allow extensions to be used in the reserved bits of the web socket frame
|
||||
* @param maxFramePayloadLength
|
||||
* Maximum allowable frame payload length. Setting this value to your application's requirement may
|
||||
* reduce denial of service attacks using long data frames.
|
||||
* 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,
|
||||
long maxFramePayloadLength) {
|
||||
@ -73,8 +73,8 @@ public class WebSocketServerHandshakerFactory {
|
||||
/**
|
||||
* Instances a new handshaker
|
||||
*
|
||||
* @return A new WebSocketServerHandshaker for the requested web socket version. Null if web socket version is not
|
||||
* supported.
|
||||
* @return A new WebSocketServerHandshaker for the requested web socket version. Null if web
|
||||
* socket version is not supported.
|
||||
*/
|
||||
public WebSocketServerHandshaker newHandshaker(HttpRequest req) {
|
||||
|
||||
@ -82,16 +82,19 @@ public class WebSocketServerHandshakerFactory {
|
||||
if (version != null) {
|
||||
if (version.equals(WebSocketVersion.V13.toHttpHeaderValue())) {
|
||||
// Version 13 of the wire protocol - RFC 6455 (version 17 of the draft hybi specification).
|
||||
return new WebSocketServerHandshaker13(webSocketURL, subprotocols, allowExtensions, maxFramePayloadLength);
|
||||
return new WebSocketServerHandshaker13(
|
||||
webSocketURL, subprotocols, allowExtensions, maxFramePayloadLength);
|
||||
} else if (version.equals(WebSocketVersion.V08.toHttpHeaderValue())) {
|
||||
// Version 8 of the wire protocol - version 10 of the draft hybi specification.
|
||||
return new WebSocketServerHandshaker08(webSocketURL, subprotocols, allowExtensions, maxFramePayloadLength);
|
||||
return new WebSocketServerHandshaker08(
|
||||
webSocketURL, subprotocols, allowExtensions, maxFramePayloadLength);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
// Assume version 00 where version header was not specified
|
||||
return new WebSocketServerHandshaker00(webSocketURL, subprotocols, maxFramePayloadLength);
|
||||
return new WebSocketServerHandshaker00(
|
||||
webSocketURL, subprotocols, maxFramePayloadLength);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,9 +21,10 @@
|
||||
* This package supports different web socket specification versions (hence the X suffix).
|
||||
* The specification current supported are:
|
||||
* <ul>
|
||||
* <li><a href="http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-00">draft-ietf-hybi-thewebsocketprotocol-00</a></li>
|
||||
* <li><a href="http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10">draft-ietf-hybi-thewebsocketprotocol-10</a></li>
|
||||
* <li><a href="http://tools.ietf.org/html/rfc6455 ">RFC 6455</a> (originally <a href="http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17">draft-ietf-hybi-thewebsocketprotocol-17</a>)</li>
|
||||
* <li><a href="http://goo.gl/wFiu3">draft-ietf-hybi-thewebsocketprotocol-00</a></li>
|
||||
* <li><a href="http://goo.gl/h27VE">draft-ietf-hybi-thewebsocketprotocol-10</a></li>
|
||||
* <li><a href="http://tools.ietf.org/html/rfc6455 ">RFC 6455</a> (originally
|
||||
* <a href="http://goo.gl/zVBkL">draft-ietf-hybi-thewebsocketprotocol-17</a>)</li>
|
||||
* </ul>
|
||||
* </p>
|
||||
* <p>
|
||||
|
@ -42,12 +42,15 @@ public class CompatibleMarshallingDecoder extends ReplayingDecoder<VoidEnum> {
|
||||
/**
|
||||
* Create a new instance of {@link CompatibleMarshallingDecoder}.
|
||||
*
|
||||
* @param provider the {@link UnmarshallerProvider} which is used to obtain the {@link Unmarshaller} for the {@link Channel}
|
||||
* @param maxObjectSize the maximal size (in bytes) of the {@link Object} to unmarshal. Once the size is exceeded
|
||||
* the {@link Channel} will get closed. Use a a maxObjectSize of {@link Integer#MAX_VALUE} to disable this.
|
||||
* You should only do this if you are sure that the received Objects will never be big and the
|
||||
* sending side are trusted, as this opens the possibility for a DOS-Attack due an {@link OutOfMemoryError}.
|
||||
*
|
||||
* @param provider
|
||||
* the {@link UnmarshallerProvider} which is used to obtain the {@link Unmarshaller}
|
||||
* for the {@link Channel}
|
||||
* @param maxObjectSize
|
||||
* the maximal size (in bytes) of the {@link Object} to unmarshal. Once the size is
|
||||
* exceeded the {@link Channel} will get closed. Use a a maxObjectSize of
|
||||
* {@link Integer#MAX_VALUE} to disable this. You should only do this if you are sure
|
||||
* that the received Objects will never be big and the sending side are trusted, as
|
||||
* this opens the possibility for a DOS-Attack due an {@link OutOfMemoryError}.
|
||||
*/
|
||||
public CompatibleMarshallingDecoder(UnmarshallerProvider provider, int maxObjectSize) {
|
||||
this.provider = provider;
|
||||
@ -55,7 +58,8 @@ public class CompatibleMarshallingDecoder extends ReplayingDecoder<VoidEnum> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer, VoidEnum state) throws Exception {
|
||||
protected Object decode(
|
||||
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer, VoidEnum state) throws Exception {
|
||||
Unmarshaller unmarshaller = provider.getUnmarshaller(ctx);
|
||||
ByteInput input = new ChannelBufferByteInput(buffer);
|
||||
if (maxObjectSize != Integer.MAX_VALUE) {
|
||||
|
@ -50,7 +50,8 @@ public class CompatibleMarshallingEncoder extends OneToOneEncoder {
|
||||
@Override
|
||||
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
|
||||
Marshaller marshaller = provider.getMarshaller(ctx);
|
||||
ChannelBufferByteOutput output = new ChannelBufferByteOutput(ctx.getChannel().getConfig().getBufferFactory(), 256);
|
||||
ChannelBufferByteOutput output =
|
||||
new ChannelBufferByteOutput(ctx.getChannel().getConfig().getBufferFactory(), 256);
|
||||
marshaller.start(output);
|
||||
marshaller.writeObject(msg);
|
||||
marshaller.finish();
|
||||
@ -58,5 +59,4 @@ public class CompatibleMarshallingEncoder extends OneToOneEncoder {
|
||||
|
||||
return output.getBuffer();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,7 +27,8 @@ import org.jboss.netty.handler.codec.frame.TooLongFrameException;
|
||||
/**
|
||||
* Decoder which MUST be used with {@link MarshallingEncoder}.
|
||||
*
|
||||
* A {@link LengthFieldBasedFrameDecoder} which use an {@link Unmarshaller} to read the Object out of the {@link ChannelBuffer}.
|
||||
* A {@link LengthFieldBasedFrameDecoder} which use an {@link Unmarshaller} to read the Object out
|
||||
* of the {@link ChannelBuffer}.
|
||||
*
|
||||
*/
|
||||
public class MarshallingDecoder extends LengthFieldBasedFrameDecoder {
|
||||
@ -77,8 +78,8 @@ public class MarshallingDecoder extends LengthFieldBasedFrameDecoder {
|
||||
unmarshaller.finish();
|
||||
return obj;
|
||||
} finally {
|
||||
// Call close in a finally block as the ReplayingDecoder will throw an Error if not enough bytes are
|
||||
// readable. This helps to be sure that we do not leak resource
|
||||
// Call close in a finally block as the ReplayingDecoder will throw an Error if not
|
||||
// enough bytes are readable. This helps to be sure that we do not leak resource
|
||||
unmarshaller.close();
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,8 @@ public class MarshallingEncoder extends OneToOneEncoder {
|
||||
@Override
|
||||
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
|
||||
Marshaller marshaller = provider.getMarshaller(ctx);
|
||||
ChannelBufferByteOutput output = new ChannelBufferByteOutput(ctx.getChannel().getConfig().getBufferFactory(), estimatedLength);
|
||||
ChannelBufferByteOutput output = new ChannelBufferByteOutput(
|
||||
ctx.getChannel().getConfig().getBufferFactory(), estimatedLength);
|
||||
output.getBuffer().writeBytes(LENGTH_PLACEHOLDER);
|
||||
marshaller.start(output);
|
||||
marshaller.writeObject(msg);
|
||||
|
@ -389,8 +389,9 @@ public abstract class ReplayingDecoder<T extends Enum<T>>
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@link #decode(ChannelHandlerContext, Channel, ChannelBuffer, Enum)}. This method should be never used by {@link ReplayingDecoder} itself.
|
||||
* But to be safe we should handle it anyway
|
||||
* Calls {@link #decode(ChannelHandlerContext, Channel, ChannelBuffer, Enum)}. This method
|
||||
* should be never used by {@link ReplayingDecoder} itself. But to be safe we should handle it
|
||||
* anyway
|
||||
*/
|
||||
@Override
|
||||
protected final Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
|
||||
@ -520,7 +521,9 @@ public abstract class ReplayingDecoder<T extends Enum<T>>
|
||||
}
|
||||
}
|
||||
|
||||
private void callDecode(ChannelHandlerContext context, Channel channel, ChannelBuffer input, ChannelBuffer replayableInput, SocketAddress remoteAddress) throws Exception {
|
||||
private void callDecode(
|
||||
ChannelHandlerContext context, Channel channel,
|
||||
ChannelBuffer input, ChannelBuffer replayableInput, SocketAddress remoteAddress) throws Exception {
|
||||
while (input.readable()) {
|
||||
int oldReaderIndex = checkpoint = input.readerIndex();
|
||||
Object result = null;
|
||||
|
@ -27,10 +27,11 @@ import org.jboss.netty.handler.codec.http.HttpMethod;
|
||||
public final class RtspMethods {
|
||||
|
||||
/**
|
||||
* The OPTIONS method represents a request for information about the communication options available on the request/response
|
||||
* chain identified by the Request-URI. This method allows the client to determine the options and/or requirements
|
||||
* associated with a resource, or the capabilities of a server, without implying a resource action or initiating a
|
||||
* resource retrieval.
|
||||
* The OPTIONS method represents a request for information about the communication options
|
||||
* available on the request/response chain identified by the Request-URI. This method allows
|
||||
* the client to determine the options and/or requirements associated with a resource, or the
|
||||
* capabilities of a server, without implying a resource action or initiating a resource
|
||||
* retrieval.
|
||||
*/
|
||||
public static final HttpMethod OPTIONS = HttpMethod.OPTIONS;
|
||||
|
||||
|
@ -107,7 +107,8 @@ public final class RtspResponseStatuses {
|
||||
/**
|
||||
* 407 Proxy Authentication Required
|
||||
*/
|
||||
public static final HttpResponseStatus PROXY_AUTHENTICATION_REQUIRED = HttpResponseStatus.PROXY_AUTHENTICATION_REQUIRED;
|
||||
public static final HttpResponseStatus PROXY_AUTHENTICATION_REQUIRED =
|
||||
HttpResponseStatus.PROXY_AUTHENTICATION_REQUIRED;
|
||||
|
||||
/**
|
||||
* 408 Request Timeout
|
||||
|
@ -38,7 +38,9 @@ public final class ClassResolvers {
|
||||
* @return new instance of class resolver
|
||||
*/
|
||||
public static ClassResolver weakCachingResolver(ClassLoader classLoader) {
|
||||
return new CachingClassResolver(new ClassLoaderClassResolver(defaultClassLoader(classLoader)), new WeakReferenceMap<String, Class<?>>(new HashMap<String, Reference<Class<?>>>()));
|
||||
return new CachingClassResolver(
|
||||
new ClassLoaderClassResolver(defaultClassLoader(classLoader)),
|
||||
new WeakReferenceMap<String, Class<?>>(new HashMap<String, Reference<Class<?>>>()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -49,7 +51,9 @@ public final class ClassResolvers {
|
||||
* @return new instance of class resolver
|
||||
*/
|
||||
public static ClassResolver softCachingResolver(ClassLoader classLoader) {
|
||||
return new CachingClassResolver(new ClassLoaderClassResolver(defaultClassLoader(classLoader)), new SoftReferenceMap<String, Class<?>>(new HashMap<String, Reference<Class<?>>>()));
|
||||
return new CachingClassResolver(
|
||||
new ClassLoaderClassResolver(defaultClassLoader(classLoader)),
|
||||
new SoftReferenceMap<String, Class<?>>(new HashMap<String, Reference<Class<?>>>()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -60,7 +64,9 @@ public final class ClassResolvers {
|
||||
* @return new instance of class resolver
|
||||
*/
|
||||
public static ClassResolver weakCachingConcurrentResolver(ClassLoader classLoader) {
|
||||
return new CachingClassResolver(new ClassLoaderClassResolver(defaultClassLoader(classLoader)), new WeakReferenceMap<String, Class<?>>(new ConcurrentHashMap<String, Reference<Class<?>>>()));
|
||||
return new CachingClassResolver(
|
||||
new ClassLoaderClassResolver(defaultClassLoader(classLoader)),
|
||||
new WeakReferenceMap<String, Class<?>>(new ConcurrentHashMap<String, Reference<Class<?>>>()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,7 +77,9 @@ public final class ClassResolvers {
|
||||
* @return new instance of class resolver
|
||||
*/
|
||||
public static ClassResolver softCachingConcurrentResolver(ClassLoader classLoader) {
|
||||
return new CachingClassResolver(new ClassLoaderClassResolver(defaultClassLoader(classLoader)), new SoftReferenceMap<String, Class<?>>(new ConcurrentHashMap<String, Reference<Class<?>>>()));
|
||||
return new CachingClassResolver(
|
||||
new ClassLoaderClassResolver(defaultClassLoader(classLoader)),
|
||||
new SoftReferenceMap<String, Class<?>>(new ConcurrentHashMap<String, Reference<Class<?>>>()));
|
||||
}
|
||||
|
||||
static ClassLoader defaultClassLoader(ClassLoader classLoader) {
|
||||
|
@ -74,7 +74,8 @@ public class CompatibleObjectDecoder extends ReplayingDecoder<CompatibleObjectDe
|
||||
|
||||
@Override
|
||||
protected Object decode(
|
||||
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer, CompatibleObjectDecoderState state) throws Exception {
|
||||
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer,
|
||||
CompatibleObjectDecoderState state) throws Exception {
|
||||
bin.switchStream(new ChannelBufferInputStream(buffer));
|
||||
switch (state) {
|
||||
case READ_HEADER:
|
||||
|
@ -97,7 +97,8 @@ public class ObjectDecoder extends LengthFieldBasedFrameDecoder {
|
||||
|
||||
|
||||
/**
|
||||
* Create a new decoder with the specified maximum object size and the {@link ClassLoader} wrapped in {@link ClassResolvers#weakCachingResolver(ClassLoader)}
|
||||
* Create a new decoder with the specified maximum object size and the {@link ClassLoader}
|
||||
* wrapped in {@link ClassResolvers#weakCachingResolver(ClassLoader)}.
|
||||
*
|
||||
* @param maxObjectSize the maximum byte length of the serialized object.
|
||||
* if the length of the received object is greater
|
||||
|
@ -280,7 +280,8 @@ public class SpdyHttpEncoder implements ChannelDownstreamHandler {
|
||||
httpMessage.removeHeader("Proxy-Connection");
|
||||
httpMessage.removeHeader(HttpHeaders.Names.TRANSFER_ENCODING);
|
||||
|
||||
SpdySynStreamFrame spdySynStreamFrame = new DefaultSpdySynStreamFrame(streamID, associatedToStreamID, priority);
|
||||
SpdySynStreamFrame spdySynStreamFrame =
|
||||
new DefaultSpdySynStreamFrame(streamID, associatedToStreamID, priority);
|
||||
|
||||
// Unfold the first line of the message into name/value pairs
|
||||
if (httpMessage instanceof HttpRequest) {
|
||||
|
@ -479,7 +479,8 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
|
||||
e.getFuture().addListener(new ChannelFutureListener() {
|
||||
public void operationComplete(ChannelFuture future) throws Exception {
|
||||
if (!future.isSuccess()) {
|
||||
issueStreamError(context, remoteAddress, streamID, SpdyStreamStatus.INTERNAL_ERROR);
|
||||
issueStreamError(
|
||||
context, remoteAddress, streamID, SpdyStreamStatus.INTERNAL_ERROR);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -504,7 +505,8 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
|
||||
e.getFuture().addListener(new ChannelFutureListener() {
|
||||
public void operationComplete(ChannelFuture future) throws Exception {
|
||||
if (!future.isSuccess()) {
|
||||
issueStreamError(context, remoteAddress, streamID, SpdyStreamStatus.INTERNAL_ERROR);
|
||||
issueStreamError(
|
||||
context, remoteAddress, streamID, SpdyStreamStatus.INTERNAL_ERROR);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -737,7 +739,8 @@ public class SpdySessionHandler extends SimpleChannelUpstreamHandler
|
||||
return false;
|
||||
}
|
||||
spdySession.acceptStream(
|
||||
streamID, priority, remoteSideClosed, localSideClosed, initialSendWindowSize, initialReceiveWindowSize);
|
||||
streamID, priority, remoteSideClosed, localSideClosed,
|
||||
initialSendWindowSize, initialReceiveWindowSize);
|
||||
if (isRemoteInitiatedID(streamID)) {
|
||||
lastGoodStreamID = streamID;
|
||||
}
|
||||
|
@ -32,10 +32,12 @@ public class ChainedExecutor implements Executor, ExternalResourceReleasable {
|
||||
private final ChannelEventRunnableFilter filter;
|
||||
|
||||
/**
|
||||
* Create a new {@link ChainedExecutor} which will used the given {@link ChannelEventRunnableFilter} to see if the {@link #cur} {@link Executor} should get used.
|
||||
* Otherwise it will pass the work to the {@link #next} {@link Executor}
|
||||
* Create a new {@link ChainedExecutor} which will used the given
|
||||
* {@link ChannelEventRunnableFilter} to see if the {@link #cur} {@link Executor} should get
|
||||
* used. Otherwise it will pass the work to the {@link #next} {@link Executor}
|
||||
*
|
||||
* @param filter the {@link ChannelEventRunnableFilter} which will be used to check if the {@link ChannelEventRunnable} should be passed to the cur or next {@link Executor}
|
||||
* @param filter the {@link ChannelEventRunnableFilter} which will be used to check if the
|
||||
* {@link ChannelEventRunnable} should be passed to the cur or next {@link Executor}
|
||||
* @param cur the {@link Executor} to use if the {@link ChannelEventRunnableFilter} match
|
||||
* @param next the {@link Executor} to use if the {@link ChannelEventRunnableFilter} does not match
|
||||
*/
|
||||
@ -56,8 +58,9 @@ public class ChainedExecutor implements Executor, ExternalResourceReleasable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the passed {@link ChannelEventRunnable} with the current {@link Executor} if the {@link ChannelEventRunnableFilter} match.
|
||||
* Otherwise pass it to the next {@link Executor} in the chain.
|
||||
* Execute the passed {@link ChannelEventRunnable} with the current {@link Executor} if the
|
||||
* {@link ChannelEventRunnableFilter} match. Otherwise pass it to the next {@link Executor} in
|
||||
* the chain.
|
||||
*/
|
||||
public void execute(Runnable command) {
|
||||
assert command instanceof ChannelEventRunnable;
|
||||
|
@ -16,6 +16,8 @@
|
||||
package org.jboss.netty.handler.execution;
|
||||
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.jboss.netty.channel.ChannelEvent;
|
||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
|
||||
@ -24,14 +26,15 @@ import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
*/
|
||||
public class ChannelDownstreamEventRunnable extends ChannelEventRunnable {
|
||||
|
||||
public ChannelDownstreamEventRunnable(ChannelHandlerContext ctx, ChannelEvent e) {
|
||||
super(ctx, e);
|
||||
public ChannelDownstreamEventRunnable(ChannelHandlerContext ctx, ChannelEvent e, Executor executor) {
|
||||
super(ctx, e, executor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the {@link ChannelEvent} downstream
|
||||
*/
|
||||
public void run() {
|
||||
@Override
|
||||
protected void doRun() {
|
||||
ctx.sendDownstream(e);
|
||||
}
|
||||
}
|
||||
|
@ -15,23 +15,28 @@
|
||||
*/
|
||||
package org.jboss.netty.handler.execution;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.jboss.netty.channel.ChannelEvent;
|
||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
import org.jboss.netty.util.EstimatableObjectWrapper;
|
||||
import org.jboss.netty.util.internal.DeadLockProofWorker;
|
||||
|
||||
public abstract class ChannelEventRunnable implements Runnable, EstimatableObjectWrapper {
|
||||
|
||||
protected final ChannelHandlerContext ctx;
|
||||
protected final ChannelEvent e;
|
||||
int estimatedSize;
|
||||
private final Executor executor;
|
||||
|
||||
/**
|
||||
* Creates a {@link Runnable} which sends the specified {@link ChannelEvent}
|
||||
* upstream via the specified {@link ChannelHandlerContext}.
|
||||
*/
|
||||
public ChannelEventRunnable(ChannelHandlerContext ctx, ChannelEvent e) {
|
||||
public ChannelEventRunnable(ChannelHandlerContext ctx, ChannelEvent e, Executor executor) {
|
||||
this.ctx = ctx;
|
||||
this.e = e;
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -52,4 +57,16 @@ public abstract class ChannelEventRunnable implements Runnable, EstimatableObjec
|
||||
public Object unwrap() {
|
||||
return e;
|
||||
}
|
||||
|
||||
public final void run() {
|
||||
try {
|
||||
DeadLockProofWorker.PARENT.set(executor);
|
||||
doRun();
|
||||
} finally {
|
||||
DeadLockProofWorker.PARENT.remove();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected abstract void doRun();
|
||||
}
|
||||
|
@ -32,15 +32,16 @@ public class ChannelUpstreamEventRunnable extends ChannelEventRunnable {
|
||||
* Creates a {@link Runnable} which sends the specified {@link ChannelEvent}
|
||||
* upstream via the specified {@link ChannelHandlerContext}.
|
||||
*/
|
||||
public ChannelUpstreamEventRunnable(ChannelHandlerContext ctx, ChannelEvent e) {
|
||||
super(ctx, e);
|
||||
public ChannelUpstreamEventRunnable(ChannelHandlerContext ctx, ChannelEvent e, Executor executor) {
|
||||
super(ctx, e, executor);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sends the event upstream.
|
||||
*/
|
||||
public void run() {
|
||||
@Override
|
||||
protected void doRun() {
|
||||
ctx.sendUpstream(e);
|
||||
}
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ public class ExecutionHandler implements ChannelUpstreamHandler, ChannelDownstre
|
||||
public void handleUpstream(
|
||||
ChannelHandlerContext context, ChannelEvent e) throws Exception {
|
||||
if (handleUpstream) {
|
||||
executor.execute(new ChannelUpstreamEventRunnable(context, e));
|
||||
executor.execute(new ChannelUpstreamEventRunnable(context, e, executor));
|
||||
} else {
|
||||
context.sendUpstream(e);
|
||||
}
|
||||
@ -180,7 +180,7 @@ public class ExecutionHandler implements ChannelUpstreamHandler, ChannelDownstre
|
||||
// check if the read was suspend
|
||||
if (!handleReadSuspend(ctx, e)) {
|
||||
if (handleDownstream) {
|
||||
executor.execute(new ChannelDownstreamEventRunnable(ctx, e));
|
||||
executor.execute(new ChannelDownstreamEventRunnable(ctx, e, executor));
|
||||
} else {
|
||||
ctx.sendDownstream(e);
|
||||
}
|
||||
|
@ -182,7 +182,9 @@ public class MemoryAwareThreadPoolExecutor extends ThreadPoolExecutor {
|
||||
int corePoolSize, long maxChannelMemorySize, long maxTotalMemorySize,
|
||||
long keepAliveTime, TimeUnit unit) {
|
||||
|
||||
this(corePoolSize, maxChannelMemorySize, maxTotalMemorySize, keepAliveTime, unit, Executors.defaultThreadFactory());
|
||||
this(
|
||||
corePoolSize, maxChannelMemorySize, maxTotalMemorySize, keepAliveTime, unit,
|
||||
Executors.defaultThreadFactory());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -201,7 +203,9 @@ public class MemoryAwareThreadPoolExecutor extends ThreadPoolExecutor {
|
||||
int corePoolSize, long maxChannelMemorySize, long maxTotalMemorySize,
|
||||
long keepAliveTime, TimeUnit unit, ThreadFactory threadFactory) {
|
||||
|
||||
this(corePoolSize, maxChannelMemorySize, maxTotalMemorySize, keepAliveTime, unit, new DefaultObjectSizeEstimator(), threadFactory);
|
||||
this(
|
||||
corePoolSize, maxChannelMemorySize, maxTotalMemorySize, keepAliveTime, unit,
|
||||
new DefaultObjectSizeEstimator(), threadFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -277,11 +281,13 @@ public class MemoryAwareThreadPoolExecutor extends ThreadPoolExecutor {
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link ThreadPoolExecutor#shutdownNow()} for how it handles the shutdown. If <code>true</code> is given to this method it also notifies all {@link ChannelFuture}'s
|
||||
* See {@link ThreadPoolExecutor#shutdownNow()} for how it handles the shutdown.
|
||||
* If <code>true</code> is given to this method it also notifies all {@link ChannelFuture}'s
|
||||
* of the not executed {@link ChannelEventRunnable}'s.
|
||||
*
|
||||
* <p>
|
||||
* Be aware that if you call this with <code>false</code> you will need to handle the notification of the {@link ChannelFuture}'s by your self. So only use this if you
|
||||
* Be aware that if you call this with <code>false</code> you will need to handle the
|
||||
* notification of the {@link ChannelFuture}'s by your self. So only use this if you
|
||||
* really have a use-case for it.
|
||||
* </p>
|
||||
*
|
||||
@ -395,11 +401,13 @@ public class MemoryAwareThreadPoolExecutor extends ThreadPoolExecutor {
|
||||
}
|
||||
|
||||
/**
|
||||
* If set to <code>false</code> no queued {@link ChannelEventRunnable}'s {@link ChannelFuture} will get notified once {@link #shutdownNow()} is called.
|
||||
* If set to <code>true</code> every queued {@link ChannelEventRunnable} will get marked as failed via {@link ChannelFuture#setFailure(Throwable)}.
|
||||
* If set to <code>false</code> no queued {@link ChannelEventRunnable}'s {@link ChannelFuture}
|
||||
* will get notified once {@link #shutdownNow()} is called. If set to <code>true</code> every
|
||||
* queued {@link ChannelEventRunnable} will get marked as failed via {@link ChannelFuture#setFailure(Throwable)}.
|
||||
*
|
||||
* <p>
|
||||
* Please only set this to <code>false</code> if you want to handle the notification by yourself and know what you are doing. Default is <code>true</code>.
|
||||
* Please only set this to <code>false</code> if you want to handle the notification by yourself
|
||||
* and know what you are doing. Default is <code>true</code>.
|
||||
* </p>
|
||||
*/
|
||||
public void setNotifyChannelFuturesOnShutdown(boolean notifyOnShutdown) {
|
||||
@ -407,8 +415,8 @@ public class MemoryAwareThreadPoolExecutor extends ThreadPoolExecutor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the {@link ChannelFuture}'s of the {@link ChannelEventRunnable}'s should be notified about the shutdown of this {@link MemoryAwareThreadPoolExecutor}.
|
||||
*
|
||||
* Returns if the {@link ChannelFuture}'s of the {@link ChannelEventRunnable}'s should be
|
||||
* notified about the shutdown of this {@link MemoryAwareThreadPoolExecutor}.
|
||||
*/
|
||||
public boolean getNotifyChannelFuturesOnShutdown() {
|
||||
return notifyOnShutdown;
|
||||
@ -524,8 +532,9 @@ public class MemoryAwareThreadPoolExecutor extends ThreadPoolExecutor {
|
||||
//System.out.println("READABLE");
|
||||
ChannelHandlerContext ctx = eventTask.getContext();
|
||||
if (ctx.getHandler() instanceof ExecutionHandler) {
|
||||
// check if the attachment was set as this means that we suspend the channel from reads. This only works when
|
||||
// this pool is used with ExecutionHandler but I guess thats good enough for us.
|
||||
// check if the attachment was set as this means that we suspend the channel
|
||||
// from reads. This only works when this pool is used with ExecutionHandler
|
||||
// but I guess thats good enough for us.
|
||||
//
|
||||
// See #215
|
||||
if (ctx.getAttachment() != null) {
|
||||
|
@ -28,13 +28,13 @@ import org.jboss.netty.channel.ChannelFutureListener;
|
||||
import org.jboss.netty.util.ObjectSizeEstimator;
|
||||
|
||||
/**
|
||||
* {@link Executor} which should be used for downstream {@link ChannelEvent}'s. This implementation will take care of preserve the order of the events in a {@link Channel}.
|
||||
* If you don't need to preserve the order just use one of the {@link Executor} implementations provided by the static methods of {@link Executors}.
|
||||
* {@link Executor} which should be used for downstream {@link ChannelEvent}'s. This implementation
|
||||
* will take care of preserve the order of the events in a {@link Channel}. If you don't need to
|
||||
* preserve the order just use one of the {@link Executor} implementations provided by the static
|
||||
* methods of {@link Executors}.
|
||||
* <br>
|
||||
* <br>
|
||||
*
|
||||
* For more informations about how the order is preserved see {@link OrderedMemoryAwareThreadPoolExecutor}
|
||||
*
|
||||
*/
|
||||
public final class OrderedDownstreamThreadPoolExecutor extends OrderedMemoryAwareThreadPoolExecutor {
|
||||
|
||||
@ -83,7 +83,8 @@ public final class OrderedDownstreamThreadPoolExecutor extends OrderedMemoryAwar
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws {@link UnsupportedOperationException} as there is not support for limit the memory size in this implementation
|
||||
* Throws {@link UnsupportedOperationException} as there is not support for limit the memory
|
||||
* size in this implementation
|
||||
*/
|
||||
@Override
|
||||
public void setObjectSizeEstimator(ObjectSizeEstimator objectSizeEstimator) {
|
||||
@ -99,7 +100,8 @@ public final class OrderedDownstreamThreadPoolExecutor extends OrderedMemoryAwar
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws {@link UnsupportedOperationException} as there is not support for limit the memory size in this implementation
|
||||
* Throws {@link UnsupportedOperationException} as there is not support for limit the memory
|
||||
* size in this implementation
|
||||
*/
|
||||
@Override
|
||||
public void setMaxChannelMemorySize(long maxChannelMemorySize) {
|
||||
@ -115,7 +117,8 @@ public final class OrderedDownstreamThreadPoolExecutor extends OrderedMemoryAwar
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws {@link UnsupportedOperationException} as there is not support for limit the memory size in this implementation
|
||||
* Throws {@link UnsupportedOperationException} as there is not support for limit the memory
|
||||
* size in this implementation
|
||||
*/
|
||||
@Override
|
||||
public void setMaxTotalMemorySize(long maxTotalMemorySize) {
|
||||
|
@ -125,7 +125,7 @@ import org.jboss.netty.util.internal.QueueFactory;
|
||||
* </pre>
|
||||
*
|
||||
* If the expected maximum number of keys is small and deterministic, you could
|
||||
* use a weak key map such as <a href="http://viewvc.jboss.org/cgi-bin/viewvc.cgi/jbosscache/experimental/jsr166/src/jsr166y/ConcurrentWeakHashMap.java?view=markup">ConcurrentWeakHashMap</a>
|
||||
* use a weak key map such as <a href="http://goo.gl/TqGl1">ConcurrentWeakHashMap</a>
|
||||
* or synchronized {@link WeakHashMap} instead of managing the life cycle of the
|
||||
* keys by yourself.
|
||||
*
|
||||
|
@ -30,7 +30,8 @@ import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
* Implementation of Filter of IP based on ALLOW and DENY rules.<br>
|
||||
* <br><br>
|
||||
* This implementation could be changed by implementing a new {@link IpFilterRule} than default
|
||||
* {@link IpV4SubnetFilterRule} (IPV4 support only), {@link IpSubnetFilterRule} (IPV4 and IPV6 support) or {@link IpFilterRule} (IP and host name string pattern support) .<br>
|
||||
* {@link IpV4SubnetFilterRule} (IPV4 support only), {@link IpSubnetFilterRule} (IPV4 and IPV6 support)
|
||||
* or {@link IpFilterRule} (IP and host name string pattern support) .<br>
|
||||
* <br>
|
||||
* The check is done by going from step to step in the underlying array of IpFilterRule.<br>
|
||||
* Each {@link IpFilterRule} answers to the method accept if the {@link InetAddress} is accepted or not,
|
||||
|
@ -18,17 +18,20 @@
|
||||
* Implementation of a Ip based Filter handlers.<br>
|
||||
* <br><br>
|
||||
* <P>The main goal of this package is to allow to filter connections based on IP rules.
|
||||
* The main interface is <tt>{@link org.jboss.netty.handler.ipfilter.IpFilteringHandler}</tt> which all filters will extend.</P>
|
||||
* The main interface is <tt>{@link org.jboss.netty.handler.ipfilter.IpFilteringHandler}</tt> which
|
||||
* all filters will extend.</P>
|
||||
*
|
||||
* <P>Two IP filtering are proposed:<br>
|
||||
* <ul>
|
||||
* <li> <tt>{@link org.jboss.netty.handler.ipfilter.OneIpFilterHandler}</tt>: This filter proposes to allow only one connection by client's IP Address.
|
||||
* I.E. this filter will prevent two connections from the same client based on its IP address.</li><br><br>
|
||||
* <li>{@link org.jboss.netty.handler.ipfilter.OneIpFilterHandler}: This filter proposes to allow
|
||||
* only one connection by client's IP Address. I.E. this filter will prevent two connections
|
||||
* from the same client based on its IP address.</li><br><br>
|
||||
*
|
||||
* <li> <tt>{@link org.jboss.netty.handler.ipfilter.IpFilterRuleHandler}</tt>: This filter proposes to allow or block IP range (based on standard notation
|
||||
* or on CIDR notation) when the connection is running. It relies on another class like
|
||||
* <tt>IpV4SubnetFilterRule</tt> (IPV4 support only), <tt>IpSubnetFilterRule</tt> (IPV4 and IPV6 support) or <tt>PatternRule</tt> (string pattern support)
|
||||
* which implements those Ip ranges.</li><br><br>
|
||||
* <li>{@link org.jboss.netty.handler.ipfilter.IpFilterRuleHandler}: This filter proposes to allow
|
||||
* or block IP range (based on standard notation or on CIDR notation) when the connection is
|
||||
* running. It relies on another class like <tt>IpV4SubnetFilterRule</tt> (IPV4 support only),
|
||||
* <tt>IpSubnetFilterRule</tt> (IPV4 and IPV6 support) or <tt>PatternRule</tt> (string pattern
|
||||
* support) which implements those Ip ranges.</li><br><br>
|
||||
*
|
||||
* </ul></P>
|
||||
*
|
||||
@ -42,27 +45,32 @@
|
||||
* this method is already implemented.<br>
|
||||
* <br>
|
||||
*
|
||||
* <li><tt>handleRefusedChannel</tt> method is executed when the accept method filters (blocks, so returning false)
|
||||
* the new connection. This method allows you to implement specific actions to be taken before the channel is
|
||||
* closed. After this method is called, the channel is immediately closed.</li><br>
|
||||
* So if you want to send back a message to the client, <b>don't forget to return a respectful ChannelFuture,
|
||||
* otherwise the message could be missed since the channel will be closed immediately after this
|
||||
* call and the waiting on this channelFuture</b> (at least with respect of asynchronous operations).<br><br>
|
||||
* Per default implementation this method invokes an {@link org.jboss.netty.handler.ipfilter.IpFilterListener} or returns null if no listener has been set.
|
||||
* <li>handleRefusedChannel method is executed when the accept method filters (blocks, so returning
|
||||
* false) the new connection. This method allows you to implement specific actions to be taken
|
||||
* before the channel is closed. After this method is called, the channel is immediately closed.</li><br>
|
||||
*
|
||||
* So if you want to send back a message to the client, <b>don't forget to return a respectful
|
||||
* ChannelFuture, otherwise the message could be missed since the channel will be closed immediately
|
||||
* after this call and the waiting on this channelFuture</b> (at least with respect of asynchronous
|
||||
* operations).<br><br>
|
||||
* Per default implementation this method invokes an {@link org.jboss.netty.handler.ipfilter.IpFilterListener}
|
||||
* or returns null if no listener has been set.
|
||||
* <br><br>
|
||||
*
|
||||
* <li><tt>continues</tt> is called when any event appears after CONNECTED event and only for
|
||||
* blocked channels.</li><br>
|
||||
* It should return True if this new event has to go to next handlers
|
||||
* in the pipeline if any, and False (default) if no events has to be passed to the next
|
||||
* handlers when a channel is blocked. This is intend to prevent any unnecessary action since the connection is refused.<br>
|
||||
* handlers when a channel is blocked. This is intend to prevent any unnecessary action since the
|
||||
* connection is refused.<br>
|
||||
* However, you could change its behavior for instance because you don't want that any event
|
||||
* will be blocked by this filter by returning always true or according to some events.<br>
|
||||
* <b>Note that OPENED and BOUND events are still passed to the next entry in the pipeline since
|
||||
* those events come out before the CONNECTED event, so there is no possibility to filter those two events
|
||||
* before the CONNECTED event shows up. Therefore, you might want to let CLOSED and UNBOUND be passed
|
||||
* to the next entry in the pipeline.</b><br><br>
|
||||
* Per default implementation this method invokes an {@link org.jboss.netty.handler.ipfilter.IpFilterListener} or returns false if no listener has been set.
|
||||
* Per default implementation this method invokes an {@link org.jboss.netty.handler.ipfilter.IpFilterListener}
|
||||
* or returns false if no listener has been set.
|
||||
* <br><br>
|
||||
*
|
||||
* <li>Finally <tt>handleUpstream</tt> traps the CONNECTED and DISCONNECTED events.</li><br>
|
||||
@ -70,7 +78,8 @@
|
||||
* then any new events on this channel will be blocked.<br>
|
||||
* However, you could change its behavior for instance because you don't want that all events
|
||||
* will be blocked by this filter by testing the result of isBlocked, and if so,
|
||||
* calling <tt>ctx.sendUpstream(e);</tt> after calling the super method or by changing the <tt>continues</tt> method.<br><br>
|
||||
* calling <tt>ctx.sendUpstream(e);</tt> after calling the super method or by changing the
|
||||
* <tt>continues</tt> method.<br><br>
|
||||
|
||||
* </ul></P><br><br>
|
||||
*
|
||||
|
@ -219,7 +219,8 @@ public class BlockingReadHandler<E> extends SimpleChannelUpstreamHandler {
|
||||
* @throws InterruptedException
|
||||
* if the operation has been interrupted
|
||||
*/
|
||||
public ChannelEvent readEvent(long timeout, TimeUnit unit) throws InterruptedException, BlockingReadTimeoutException {
|
||||
public ChannelEvent readEvent(
|
||||
long timeout, TimeUnit unit) throws InterruptedException, BlockingReadTimeoutException {
|
||||
detectDeadLock();
|
||||
if (isClosed()) {
|
||||
if (getQueue().isEmpty()) {
|
||||
|
@ -142,7 +142,8 @@ import org.jboss.netty.util.internal.QueueFactory;
|
||||
* }
|
||||
*
|
||||
* {@literal @Override}
|
||||
* public void channelInterestChanged({@link ChannelHandlerContext} ctx, {@link ChannelStateEvent} e) throws Exception {
|
||||
* public void channelInterestChanged(
|
||||
* {@link ChannelHandlerContext} ctx, {@link ChannelStateEvent} e) throws Exception {
|
||||
* if (e.getChannel().isWritable()) {
|
||||
* flush();
|
||||
* }
|
||||
@ -355,7 +356,8 @@ public class BufferedWriteHandler extends SimpleChannelHandler implements LifeCy
|
||||
}
|
||||
|
||||
/**
|
||||
* Fail all buffered writes that are left. See <a href="https://github.com/netty/netty/issues/308>#308</a> for more details
|
||||
* Fail all buffered writes that are left. See
|
||||
* <a href="https://github.com/netty/netty/issues/308>#308</a> for more details.
|
||||
*/
|
||||
@Override
|
||||
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
|
||||
@ -396,7 +398,8 @@ public class BufferedWriteHandler extends SimpleChannelHandler implements LifeCy
|
||||
}
|
||||
|
||||
/**
|
||||
* Fail all buffered writes that are left. See <a href="https://github.com/netty/netty/issues/308>#308</a> for more details
|
||||
* Fail all buffered writes that are left.
|
||||
* See <a href="https://github.com/netty/netty/issues/308>#308</a> for more details.
|
||||
*/
|
||||
public void afterRemove(ChannelHandlerContext ctx) throws Exception {
|
||||
Throwable cause = null;
|
||||
|
@ -70,9 +70,10 @@ import org.jboss.netty.util.internal.QueueFactory;
|
||||
* <h3>Handshake</h3>
|
||||
* <p>
|
||||
* If {@link #isIssueHandshake()} is {@code false}
|
||||
* (default) you will need to take care of calling {@link #handshake()} by your own. In most situations were {@link SslHandler} is used in 'client mode'
|
||||
* you want to issue a handshake once the connection was established. if {@link #setIssueHandshake(boolean)} is set to <code>true</code> you don't need to
|
||||
* worry about this as the {@link SslHandler} will take care of it.
|
||||
* (default) you will need to take care of calling {@link #handshake()} by your own. In most
|
||||
* situations were {@link SslHandler} is used in 'client mode' you want to issue a handshake once
|
||||
* the connection was established. if {@link #setIssueHandshake(boolean)} is set to <code>true</code>
|
||||
* you don't need to worry about this as the {@link SslHandler} will take care of it.
|
||||
* <p>
|
||||
*
|
||||
* <h3>Renegotiation</h3>
|
||||
@ -91,7 +92,8 @@ import org.jboss.netty.util.internal.QueueFactory;
|
||||
* <ul>
|
||||
* <li><a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-3555">CVE-2009-3555</a></li>
|
||||
* <li><a href="http://www.ietf.org/rfc/rfc5746.txt">RFC5746</a></li>
|
||||
* <li><a href="http://www.oracle.com/technetwork/java/javase/documentation/tlsreadme2-176330.html">Phased Approach to Fixing the TLS Renegotiation Issue</a></li>
|
||||
* <li><a href="http://www.oracle.com/technetwork/java/javase/documentation/tlsreadme2-176330.html">Phased
|
||||
* Approach to Fixing the TLS Renegotiation Issue</a></li>
|
||||
* </ul>
|
||||
*
|
||||
* <h3>Closing the session</h3>
|
||||
@ -869,7 +871,8 @@ public class SslHandler extends FrameDecoder
|
||||
|
||||
if (result.bytesProduced() > 0) {
|
||||
outNetBuf.flip();
|
||||
ChannelBuffer msg = ctx.getChannel().getConfig().getBufferFactory().getBuffer(outNetBuf.remaining());
|
||||
ChannelBuffer msg =
|
||||
ctx.getChannel().getConfig().getBufferFactory().getBuffer(outNetBuf.remaining());
|
||||
|
||||
|
||||
// Transfer the bytes to the new ChannelBuffer using some safe method that will also
|
||||
@ -939,7 +942,8 @@ public class SslHandler extends FrameDecoder
|
||||
}
|
||||
|
||||
private ChannelBuffer unwrap(
|
||||
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer, int offset, int length) throws SSLException {
|
||||
ChannelHandlerContext ctx, Channel channel,
|
||||
ChannelBuffer buffer, int offset, int length) throws SSLException {
|
||||
ByteBuffer inNetBuf = buffer.toByteBuffer(offset, length);
|
||||
ByteBuffer outAppBuf = bufferPool.acquireBuffer();
|
||||
|
||||
@ -1275,7 +1279,8 @@ public class SslHandler extends FrameDecoder
|
||||
@Override
|
||||
public void channelConnected(final ChannelHandlerContext ctx, final ChannelStateEvent e) throws Exception {
|
||||
if (issueHandshake) {
|
||||
// issue and handshake and add a listener to it which will fire an exception event if an exception was thrown while doing the handshake
|
||||
// issue and handshake and add a listener to it which will fire an exception event if
|
||||
// an exception was thrown while doing the handshake
|
||||
handshake().addListener(new ChannelFutureListener() {
|
||||
|
||||
public void operationComplete(ChannelFuture future) throws Exception {
|
||||
|
@ -73,7 +73,8 @@ import org.jboss.netty.util.internal.QueueFactory;
|
||||
* @apiviz.landmark
|
||||
* @apiviz.has org.jboss.netty.handler.stream.ChunkedInput oneway - - reads from
|
||||
*/
|
||||
public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDownstreamHandler, LifeCycleAwareChannelHandler {
|
||||
public class ChunkedWriteHandler
|
||||
implements ChannelUpstreamHandler, ChannelDownstreamHandler, LifeCycleAwareChannelHandler {
|
||||
|
||||
private static final InternalLogger logger =
|
||||
InternalLoggerFactory.getInstance(ChunkedWriteHandler.class);
|
||||
@ -251,8 +252,9 @@ public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDowns
|
||||
this.currentEvent = null;
|
||||
writeFuture = currentEvent.getFuture();
|
||||
|
||||
// Register a listener which will close the input once the write is complete. This is needed because the Chunk may have
|
||||
// some resource bound that can not be closed before its not written
|
||||
// Register a listener which will close the input once the write
|
||||
// is complete. This is needed because the Chunk may have some
|
||||
// resource bound that can not be closed before its not written
|
||||
//
|
||||
// See https://github.com/netty/netty/issues/303
|
||||
writeFuture.addListener(new ChannelFutureListener() {
|
||||
|
@ -25,14 +25,16 @@
|
||||
*
|
||||
* <P>Two classes implement this behavior:<br>
|
||||
* <ul>
|
||||
* <li> <tt>{@link org.jboss.netty.handler.traffic.TrafficCounter}</tt>: this class implements the counters needed by the handlers.
|
||||
* It can be accessed to get some extra information like the read or write bytes since last check, the read and write
|
||||
* bandwidth from last check...</li><br><br>
|
||||
* <li>{@link org.jboss.netty.handler.traffic.TrafficCounter}: this class implements the counters
|
||||
* needed by the handlers. It can be accessed to get some extra information like the read or
|
||||
* write bytes since last check, the read and write bandwidth from last check...</li><br><br>
|
||||
*
|
||||
* <li> <tt>{@link org.jboss.netty.handler.traffic.AbstractTrafficShapingHandler}</tt>: this abstract class implements the kernel
|
||||
* of the traffic shaping. It could be extended to fit your needs. Two classes are proposed as default
|
||||
* implementations: see {@link org.jboss.netty.handler.traffic.ChannelTrafficShapingHandler} and see {@link org.jboss.netty.handler.traffic.GlobalTrafficShapingHandler}
|
||||
* respectively for Channel traffic shaping and Global traffic shaping.</li><br><br>
|
||||
* <li>{@link org.jboss.netty.handler.traffic.AbstractTrafficShapingHandler}: this abstract class
|
||||
* implements the kernel of the traffic shaping. It could be extended to fit your needs. Two
|
||||
* classes are proposed as default implementations: see
|
||||
* {@link org.jboss.netty.handler.traffic.ChannelTrafficShapingHandler} and
|
||||
* {@link org.jboss.netty.handler.traffic.GlobalTrafficShapingHandler} respectively for
|
||||
* Channel traffic shaping and Global traffic shaping.</li><br><br>
|
||||
*
|
||||
* The insertion in the pipeline of one of those handlers can be wherever you want, but
|
||||
* <b>it must be placed before any <tt>{@link MemoryAwareThreadPoolExecutor}</tt>
|
||||
@ -62,14 +64,16 @@
|
||||
* [Global or per Channel] [Write or Read] Limitation in byte/s.</li><br>
|
||||
* A value of <tt>0</tt>
|
||||
* stands for no limitation, so the traffic shaping is deactivate (on what you specified).<br>
|
||||
* You can either change those values with the method <tt>configure</tt> in {@link org.jboss.netty.handler.traffic.AbstractTrafficShapingHandler}.<br>
|
||||
* You can either change those values with the method <tt>configure</tt> in
|
||||
* {@link org.jboss.netty.handler.traffic.AbstractTrafficShapingHandler}.<br>
|
||||
* <br>
|
||||
*
|
||||
* <li>To activate or deactivate the statistics, you can adjust the delay to a low (suggested not less than 200ms
|
||||
* for efficiency reasons) or a high value (let say 24H in millisecond is huge enough to not get the problem)
|
||||
* or even using <tt>0</tt> which means no computation will be done.</li><br>
|
||||
* If you want to do anything with this statistics, just override the <tt>doAccounting</tt> method.<br>
|
||||
* This interval can be changed either from the method <tt>configure</tt> in {@link org.jboss.netty.handler.traffic.AbstractTrafficShapingHandler}
|
||||
* This interval can be changed either from the method <tt>configure</tt> in
|
||||
* {@link org.jboss.netty.handler.traffic.AbstractTrafficShapingHandler}
|
||||
* or directly using the method <tt>configure</tt> of {@link org.jboss.netty.handler.traffic.TrafficCounter}.<br><br>
|
||||
*
|
||||
* </ul></P><br><br>
|
||||
@ -81,8 +85,9 @@
|
||||
* <tt>pipeline.addLast("XXXXX_TRAFFIC_SHAPING", myHandler);</tt><br>
|
||||
* <tt>...</tt><br>
|
||||
* <tt>pipeline.addLast("MemoryExecutor",new ExecutionHandler(memoryAwareThreadPoolExecutor));</tt><br><br>
|
||||
* <P>Note that a new {@link org.jboss.netty.handler.traffic.ChannelTrafficShapingHandler} must be created for each new channel,
|
||||
* but only one {@link org.jboss.netty.handler.traffic.GlobalTrafficShapingHandler} must be created for all channels.</P>
|
||||
* <P>Note that a new {@link org.jboss.netty.handler.traffic.ChannelTrafficShapingHandler} must be
|
||||
* created for each new channel, but only one {@link org.jboss.netty.handler.traffic.GlobalTrafficShapingHandler}
|
||||
* must be created for all channels.</P>
|
||||
*
|
||||
* <P>Note also that you can create different GlobalTrafficShapingHandler if you want to separate classes of
|
||||
* channels (for instance either from business point of view or from bind address point of view).</P>
|
||||
|
@ -55,8 +55,9 @@ public final class QueueFactory {
|
||||
} catch (Throwable t) {
|
||||
// For whatever reason an exception was thrown while loading the LinkedTransferQueue
|
||||
//
|
||||
// This mostly happens because of a custom classloader or security policy that did not allow us to access the
|
||||
// com.sun.Unmisc class. So just log it and fallback to the old LegacyLinkedTransferQueue that works in all cases
|
||||
// This mostly happens because of a custom classloader or security policy that did not
|
||||
// allow us to access the com.sun.Unmisc class. So just log it and fallback to the old
|
||||
// LegacyLinkedTransferQueue that works in all cases
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Unable to instance LinkedTransferQueue, fallback to LegacyLinkedTransferQueue", t);
|
||||
}
|
||||
@ -87,8 +88,9 @@ public final class QueueFactory {
|
||||
} catch (Throwable t) {
|
||||
// For whatever reason an exception was thrown while loading the LinkedTransferQueue
|
||||
//
|
||||
// This mostly happens because of a custom classloader or security policy that did not allow us to access the
|
||||
// com.sun.Unmisc class. So just log it and fallback to the old LegacyLinkedTransferQueue that works in all cases
|
||||
// This mostly happens because of a custom classloader or security policy that did not
|
||||
// allow us to access the com.sun.Unmisc class. So just log it and fallback to the old
|
||||
// LegacyLinkedTransferQueue that works in all cases
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Unable to instance LinkedTransferQueue, fallback to LegacyLinkedTransferQueue", t);
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ import static org.junit.Assert.*;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@ -29,8 +31,8 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.jboss.netty.bootstrap.ConnectionlessBootstrap;
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
import org.jboss.netty.buffer.ChannelBuffers;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
import org.jboss.netty.channel.ExceptionEvent;
|
||||
import org.jboss.netty.channel.MessageEvent;
|
||||
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
|
||||
import org.jboss.netty.util.TestUtil;
|
||||
@ -63,57 +65,76 @@ public abstract class AbstractDatagramMulticastTest {
|
||||
public void testMulticast() throws Throwable {
|
||||
ConnectionlessBootstrap sb = new ConnectionlessBootstrap(newServerSocketChannelFactory(executor));
|
||||
ConnectionlessBootstrap cb = new ConnectionlessBootstrap(newClientSocketChannelFactory(executor));
|
||||
MulticastTestHandler mhandler = new MulticastTestHandler();
|
||||
DatagramChannel sc = null;
|
||||
DatagramChannel cc = null;
|
||||
try {
|
||||
MulticastTestHandler mhandler = new MulticastTestHandler();
|
||||
|
||||
cb.getPipeline().addFirst("handler", mhandler);
|
||||
sb.getPipeline().addFirst("handler", new SimpleChannelUpstreamHandler());
|
||||
cb.getPipeline().addFirst("handler", mhandler);
|
||||
sb.getPipeline().addFirst("handler", new SimpleChannelUpstreamHandler());
|
||||
|
||||
int port = TestUtil.getFreePort();
|
||||
int port = TestUtil.getFreePort();
|
||||
|
||||
NetworkInterface iface = NetworkInterface.getByInetAddress(InetAddress.getLocalHost());
|
||||
NetworkInterface loopbackIf;
|
||||
try {
|
||||
loopbackIf = NetworkInterface.getByInetAddress(InetAddress.getLocalHost());
|
||||
} catch (SocketException e) {
|
||||
loopbackIf = null;
|
||||
}
|
||||
|
||||
// check if the NetworkInterface is null, this is the case on my ubuntu dev machine but not on osx and windows.
|
||||
// if so fail back the the first interface
|
||||
if (iface == null) {
|
||||
// use nextElement() as NetWorkInterface.getByIndex(0) returns null
|
||||
iface = NetworkInterface.getNetworkInterfaces().nextElement();
|
||||
// check if the NetworkInterface is null, this is the case on my ubuntu dev machine but not on osx and windows.
|
||||
// if so fail back the the first interface
|
||||
if (loopbackIf == null) {
|
||||
for (Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
|
||||
e.hasMoreElements();) {
|
||||
NetworkInterface nif = e.nextElement();
|
||||
if (nif.isLoopback()) {
|
||||
loopbackIf = nif;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sb.setOption("networkInterface", loopbackIf);
|
||||
sb.setOption("reuseAddress", true);
|
||||
|
||||
sc = (DatagramChannel) sb.bind(new InetSocketAddress(port));
|
||||
|
||||
|
||||
String group = "230.0.0.1";
|
||||
InetSocketAddress groupAddress = new InetSocketAddress(group, port);
|
||||
|
||||
cb.setOption("networkInterface", loopbackIf);
|
||||
cb.setOption("reuseAddress", true);
|
||||
|
||||
cc = (DatagramChannel) cb.bind(new InetSocketAddress(port));
|
||||
|
||||
assertTrue(cc.joinGroup(groupAddress, loopbackIf).awaitUninterruptibly().isSuccess());
|
||||
|
||||
assertTrue(sc.write(wrapInt(1), groupAddress).awaitUninterruptibly().isSuccess());
|
||||
|
||||
assertTrue(mhandler.await());
|
||||
|
||||
assertTrue(sc.write(wrapInt(1), groupAddress).awaitUninterruptibly().isSuccess());
|
||||
|
||||
// leave the group
|
||||
assertTrue(cc.leaveGroup(groupAddress, loopbackIf).awaitUninterruptibly().isSuccess());
|
||||
|
||||
// sleep a second to make sure we left the group
|
||||
Thread.sleep(1000);
|
||||
|
||||
// we should not receive a message anymore as we left the group before
|
||||
assertTrue(sc.write(wrapInt(1), groupAddress).awaitUninterruptibly().isSuccess());
|
||||
} finally {
|
||||
if (sc != null) {
|
||||
sc.close().awaitUninterruptibly();
|
||||
}
|
||||
if (cc != null) {
|
||||
cc.close().awaitUninterruptibly();
|
||||
}
|
||||
sb.releaseExternalResources();
|
||||
cb.releaseExternalResources();
|
||||
}
|
||||
sb.setOption("networkInterface", iface);
|
||||
sb.setOption("reuseAddress", true);
|
||||
|
||||
Channel sc = sb.bind(new InetSocketAddress(port));
|
||||
|
||||
|
||||
String group = "230.0.0.1";
|
||||
InetSocketAddress groupAddress = new InetSocketAddress(group, port);
|
||||
|
||||
cb.setOption("networkInterface", iface);
|
||||
cb.setOption("reuseAddress", true);
|
||||
|
||||
DatagramChannel cc = (DatagramChannel) cb.bind(new InetSocketAddress(port));
|
||||
|
||||
assertTrue(cc.joinGroup(groupAddress, iface).awaitUninterruptibly().isSuccess());
|
||||
|
||||
assertTrue(sc.write(wrapInt(1), groupAddress).awaitUninterruptibly().isSuccess());
|
||||
|
||||
|
||||
assertTrue(mhandler.await());
|
||||
|
||||
assertTrue(sc.write(wrapInt(1), groupAddress).awaitUninterruptibly().isSuccess());
|
||||
|
||||
|
||||
// leave the group
|
||||
assertTrue(cc.leaveGroup(groupAddress, iface).awaitUninterruptibly().isSuccess());
|
||||
|
||||
// sleep a second to make sure we left the group
|
||||
Thread.sleep(1000);
|
||||
|
||||
// we should not receive a message anymore as we left the group before
|
||||
assertTrue(sc.write(wrapInt(1), groupAddress).awaitUninterruptibly().isSuccess());
|
||||
|
||||
sc.close().awaitUninterruptibly();
|
||||
cc.close().awaitUninterruptibly();
|
||||
|
||||
}
|
||||
|
||||
private static ChannelBuffer wrapInt(int value) {
|
||||
@ -135,7 +156,7 @@ public abstract class AbstractDatagramMulticastTest {
|
||||
fail = true;
|
||||
}
|
||||
|
||||
Assert.assertEquals(1,((ChannelBuffer)e.getMessage()).readInt());
|
||||
Assert.assertEquals(1, ((ChannelBuffer)e.getMessage()).readInt());
|
||||
|
||||
latch.countDown();
|
||||
|
||||
@ -143,6 +164,12 @@ public abstract class AbstractDatagramMulticastTest {
|
||||
done = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
|
||||
throws Exception {
|
||||
e.getCause().printStackTrace();
|
||||
}
|
||||
|
||||
public boolean await() throws Exception {
|
||||
boolean success = latch.await(10, TimeUnit.SECONDS);
|
||||
if (fail) {
|
||||
|
@ -18,8 +18,9 @@ package org.jboss.netty.channel.socket;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory;
|
||||
import org.jboss.netty.channel.socket.oio.OioDatagramChannelFactory;
|
||||
import org.junit.Ignore;
|
||||
|
||||
@Ignore
|
||||
public class NioNioDatagramMulticastTest extends AbstractDatagramMulticastTest {
|
||||
|
||||
@Override
|
||||
@ -29,7 +30,7 @@ public class NioNioDatagramMulticastTest extends AbstractDatagramMulticastTest {
|
||||
|
||||
@Override
|
||||
protected DatagramChannelFactory newClientSocketChannelFactory(Executor executor) {
|
||||
return new OioDatagramChannelFactory(executor);
|
||||
return new NioDatagramChannelFactory(executor, InternetProtocolFamily.IPv4);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,7 +19,9 @@ import java.util.concurrent.Executor;
|
||||
|
||||
import org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory;
|
||||
import org.jboss.netty.channel.socket.oio.OioDatagramChannelFactory;
|
||||
import org.junit.Ignore;
|
||||
|
||||
@Ignore
|
||||
public class NioOioDatagramMulticastTest extends AbstractDatagramMulticastTest {
|
||||
|
||||
@Override
|
||||
|
@ -18,7 +18,10 @@ package org.jboss.netty.channel.socket;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory;
|
||||
import org.jboss.netty.channel.socket.oio.OioDatagramChannelFactory;
|
||||
import org.junit.Ignore;
|
||||
|
||||
@Ignore
|
||||
public class OioNioDatagramMulticastTest extends AbstractDatagramMulticastTest {
|
||||
|
||||
@Override
|
||||
@ -28,7 +31,7 @@ public class OioNioDatagramMulticastTest extends AbstractDatagramMulticastTest {
|
||||
|
||||
@Override
|
||||
protected DatagramChannelFactory newClientSocketChannelFactory(Executor executor) {
|
||||
return new NioDatagramChannelFactory(executor, InternetProtocolFamily.IPv4);
|
||||
return new OioDatagramChannelFactory(executor);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,7 +18,9 @@ package org.jboss.netty.channel.socket;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.jboss.netty.channel.socket.oio.OioDatagramChannelFactory;
|
||||
import org.junit.Ignore;
|
||||
|
||||
@Ignore
|
||||
public class OioOioDatagramMulticastTest extends AbstractDatagramMulticastTest {
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user