Merge branch '3' of ssh://github.com/netty/netty into 3
This commit is contained in:
commit
9d9f96bb5e
@ -229,12 +229,12 @@ public class ClientBootstrap extends Bootstrap {
|
||||
// Connect.
|
||||
return ch.connect(remoteAddress);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Attempts to bind a channel with the specified {@code localAddress}. later the channel can be connected
|
||||
* to a remoteAddress by calling {@link Channel#connect(SocketAddress)}.This method is useful where bind and connect
|
||||
* need to be done in separate steps.
|
||||
*
|
||||
* need to be done in separate steps.
|
||||
*
|
||||
* This can also be useful if you want to set an attachment to the {@link Channel} via
|
||||
* {@link Channel#setAttachment(Object)} so you can use it after the {@link #bind(SocketAddress)} was done.
|
||||
* <br>
|
||||
@ -247,7 +247,7 @@ public class ClientBootstrap extends Bootstrap {
|
||||
* bootstrap.connect(new InetSocketAddress("192.168.0.30", 8080));
|
||||
* </pre>
|
||||
* <br>
|
||||
*
|
||||
*
|
||||
* You can use it then in your handlers like this:
|
||||
*
|
||||
* <pre>
|
||||
@ -256,7 +256,7 @@ public class ClientBootstrap extends Bootstrap {
|
||||
* Object dataObject = ctx.getChannel().getAttachment();
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @return a future object which notifies when this bind attempt
|
||||
|
@ -52,7 +52,7 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
|
||||
|
||||
public void writerIndex(int writerIndex) {
|
||||
if (writerIndex < readerIndex || writerIndex > capacity()) {
|
||||
throw new IndexOutOfBoundsException("Invalid readerIndex: "
|
||||
throw new IndexOutOfBoundsException("Invalid readerIndex: "
|
||||
+ readerIndex + " - Maximum is " + writerIndex);
|
||||
}
|
||||
this.writerIndex = writerIndex;
|
||||
@ -60,7 +60,7 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
|
||||
|
||||
public void setIndex(int readerIndex, int writerIndex) {
|
||||
if (readerIndex < 0 || readerIndex > writerIndex || writerIndex > capacity()) {
|
||||
throw new IndexOutOfBoundsException("Invalid writerIndex: "
|
||||
throw new IndexOutOfBoundsException("Invalid writerIndex: "
|
||||
+ writerIndex + " - Maximum is " + readerIndex + " or " + capacity());
|
||||
}
|
||||
this.readerIndex = readerIndex;
|
||||
@ -116,7 +116,7 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
|
||||
|
||||
public void ensureWritableBytes(int writableBytes) {
|
||||
if (writableBytes > writableBytes()) {
|
||||
throw new IndexOutOfBoundsException("Writable bytes exceeded: Got "
|
||||
throw new IndexOutOfBoundsException("Writable bytes exceeded: Got "
|
||||
+ writableBytes + ", maximum is " + writableBytes());
|
||||
}
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ public class ChannelBufferInputStream extends InputStream implements DataInput {
|
||||
lineBuf.setLength(lineBuf.length() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return lineBuf.toString();
|
||||
}
|
||||
@ -227,7 +227,7 @@ public class ChannelBufferInputStream extends InputStream implements DataInput {
|
||||
throw new IndexOutOfBoundsException("fieldSize cannot be a negative number");
|
||||
}
|
||||
if (fieldSize > available()) {
|
||||
throw new EOFException("fieldSize is too long! Length is " + fieldSize
|
||||
throw new EOFException("fieldSize is too long! Length is " + fieldSize
|
||||
+ ", but maximum is " + available());
|
||||
}
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
int componentId = componentId(index);
|
||||
if (index > capacity() - length || dstIndex > dst.length - length) {
|
||||
throw new IndexOutOfBoundsException("Too many bytes to read - Needs "
|
||||
+ (index + length) + ", maximum is " + capacity() + " or "
|
||||
+ (index + length) + ", maximum is " + capacity() + " or "
|
||||
+ dst.length);
|
||||
}
|
||||
|
||||
@ -286,7 +286,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
if (DetectionUtil.javaVersion() >= 7) {
|
||||
return (int) out.write(toByteBuffers(index, length));
|
||||
}
|
||||
|
||||
|
||||
// XXX Gathering write is not supported because of a known issue.
|
||||
// See http://bugs.sun.com/view_bug.do?bug_id=6210541
|
||||
// This issue appeared in 2004 and is still unresolved!?
|
||||
@ -297,7 +297,7 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
throws IOException {
|
||||
int componentId = componentId(index);
|
||||
if (index > capacity() - length) {
|
||||
throw new IndexOutOfBoundsException("Too many bytes to be read - needs "
|
||||
throw new IndexOutOfBoundsException("Too many bytes to be read - needs "
|
||||
+ (index + length) + ", maximum of " + capacity());
|
||||
}
|
||||
|
||||
@ -647,9 +647,9 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
||||
|
||||
final int bytesToMove = capacity() - localReaderIndex;
|
||||
List<ChannelBuffer> list = decompose(localReaderIndex, bytesToMove);
|
||||
|
||||
|
||||
// If the list is empty we need to assign a new one because
|
||||
// we get a List that is immutable.
|
||||
// we get a List that is immutable.
|
||||
//
|
||||
// See https://github.com/netty/netty/issues/325
|
||||
if (list.isEmpty()) {
|
||||
|
@ -73,8 +73,8 @@ public class DynamicChannelBuffer extends AbstractChannelBuffer {
|
||||
int minNewCapacity = writerIndex() + minWritableBytes;
|
||||
while (newCapacity < minNewCapacity) {
|
||||
newCapacity <<= 1;
|
||||
|
||||
// Check if we exceeded the maximum size of 2gb if this is the case then
|
||||
|
||||
// Check if we exceeded the maximum size of 2gb if this is the case then
|
||||
// newCapacity == 0
|
||||
//
|
||||
// https://github.com/netty/netty/issues/258
|
||||
|
@ -359,11 +359,11 @@ public interface Channel extends Comparable<Channel> {
|
||||
* {@code interestOps} change request succeeds or fails
|
||||
*/
|
||||
ChannelFuture setReadable(boolean readable);
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves an object which is {@link #setAttachment(Object) attached} to
|
||||
* this {@link Channel}.
|
||||
*
|
||||
*
|
||||
* @return {@code null} if no object was attached or {@code null} was
|
||||
* attached
|
||||
*/
|
||||
|
@ -57,7 +57,7 @@ package org.jboss.netty.channel;
|
||||
* You will also find various helper methods in {@link Channels} to be useful
|
||||
* to generate and send an artificial or manipulated event.
|
||||
* <p>
|
||||
* <strong>Caution:</strong>
|
||||
* <strong>Caution:</strong>
|
||||
* <p>
|
||||
* Use the *Later(..) methods of the {@link Channels} class if you want to send an upstream event from a {@link ChannelDownstreamHandler} otherwise you may run into threading issues.
|
||||
*
|
||||
|
@ -460,7 +460,7 @@ public interface ChannelPipeline {
|
||||
* with this pipeline's {@link Channel}.
|
||||
*/
|
||||
ChannelFuture execute(Runnable task);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the {@link Channel} that this pipeline is attached to.
|
||||
*
|
||||
|
@ -38,7 +38,7 @@ public interface ChannelSink {
|
||||
* one of its {@link ChannelHandler}s process a {@link ChannelEvent}.
|
||||
*/
|
||||
void exceptionCaught(ChannelPipeline pipeline, ChannelEvent e, ChannelPipelineException cause) throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* Execute the given {@link Runnable} later in the io-thread.
|
||||
* Some implementation may not support this and just execute it directly.
|
||||
|
@ -304,15 +304,15 @@ public final class Channels {
|
||||
*/
|
||||
public static ChannelFuture fireWriteCompleteLater(final Channel channel, final long amount) {
|
||||
return channel.getPipeline().execute(new Runnable() {
|
||||
|
||||
|
||||
public void run() {
|
||||
fireWriteComplete(channel, amount);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sends a {@code "writeComplete"} event to the first
|
||||
* {@link ChannelUpstreamHandler} in the {@link ChannelPipeline} of
|
||||
@ -336,7 +336,7 @@ public final class Channels {
|
||||
public static void fireWriteComplete(ChannelHandlerContext ctx, long amount) {
|
||||
ctx.sendUpstream(new DefaultWriteCompletionEvent(ctx.getChannel(), amount));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sends a {@code "channelInterestChanged"} event to the first
|
||||
* {@link ChannelUpstreamHandler} in the {@link ChannelPipeline} of
|
||||
@ -344,14 +344,14 @@ public final class Channels {
|
||||
*/
|
||||
public static ChannelFuture fireChannelInterestChangedLater(final Channel channel) {
|
||||
return channel.getPipeline().execute(new Runnable() {
|
||||
|
||||
|
||||
public void run() {
|
||||
fireChannelInterestChanged(channel);
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sends a {@code "channelInterestChanged"} event to the first
|
||||
* {@link ChannelUpstreamHandler} in the {@link ChannelPipeline} of
|
||||
@ -384,7 +384,7 @@ public final class Channels {
|
||||
*/
|
||||
public static ChannelFuture fireChannelDisconnectedLater(final Channel channel) {
|
||||
return channel.getPipeline().execute(new Runnable() {
|
||||
|
||||
|
||||
public void run() {
|
||||
fireChannelDisconnected(channel);
|
||||
}
|
||||
@ -419,14 +419,14 @@ public final class Channels {
|
||||
*/
|
||||
public static ChannelFuture fireChannelUnboundLater(final Channel channel) {
|
||||
return channel.getPipeline().execute(new Runnable() {
|
||||
|
||||
|
||||
public void run() {
|
||||
fireChannelUnbound(channel);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sends a {@code "channelUnbound"} event to the first
|
||||
* {@link ChannelUpstreamHandler} in the {@link ChannelPipeline} of
|
||||
@ -449,8 +449,8 @@ public final class Channels {
|
||||
ctx.getChannel(), ChannelState.BOUND, null));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sends a {@code "channelClosed"} event to the first
|
||||
* {@link ChannelUpstreamHandler} in the {@link ChannelPipeline} of
|
||||
@ -458,15 +458,15 @@ public final class Channels {
|
||||
*/
|
||||
public static ChannelFuture fireChannelClosedLater(final Channel channel) {
|
||||
return channel.getPipeline().execute(new Runnable() {
|
||||
|
||||
|
||||
public void run() {
|
||||
fireChannelClosed(channel);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sends a {@code "channelClosed"} event to the first
|
||||
* {@link ChannelUpstreamHandler} in the {@link ChannelPipeline} of
|
||||
@ -502,7 +502,7 @@ public final class Channels {
|
||||
*/
|
||||
public static ChannelFuture fireExceptionCaughtLater(final Channel channel, final Throwable cause) {
|
||||
return channel.getPipeline().execute(new Runnable() {
|
||||
|
||||
|
||||
public void run() {
|
||||
fireExceptionCaught(channel, cause);
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ import java.net.SocketAddress;
|
||||
* }
|
||||
* }</pre>
|
||||
* <p>
|
||||
* <strong>Caution:</strong>
|
||||
* <strong>Caution:</strong>
|
||||
* <p>
|
||||
* Use the *Later(..) methods of the {@link Channels} class if you want to send an upstream event from a {@link ChannelDownstreamHandler} otherwise you may run into threading issues.
|
||||
*
|
||||
|
@ -146,7 +146,7 @@ public class SimpleChannelUpstreamHandler implements ChannelUpstreamHandler {
|
||||
/**
|
||||
* Invoked when a {@link Channel} is open, but not bound nor connected.
|
||||
* <br/>
|
||||
*
|
||||
*
|
||||
* <strong>Be aware that this event is fired from within the Boss-Thread so you should not execute any heavy operation in there as it will block the dispatching to other workers!</strong>
|
||||
*/
|
||||
public void channelOpen(
|
||||
@ -158,7 +158,7 @@ public class SimpleChannelUpstreamHandler implements ChannelUpstreamHandler {
|
||||
* Invoked when a {@link Channel} is open and bound to a local address,
|
||||
* but not connected.
|
||||
* <br/>
|
||||
*
|
||||
*
|
||||
* <strong>Be aware that this event is fired from within the Boss-Thread so you should not execute any heavy operation in there as it will block the dispatching to other workers!</strong>
|
||||
*/
|
||||
public void channelBound(
|
||||
@ -170,7 +170,7 @@ public class SimpleChannelUpstreamHandler implements ChannelUpstreamHandler {
|
||||
* Invoked when a {@link Channel} is open, bound to a local address, and
|
||||
* connected to a remote address.
|
||||
* <br/>
|
||||
*
|
||||
*
|
||||
* <strong>Be aware that this event is fired from within the Boss-Thread so you should not execute any heavy operation in there as it will block the dispatching to other workers!</strong>
|
||||
*/
|
||||
public void channelConnected(
|
||||
|
@ -22,13 +22,13 @@ public class ChannelRunnableWrapper extends DefaultChannelFuture implements Runn
|
||||
|
||||
private final Runnable task;
|
||||
private boolean started;
|
||||
|
||||
|
||||
public ChannelRunnableWrapper(Channel channel, Runnable task) {
|
||||
super(channel, true);
|
||||
this.task = task;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void run() {
|
||||
synchronized (this) {
|
||||
if (!isCancelled()) {
|
||||
@ -52,7 +52,7 @@ public class ChannelRunnableWrapper extends DefaultChannelFuture implements Runn
|
||||
}
|
||||
return super.cancel();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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.channel.socket;
|
||||
|
||||
/**
|
||||
* Internet Protocol (IP) families
|
||||
*/
|
||||
public enum InternetProtocolFamily {
|
||||
IPv4,
|
||||
IPv6;
|
||||
}
|
@ -18,14 +18,14 @@ package org.jboss.netty.channel.socket;
|
||||
|
||||
/**
|
||||
* A {@link Worker} is responsible to dispatch IO operations
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface Worker extends Runnable {
|
||||
|
||||
/**
|
||||
* Execute the given {@link Runnable} in the IO-Thread. This may be now or
|
||||
* later once the IO-Thread do some other work.
|
||||
*
|
||||
*
|
||||
* @param task
|
||||
* the {@link Runnable} to execute
|
||||
*/
|
||||
|
@ -35,7 +35,7 @@ public abstract class AbstractNioChannelSink extends AbstractChannelSink {
|
||||
return wrapper;
|
||||
}
|
||||
return super.execute(pipeline, task);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -17,18 +17,6 @@ package org.jboss.netty.channel.socket.nio;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelException;
|
||||
import org.jboss.netty.channel.ChannelFuture;
|
||||
import org.jboss.netty.channel.MessageEvent;
|
||||
import org.jboss.netty.channel.socket.Worker;
|
||||
import org.jboss.netty.channel.socket.nio.SocketSendBufferPool.SendBuffer;
|
||||
import org.jboss.netty.logging.InternalLogger;
|
||||
import org.jboss.netty.logging.InternalLoggerFactory;
|
||||
import org.jboss.netty.util.ThreadRenamingRunnable;
|
||||
import org.jboss.netty.util.internal.DeadLockProofWorker;
|
||||
import org.jboss.netty.util.internal.QueueFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.AsynchronousCloseException;
|
||||
import java.nio.channels.CancelledKeyException;
|
||||
@ -47,8 +35,20 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelException;
|
||||
import org.jboss.netty.channel.ChannelFuture;
|
||||
import org.jboss.netty.channel.MessageEvent;
|
||||
import org.jboss.netty.channel.socket.Worker;
|
||||
import org.jboss.netty.channel.socket.nio.SocketSendBufferPool.SendBuffer;
|
||||
import org.jboss.netty.logging.InternalLogger;
|
||||
import org.jboss.netty.logging.InternalLoggerFactory;
|
||||
import org.jboss.netty.util.ThreadRenamingRunnable;
|
||||
import org.jboss.netty.util.internal.DeadLockProofWorker;
|
||||
import org.jboss.netty.util.internal.QueueFactory;
|
||||
|
||||
abstract class AbstractNioWorker implements Worker {
|
||||
|
||||
|
||||
|
||||
private static final AtomicInteger nextId = new AtomicInteger();
|
||||
|
||||
@ -64,7 +64,7 @@ abstract class AbstractNioWorker implements Worker {
|
||||
|
||||
static final int CLEANUP_INTERVAL = 256; // XXX Hard-coded value, but won't need customization.
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Executor used to execute {@link Runnable}s such as channel registration
|
||||
* task.
|
||||
@ -117,7 +117,7 @@ abstract class AbstractNioWorker implements Worker {
|
||||
|
||||
private final Queue<Runnable> eventQueue = QueueFactory.createQueue(Runnable.class);
|
||||
|
||||
|
||||
|
||||
private volatile int cancelledKeys; // should use AtomicInteger but we just need approximation
|
||||
|
||||
protected final SocketSendBufferPool sendBufferPool = new SocketSendBufferPool();
|
||||
@ -132,16 +132,16 @@ abstract class AbstractNioWorker implements Worker {
|
||||
this.executor = executor;
|
||||
this.allowShutdownOnIdle = allowShutdownOnIdle;
|
||||
}
|
||||
|
||||
|
||||
void register(AbstractNioChannel<?> channel, ChannelFuture future) {
|
||||
|
||||
Runnable registerTask = createRegisterTask(channel, future);
|
||||
Selector selector = start();
|
||||
|
||||
|
||||
|
||||
boolean offered = registerTaskQueue.offer(registerTask);
|
||||
assert offered;
|
||||
|
||||
|
||||
if (wakenUp.compareAndSet(false, true)) {
|
||||
selector.wakeup();
|
||||
}
|
||||
@ -149,7 +149,7 @@ abstract class AbstractNioWorker implements Worker {
|
||||
|
||||
/**
|
||||
* Start the {@link AbstractNioWorker} and return the {@link Selector} that will be used for the {@link AbstractNioChannel}'s when they get registered
|
||||
*
|
||||
*
|
||||
* @return selector
|
||||
*/
|
||||
private Selector start() {
|
||||
@ -157,7 +157,7 @@ abstract class AbstractNioWorker implements Worker {
|
||||
if (!started) {
|
||||
// Open a selector if this worker didn't start yet.
|
||||
try {
|
||||
this.selector = Selector.open();
|
||||
selector = Selector.open();
|
||||
} catch (Throwable t) {
|
||||
throw new ChannelException("Failed to create a selector.", t);
|
||||
}
|
||||
@ -175,7 +175,7 @@ abstract class AbstractNioWorker implements Worker {
|
||||
} catch (Throwable t) {
|
||||
logger.warn("Failed to close a selector.", t);
|
||||
}
|
||||
this.selector = null;
|
||||
selector = null;
|
||||
// The method will return to the caller at this point.
|
||||
}
|
||||
}
|
||||
@ -297,10 +297,10 @@ abstract class AbstractNioWorker implements Worker {
|
||||
public void executeInIoThread(Runnable task) {
|
||||
executeInIoThread(task, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute the {@link Runnable} in a IO-Thread
|
||||
*
|
||||
*
|
||||
* @param task
|
||||
* the {@link Runnable} to execute
|
||||
* @param alwaysAsync
|
||||
@ -325,8 +325,8 @@ abstract class AbstractNioWorker implements Worker {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void processRegisterTaskQueue() throws IOException {
|
||||
for (;;) {
|
||||
final Runnable task = registerTaskQueue.poll();
|
||||
@ -350,7 +350,7 @@ abstract class AbstractNioWorker implements Worker {
|
||||
cleanUpCancelledKeys();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void processEventQueue() throws IOException {
|
||||
for (;;) {
|
||||
final Runnable task = eventQueue.poll();
|
||||
@ -361,7 +361,7 @@ abstract class AbstractNioWorker implements Worker {
|
||||
cleanUpCancelledKeys();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void processSelectedKeys(Set<SelectionKey> selectedKeys) throws IOException {
|
||||
for (Iterator<SelectionKey> i = selectedKeys.iterator(); i.hasNext();) {
|
||||
SelectionKey k = i.next();
|
||||
@ -395,9 +395,9 @@ abstract class AbstractNioWorker implements Worker {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void close(SelectionKey k) {
|
||||
AbstractNioChannel<?> ch = (AbstractNioChannel<?>) k.attachment();
|
||||
close(ch, succeededFuture(ch));
|
||||
@ -431,7 +431,7 @@ abstract class AbstractNioWorker implements Worker {
|
||||
write0(ch);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void writeFromSelectorLoop(final SelectionKey k) {
|
||||
AbstractNioChannel<?> ch = (AbstractNioChannel<?>) k.attachment();
|
||||
ch.writeSuspended = false;
|
||||
@ -552,7 +552,7 @@ abstract class AbstractNioWorker implements Worker {
|
||||
static boolean isIoThread(AbstractNioChannel<?> channel) {
|
||||
return Thread.currentThread() == channel.worker.thread;
|
||||
}
|
||||
|
||||
|
||||
protected void setOpWrite(AbstractNioChannel<?> channel) {
|
||||
Selector selector = this.selector;
|
||||
SelectionKey key = channel.channel.keyFor(selector);
|
||||
@ -598,13 +598,13 @@ abstract class AbstractNioWorker implements Worker {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void close(AbstractNioChannel<?> channel, ChannelFuture future) {
|
||||
boolean connected = channel.isConnected();
|
||||
boolean bound = channel.isBound();
|
||||
boolean iothread = isIoThread(channel);
|
||||
|
||||
|
||||
try {
|
||||
channel.channel.close();
|
||||
cancelledKeys ++;
|
||||
@ -688,7 +688,7 @@ abstract class AbstractNioWorker implements Worker {
|
||||
}
|
||||
evt.getFuture().setFailure(cause);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -714,16 +714,16 @@ abstract class AbstractNioWorker implements Worker {
|
||||
// Override OP_WRITE flag - a user cannot change this flag.
|
||||
interestOps &= ~Channel.OP_WRITE;
|
||||
interestOps |= channel.getRawInterestOps() & Channel.OP_WRITE;
|
||||
|
||||
|
||||
if (key == null || selector == null) {
|
||||
if (channel.getRawInterestOps() != interestOps) {
|
||||
changed = true;
|
||||
}
|
||||
|
||||
|
||||
// Not registered to the worker yet.
|
||||
// Set the rawInterestOps immediately; RegisterTask will pick it up.
|
||||
channel.setRawInterestOpsNow(interestOps);
|
||||
|
||||
|
||||
future.setSuccess();
|
||||
if (changed) {
|
||||
if (iothread) {
|
||||
@ -732,7 +732,7 @@ abstract class AbstractNioWorker implements Worker {
|
||||
fireChannelInterestChangedLater(channel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -802,7 +802,7 @@ abstract class AbstractNioWorker implements Worker {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read is called when a Selector has been notified that the underlying channel
|
||||
* was something to be read. The channel would previously have registered its interest
|
||||
@ -814,11 +814,11 @@ abstract class AbstractNioWorker implements Worker {
|
||||
|
||||
/**
|
||||
* Create a new {@link Runnable} which will register the {@link AbstractNioWorker} with the {@link Channel}
|
||||
*
|
||||
*
|
||||
* @param channel
|
||||
* @param future
|
||||
* @return task
|
||||
*/
|
||||
protected abstract Runnable createRegisterTask(AbstractNioChannel<?> channel, ChannelFuture future);
|
||||
|
||||
|
||||
}
|
||||
|
@ -16,14 +16,14 @@
|
||||
|
||||
package org.jboss.netty.channel.socket.nio;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.socket.Worker;
|
||||
import org.jboss.netty.util.ExternalResourceReleasable;
|
||||
import org.jboss.netty.util.internal.ExecutorUtil;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* Abstract base class for {@link WorkerPool} implementations that create the {@link Worker}'s up-front and return them in a "fair" fashion when calling
|
||||
* {@link #nextWorker()}
|
||||
@ -34,10 +34,10 @@ public abstract class AbstractNioWorkerPool<E extends AbstractNioWorker> impleme
|
||||
private final AbstractNioWorker[] workers;
|
||||
private final AtomicInteger workerIndex = new AtomicInteger();
|
||||
private final Executor workerExecutor;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new instance
|
||||
*
|
||||
*
|
||||
* @param workerExecutor the {@link Executor} to use for the {@link Worker}'s
|
||||
* @param allowShutdownOnIdle allow the {@link Worker}'s to shutdown when there is not {@link Channel} is registered with it
|
||||
* @param workerCount the count of {@link Worker}'s to create
|
||||
@ -50,7 +50,7 @@ public abstract class AbstractNioWorkerPool<E extends AbstractNioWorker> impleme
|
||||
throw new IllegalArgumentException(
|
||||
"workerCount (" + workerCount + ") " +
|
||||
"must be a positive integer.");
|
||||
}
|
||||
}
|
||||
workers = new AbstractNioWorker[workerCount];
|
||||
|
||||
for (int i = 0; i < workers.length; i++) {
|
||||
@ -62,11 +62,11 @@ public abstract class AbstractNioWorkerPool<E extends AbstractNioWorker> impleme
|
||||
|
||||
/**
|
||||
* Create a new {@link Worker} which uses the given {@link Executor} to service IO
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param executor the {@link Executor} to use
|
||||
* @param allowShutdownOnIdle allow the {@link Worker} to shutdown when there is not {@link Channel} is registered with it
|
||||
* @return worker the new {@link Worker}
|
||||
* @return worker the new {@link Worker}
|
||||
*/
|
||||
protected abstract E createWorker(Executor executor, boolean allowShutdownOnIdle);
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.jboss.netty.channel.socket.nio;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.fireChannelOpen;
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
import java.nio.channels.SocketChannel;
|
||||
|
||||
@ -38,7 +38,7 @@ final class NioAcceptedSocketChannel extends NioSocketChannel {
|
||||
this.bossThread = bossThread;
|
||||
|
||||
setConnected();
|
||||
|
||||
|
||||
fireChannelOpen(this);
|
||||
}
|
||||
}
|
||||
|
@ -88,14 +88,14 @@ public class NioClientSocketChannelFactory implements ClientSocketChannelFactory
|
||||
private final NioClientSocketPipelineSink sink;
|
||||
|
||||
/**
|
||||
* Creates a new {@link NioClientSocketChannelFactory} which uses {@link Executors#newCachedThreadPool()} for the worker and boss executors.
|
||||
*
|
||||
* Creates a new {@link NioClientSocketChannelFactory} which uses {@link Executors#newCachedThreadPool()} for the worker and boss executors.
|
||||
*
|
||||
* See {@link #NioClientSocketChannelFactory(Executor, Executor)}
|
||||
*/
|
||||
public NioClientSocketChannelFactory() {
|
||||
this(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance. Calling this constructor is same with calling
|
||||
* {@link #NioClientSocketChannelFactory(Executor, Executor, int, int)} with
|
||||
@ -163,7 +163,7 @@ public class NioClientSocketChannelFactory implements ClientSocketChannelFactory
|
||||
"bossCount (" + bossCount + ") " +
|
||||
"must be a positive integer.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
this.bossExecutor = bossExecutor;
|
||||
this.workerPool = workerPool;
|
||||
|
@ -38,6 +38,7 @@ import org.jboss.netty.channel.ChannelPipeline;
|
||||
import org.jboss.netty.channel.ChannelSink;
|
||||
import org.jboss.netty.channel.Channels;
|
||||
import org.jboss.netty.channel.socket.DatagramChannelConfig;
|
||||
import org.jboss.netty.channel.socket.InternetProtocolFamily;
|
||||
import org.jboss.netty.util.internal.DetectionUtil;
|
||||
|
||||
/**
|
||||
@ -46,34 +47,15 @@ import org.jboss.netty.util.internal.DetectionUtil;
|
||||
public final class NioDatagramChannel extends AbstractNioChannel<DatagramChannel>
|
||||
implements org.jboss.netty.channel.socket.DatagramChannel {
|
||||
|
||||
/**
|
||||
* The supported ProtocolFamily by UDP
|
||||
*
|
||||
*/
|
||||
public enum ProtocolFamily {
|
||||
INET,
|
||||
INET6
|
||||
}
|
||||
|
||||
/**
|
||||
* The {@link DatagramChannelConfig}.
|
||||
*/
|
||||
private final NioDatagramChannelConfig config;
|
||||
private Map<InetAddress, List<MembershipKey>> memberships;
|
||||
|
||||
/**
|
||||
* Use {@link #NioDatagramChannel(ChannelFactory, ChannelPipeline, ChannelSink, NioDatagramWorker, ProtocolFamily)}
|
||||
*/
|
||||
@Deprecated
|
||||
NioDatagramChannel(final ChannelFactory factory,
|
||||
final ChannelPipeline pipeline, final ChannelSink sink,
|
||||
final NioDatagramWorker worker) {
|
||||
this(factory, pipeline, sink, worker, null);
|
||||
}
|
||||
|
||||
NioDatagramChannel(final ChannelFactory factory,
|
||||
final ChannelPipeline pipeline, final ChannelSink sink,
|
||||
final NioDatagramWorker worker, ProtocolFamily family) {
|
||||
final NioDatagramWorker worker, InternetProtocolFamily family) {
|
||||
super(null, factory, pipeline, sink, worker, openNonBlockingChannel(family));
|
||||
config = new DefaultNioDatagramChannelConfig(channel);
|
||||
|
||||
@ -81,7 +63,7 @@ public final class NioDatagramChannel extends AbstractNioChannel<DatagramChannel
|
||||
|
||||
}
|
||||
|
||||
private static DatagramChannel openNonBlockingChannel(ProtocolFamily family) {
|
||||
private static DatagramChannel openNonBlockingChannel(InternetProtocolFamily family) {
|
||||
try {
|
||||
final DatagramChannel channel;
|
||||
|
||||
@ -95,11 +77,11 @@ public final class NioDatagramChannel extends AbstractNioChannel<DatagramChannel
|
||||
//
|
||||
// See #368
|
||||
switch (family) {
|
||||
case INET:
|
||||
case IPv4:
|
||||
channel = DatagramChannel.open(ProtocolFamilyConverter.convert(family));
|
||||
break;
|
||||
|
||||
case INET6:
|
||||
case IPv6:
|
||||
channel = DatagramChannel.open(ProtocolFamilyConverter.convert(family));
|
||||
break;
|
||||
|
||||
|
@ -24,8 +24,8 @@ import org.jboss.netty.channel.ChannelPipeline;
|
||||
import org.jboss.netty.channel.group.ChannelGroup;
|
||||
import org.jboss.netty.channel.socket.DatagramChannel;
|
||||
import org.jboss.netty.channel.socket.DatagramChannelFactory;
|
||||
import org.jboss.netty.channel.socket.InternetProtocolFamily;
|
||||
import org.jboss.netty.channel.socket.Worker;
|
||||
import org.jboss.netty.channel.socket.nio.NioDatagramChannel.ProtocolFamily;
|
||||
import org.jboss.netty.channel.socket.oio.OioDatagramChannelFactory;
|
||||
import org.jboss.netty.util.ExternalResourceReleasable;
|
||||
|
||||
@ -80,14 +80,16 @@ public class NioDatagramChannelFactory implements DatagramChannelFactory {
|
||||
|
||||
private final NioDatagramPipelineSink sink;
|
||||
private final WorkerPool<NioDatagramWorker> workerPool;
|
||||
private final NioDatagramChannel.ProtocolFamily family;
|
||||
private final InternetProtocolFamily family;
|
||||
|
||||
/**
|
||||
* Create a new {@link NioDatagramChannelFactory} with a {@link Executors#newCachedThreadPool()}.
|
||||
* Create a new {@link NioDatagramChannelFactory} with a {@link Executors#newCachedThreadPool()}
|
||||
* and without preferred {@link InternetProtocolFamily}. Please note that the {@link InternetProtocolFamily}
|
||||
* of the channel will be platform (and possibly configuration) dependent and therefore
|
||||
* unspecified. Use {@link #NioDatagramChannelFactory(InternetProtocolFamily)} if unsure.
|
||||
*
|
||||
* See {@link #NioDatagramChannelFactory(Executor)}
|
||||
*/
|
||||
@Deprecated
|
||||
public NioDatagramChannelFactory() {
|
||||
this(Executors.newCachedThreadPool(), null);
|
||||
}
|
||||
@ -97,7 +99,7 @@ public class NioDatagramChannelFactory implements DatagramChannelFactory {
|
||||
*
|
||||
* See {@link #NioDatagramChannelFactory(Executor)}
|
||||
*/
|
||||
public NioDatagramChannelFactory(ProtocolFamily family) {
|
||||
public NioDatagramChannelFactory(InternetProtocolFamily family) {
|
||||
this(Executors.newCachedThreadPool(), family);
|
||||
}
|
||||
|
||||
@ -106,35 +108,44 @@ public class NioDatagramChannelFactory implements DatagramChannelFactory {
|
||||
* {@link #NioDatagramChannelFactory(Executor, int)} with 2 * the number of
|
||||
* available processors in the machine. The number of available processors
|
||||
* is obtained by {@link Runtime#availableProcessors()}.
|
||||
* <p>
|
||||
* Please note that the {@link InternetProtocolFamily} of the channel will be platform (and possibly
|
||||
* configuration) dependent and therefore unspecified.
|
||||
* Use {@link #NioDatagramChannelFactory(Executor, InternetProtocolFamily)} if unsure.
|
||||
*
|
||||
* @param workerExecutor
|
||||
* the {@link Executor} which will execute the I/O worker threads
|
||||
*/
|
||||
@Deprecated
|
||||
public NioDatagramChannelFactory(final Executor workerExecutor) {
|
||||
this(workerExecutor, SelectorUtil.DEFAULT_IO_THREADS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
* <p>
|
||||
* Please note that the {@link InternetProtocolFamily} of the channel will be platform (and possibly
|
||||
* configuration) dependent and therefore unspecified.
|
||||
* Use {@link #NioDatagramChannelFactory(Executor, int, InternetProtocolFamily)} if unsure.
|
||||
*
|
||||
* @param workerExecutor
|
||||
* the {@link Executor} which will execute the I/O worker threads
|
||||
* @param workerCount
|
||||
* the maximum number of I/O worker threads
|
||||
*/
|
||||
@Deprecated
|
||||
public NioDatagramChannelFactory(final Executor workerExecutor, final int workerCount) {
|
||||
this(new NioDatagramWorkerPool(workerExecutor, workerCount, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
* <p>
|
||||
* Please note that the {@link InternetProtocolFamily} of the channel will be platform (and possibly
|
||||
* configuration) dependent and therefore unspecified.
|
||||
* 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
|
||||
*/
|
||||
@Deprecated
|
||||
public NioDatagramChannelFactory(WorkerPool<NioDatagramWorker> workerPool) {
|
||||
this(workerPool, null);
|
||||
}
|
||||
@ -148,10 +159,10 @@ public class NioDatagramChannelFactory implements DatagramChannelFactory {
|
||||
* @param workerExecutor
|
||||
* the {@link Executor} which will execute the I/O worker threads
|
||||
* @param family
|
||||
* the {@link ProtocolFamily} to use. This should be used for UDP multicast.
|
||||
* 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>
|
||||
*/
|
||||
public NioDatagramChannelFactory(final Executor workerExecutor, ProtocolFamily family) {
|
||||
public NioDatagramChannelFactory(final Executor workerExecutor, InternetProtocolFamily family) {
|
||||
this(workerExecutor, SelectorUtil.DEFAULT_IO_THREADS, family);
|
||||
}
|
||||
|
||||
@ -163,11 +174,11 @@ public class NioDatagramChannelFactory implements DatagramChannelFactory {
|
||||
* @param workerCount
|
||||
* the maximum number of I/O worker threads
|
||||
* @param family
|
||||
* the {@link ProtocolFamily} to use. This should be used for UDP multicast.
|
||||
* 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>
|
||||
*/
|
||||
public NioDatagramChannelFactory(final Executor workerExecutor,
|
||||
final int workerCount, ProtocolFamily family) {
|
||||
final int workerCount, InternetProtocolFamily family) {
|
||||
this(new NioDatagramWorkerPool(workerExecutor, workerCount, true), family);
|
||||
}
|
||||
|
||||
@ -177,10 +188,10 @@ public class NioDatagramChannelFactory implements DatagramChannelFactory {
|
||||
* @param workerPool
|
||||
* the {@link WorkerPool} which will be used to obtain the {@link Worker} that execute the I/O worker threads
|
||||
* @param family
|
||||
* the {@link ProtocolFamily} to use. This should be used for UDP multicast.
|
||||
* 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>
|
||||
*/
|
||||
public NioDatagramChannelFactory(WorkerPool<NioDatagramWorker> workerPool, ProtocolFamily family) {
|
||||
public NioDatagramChannelFactory(WorkerPool<NioDatagramWorker> workerPool, InternetProtocolFamily family) {
|
||||
this.workerPool = workerPool;
|
||||
this.family = family;
|
||||
sink = new NioDatagramPipelineSink(workerPool);
|
||||
|
@ -15,18 +15,7 @@
|
||||
*/
|
||||
package org.jboss.netty.channel.socket.nio;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.fireChannelDisconnected;
|
||||
import static org.jboss.netty.channel.Channels.fireChannelDisconnectedLater;
|
||||
import static org.jboss.netty.channel.Channels.fireExceptionCaught;
|
||||
import static org.jboss.netty.channel.Channels.fireExceptionCaughtLater;
|
||||
import static org.jboss.netty.channel.Channels.fireMessageReceived;
|
||||
import static org.jboss.netty.channel.Channels.succeededFuture;
|
||||
import org.jboss.netty.buffer.ChannelBufferFactory;
|
||||
import org.jboss.netty.channel.ChannelException;
|
||||
import org.jboss.netty.channel.ChannelFuture;
|
||||
import org.jboss.netty.channel.Channels;
|
||||
import org.jboss.netty.channel.MessageEvent;
|
||||
import org.jboss.netty.channel.ReceiveBufferSizePredictor;
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.SocketAddress;
|
||||
@ -39,6 +28,13 @@ import java.nio.channels.Selector;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.jboss.netty.buffer.ChannelBufferFactory;
|
||||
import org.jboss.netty.channel.ChannelException;
|
||||
import org.jboss.netty.channel.ChannelFuture;
|
||||
import org.jboss.netty.channel.Channels;
|
||||
import org.jboss.netty.channel.MessageEvent;
|
||||
import org.jboss.netty.channel.ReceiveBufferSizePredictor;
|
||||
|
||||
/**
|
||||
* A class responsible for registering channels with {@link Selector}.
|
||||
* It also implements the {@link Selector} loop.
|
||||
@ -58,7 +54,7 @@ public class NioDatagramWorker extends AbstractNioWorker {
|
||||
NioDatagramWorker(final Executor executor, boolean allowShutdownOnIdle) {
|
||||
super(executor, allowShutdownOnIdle);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean read(final SelectionKey key) {
|
||||
final NioDatagramChannel channel = (NioDatagramChannel) key.attachment();
|
||||
@ -110,7 +106,7 @@ public class NioDatagramWorker extends AbstractNioWorker {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean scheduleWriteIfNecessary(final AbstractNioChannel<?> channel) {
|
||||
@ -163,7 +159,7 @@ public class NioDatagramWorker extends AbstractNioWorker {
|
||||
protected Runnable createRegisterTask(AbstractNioChannel<?> channel, ChannelFuture future) {
|
||||
return new ChannelRegistionTask((NioDatagramChannel) channel, future);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* RegisterTask is a task responsible for registering a channel with a
|
||||
* selector.
|
||||
@ -206,7 +202,7 @@ public class NioDatagramWorker extends AbstractNioWorker {
|
||||
future.setFailure(e);
|
||||
}
|
||||
close(channel, succeededFuture(channel));
|
||||
|
||||
|
||||
if (!(e instanceof ClosedChannelException)) {
|
||||
throw new ChannelException(
|
||||
"Failed to register a socket to the selector.", e);
|
||||
@ -214,7 +210,7 @@ public class NioDatagramWorker extends AbstractNioWorker {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeFromUserCode(final AbstractNioChannel<?> channel) {
|
||||
/*
|
||||
@ -243,7 +239,7 @@ public class NioDatagramWorker extends AbstractNioWorker {
|
||||
|
||||
write0(channel);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void write0(final AbstractNioChannel<?> channel) {
|
||||
|
||||
|
@ -20,7 +20,7 @@ import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* Default implementation which hands of {@link NioDatagramWorker}'s
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class NioDatagramWorkerPool extends AbstractNioWorkerPool<NioDatagramWorker> {
|
||||
|
@ -90,14 +90,14 @@ public class NioServerSocketChannelFactory implements ServerSocketChannelFactory
|
||||
private final ChannelSink sink;
|
||||
|
||||
/**
|
||||
* Create a new {@link NioServerSocketChannelFactory} using {@link Executors#newCachedThreadPool()} for the boss and worker.
|
||||
*
|
||||
* Create a new {@link NioServerSocketChannelFactory} using {@link Executors#newCachedThreadPool()} for the boss and worker.
|
||||
*
|
||||
* See {@link #NioServerSocketChannelFactory(Executor, Executor)}
|
||||
*/
|
||||
public NioServerSocketChannelFactory() {
|
||||
this(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance. Calling this constructor is same with calling
|
||||
* {@link #NioServerSocketChannelFactory(Executor, Executor, int)} with 2 *
|
||||
@ -146,7 +146,7 @@ public class NioServerSocketChannelFactory implements ServerSocketChannelFactory
|
||||
if (workerPool == null) {
|
||||
throw new NullPointerException("workerPool");
|
||||
}
|
||||
|
||||
|
||||
this.bossExecutor = bossExecutor;
|
||||
this.workerPool = workerPool;
|
||||
sink = new NioServerSocketPipelineSink(workerPool);
|
||||
|
@ -15,16 +15,7 @@
|
||||
*/
|
||||
package org.jboss.netty.channel.socket.nio;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.fireChannelBound;
|
||||
import static org.jboss.netty.channel.Channels.fireChannelConnected;
|
||||
import static org.jboss.netty.channel.Channels.fireExceptionCaught;
|
||||
import static org.jboss.netty.channel.Channels.fireMessageReceived;
|
||||
import static org.jboss.netty.channel.Channels.succeededFuture;
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
import org.jboss.netty.buffer.ChannelBufferFactory;
|
||||
import org.jboss.netty.channel.ChannelException;
|
||||
import org.jboss.netty.channel.ChannelFuture;
|
||||
import org.jboss.netty.channel.ReceiveBufferSizePredictor;
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.SocketAddress;
|
||||
@ -35,6 +26,12 @@ import java.nio.channels.Selector;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
import org.jboss.netty.buffer.ChannelBufferFactory;
|
||||
import org.jboss.netty.channel.ChannelException;
|
||||
import org.jboss.netty.channel.ChannelFuture;
|
||||
import org.jboss.netty.channel.ReceiveBufferSizePredictor;
|
||||
|
||||
public class NioWorker extends AbstractNioWorker {
|
||||
|
||||
private final SocketReceiveBufferPool recvBufferPool = new SocketReceiveBufferPool();
|
||||
@ -42,7 +39,7 @@ public class NioWorker extends AbstractNioWorker {
|
||||
public NioWorker(Executor executor) {
|
||||
super(executor);
|
||||
}
|
||||
|
||||
|
||||
public NioWorker(Executor executor, boolean allowShutdownOnIdle) {
|
||||
super(executor, allowShutdownOnIdle);
|
||||
}
|
||||
@ -141,13 +138,13 @@ public class NioWorker extends AbstractNioWorker {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Runnable createRegisterTask(AbstractNioChannel<?> channel, ChannelFuture future) {
|
||||
boolean server = !(channel instanceof NioClientSocketChannel);
|
||||
return new RegisterTask((NioSocketChannel) channel, future, server);
|
||||
}
|
||||
|
||||
|
||||
private final class RegisterTask implements Runnable {
|
||||
private final NioSocketChannel channel;
|
||||
private final ChannelFuture future;
|
||||
@ -186,7 +183,7 @@ public class NioWorker extends AbstractNioWorker {
|
||||
channel.setConnected();
|
||||
future.setSuccess();
|
||||
}
|
||||
|
||||
|
||||
if (server || !((NioClientSocketChannel) channel).boundManually) {
|
||||
fireChannelBound(channel, localAddress);
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* Default implementation which hands of {@link NioWorker}'s
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class NioWorkerPool extends AbstractNioWorkerPool<NioWorker> {
|
||||
|
@ -15,12 +15,13 @@
|
||||
*/
|
||||
package org.jboss.netty.channel.socket.nio;
|
||||
|
||||
import java.net.ProtocolFamily;
|
||||
import org.jboss.netty.channel.socket.InternetProtocolFamily;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Helper class which convert the {@link ProtocolFamily}.
|
||||
*
|
||||
* Helper class which convert the {@link InternetProtocolFamily}.
|
||||
*
|
||||
*
|
||||
*/
|
||||
final class ProtocolFamilyConverter {
|
||||
@ -28,16 +29,16 @@ final class ProtocolFamilyConverter {
|
||||
private ProtocolFamilyConverter() {
|
||||
// Utility class
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert the {@link NioDatagramChannel.ProtocolFamily}. This MUST only be called on jdk version >= 7.
|
||||
* Convert the {@link InternetProtocolFamily}. This MUST only be called on jdk version >= 7.
|
||||
*/
|
||||
public static ProtocolFamily convert(NioDatagramChannel.ProtocolFamily family) {
|
||||
public static java.net.ProtocolFamily convert(InternetProtocolFamily family) {
|
||||
switch (family) {
|
||||
case INET:
|
||||
case IPv4:
|
||||
return java.net.StandardProtocolFamily.INET;
|
||||
|
||||
case INET6:
|
||||
case IPv6:
|
||||
return java.net.StandardProtocolFamily.INET6;
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
|
@ -21,8 +21,8 @@ import org.jboss.netty.util.ExternalResourceReleasable;
|
||||
/**
|
||||
* This implementation of a {@link WorkerPool} should be used if you plan to share a {@link WorkerPool} between different Factories. You will need to call {@link #destroy()} by your own once
|
||||
* you want to release any resources of it.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public final class ShareableWorkerPool<E extends Worker> implements WorkerPool<E> {
|
||||
|
||||
|
@ -72,7 +72,7 @@ final class SocketSendBufferPool {
|
||||
if (src instanceof CompositeChannelBuffer && DetectionUtil.javaVersion() >= 7) {
|
||||
return new GatheringSendBuffer(src.toByteBuffers());
|
||||
}
|
||||
|
||||
|
||||
if (src.isDirect()) {
|
||||
return new UnpooledSendBuffer(src.toByteBuffer());
|
||||
}
|
||||
@ -257,7 +257,7 @@ final class SocketSendBufferPool {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class GatheringSendBuffer implements SendBuffer {
|
||||
|
||||
private final ByteBuffer[] buffers;
|
||||
@ -267,14 +267,14 @@ final class SocketSendBufferPool {
|
||||
|
||||
GatheringSendBuffer(ByteBuffer[] buffers) {
|
||||
this.buffers = buffers;
|
||||
this.last = buffers.length - 1;
|
||||
last = buffers.length - 1;
|
||||
int total = 0;
|
||||
for (ByteBuffer buf: buffers) {
|
||||
total += buf.remaining();
|
||||
}
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
|
||||
public boolean finished() {
|
||||
return !buffers[last].hasRemaining();
|
||||
}
|
||||
@ -329,7 +329,7 @@ final class SocketSendBufferPool {
|
||||
public void release() {
|
||||
// nothing todo
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
final class FileSendBuffer implements SendBuffer {
|
||||
|
@ -26,10 +26,10 @@ public interface WorkerPool<E extends Worker> {
|
||||
|
||||
/**
|
||||
* Return the next {@link Worker} to use
|
||||
*
|
||||
*
|
||||
* @return worker
|
||||
*/
|
||||
E nextWorker();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -37,10 +37,10 @@ public abstract class AbstractOioChannelSink extends AbstractChannelSink {
|
||||
channel.worker.executeInIoThread(wrapper);
|
||||
return wrapper;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return super.execute(pipeline, task);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -16,15 +16,16 @@
|
||||
package org.jboss.netty.channel.socket.oio;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Queue;
|
||||
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelFuture;
|
||||
import org.jboss.netty.channel.Channels;
|
||||
import org.jboss.netty.channel.socket.Worker;
|
||||
import org.jboss.netty.util.internal.QueueFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Queue;
|
||||
|
||||
/**
|
||||
* Abstract base class for Oio-Worker implementations
|
||||
*
|
||||
@ -33,7 +34,7 @@ import java.util.Queue;
|
||||
abstract class AbstractOioWorker<C extends AbstractOioChannel> implements Worker {
|
||||
|
||||
private final Queue<Runnable> eventQueue = QueueFactory.createQueue(Runnable.class);
|
||||
|
||||
|
||||
protected final C channel;
|
||||
|
||||
/**
|
||||
@ -41,15 +42,15 @@ abstract class AbstractOioWorker<C extends AbstractOioChannel> implements Worker
|
||||
* used when starting. i.e. the current thread when the run method is executed.
|
||||
*/
|
||||
protected volatile Thread thread;
|
||||
|
||||
|
||||
private volatile boolean done;
|
||||
|
||||
|
||||
public AbstractOioWorker(C channel) {
|
||||
this.channel = channel;
|
||||
channel.worker = this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void run() {
|
||||
thread = channel.workerThread = Thread.currentThread();
|
||||
|
||||
@ -67,7 +68,7 @@ abstract class AbstractOioWorker<C extends AbstractOioChannel> implements Worker
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boolean cont = false;
|
||||
try {
|
||||
cont = process();
|
||||
@ -77,7 +78,7 @@ abstract class AbstractOioWorker<C extends AbstractOioChannel> implements Worker
|
||||
}
|
||||
} finally {
|
||||
processEventQueue();
|
||||
|
||||
|
||||
if (!cont) {
|
||||
break;
|
||||
}
|
||||
@ -90,37 +91,37 @@ abstract class AbstractOioWorker<C extends AbstractOioChannel> implements Worker
|
||||
|
||||
// Clean up.
|
||||
close(channel, succeededFuture(channel), true);
|
||||
|
||||
|
||||
// Mark the worker event loop as done so we know that we need to run tasks directly and not queue them
|
||||
// See #287
|
||||
done = true;
|
||||
|
||||
|
||||
// just to make we don't have something left
|
||||
processEventQueue();
|
||||
|
||||
}
|
||||
|
||||
|
||||
static boolean isIoThread(AbstractOioChannel channel) {
|
||||
return Thread.currentThread() == channel.workerThread;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void executeInIoThread(Runnable task) {
|
||||
// check if the current thread is the worker thread
|
||||
//
|
||||
// Also check if the event loop of the worker is complete. If so we need to run the task now.
|
||||
// Also check if the event loop of the worker is complete. If so we need to run the task now.
|
||||
// See #287
|
||||
if (Thread.currentThread() == thread || done) {
|
||||
task.run();
|
||||
} else {
|
||||
boolean added = eventQueue.offer(task);
|
||||
|
||||
|
||||
if (added) {
|
||||
// as we set the SO_TIMEOUT to 1 second this task will get picked up in 1 second at latest
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void processEventQueue() {
|
||||
for (;;) {
|
||||
final Runnable task = eventQueue.poll();
|
||||
@ -130,21 +131,21 @@ abstract class AbstractOioWorker<C extends AbstractOioChannel> implements Worker
|
||||
task.run();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Process the incoming messages and also is responsible for call {@link Channels#fireMessageReceived(Channel, Object)} once a message
|
||||
* was processed without errors.
|
||||
*
|
||||
* was processed without errors.
|
||||
*
|
||||
* @return continue returns <code>true</code> as long as this worker should continue to try processing incoming messages
|
||||
* @throws IOException
|
||||
*/
|
||||
abstract boolean process() throws IOException;
|
||||
|
||||
|
||||
static void setInterestOps(
|
||||
AbstractOioChannel channel, ChannelFuture future, int interestOps) {
|
||||
boolean iothread = isIoThread(channel);
|
||||
|
||||
|
||||
// Override OP_WRITE flag - a user cannot change this flag.
|
||||
interestOps &= ~Channel.OP_WRITE;
|
||||
interestOps |= channel.getInterestOps() & Channel.OP_WRITE;
|
||||
@ -187,15 +188,15 @@ abstract class AbstractOioWorker<C extends AbstractOioChannel> implements Worker
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void close(AbstractOioChannel channel, ChannelFuture future) {
|
||||
close(channel, future, isIoThread(channel));
|
||||
}
|
||||
|
||||
|
||||
private static void close(AbstractOioChannel channel, ChannelFuture future, boolean iothread) {
|
||||
boolean connected = channel.isConnected();
|
||||
boolean bound = channel.isBound();
|
||||
|
||||
|
||||
try {
|
||||
channel.closeSocket();
|
||||
if (channel.setClosed()) {
|
||||
|
@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.jboss.netty.channel.socket.oio;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.fireChannelBound;
|
||||
import static org.jboss.netty.channel.Channels.fireChannelOpen;
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
@ -53,7 +52,7 @@ class OioAcceptedSocketChannel extends OioSocketChannel {
|
||||
} catch (IOException e) {
|
||||
throw new ChannelException("Failed to obtain an OutputStream.", e);
|
||||
}
|
||||
|
||||
|
||||
fireChannelOpen(this);
|
||||
fireChannelBound(this, getLocalAddress());
|
||||
}
|
||||
|
@ -78,14 +78,14 @@ public class OioClientSocketChannelFactory implements ClientSocketChannelFactory
|
||||
final OioClientSocketPipelineSink sink;
|
||||
|
||||
/**
|
||||
* Creates a new instance with a {@link Executors#newCachedThreadPool()} as worker executor.
|
||||
*
|
||||
* Creates a new instance with a {@link Executors#newCachedThreadPool()} as worker executor.
|
||||
*
|
||||
* See {@link #OioClientSocketChannelFactory(Executor)}
|
||||
*/
|
||||
public OioClientSocketChannelFactory() {
|
||||
this(Executors.newCachedThreadPool());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
*
|
||||
|
@ -61,7 +61,7 @@ final class OioDatagramChannel extends AbstractOioChannel
|
||||
"Failed to configure the datagram socket timeout.", e);
|
||||
}
|
||||
config = new DefaultDatagramChannelConfig(socket);
|
||||
|
||||
|
||||
fireChannelOpen(this);
|
||||
|
||||
}
|
||||
@ -147,6 +147,6 @@ final class OioDatagramChannel extends AbstractOioChannel
|
||||
boolean isSocketClosed() {
|
||||
return socket.isClosed();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -78,13 +78,13 @@ public class OioDatagramChannelFactory implements DatagramChannelFactory {
|
||||
|
||||
/**
|
||||
* Creates a new instance with a {@link Executors#newCachedThreadPool()}
|
||||
*
|
||||
*
|
||||
* See {@link #OioDatagramChannelFactory(Executor)}
|
||||
*/
|
||||
public OioDatagramChannelFactory() {
|
||||
this(Executors.newCachedThreadPool());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
*
|
||||
|
@ -33,7 +33,7 @@ class OioDatagramWorker extends AbstractOioWorker<OioDatagramChannel> {
|
||||
super(channel);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
boolean process() throws IOException {
|
||||
@ -49,7 +49,7 @@ class OioDatagramWorker extends AbstractOioWorker<OioDatagramChannel> {
|
||||
// Can happen on interruption.
|
||||
// Keep receiving unless the channel is closed.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
fireMessageReceived(
|
||||
channel,
|
||||
@ -64,7 +64,7 @@ class OioDatagramWorker extends AbstractOioWorker<OioDatagramChannel> {
|
||||
OioDatagramChannel channel, ChannelFuture future,
|
||||
Object message, SocketAddress remoteAddress) {
|
||||
boolean iothread = isIoThread(channel);
|
||||
|
||||
|
||||
try {
|
||||
ChannelBuffer buf = (ChannelBuffer) message;
|
||||
int offset = buf.readerIndex();
|
||||
@ -102,11 +102,11 @@ class OioDatagramWorker extends AbstractOioWorker<OioDatagramChannel> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void disconnect(OioDatagramChannel channel, ChannelFuture future) {
|
||||
boolean connected = channel.isConnected();
|
||||
boolean iothread = isIoThread(channel);
|
||||
|
||||
|
||||
try {
|
||||
channel.socket.disconnect();
|
||||
future.setSuccess();
|
||||
|
@ -68,7 +68,7 @@ class OioServerSocketChannel extends AbstractServerChannel
|
||||
logger.warn(
|
||||
"Failed to close a partially initialized socket.", e2);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
throw new ChannelException(
|
||||
"Failed to set the server socket timeout.", e);
|
||||
|
@ -92,13 +92,13 @@ public class OioServerSocketChannelFactory implements ServerSocketChannelFactory
|
||||
|
||||
/**
|
||||
* Create a new {@link OioServerSocketChannelFactory} with a {@link Executors#newCachedThreadPool()} for the boss and worker executor.
|
||||
*
|
||||
*
|
||||
* See {@link #OioServerSocketChannelFactory(Executor, Executor)}
|
||||
*/
|
||||
public OioServerSocketChannelFactory() {
|
||||
this(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
*
|
||||
|
@ -47,7 +47,7 @@ class OioWorker extends AbstractOioWorker<OioSocketChannel> {
|
||||
// Fire the channelConnected event for OioAcceptedSocketChannel.
|
||||
// See #287
|
||||
fireChannelConnected(channel, channel.getRemoteAddress());
|
||||
|
||||
|
||||
}
|
||||
super.run();
|
||||
}
|
||||
@ -70,7 +70,7 @@ class OioWorker extends AbstractOioWorker<OioSocketChannel> {
|
||||
return true;
|
||||
}
|
||||
fireMessageReceived(channel, channel.getConfig().getBufferFactory().getBuffer(buf, 0, readBytes));
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -94,14 +94,14 @@ class OioWorker extends AbstractOioWorker<OioSocketChannel> {
|
||||
try {
|
||||
int length = 0;
|
||||
|
||||
// Add support to write a FileRegion. This in fact will not give any performance gain but at least it not fail and
|
||||
// Add support to write a FileRegion. This in fact will not give any performance gain but at least it not fail and
|
||||
// we did the best to emulate it
|
||||
if (message instanceof FileRegion) {
|
||||
FileRegion fr = (FileRegion) message;
|
||||
try {
|
||||
synchronized (out) {
|
||||
WritableByteChannel bchannel = Channels.newChannel(out);
|
||||
|
||||
|
||||
long i = 0;
|
||||
while ((i = fr.transferTo(bchannel, length)) > 0) {
|
||||
length += i;
|
||||
@ -126,14 +126,14 @@ class OioWorker extends AbstractOioWorker<OioSocketChannel> {
|
||||
a.getBytes(a.readerIndex(), out, length);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
future.setSuccess();
|
||||
if (iothread) {
|
||||
fireWriteComplete(channel, length);
|
||||
} else {
|
||||
fireWriteCompleteLater(channel, length);
|
||||
}
|
||||
|
||||
|
||||
} catch (Throwable t) {
|
||||
// Convert 'SocketException: Socket closed' to
|
||||
// ClosedChannelException.
|
||||
|
@ -34,7 +34,7 @@ public class DiscardServer {
|
||||
public DiscardServer(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
// Configure the server.
|
||||
ServerBootstrap bootstrap = new ServerBootstrap(
|
||||
|
@ -30,11 +30,11 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
public class EchoServer {
|
||||
|
||||
private final int port;
|
||||
|
||||
|
||||
public EchoServer(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
// Configure the server.
|
||||
ServerBootstrap bootstrap = new ServerBootstrap(
|
||||
|
@ -32,7 +32,7 @@ public class FactorialClient {
|
||||
private final String host;
|
||||
private final int port;
|
||||
private final int count;
|
||||
|
||||
|
||||
public FactorialClient(String host, int port, int count) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
|
@ -28,11 +28,11 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
public class FactorialServer {
|
||||
|
||||
private final int port;
|
||||
|
||||
|
||||
public FactorialServer(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
// Configure the server.
|
||||
ServerBootstrap bootstrap = new ServerBootstrap(
|
||||
|
@ -22,13 +22,13 @@ import org.jboss.netty.bootstrap.ServerBootstrap;
|
||||
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
|
||||
public class HttpStaticFileServer {
|
||||
|
||||
|
||||
private final int port;
|
||||
|
||||
|
||||
public HttpStaticFileServer(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
// Configure the server.
|
||||
ServerBootstrap bootstrap = new ServerBootstrap(
|
||||
|
@ -37,7 +37,7 @@ import org.jboss.netty.handler.codec.http.HttpVersion;
|
||||
public class HttpSnoopClient {
|
||||
|
||||
private final URI uri;
|
||||
|
||||
|
||||
public HttpSnoopClient(URI uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
* in a pretty plaintext form.
|
||||
*/
|
||||
public class HttpSnoopServer {
|
||||
|
||||
|
||||
private final int port;
|
||||
|
||||
public HttpSnoopServer(int port) {
|
||||
|
@ -44,7 +44,7 @@ import org.jboss.netty.logging.InternalLogLevel;
|
||||
public class HttpTunnelingClientExample {
|
||||
|
||||
private final URI uri;
|
||||
|
||||
|
||||
public HttpTunnelingClientExample(URI uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
@ -28,30 +28,30 @@ import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelFuture;
|
||||
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
||||
import org.jboss.netty.handler.codec.http.CookieEncoder;
|
||||
import org.jboss.netty.handler.codec.http.DefaultHttpDataFactory;
|
||||
import org.jboss.netty.handler.codec.http.DefaultHttpRequest;
|
||||
import org.jboss.netty.handler.codec.http.DiskAttribute;
|
||||
import org.jboss.netty.handler.codec.http.DiskFileUpload;
|
||||
import org.jboss.netty.handler.codec.http.HttpDataFactory;
|
||||
import org.jboss.netty.handler.codec.http.HttpHeaders;
|
||||
import org.jboss.netty.handler.codec.http.HttpMethod;
|
||||
import org.jboss.netty.handler.codec.http.HttpPostRequestEncoder;
|
||||
import org.jboss.netty.handler.codec.http.HttpPostRequestEncoder.ErrorDataEncoderException;
|
||||
import org.jboss.netty.handler.codec.http.HttpRequest;
|
||||
import org.jboss.netty.handler.codec.http.HttpVersion;
|
||||
import org.jboss.netty.handler.codec.http.InterfaceHttpData;
|
||||
import org.jboss.netty.handler.codec.http.QueryStringEncoder;
|
||||
import org.jboss.netty.handler.codec.http.multipart.DefaultHttpDataFactory;
|
||||
import org.jboss.netty.handler.codec.http.multipart.DiskAttribute;
|
||||
import org.jboss.netty.handler.codec.http.multipart.DiskFileUpload;
|
||||
import org.jboss.netty.handler.codec.http.multipart.HttpDataFactory;
|
||||
import org.jboss.netty.handler.codec.http.multipart.HttpPostRequestEncoder;
|
||||
import org.jboss.netty.handler.codec.http.multipart.HttpPostRequestEncoder.ErrorDataEncoderException;
|
||||
import org.jboss.netty.handler.codec.http.multipart.InterfaceHttpData;
|
||||
import org.jboss.netty.logging.InternalLogger;
|
||||
import org.jboss.netty.logging.InternalLoggerFactory;
|
||||
|
||||
public class HttpUploadClient {
|
||||
|
||||
|
||||
private static final InternalLogger logger =
|
||||
InternalLoggerFactory.getInstance(HttpUploadClient.class);
|
||||
|
||||
|
||||
private final String baseUri;
|
||||
private final String filePath;
|
||||
|
||||
|
||||
public HttpUploadClient(String baseUri, String filePath) {
|
||||
this.baseUri = baseUri;
|
||||
this.filePath = filePath;
|
||||
|
@ -27,7 +27,7 @@ import org.jboss.netty.logging.InternalLoggerFactory;
|
||||
import org.jboss.netty.util.CharsetUtil;
|
||||
|
||||
public class HttpUploadClientHandler extends SimpleChannelUpstreamHandler {
|
||||
|
||||
|
||||
private static final InternalLogger logger =
|
||||
InternalLoggerFactory.getInstance(HttpUploadClientHandler.class);
|
||||
|
||||
|
@ -54,7 +54,7 @@ public class HttpUploadClientPipelineFactory implements ChannelPipelineFactory {
|
||||
|
||||
// to be used since huge file transfer
|
||||
pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
|
||||
|
||||
|
||||
pipeline.addLast("handler", new HttpUploadClientHandler());
|
||||
return pipeline;
|
||||
}
|
||||
|
@ -22,13 +22,13 @@ import org.jboss.netty.bootstrap.ServerBootstrap;
|
||||
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
|
||||
public class HttpUploadServer {
|
||||
|
||||
|
||||
private final int port;
|
||||
|
||||
|
||||
public HttpUploadServer(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
// Configure the server.
|
||||
ServerBootstrap bootstrap = new ServerBootstrap(
|
||||
|
@ -34,30 +34,30 @@ import org.jboss.netty.channel.Channels;
|
||||
import org.jboss.netty.channel.ExceptionEvent;
|
||||
import org.jboss.netty.channel.MessageEvent;
|
||||
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
|
||||
import org.jboss.netty.handler.codec.http.Attribute;
|
||||
import org.jboss.netty.handler.codec.http.Cookie;
|
||||
import org.jboss.netty.handler.codec.http.CookieDecoder;
|
||||
import org.jboss.netty.handler.codec.http.CookieEncoder;
|
||||
import org.jboss.netty.handler.codec.http.DefaultHttpDataFactory;
|
||||
import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
|
||||
import org.jboss.netty.handler.codec.http.DiskAttribute;
|
||||
import org.jboss.netty.handler.codec.http.DiskFileUpload;
|
||||
import org.jboss.netty.handler.codec.http.FileUpload;
|
||||
import org.jboss.netty.handler.codec.http.HttpChunk;
|
||||
import org.jboss.netty.handler.codec.http.HttpDataFactory;
|
||||
import org.jboss.netty.handler.codec.http.HttpHeaders;
|
||||
import org.jboss.netty.handler.codec.http.HttpPostRequestDecoder;
|
||||
import org.jboss.netty.handler.codec.http.HttpPostRequestDecoder.EndOfDataDecoderException;
|
||||
import org.jboss.netty.handler.codec.http.HttpPostRequestDecoder.ErrorDataDecoderException;
|
||||
import org.jboss.netty.handler.codec.http.HttpPostRequestDecoder.IncompatibleDataDecoderException;
|
||||
import org.jboss.netty.handler.codec.http.HttpPostRequestDecoder.NotEnoughDataDecoderException;
|
||||
import org.jboss.netty.handler.codec.http.HttpRequest;
|
||||
import org.jboss.netty.handler.codec.http.HttpResponse;
|
||||
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
|
||||
import org.jboss.netty.handler.codec.http.HttpVersion;
|
||||
import org.jboss.netty.handler.codec.http.InterfaceHttpData;
|
||||
import org.jboss.netty.handler.codec.http.InterfaceHttpData.HttpDataType;
|
||||
import org.jboss.netty.handler.codec.http.QueryStringDecoder;
|
||||
import org.jboss.netty.handler.codec.http.multipart.Attribute;
|
||||
import org.jboss.netty.handler.codec.http.multipart.DefaultHttpDataFactory;
|
||||
import org.jboss.netty.handler.codec.http.multipart.DiskAttribute;
|
||||
import org.jboss.netty.handler.codec.http.multipart.DiskFileUpload;
|
||||
import org.jboss.netty.handler.codec.http.multipart.FileUpload;
|
||||
import org.jboss.netty.handler.codec.http.multipart.HttpDataFactory;
|
||||
import org.jboss.netty.handler.codec.http.multipart.HttpPostRequestDecoder;
|
||||
import org.jboss.netty.handler.codec.http.multipart.HttpPostRequestDecoder.EndOfDataDecoderException;
|
||||
import org.jboss.netty.handler.codec.http.multipart.HttpPostRequestDecoder.ErrorDataDecoderException;
|
||||
import org.jboss.netty.handler.codec.http.multipart.HttpPostRequestDecoder.IncompatibleDataDecoderException;
|
||||
import org.jboss.netty.handler.codec.http.multipart.HttpPostRequestDecoder.NotEnoughDataDecoderException;
|
||||
import org.jboss.netty.handler.codec.http.multipart.InterfaceHttpData;
|
||||
import org.jboss.netty.handler.codec.http.multipart.InterfaceHttpData.HttpDataType;
|
||||
import org.jboss.netty.logging.InternalLogger;
|
||||
import org.jboss.netty.logging.InternalLoggerFactory;
|
||||
import org.jboss.netty.util.CharsetUtil;
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.jboss.netty.example.http.upload;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.pipeline;
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
|
||||
import org.jboss.netty.channel.ChannelPipeline;
|
||||
import org.jboss.netty.channel.ChannelPipelineFactory;
|
||||
|
@ -26,13 +26,13 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
* suite
|
||||
*/
|
||||
public class AutobahnServer {
|
||||
|
||||
|
||||
private final int port;
|
||||
|
||||
public AutobahnServer(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
// Configure the server.
|
||||
ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
|
||||
|
@ -15,28 +15,28 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* This package is intended for use with testing against the Python
|
||||
* This package is intended for use with testing against the Python
|
||||
* <a href="http://www.tavendo.de/autobahn/testsuite.html">AutoBahn test suite</a>.
|
||||
*
|
||||
* <h3>How to run the tests on Ubuntu</h3>
|
||||
*
|
||||
*
|
||||
* <p>01. Add <tt>ppa:twisted-dev/ppa</tt> to your system's Software Sources
|
||||
*
|
||||
*
|
||||
* <p>02. Install Twisted V11: <tt>sudo apt-get install python-twisted</tt>
|
||||
*
|
||||
*
|
||||
* <p>03. Intall Python Setup Tools: <tt>sudo apt-get install python-setuptools</tt>
|
||||
*
|
||||
*
|
||||
* <p>04. Install AutoBahn: <tt>sudo easy_install Autobahn</tt>. If you already have Autobahn installed, you may need
|
||||
* to upgrade it: <tt>sudo easy_install --upgrade Autobahn</tt>. Make suer v0.4.10 is installed.
|
||||
*
|
||||
*
|
||||
* <p>05. Get AutoBahn testsuite source code: <tt>git clone git@github.com:tavendo/AutobahnPython.git</tt>
|
||||
*
|
||||
*
|
||||
* <p>06. Go to AutoBahn directory: <tt>cd AutobahnPython</tt>
|
||||
*
|
||||
*
|
||||
* <p>07. Checkout stable version: <tt>git checkout v0.4.10</tt>
|
||||
*
|
||||
*
|
||||
* <p>08. Go to test suite directory: <tt>cd testsuite/websockets</tt>
|
||||
*
|
||||
*
|
||||
* <p>09. Edit <tt>fuzzing_clinet_spec.json</tt> and set the hybi specification version to 10 or 17 (RFC 6455).
|
||||
* <code>
|
||||
* {
|
||||
@ -47,14 +47,14 @@
|
||||
* "exclude-agent-cases": {"FoobarServer*": ["4.*", "1.1.3"]}
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* <p>10. Run our <tt>AutobahnServer</tt> located in this package. If you are in Eclipse IDE, right click on
|
||||
*
|
||||
* <p>10. Run our <tt>AutobahnServer</tt> located in this package. If you are in Eclipse IDE, right click on
|
||||
* <tt>AutobahnServer.java</tt> and select Run As > Java Application.
|
||||
*
|
||||
* <p>11. Run the Autobahn test <tt>python fuzzing_client.py</tt>. Note that the actual test case python code is
|
||||
*
|
||||
* <p>11. Run the Autobahn test <tt>python fuzzing_client.py</tt>. Note that the actual test case python code is
|
||||
* located with the easy_install package (e.g. in <tt>/usr/local/lib/python2.7/dist-packages/
|
||||
* autobahn-0.4.10-py2.7.egg/autobahn/cases</tt>) and not in the checked out git repository.
|
||||
*
|
||||
*
|
||||
* <p>12. See the results in <tt>reports/servers/index.html</tt>
|
||||
*/
|
||||
package org.jboss.netty.example.http.websocketx.autobahn;
|
||||
|
@ -23,14 +23,14 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
|
||||
/**
|
||||
* A HTTP server which serves Web Socket requests at:
|
||||
*
|
||||
*
|
||||
* http://localhost:8080/websocket
|
||||
*
|
||||
*
|
||||
* Open your browser at http://localhost:8080/, then the demo page will be loaded and a Web Socket connection will be
|
||||
* made automatically.
|
||||
*
|
||||
*
|
||||
* This server illustrates support for the different web socket specification versions and will work with:
|
||||
*
|
||||
*
|
||||
* <ul>
|
||||
* <li>Safari 5+ (draft-ietf-hybi-thewebsocketprotocol-00)
|
||||
* <li>Chrome 6-13 (draft-ietf-hybi-thewebsocketprotocol-00)
|
||||
@ -41,13 +41,13 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
* </ul>
|
||||
*/
|
||||
public class WebSocketServer {
|
||||
|
||||
|
||||
private final int port;
|
||||
|
||||
|
||||
public WebSocketServer(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
// Configure the server.
|
||||
ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
|
||||
|
@ -16,12 +16,12 @@
|
||||
|
||||
/**
|
||||
* <p>This package contains an example web socket web server.
|
||||
* <p>The web server only handles text, ping and closing frames. For text frames,
|
||||
* <p>The web server only handles text, ping and closing frames. For text frames,
|
||||
* it echoes the received text in upper case.
|
||||
* <p>Once started, you can test the web server against your browser by navigating
|
||||
* <p>Once started, you can test the web server against your browser by navigating
|
||||
* to http://localhost:8080/
|
||||
* <p>You can also test it with a web socket client. Send web socket traffic to
|
||||
* ws://localhost:8080/websocket.
|
||||
* <p>You can also test it with a web socket client. Send web socket traffic to
|
||||
* ws://localhost:8080/websocket.
|
||||
*/
|
||||
package org.jboss.netty.example.http.websocketx.server;
|
||||
|
||||
|
@ -23,14 +23,14 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
|
||||
/**
|
||||
* A HTTP server which serves Web Socket requests at:
|
||||
*
|
||||
*
|
||||
* https://localhost:8081/websocket
|
||||
*
|
||||
*
|
||||
* Open your browser at https://localhost:8081/, then the demo page will be loaded and a Web Socket connection will be
|
||||
* made automatically.
|
||||
*
|
||||
*
|
||||
* This server illustrates support for the different web socket specification versions and will work with:
|
||||
*
|
||||
*
|
||||
* <ul>
|
||||
* <li>Safari 5+ (draft-ietf-hybi-thewebsocketprotocol-00)
|
||||
* <li>Chrome 6-13 (draft-ietf-hybi-thewebsocketprotocol-00)
|
||||
@ -40,7 +40,7 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
* </ul>
|
||||
*/
|
||||
public class WebSocketSslServer {
|
||||
|
||||
|
||||
private final int port;
|
||||
|
||||
public WebSocketSslServer(int port) {
|
||||
@ -81,7 +81,7 @@ public class WebSocketSslServer {
|
||||
System.out.println("ERROR: System property keystore.file.password not set. Exiting now!");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
|
||||
new WebSocketSslServer(port).run();
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public final class WebSocketSslServerSslContext {
|
||||
/**
|
||||
* SingletonHolder is loaded on the first execution of Singleton.getInstance() or the first access to
|
||||
* SingletonHolder.INSTANCE, not before.
|
||||
*
|
||||
*
|
||||
* See http://en.wikipedia.org/wiki/Singleton_pattern
|
||||
*/
|
||||
private static class SingletonHolder {
|
||||
|
@ -37,7 +37,7 @@ import org.jboss.netty.logging.InternalLogLevel;
|
||||
public class LocalExample {
|
||||
|
||||
private final String port;
|
||||
|
||||
|
||||
public LocalExample(String port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ import org.jboss.netty.logging.InternalLogLevel;
|
||||
public class LocalExampleMultithreaded {
|
||||
|
||||
private final String port;
|
||||
|
||||
|
||||
public LocalExampleMultithreaded(String port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class LocalTimeClient {
|
||||
private final String host;
|
||||
private final int port;
|
||||
private final Collection<String> cities;
|
||||
|
||||
|
||||
public LocalTimeClient(String host, int port, Collection<String> cities) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -38,7 +38,7 @@ public class PortUnificationServer {
|
||||
public PortUnificationServer(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
// Configure the server.
|
||||
ServerBootstrap bootstrap = new ServerBootstrap(
|
||||
|
@ -29,7 +29,7 @@ public class HexDumpProxy {
|
||||
private final int localPort;
|
||||
private final String remoteHost;
|
||||
private final int remotePort;
|
||||
|
||||
|
||||
public HexDumpProxy(int localPort, String remoteHost, int remotePort) {
|
||||
this.localPort = localPort;
|
||||
this.remoteHost = remoteHost;
|
||||
|
@ -16,7 +16,6 @@
|
||||
package org.jboss.netty.example.qotm;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.jboss.netty.bootstrap.ConnectionlessBootstrap;
|
||||
import org.jboss.netty.channel.ChannelPipeline;
|
||||
@ -44,9 +43,7 @@ public class QuoteOfTheMomentServer {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
DatagramChannelFactory f =
|
||||
new NioDatagramChannelFactory(Executors.newCachedThreadPool());
|
||||
|
||||
DatagramChannelFactory f = new NioDatagramChannelFactory();
|
||||
ConnectionlessBootstrap b = new ConnectionlessBootstrap(f);
|
||||
|
||||
// Configure the pipeline factory.
|
||||
|
@ -34,7 +34,7 @@ public class SecureChatClient {
|
||||
|
||||
private final String host;
|
||||
private final int port;
|
||||
|
||||
|
||||
public SecureChatClient(String host, int port) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
|
@ -33,7 +33,7 @@ public class TelnetClient {
|
||||
|
||||
private final String host;
|
||||
private final int port;
|
||||
|
||||
|
||||
public TelnetClient(String host, int port) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
|
@ -27,11 +27,11 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
public class TelnetServer {
|
||||
|
||||
private final int port;
|
||||
|
||||
|
||||
public TelnetServer(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
// Configure the server.
|
||||
ServerBootstrap bootstrap = new ServerBootstrap(
|
||||
|
@ -16,33 +16,33 @@
|
||||
package org.jboss.netty.handler.codec;
|
||||
|
||||
/**
|
||||
* Exception which should get thrown if a Channel got closed before it is expected
|
||||
* Exception which should get thrown if a Channel got closed before it is expected
|
||||
*/
|
||||
public class PrematureChannelClosureException extends Exception {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 233460005724966593L;
|
||||
|
||||
public PrematureChannelClosureException() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
public PrematureChannelClosureException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public PrematureChannelClosureException(String msg, Throwable t) {
|
||||
super(msg, t);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public PrematureChannelClosureException(Throwable t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -18,9 +18,9 @@ package org.jboss.netty.handler.codec.base64;
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
import org.jboss.netty.buffer.ChannelBuffers;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelHandler.Sharable;
|
||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
import org.jboss.netty.channel.ChannelPipeline;
|
||||
import org.jboss.netty.channel.ChannelHandler.Sharable;
|
||||
import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder;
|
||||
import org.jboss.netty.handler.codec.frame.Delimiters;
|
||||
import org.jboss.netty.handler.codec.frame.FrameDecoder;
|
||||
|
@ -17,9 +17,9 @@ package org.jboss.netty.handler.codec.base64;
|
||||
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelHandler.Sharable;
|
||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
import org.jboss.netty.channel.ChannelPipeline;
|
||||
import org.jboss.netty.channel.ChannelHandler.Sharable;
|
||||
import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder;
|
||||
import org.jboss.netty.handler.codec.frame.Delimiters;
|
||||
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
|
||||
|
@ -192,7 +192,7 @@ public class ZlibEncoder extends OneToOneEncoder implements LifeCycleAwareChanne
|
||||
* and the specified preset dictionary. The wrapper is always
|
||||
* {@link ZlibWrapper#ZLIB} because it is the only format that supports
|
||||
* the preset dictionary.
|
||||
*
|
||||
*
|
||||
* @param compressionLevel
|
||||
* {@code 1} yields the fastest compression and {@code 9} yields the
|
||||
* best compression. {@code 0} means no compression. The default
|
||||
|
@ -187,7 +187,7 @@ public class DelimiterBasedFrameDecoder extends FrameDecoder {
|
||||
this.stripDelimiter = stripDelimiter;
|
||||
this.failFast = failFast;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Object decode(
|
||||
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
|
||||
|
@ -40,21 +40,21 @@ public class FixedLengthFrameDecoder extends FrameDecoder {
|
||||
|
||||
private final int frameLength;
|
||||
private final boolean allocateFullBuffer;
|
||||
|
||||
|
||||
/**
|
||||
* Calls {@link #FixedLengthFrameDecoder(int, boolean)} with <code>false</code>
|
||||
*/
|
||||
public FixedLengthFrameDecoder(int frameLength) {
|
||||
this(frameLength, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
*
|
||||
* @param frameLength the length of the frame
|
||||
* @param allocateFullBuffer <code>true</code> if the cumulative {@link ChannelBuffer} should use the {@link #frameLength} as its initial size
|
||||
*/
|
||||
public FixedLengthFrameDecoder(int frameLength, boolean allocateFullBuffer) {
|
||||
public FixedLengthFrameDecoder(int frameLength, boolean allocateFullBuffer) {
|
||||
if (frameLength <= 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"frameLength must be a positive integer: " + frameLength);
|
||||
@ -72,7 +72,7 @@ public class FixedLengthFrameDecoder extends FrameDecoder {
|
||||
return buffer.readBytes(frameLength);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected ChannelBuffer newCumulationBuffer(ChannelHandlerContext ctx, int minimumCapacity) {
|
||||
ChannelBufferFactory factory = ctx.getChannel().getConfig().getBufferFactory();
|
||||
|
@ -31,6 +31,7 @@ import org.jboss.netty.channel.ExceptionEvent;
|
||||
import org.jboss.netty.channel.LifeCycleAwareChannelHandler;
|
||||
import org.jboss.netty.channel.MessageEvent;
|
||||
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
|
||||
import org.jboss.netty.handler.codec.replay.ReplayingDecoder;
|
||||
|
||||
/**
|
||||
* Decodes the received {@link ChannelBuffer}s into a meaningful frame object.
|
||||
@ -265,7 +266,7 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler implemen
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -369,7 +370,7 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler implemen
|
||||
|
||||
/**
|
||||
* Gets called on {@link #channelDisconnected(ChannelHandlerContext, ChannelStateEvent)} and {@link #channelClosed(ChannelHandlerContext, ChannelStateEvent)}
|
||||
*
|
||||
*
|
||||
*/
|
||||
protected void cleanup(ChannelHandlerContext ctx, ChannelStateEvent e)
|
||||
throws Exception {
|
||||
@ -410,12 +411,12 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler implemen
|
||||
ChannelBufferFactory factory = ctx.getChannel().getConfig().getBufferFactory();
|
||||
return factory.getBuffer(Math.max(minimumCapacity, 256));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Replace this {@link FrameDecoder} in the {@link ChannelPipeline} with the given {@link ChannelHandler}. All
|
||||
* Replace this {@link FrameDecoder} in the {@link ChannelPipeline} with the given {@link ChannelHandler}. All
|
||||
* remaining bytes in the {@link ChannelBuffer} will get send to the new {@link ChannelHandler} that was used
|
||||
* as replacement
|
||||
*
|
||||
*
|
||||
*/
|
||||
public void replace(String handlerName, ChannelHandler handler) {
|
||||
if (ctx == null) {
|
||||
@ -423,7 +424,7 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler implemen
|
||||
}
|
||||
ChannelPipeline pipeline = ctx.getPipeline();
|
||||
pipeline.addAfter(ctx.getName(), handlerName, handler);
|
||||
|
||||
|
||||
try {
|
||||
if (cumulation != null) {
|
||||
Channels.fireMessageReceived(ctx, cumulation.readBytes(actualReadableBytes()));
|
||||
@ -431,9 +432,9 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler implemen
|
||||
} finally {
|
||||
pipeline.remove(this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the actual number of readable bytes in the internal cumulative
|
||||
* buffer of this decoder. You usually do not need to rely on this value
|
||||
@ -443,7 +444,7 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler implemen
|
||||
protected int actualReadableBytes() {
|
||||
return internalBuffer().readableBytes();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@ -452,7 +453,7 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler implemen
|
||||
* Use it only when you must use it at your own risk.
|
||||
*/
|
||||
protected ChannelBuffer internalBuffer() {
|
||||
ChannelBuffer buf = this.cumulation;
|
||||
ChannelBuffer buf = cumulation;
|
||||
if (buf == null) {
|
||||
return ChannelBuffers.EMPTY_BUFFER;
|
||||
}
|
||||
@ -465,17 +466,14 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler implemen
|
||||
|
||||
public void afterAdd(ChannelHandlerContext ctx) throws Exception {
|
||||
// Nothing to do..
|
||||
|
||||
}
|
||||
|
||||
public void beforeRemove(ChannelHandlerContext ctx) throws Exception {
|
||||
// Nothing to do..
|
||||
|
||||
}
|
||||
|
||||
public void afterRemove(ChannelHandlerContext ctx) throws Exception {
|
||||
// Nothing to do..
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -402,14 +402,14 @@ public class LengthFieldBasedFrameDecoder extends FrameDecoder {
|
||||
long tooLongFrameLength = this.tooLongFrameLength;
|
||||
this.tooLongFrameLength = 0;
|
||||
discardingTooLongFrame = false;
|
||||
if ((!failFast) ||
|
||||
(failFast && firstDetectionOfTooLongFrame)) {
|
||||
if (!failFast ||
|
||||
failFast && firstDetectionOfTooLongFrame) {
|
||||
fail(ctx, tooLongFrameLength);
|
||||
}
|
||||
} else {
|
||||
// Keep discarding and notify handlers if necessary.
|
||||
if (failFast && firstDetectionOfTooLongFrame) {
|
||||
fail(ctx, this.tooLongFrameLength);
|
||||
fail(ctx, tooLongFrameLength);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,8 @@ import java.nio.ByteOrder;
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
import org.jboss.netty.buffer.ChannelBufferFactory;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
import org.jboss.netty.channel.ChannelHandler.Sharable;
|
||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
|
||||
|
||||
/**
|
||||
|
@ -82,7 +82,7 @@ public class CookieEncoder {
|
||||
* Encodes the {@link Cookie}s which were added by {@link #addCookie(Cookie)}
|
||||
* so far into an HTTP header value. If no {@link Cookie}s were added,
|
||||
* an empty string is returned.
|
||||
*
|
||||
*
|
||||
* <strong>Be aware that calling this method will clear the content of the {@link CookieEncoder}</strong>
|
||||
*/
|
||||
public String encode() {
|
||||
@ -130,11 +130,11 @@ public class CookieEncoder {
|
||||
}
|
||||
if (cookie.isSecure()) {
|
||||
sb.append(CookieHeaderNames.SECURE);
|
||||
sb.append((char) HttpCodecUtil.SEMICOLON);
|
||||
sb.append((char) HttpConstants.SEMICOLON);
|
||||
}
|
||||
if (cookie.isHttpOnly()) {
|
||||
sb.append(CookieHeaderNames.HTTPONLY);
|
||||
sb.append((char) HttpCodecUtil.SEMICOLON);
|
||||
sb.append((char) HttpConstants.SEMICOLON);
|
||||
}
|
||||
if (cookie.getVersion() >= 1) {
|
||||
if (cookie.getComment() != null) {
|
||||
@ -149,18 +149,18 @@ public class CookieEncoder {
|
||||
|
||||
if (!cookie.getPorts().isEmpty()) {
|
||||
sb.append(CookieHeaderNames.PORT);
|
||||
sb.append((char) HttpCodecUtil.EQUALS);
|
||||
sb.append((char) HttpCodecUtil.DOUBLE_QUOTE);
|
||||
sb.append((char) HttpConstants.EQUALS);
|
||||
sb.append((char) HttpConstants.DOUBLE_QUOTE);
|
||||
for (int port: cookie.getPorts()) {
|
||||
sb.append(port);
|
||||
sb.append((char) HttpCodecUtil.COMMA);
|
||||
sb.append((char) HttpConstants.COMMA);
|
||||
}
|
||||
sb.setCharAt(sb.length() - 1, (char) HttpCodecUtil.DOUBLE_QUOTE);
|
||||
sb.append((char) HttpCodecUtil.SEMICOLON);
|
||||
sb.setCharAt(sb.length() - 1, (char) HttpConstants.DOUBLE_QUOTE);
|
||||
sb.append((char) HttpConstants.SEMICOLON);
|
||||
}
|
||||
if (cookie.isDiscard()) {
|
||||
sb.append(CookieHeaderNames.DISCARD);
|
||||
sb.append((char) HttpCodecUtil.SEMICOLON);
|
||||
sb.append((char) HttpConstants.SEMICOLON);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -194,14 +194,14 @@ public class CookieEncoder {
|
||||
if (!cookie.getPorts().isEmpty()) {
|
||||
sb.append('$');
|
||||
sb.append(CookieHeaderNames.PORT);
|
||||
sb.append((char) HttpCodecUtil.EQUALS);
|
||||
sb.append((char) HttpCodecUtil.DOUBLE_QUOTE);
|
||||
sb.append((char) HttpConstants.EQUALS);
|
||||
sb.append((char) HttpConstants.DOUBLE_QUOTE);
|
||||
for (int port: cookie.getPorts()) {
|
||||
sb.append(port);
|
||||
sb.append((char) HttpCodecUtil.COMMA);
|
||||
sb.append((char) HttpConstants.COMMA);
|
||||
}
|
||||
sb.setCharAt(sb.length() - 1, (char) HttpCodecUtil.DOUBLE_QUOTE);
|
||||
sb.append((char) HttpCodecUtil.SEMICOLON);
|
||||
sb.setCharAt(sb.length() - 1, (char) HttpConstants.DOUBLE_QUOTE);
|
||||
sb.append((char) HttpConstants.SEMICOLON);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -235,9 +235,9 @@ public class CookieEncoder {
|
||||
|
||||
private static void addUnquoted(StringBuilder sb, String name, String val) {
|
||||
sb.append(name);
|
||||
sb.append((char) HttpCodecUtil.EQUALS);
|
||||
sb.append((char) HttpConstants.EQUALS);
|
||||
sb.append(val);
|
||||
sb.append((char) HttpCodecUtil.SEMICOLON);
|
||||
sb.append((char) HttpConstants.SEMICOLON);
|
||||
}
|
||||
|
||||
private static void addQuoted(StringBuilder sb, String name, String val) {
|
||||
@ -246,17 +246,17 @@ public class CookieEncoder {
|
||||
}
|
||||
|
||||
sb.append(name);
|
||||
sb.append((char) HttpCodecUtil.EQUALS);
|
||||
sb.append((char) HttpCodecUtil.DOUBLE_QUOTE);
|
||||
sb.append((char) HttpConstants.EQUALS);
|
||||
sb.append((char) HttpConstants.DOUBLE_QUOTE);
|
||||
sb.append(val.replace("\\", "\\\\").replace("\"", "\\\""));
|
||||
sb.append((char) HttpCodecUtil.DOUBLE_QUOTE);
|
||||
sb.append((char) HttpCodecUtil.SEMICOLON);
|
||||
sb.append((char) HttpConstants.DOUBLE_QUOTE);
|
||||
sb.append((char) HttpConstants.SEMICOLON);
|
||||
}
|
||||
|
||||
private static void add(StringBuilder sb, String name, int val) {
|
||||
sb.append(name);
|
||||
sb.append((char) HttpCodecUtil.EQUALS);
|
||||
sb.append((char) HttpConstants.EQUALS);
|
||||
sb.append(val);
|
||||
sb.append((char) HttpCodecUtil.SEMICOLON);
|
||||
sb.append((char) HttpConstants.SEMICOLON);
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.jboss.netty.util.internal.CaseIgnoringComparator;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
@ -36,10 +36,10 @@ import org.jboss.netty.util.internal.QueueFactory;
|
||||
* {@link HttpResponseDecoder} to learn what additional state management needs
|
||||
* to be done for <tt>HEAD</tt> and <tt>CONNECT</tt> and why
|
||||
* {@link HttpResponseDecoder} can not handle it by itself.
|
||||
*
|
||||
*
|
||||
* If the {@link Channel} gets closed and there are requests missing for a response
|
||||
* a {@link PrematureChannelClosureException} is thrown.
|
||||
*
|
||||
*
|
||||
* @see HttpServerCodec
|
||||
*
|
||||
* @apiviz.has org.jboss.netty.handler.codec.http.HttpResponseDecoder
|
||||
@ -64,7 +64,7 @@ public class HttpClientCodec implements ChannelUpstreamHandler,
|
||||
* Creates a new instance with the default decoder options
|
||||
* ({@code maxInitialLineLength (4096}}, {@code maxHeaderSize (8192)}, and
|
||||
* {@code maxChunkSize (8192)}).
|
||||
*
|
||||
*
|
||||
*/
|
||||
public HttpClientCodec() {
|
||||
this(4096, 8192, 8192, false);
|
||||
@ -109,9 +109,9 @@ public class HttpClientCodec implements ChannelUpstreamHandler,
|
||||
if (msg instanceof HttpRequest && !done) {
|
||||
queue.offer(((HttpRequest) msg).getMethod());
|
||||
}
|
||||
|
||||
|
||||
Object obj = super.encode(ctx, channel, msg);
|
||||
|
||||
|
||||
if (failOnMissingResponse) {
|
||||
// check if the request is chunked if so do not increment
|
||||
if (msg instanceof HttpRequest && !((HttpRequest) msg).isChunked()) {
|
||||
@ -149,7 +149,7 @@ public class HttpClientCodec implements ChannelUpstreamHandler,
|
||||
if (msg == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// check if its a HttpMessage and its not chunked
|
||||
if (msg instanceof HttpMessage && !((HttpMessage) msg).isChunked()) {
|
||||
requestResponseCounter.decrementAndGet();
|
||||
@ -212,7 +212,7 @@ public class HttpClientCodec implements ChannelUpstreamHandler,
|
||||
|
||||
return super.isContentAlwaysEmpty(msg);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
|
||||
super.channelClosed(ctx, e);
|
||||
|
@ -15,60 +15,9 @@
|
||||
*/
|
||||
package org.jboss.netty.handler.codec.http;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
|
||||
import org.jboss.netty.util.CharsetUtil;
|
||||
|
||||
final class HttpCodecUtil {
|
||||
//space ' '
|
||||
static final byte SP = 32;
|
||||
|
||||
//tab ' '
|
||||
static final byte HT = 9;
|
||||
|
||||
/**
|
||||
* Carriage return
|
||||
*/
|
||||
static final byte CR = 13;
|
||||
|
||||
/**
|
||||
* Equals '='
|
||||
*/
|
||||
static final byte EQUALS = 61;
|
||||
|
||||
/**
|
||||
* Line feed character
|
||||
*/
|
||||
static final byte LF = 10;
|
||||
|
||||
/**
|
||||
* carriage return line feed
|
||||
*/
|
||||
static final byte[] CRLF = new byte[] { CR, LF };
|
||||
|
||||
/**
|
||||
* Colon ':'
|
||||
*/
|
||||
static final byte COLON = 58;
|
||||
|
||||
/**
|
||||
* Semicolon ';'
|
||||
*/
|
||||
static final byte SEMICOLON = 59;
|
||||
|
||||
/**
|
||||
* comma ','
|
||||
*/
|
||||
static final byte COMMA = 44;
|
||||
|
||||
static final byte DOUBLE_QUOTE = '"';
|
||||
|
||||
static final Charset DEFAULT_CHARSET = CharsetUtil.UTF_8;
|
||||
|
||||
private HttpCodecUtil() {
|
||||
super();
|
||||
}
|
||||
|
||||
static void validateHeaderName(String name) {
|
||||
if (name == null) {
|
||||
@ -168,4 +117,8 @@ final class HttpCodecUtil {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private HttpCodecUtil() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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.handler.codec.http;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.jboss.netty.util.CharsetUtil;
|
||||
|
||||
public final class HttpConstants {
|
||||
|
||||
/**
|
||||
* Horizontal space
|
||||
*/
|
||||
public static final byte SP = 32;
|
||||
|
||||
/**
|
||||
* Horizontal tab
|
||||
*/
|
||||
public static final byte HT = 9;
|
||||
|
||||
/**
|
||||
* Carriage return
|
||||
*/
|
||||
public static final byte CR = 13;
|
||||
|
||||
/**
|
||||
* Equals '='
|
||||
*/
|
||||
public static final byte EQUALS = 61;
|
||||
|
||||
/**
|
||||
* Line feed character
|
||||
*/
|
||||
public static final byte LF = 10;
|
||||
|
||||
/**
|
||||
* Colon ':'
|
||||
*/
|
||||
public static final byte COLON = 58;
|
||||
|
||||
/**
|
||||
* Semicolon ';'
|
||||
*/
|
||||
public static final byte SEMICOLON = 59;
|
||||
|
||||
/**
|
||||
* Comma ','
|
||||
*/
|
||||
public static final byte COMMA = 44;
|
||||
|
||||
/**
|
||||
* Double quote '"'
|
||||
*/
|
||||
public static final byte DOUBLE_QUOTE = '"';
|
||||
|
||||
/**
|
||||
* Default character set (UTF-8)
|
||||
*/
|
||||
public static final Charset DEFAULT_CHARSET = CharsetUtil.UTF_8;
|
||||
|
||||
private HttpConstants() {
|
||||
// Unused
|
||||
}
|
||||
}
|
@ -21,6 +21,8 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.jboss.netty.util.internal.CaseIgnoringComparator;
|
||||
|
||||
|
||||
/**
|
||||
* Provides the constants for the standard HTTP header names and values and
|
||||
@ -321,7 +323,7 @@ public class HttpHeaders {
|
||||
/**
|
||||
* {@code "boundary"}
|
||||
*/
|
||||
static final String BOUNDARY = "boundary";
|
||||
public static final String BOUNDARY = "boundary";
|
||||
/**
|
||||
* {@code "bytes"}
|
||||
*/
|
||||
@ -377,7 +379,7 @@ public class HttpHeaders {
|
||||
/**
|
||||
* {@code "multipart/form-data"}
|
||||
*/
|
||||
static final String MULTIPART_FORM_DATA = "multipart/form-data";
|
||||
public static final String MULTIPART_FORM_DATA = "multipart/form-data";
|
||||
/**
|
||||
* {@code "must-revalidate"}
|
||||
*/
|
||||
|
@ -335,12 +335,12 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<HttpMessageDec
|
||||
case READ_CHUNK_DELIMITER: {
|
||||
for (;;) {
|
||||
byte next = buffer.readByte();
|
||||
if (next == HttpCodecUtil.CR) {
|
||||
if (buffer.readByte() == HttpCodecUtil.LF) {
|
||||
if (next == HttpConstants.CR) {
|
||||
if (buffer.readByte() == HttpConstants.LF) {
|
||||
checkpoint(State.READ_CHUNK_SIZE);
|
||||
return null;
|
||||
}
|
||||
} else if (next == HttpCodecUtil.LF) {
|
||||
} else if (next == HttpConstants.LF) {
|
||||
checkpoint(State.READ_CHUNK_SIZE);
|
||||
return null;
|
||||
}
|
||||
@ -524,14 +524,14 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<HttpMessageDec
|
||||
headerSize ++;
|
||||
|
||||
switch (nextByte) {
|
||||
case HttpCodecUtil.CR:
|
||||
case HttpConstants.CR:
|
||||
nextByte = (char) buffer.readByte();
|
||||
headerSize ++;
|
||||
if (nextByte == HttpCodecUtil.LF) {
|
||||
if (nextByte == HttpConstants.LF) {
|
||||
break loop;
|
||||
}
|
||||
break;
|
||||
case HttpCodecUtil.LF:
|
||||
case HttpConstants.LF:
|
||||
break loop;
|
||||
}
|
||||
|
||||
@ -575,12 +575,12 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<HttpMessageDec
|
||||
int lineLength = 0;
|
||||
while (true) {
|
||||
byte nextByte = buffer.readByte();
|
||||
if (nextByte == HttpCodecUtil.CR) {
|
||||
if (nextByte == HttpConstants.CR) {
|
||||
nextByte = buffer.readByte();
|
||||
if (nextByte == HttpCodecUtil.LF) {
|
||||
if (nextByte == HttpConstants.LF) {
|
||||
return sb.toString();
|
||||
}
|
||||
} else if (nextByte == HttpCodecUtil.LF) {
|
||||
} else if (nextByte == HttpConstants.LF) {
|
||||
return sb.toString();
|
||||
} else {
|
||||
if (lineLength >= maxLineLength) {
|
||||
|
@ -16,7 +16,7 @@
|
||||
package org.jboss.netty.handler.codec.http;
|
||||
|
||||
import static org.jboss.netty.buffer.ChannelBuffers.*;
|
||||
import static org.jboss.netty.handler.codec.http.HttpCodecUtil.*;
|
||||
import static org.jboss.netty.handler.codec.http.HttpConstants.*;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Map;
|
||||
@ -46,6 +46,7 @@ import org.jboss.netty.util.CharsetUtil;
|
||||
*/
|
||||
public abstract class HttpMessageEncoder extends OneToOneEncoder {
|
||||
|
||||
private static final byte[] CRLF = new byte[] { CR, LF };
|
||||
private static final ChannelBuffer LAST_CHUNK =
|
||||
copiedBuffer("0\r\n\r\n", CharsetUtil.US_ASCII);
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.jboss.netty.handler.codec.http;
|
||||
|
||||
import static org.jboss.netty.handler.codec.http.HttpCodecUtil.*;
|
||||
import static org.jboss.netty.handler.codec.http.HttpConstants.*;
|
||||
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.jboss.netty.handler.codec.http;
|
||||
|
||||
import static org.jboss.netty.handler.codec.http.HttpCodecUtil.*;
|
||||
import static org.jboss.netty.handler.codec.http.HttpConstants.*;
|
||||
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
|
||||
|
@ -60,7 +60,7 @@ import org.jboss.netty.util.CharsetUtil;
|
||||
public class QueryStringDecoder {
|
||||
|
||||
private static final int DEFAULT_MAX_PARAMS = 1024;
|
||||
|
||||
|
||||
private final Charset charset;
|
||||
private final String uri;
|
||||
private final boolean hasPath;
|
||||
@ -74,7 +74,7 @@ public class QueryStringDecoder {
|
||||
* assume that the query string is encoded in UTF-8.
|
||||
*/
|
||||
public QueryStringDecoder(String uri) {
|
||||
this(uri, HttpCodecUtil.DEFAULT_CHARSET);
|
||||
this(uri, HttpConstants.DEFAULT_CHARSET);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,7 +82,7 @@ public class QueryStringDecoder {
|
||||
* specified charset.
|
||||
*/
|
||||
public QueryStringDecoder(String uri, boolean hasPath) {
|
||||
this(uri, HttpCodecUtil.DEFAULT_CHARSET, hasPath);
|
||||
this(uri, HttpConstants.DEFAULT_CHARSET, hasPath);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,7 +137,7 @@ public class QueryStringDecoder {
|
||||
* assume that the query string is encoded in UTF-8.
|
||||
*/
|
||||
public QueryStringDecoder(URI uri) {
|
||||
this(uri, HttpCodecUtil.DEFAULT_CHARSET);
|
||||
this(uri, HttpConstants.DEFAULT_CHARSET);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -147,7 +147,7 @@ public class QueryStringDecoder {
|
||||
public QueryStringDecoder(URI uri, Charset charset) {
|
||||
this(uri, charset, DEFAULT_MAX_PARAMS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new decoder that decodes the specified URI encoded in the
|
||||
* specified charset.
|
||||
@ -163,7 +163,7 @@ public class QueryStringDecoder {
|
||||
throw new IllegalArgumentException(
|
||||
"maxParams: " + maxParams + " (expected: a positive integer)");
|
||||
}
|
||||
|
||||
|
||||
String rawPath = uri.getRawPath();
|
||||
if (rawPath != null) {
|
||||
hasPath = true;
|
||||
@ -171,7 +171,7 @@ public class QueryStringDecoder {
|
||||
rawPath = "";
|
||||
hasPath = false;
|
||||
}
|
||||
// Also take care of cut of things like "http://localhost"
|
||||
// Also take care of cut of things like "http://localhost"
|
||||
String newUri = rawPath + "?" + uri.getRawQuery();
|
||||
|
||||
// http://en.wikipedia.org/wiki/Query_string
|
||||
@ -305,7 +305,7 @@ public class QueryStringDecoder {
|
||||
* escape sequence.
|
||||
*/
|
||||
public static String decodeComponent(final String s) {
|
||||
return decodeComponent(s, HttpCodecUtil.DEFAULT_CHARSET);
|
||||
return decodeComponent(s, HttpConstants.DEFAULT_CHARSET);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,7 +49,7 @@ public class QueryStringEncoder {
|
||||
* path string. The encoder will encode the URI in UTF-8.
|
||||
*/
|
||||
public QueryStringEncoder(String uri) {
|
||||
this(uri, HttpCodecUtil.DEFAULT_CHARSET);
|
||||
this(uri, HttpConstants.DEFAULT_CHARSET);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,7 +13,7 @@
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jboss.netty.handler.codec.http;
|
||||
package org.jboss.netty.handler.codec.http.multipart;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@ -26,6 +26,7 @@ import java.nio.charset.Charset;
|
||||
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
import org.jboss.netty.buffer.ChannelBuffers;
|
||||
import org.jboss.netty.handler.codec.http.HttpConstants;
|
||||
|
||||
/**
|
||||
* Abstract Disk HttpData implementation
|
||||
@ -259,7 +260,7 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
|
||||
}
|
||||
|
||||
public String getString() throws IOException {
|
||||
return getString(HttpCodecUtil.DEFAULT_CHARSET);
|
||||
return getString(HttpConstants.DEFAULT_CHARSET);
|
||||
}
|
||||
|
||||
public String getString(Charset encoding) throws IOException {
|
||||
@ -268,7 +269,7 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
|
||||
}
|
||||
if (encoding == null) {
|
||||
byte[] array = readFrom(file);
|
||||
return new String(array, HttpCodecUtil.DEFAULT_CHARSET.name());
|
||||
return new String(array, HttpConstants.DEFAULT_CHARSET.name());
|
||||
}
|
||||
byte[] array = readFrom(file);
|
||||
return new String(array, encoding.name());
|
@ -13,10 +13,12 @@
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jboss.netty.handler.codec.http;
|
||||
package org.jboss.netty.handler.codec.http.multipart;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.jboss.netty.handler.codec.http.HttpConstants;
|
||||
|
||||
/**
|
||||
* Abstract HttpData implementation
|
||||
*/
|
||||
@ -25,7 +27,7 @@ public abstract class AbstractHttpData implements HttpData {
|
||||
protected final String name;
|
||||
protected long definedSize;
|
||||
protected long size;
|
||||
protected Charset charset = HttpCodecUtil.DEFAULT_CHARSET;
|
||||
protected Charset charset = HttpConstants.DEFAULT_CHARSET;
|
||||
protected boolean completed;
|
||||
|
||||
public AbstractHttpData(String name, Charset charset, long size) {
|
@ -13,7 +13,7 @@
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jboss.netty.handler.codec.http;
|
||||
package org.jboss.netty.handler.codec.http.multipart;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@ -26,6 +26,7 @@ import java.nio.charset.Charset;
|
||||
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
import org.jboss.netty.buffer.ChannelBuffers;
|
||||
import org.jboss.netty.handler.codec.http.HttpConstants;
|
||||
|
||||
/**
|
||||
* Abstract Memory HttpData implementation
|
||||
@ -138,7 +139,7 @@ public abstract class AbstractMemoryHttpData extends AbstractHttpData {
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
return getString(HttpCodecUtil.DEFAULT_CHARSET);
|
||||
return getString(HttpConstants.DEFAULT_CHARSET);
|
||||
}
|
||||
|
||||
public String getString(Charset encoding) {
|
||||
@ -146,7 +147,7 @@ public abstract class AbstractMemoryHttpData extends AbstractHttpData {
|
||||
return "";
|
||||
}
|
||||
if (encoding == null) {
|
||||
return getString(HttpCodecUtil.DEFAULT_CHARSET);
|
||||
return getString(HttpConstants.DEFAULT_CHARSET);
|
||||
}
|
||||
return channelBuffer.toString(encoding);
|
||||
}
|
@ -13,7 +13,7 @@
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jboss.netty.handler.codec.http;
|
||||
package org.jboss.netty.handler.codec.http.multipart;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jboss.netty.handler.codec.http;
|
||||
package org.jboss.netty.handler.codec.http.multipart;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
@ -21,6 +21,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.jboss.netty.handler.codec.http.HttpRequest;
|
||||
|
||||
/**
|
||||
* Default factory giving Attribute and FileUpload according to constructor
|
||||
*
|
||||
@ -35,9 +37,9 @@ public class DefaultHttpDataFactory implements HttpDataFactory {
|
||||
*/
|
||||
public static long MINSIZE = 0x4000;
|
||||
|
||||
private boolean useDisk;
|
||||
private final boolean useDisk;
|
||||
|
||||
private boolean checkSize;
|
||||
private final boolean checkSize;
|
||||
|
||||
private long minSize;
|
||||
|
||||
@ -53,7 +55,7 @@ public class DefaultHttpDataFactory implements HttpDataFactory {
|
||||
public DefaultHttpDataFactory() {
|
||||
useDisk = false;
|
||||
checkSize = true;
|
||||
this.minSize = MINSIZE;
|
||||
minSize = MINSIZE;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,7 +79,7 @@ public class DefaultHttpDataFactory implements HttpDataFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
* @return the associated list of Files for the request
|
||||
*/
|
||||
@ -89,7 +91,7 @@ public class DefaultHttpDataFactory implements HttpDataFactory {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public Attribute createAttribute(HttpRequest request, String name) {
|
||||
if (useDisk) {
|
||||
Attribute attribute = new DiskAttribute(name);
|
@ -13,12 +13,13 @@
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jboss.netty.handler.codec.http;
|
||||
package org.jboss.netty.handler.codec.http.multipart;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
import org.jboss.netty.buffer.ChannelBuffers;
|
||||
import org.jboss.netty.handler.codec.http.HttpConstants;
|
||||
|
||||
/**
|
||||
* Disk implementation of Attributes
|
||||
@ -37,7 +38,7 @@ public class DiskAttribute extends AbstractDiskHttpData implements Attribute {
|
||||
* @param name
|
||||
*/
|
||||
public DiskAttribute(String name) {
|
||||
super(name, HttpCodecUtil.DEFAULT_CHARSET, 0);
|
||||
super(name, HttpConstants.DEFAULT_CHARSET, 0);
|
||||
}
|
||||
/**
|
||||
*
|
||||
@ -48,7 +49,7 @@ public class DiskAttribute extends AbstractDiskHttpData implements Attribute {
|
||||
* @throws IOException
|
||||
*/
|
||||
public DiskAttribute(String name, String value) throws IOException {
|
||||
super(name, HttpCodecUtil.DEFAULT_CHARSET, 0); // Attribute have no default size
|
||||
super(name, HttpConstants.DEFAULT_CHARSET, 0); // Attribute have no default size
|
||||
setValue(value);
|
||||
}
|
||||
|
@ -13,11 +13,13 @@
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jboss.netty.handler.codec.http;
|
||||
package org.jboss.netty.handler.codec.http.multipart;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.jboss.netty.handler.codec.http.HttpHeaders;
|
||||
|
||||
/**
|
||||
* Disk FileUpload implementation that stores file into real files
|
||||
*/
|
@ -13,7 +13,7 @@
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jboss.netty.handler.codec.http;
|
||||
package org.jboss.netty.handler.codec.http.multipart;
|
||||
|
||||
/**
|
||||
* FileUpload interface that could be in memory, on temporary file or any other implementations.
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user