2008-08-08 00:37:18 +00:00
|
|
|
/*
|
2012-06-04 13:31:44 -07:00
|
|
|
* Copyright 2012 The Netty Project
|
2008-08-08 00:37:18 +00:00
|
|
|
*
|
2011-12-09 14:18:34 +09:00
|
|
|
* 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:
|
2008-08-08 00:37:18 +00:00
|
|
|
*
|
2012-06-04 13:31:44 -07:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2008-08-08 01:27:24 +00:00
|
|
|
*
|
2009-08-28 07:15:49 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
2011-12-09 14:18:34 +09:00
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
2009-08-28 07:15:49 +00:00
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2008-08-08 00:37:18 +00:00
|
|
|
*/
|
2011-12-09 12:38:59 +09:00
|
|
|
package io.netty.channel;
|
2008-08-08 00:37:18 +00:00
|
|
|
|
2012-05-01 17:19:41 +09:00
|
|
|
import io.netty.buffer.ChannelBuffer;
|
2012-06-04 00:24:34 -07:00
|
|
|
import io.netty.channel.DefaultChannelHandlerContext.MessageBridge;
|
|
|
|
import io.netty.channel.DefaultChannelHandlerContext.StreamBridge;
|
2012-05-01 17:19:41 +09:00
|
|
|
import io.netty.logging.InternalLogger;
|
|
|
|
import io.netty.logging.InternalLoggerFactory;
|
|
|
|
|
|
|
|
import java.net.SocketAddress;
|
2011-08-02 08:43:10 +09:00
|
|
|
import java.util.ArrayList;
|
2008-08-08 00:37:18 +00:00
|
|
|
import java.util.HashMap;
|
2012-06-01 17:51:19 -07:00
|
|
|
import java.util.IdentityHashMap;
|
2008-08-08 00:37:18 +00:00
|
|
|
import java.util.LinkedHashMap;
|
2011-08-02 08:43:10 +09:00
|
|
|
import java.util.List;
|
2008-08-08 00:37:18 +00:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.NoSuchElementException;
|
2012-05-29 12:09:29 -07:00
|
|
|
import java.util.Queue;
|
2012-06-03 18:51:42 -07:00
|
|
|
import java.util.concurrent.Executor;
|
2012-06-05 11:21:44 +02:00
|
|
|
import java.util.concurrent.Future;
|
2008-08-08 00:37:18 +00:00
|
|
|
|
2008-09-02 07:13:20 +00:00
|
|
|
/**
|
2012-05-01 17:19:41 +09:00
|
|
|
* The default {@link ChannelPipeline} implementation. It is usually created
|
|
|
|
* by a {@link Channel} implementation when the {@link Channel} is created.
|
2008-09-02 07:13:20 +00:00
|
|
|
*/
|
2008-08-08 00:37:18 +00:00
|
|
|
public class DefaultChannelPipeline implements ChannelPipeline {
|
|
|
|
|
2008-08-09 15:05:53 +00:00
|
|
|
static final InternalLogger logger = InternalLoggerFactory.getInstance(DefaultChannelPipeline.class);
|
2009-03-11 10:45:55 +00:00
|
|
|
|
2012-06-01 17:51:19 -07:00
|
|
|
final Channel channel;
|
2012-06-01 18:34:19 -07:00
|
|
|
private final Channel.Unsafe unsafe;
|
2012-06-03 18:51:42 -07:00
|
|
|
final ChannelBufferHolder<Object> directOutbound;
|
2012-06-01 18:34:19 -07:00
|
|
|
|
2012-06-03 18:51:42 -07:00
|
|
|
private final DefaultChannelHandlerContext head;
|
2008-08-08 00:37:18 +00:00
|
|
|
private volatile DefaultChannelHandlerContext tail;
|
|
|
|
private final Map<String, DefaultChannelHandlerContext> name2ctx =
|
|
|
|
new HashMap<String, DefaultChannelHandlerContext>(4);
|
2012-05-30 11:32:39 -07:00
|
|
|
private boolean firedChannelActive;
|
2012-06-04 11:56:00 -07:00
|
|
|
private boolean fireInboundBufferUpdatedOnActivation;
|
|
|
|
|
2012-06-01 17:51:19 -07:00
|
|
|
final Map<EventExecutor, EventExecutor> childExecutors =
|
|
|
|
new IdentityHashMap<EventExecutor, EventExecutor>();
|
|
|
|
|
2012-06-05 11:21:44 +02:00
|
|
|
|
2012-05-01 17:19:41 +09:00
|
|
|
public DefaultChannelPipeline(Channel channel) {
|
2008-08-08 00:37:18 +00:00
|
|
|
if (channel == null) {
|
|
|
|
throw new NullPointerException("channel");
|
|
|
|
}
|
|
|
|
this.channel = channel;
|
2012-06-03 18:51:42 -07:00
|
|
|
|
|
|
|
HeadHandler headHandler = new HeadHandler();
|
|
|
|
head = new DefaultChannelHandlerContext(
|
|
|
|
this, null, null, null, generateName(headHandler), headHandler);
|
|
|
|
tail = head;
|
|
|
|
|
|
|
|
directOutbound = head.out;
|
2012-06-01 18:34:19 -07:00
|
|
|
unsafe = channel.unsafe();
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-05-01 17:19:41 +09:00
|
|
|
public Channel channel() {
|
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-06-01 17:51:19 -07:00
|
|
|
public ChannelPipeline addFirst(String name, ChannelHandler handler) {
|
|
|
|
return addFirst(null, name, handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-06-05 11:21:44 +02:00
|
|
|
public ChannelPipeline addFirst(EventExecutor executor, final String name, final ChannelHandler handler) {
|
|
|
|
try {
|
|
|
|
Future<?> future;
|
|
|
|
|
|
|
|
synchronized (this) {
|
|
|
|
checkDuplicateName(name);
|
|
|
|
final DefaultChannelHandlerContext nextCtx = head.next;
|
|
|
|
final DefaultChannelHandlerContext newCtx = new DefaultChannelHandlerContext(this, executor, head, nextCtx, name, handler);
|
|
|
|
|
|
|
|
if (!newCtx.channel().isRegistered() || newCtx.executor().inEventLoop()) {
|
|
|
|
addFirst0(name, nextCtx, newCtx);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
future = newCtx.executor().submit(new Runnable() {
|
2012-06-04 20:49:31 +02:00
|
|
|
@Override
|
|
|
|
public void run() {
|
2012-06-05 11:21:44 +02:00
|
|
|
synchronized (DefaultChannelPipeline.this) {
|
|
|
|
checkDuplicateName(name);
|
|
|
|
addFirst0(name, nextCtx, newCtx);
|
|
|
|
}
|
|
|
|
|
2012-06-04 20:49:31 +02:00
|
|
|
}
|
2012-06-05 11:21:44 +02:00
|
|
|
});
|
2012-06-04 20:49:31 +02:00
|
|
|
}
|
2012-06-05 11:21:44 +02:00
|
|
|
// Call Future.get() outside of the synchronized block to prevent dead-lock
|
|
|
|
future.get();
|
|
|
|
return this;
|
|
|
|
|
|
|
|
} catch (RuntimeException e) {
|
|
|
|
throw e;
|
|
|
|
} catch (Error e) {
|
|
|
|
throw e;
|
|
|
|
} catch (Throwable t) {
|
|
|
|
throw new ChannelPipelineException(t);
|
2012-06-04 20:34:09 +02:00
|
|
|
}
|
2012-06-04 11:56:00 -07:00
|
|
|
|
2012-06-04 20:34:09 +02:00
|
|
|
}
|
2012-06-05 11:21:44 +02:00
|
|
|
|
2012-06-04 11:56:00 -07:00
|
|
|
private void addFirst0(final String name, DefaultChannelHandlerContext nextCtx, DefaultChannelHandlerContext newCtx) {
|
2012-06-03 18:51:42 -07:00
|
|
|
callBeforeAdd(newCtx);
|
2008-12-01 10:07:54 +00:00
|
|
|
|
2012-06-03 18:51:42 -07:00
|
|
|
if (nextCtx != null) {
|
|
|
|
nextCtx.prev = newCtx;
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
2012-06-03 18:51:42 -07:00
|
|
|
head.next = newCtx;
|
|
|
|
name2ctx.put(name, newCtx);
|
2012-05-15 14:08:42 +09:00
|
|
|
|
2012-06-03 18:51:42 -07:00
|
|
|
callAfterAdd(newCtx);
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
2012-06-04 11:56:00 -07:00
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-06-01 17:51:19 -07:00
|
|
|
public ChannelPipeline addLast(String name, ChannelHandler handler) {
|
|
|
|
return addLast(null, name, handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-06-05 11:21:44 +02:00
|
|
|
public ChannelPipeline addLast(EventExecutor executor, final String name, final ChannelHandler handler) {
|
|
|
|
try {
|
|
|
|
Future<?> future;
|
|
|
|
|
|
|
|
synchronized (this) {
|
|
|
|
checkDuplicateName(name);
|
|
|
|
|
|
|
|
final DefaultChannelHandlerContext oldTail = tail;
|
|
|
|
final DefaultChannelHandlerContext newTail = new DefaultChannelHandlerContext(this, executor, oldTail, null, name, handler);
|
|
|
|
|
|
|
|
if (!newTail.channel().isRegistered() || newTail.executor().inEventLoop()) {
|
|
|
|
addLast0(name, oldTail, newTail);
|
|
|
|
return this;
|
|
|
|
} else {
|
|
|
|
future = newTail.executor().submit(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
synchronized (DefaultChannelPipeline.this) {
|
|
|
|
checkDuplicateName(name);
|
|
|
|
addLast0(name, oldTail, newTail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2012-06-04 20:49:31 +02:00
|
|
|
}
|
2012-06-05 11:21:44 +02:00
|
|
|
// Call Future.get() outside of synchronized block to prevent dead-lock
|
|
|
|
future.get();
|
|
|
|
} catch (RuntimeException e) {
|
|
|
|
throw e;
|
|
|
|
} catch (Error e) {
|
|
|
|
throw e;
|
|
|
|
} catch (Throwable t) {
|
|
|
|
throw new ChannelPipelineException(t);
|
2012-06-04 20:34:09 +02:00
|
|
|
}
|
2012-06-05 11:21:44 +02:00
|
|
|
|
2012-06-04 20:34:09 +02:00
|
|
|
return this;
|
|
|
|
}
|
2012-06-04 11:56:00 -07:00
|
|
|
|
|
|
|
private void addLast0(final String name, DefaultChannelHandlerContext oldTail, DefaultChannelHandlerContext newTail) {
|
2012-06-03 18:51:42 -07:00
|
|
|
callBeforeAdd(newTail);
|
2008-12-01 10:07:54 +00:00
|
|
|
|
2012-06-03 18:51:42 -07:00
|
|
|
oldTail.next = newTail;
|
|
|
|
tail = newTail;
|
|
|
|
name2ctx.put(name, newTail);
|
2012-05-15 14:08:42 +09:00
|
|
|
|
2012-06-04 11:56:00 -07:00
|
|
|
callAfterAdd(newTail);
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-06-01 17:51:19 -07:00
|
|
|
public ChannelPipeline addBefore(String baseName, String name, ChannelHandler handler) {
|
|
|
|
return addBefore(null, baseName, name, handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-06-05 11:21:44 +02:00
|
|
|
public ChannelPipeline addBefore(EventExecutor executor, String baseName, final String name, final ChannelHandler handler) {
|
|
|
|
try {
|
|
|
|
Future<?> future;
|
|
|
|
|
|
|
|
synchronized (this) {
|
|
|
|
final DefaultChannelHandlerContext ctx = getContextOrDie(baseName);
|
|
|
|
checkDuplicateName(name);
|
|
|
|
final DefaultChannelHandlerContext newCtx = new DefaultChannelHandlerContext(this, executor, ctx.prev, ctx, name, handler);
|
|
|
|
|
|
|
|
if (!newCtx.channel().isRegistered() || newCtx.executor().inEventLoop()) {
|
|
|
|
addBefore0(name, ctx, newCtx);
|
|
|
|
return this;
|
|
|
|
} else {
|
|
|
|
future = newCtx.executor().submit(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
synchronized (DefaultChannelPipeline.this) {
|
|
|
|
checkDuplicateName(name);
|
|
|
|
addBefore0(name, ctx, newCtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2012-06-04 20:49:31 +02:00
|
|
|
}
|
2012-06-05 11:21:44 +02:00
|
|
|
|
|
|
|
// Call Future.get() outside of the synchronized to prevent dead-lock
|
|
|
|
future.get();
|
|
|
|
|
|
|
|
|
|
|
|
} catch (RuntimeException e) {
|
|
|
|
throw e;
|
|
|
|
} catch (Error e) {
|
|
|
|
throw e;
|
|
|
|
} catch (Throwable t) {
|
|
|
|
throw new ChannelPipelineException(t);
|
2012-06-04 20:34:09 +02:00
|
|
|
}
|
2012-06-05 11:21:44 +02:00
|
|
|
|
2012-06-04 20:34:09 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2012-06-04 11:56:00 -07:00
|
|
|
private void addBefore0(final String name, DefaultChannelHandlerContext ctx, DefaultChannelHandlerContext newCtx) {
|
2012-06-03 18:51:42 -07:00
|
|
|
callBeforeAdd(newCtx);
|
2008-12-01 10:07:54 +00:00
|
|
|
|
2012-06-03 18:51:42 -07:00
|
|
|
ctx.prev.next = newCtx;
|
|
|
|
ctx.prev = newCtx;
|
|
|
|
name2ctx.put(name, newCtx);
|
2012-05-15 14:08:42 +09:00
|
|
|
|
2012-06-04 11:56:00 -07:00
|
|
|
callAfterAdd(newCtx);
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
2012-06-04 11:56:00 -07:00
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-06-01 17:51:19 -07:00
|
|
|
public ChannelPipeline addAfter(String baseName, String name, ChannelHandler handler) {
|
|
|
|
return addAfter(null, baseName, name, handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-06-05 11:21:44 +02:00
|
|
|
public ChannelPipeline addAfter(EventExecutor executor, String baseName, final String name, final ChannelHandler handler) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
Future<?> future;
|
|
|
|
|
|
|
|
synchronized (this) {
|
|
|
|
final DefaultChannelHandlerContext ctx = getContextOrDie(baseName);
|
|
|
|
if (ctx == tail) {
|
|
|
|
return addLast(name, handler);
|
|
|
|
}
|
|
|
|
checkDuplicateName(name);
|
|
|
|
final DefaultChannelHandlerContext newCtx = new DefaultChannelHandlerContext(this, executor, ctx, ctx.next, name, handler);
|
|
|
|
|
|
|
|
if (!newCtx.channel().isRegistered() || newCtx.executor().inEventLoop()) {
|
|
|
|
addAfter0(name, ctx, newCtx);
|
|
|
|
return this;
|
|
|
|
} else {
|
|
|
|
future = newCtx.executor().submit(new Runnable() {
|
2012-06-04 20:49:31 +02:00
|
|
|
@Override
|
|
|
|
public void run() {
|
2012-06-05 11:21:44 +02:00
|
|
|
synchronized (DefaultChannelPipeline.this) {
|
|
|
|
checkDuplicateName(name);
|
|
|
|
addAfter0(name, ctx, newCtx);
|
|
|
|
}
|
2012-06-04 20:49:31 +02:00
|
|
|
}
|
2012-06-05 11:21:44 +02:00
|
|
|
});
|
2012-06-04 20:49:31 +02:00
|
|
|
}
|
2012-06-04 20:34:09 +02:00
|
|
|
}
|
2012-06-05 11:21:44 +02:00
|
|
|
future.get();
|
|
|
|
return this;
|
|
|
|
|
|
|
|
} catch (RuntimeException e) {
|
|
|
|
throw e;
|
|
|
|
} catch (Error e) {
|
|
|
|
throw e;
|
|
|
|
} catch (Throwable t) {
|
|
|
|
throw new ChannelPipelineException(t);
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
2012-06-05 11:21:44 +02:00
|
|
|
|
2012-05-15 14:08:42 +09:00
|
|
|
}
|
|
|
|
|
2012-06-04 11:56:00 -07:00
|
|
|
private void addAfter0(final String name, DefaultChannelHandlerContext ctx, DefaultChannelHandlerContext newCtx) {
|
2012-06-04 20:34:09 +02:00
|
|
|
checkDuplicateName(name);
|
|
|
|
|
|
|
|
callBeforeAdd(newCtx);
|
|
|
|
|
|
|
|
ctx.next.prev = newCtx;
|
|
|
|
ctx.next = newCtx;
|
|
|
|
name2ctx.put(name, newCtx);
|
|
|
|
|
2012-06-04 11:56:00 -07:00
|
|
|
callAfterAdd(newCtx);
|
2012-06-04 20:34:09 +02:00
|
|
|
}
|
2012-06-04 11:56:00 -07:00
|
|
|
|
2012-05-15 14:08:42 +09:00
|
|
|
@Override
|
|
|
|
public ChannelPipeline addFirst(ChannelHandler... handlers) {
|
2012-06-01 17:51:19 -07:00
|
|
|
return addFirst(null, handlers);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelPipeline addFirst(EventExecutor executor, ChannelHandler... handlers) {
|
2012-05-15 14:08:42 +09:00
|
|
|
if (handlers == null) {
|
|
|
|
throw new NullPointerException("handlers");
|
|
|
|
}
|
2012-05-15 14:49:23 +09:00
|
|
|
if (handlers.length == 0 || handlers[0] == null) {
|
2012-05-15 14:08:42 +09:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
int size;
|
|
|
|
for (size = 1; size < handlers.length; size ++) {
|
|
|
|
if (handlers[size] == null) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = size - 1; i >= 0; i --) {
|
|
|
|
ChannelHandler h = handlers[i];
|
2012-06-01 17:51:19 -07:00
|
|
|
addFirst(executor, generateName(h), h);
|
2012-05-15 14:08:42 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelPipeline addLast(ChannelHandler... handlers) {
|
2012-06-01 17:51:19 -07:00
|
|
|
return addLast(null, handlers);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelPipeline addLast(EventExecutor executor, ChannelHandler... handlers) {
|
2012-05-15 14:08:42 +09:00
|
|
|
if (handlers == null) {
|
|
|
|
throw new NullPointerException("handlers");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (ChannelHandler h: handlers) {
|
|
|
|
if (h == null) {
|
|
|
|
break;
|
|
|
|
}
|
2012-06-01 17:51:19 -07:00
|
|
|
addLast(executor, generateName(h), h);
|
2012-05-15 14:08:42 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2012-05-29 16:41:26 -07:00
|
|
|
private static String generateName(ChannelHandler handler) {
|
2012-05-15 14:08:42 +09:00
|
|
|
String type = handler.getClass().getSimpleName();
|
|
|
|
StringBuilder buf = new StringBuilder(type.length() + 10);
|
|
|
|
buf.append(type);
|
|
|
|
buf.append("-0");
|
|
|
|
buf.append(Long.toHexString(System.identityHashCode(handler) & 0xFFFFFFFFL | 0x100000000L));
|
|
|
|
buf.setCharAt(buf.length() - 9, 'x');
|
|
|
|
return buf.toString();
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-06-05 11:21:44 +02:00
|
|
|
public void remove(ChannelHandler handler) {
|
2008-08-08 00:37:18 +00:00
|
|
|
remove(getContextOrDie(handler));
|
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-06-05 11:21:44 +02:00
|
|
|
public ChannelHandler remove(String name) {
|
2012-05-01 17:19:41 +09:00
|
|
|
return remove(getContextOrDie(name)).handler();
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-06-05 11:21:44 +02:00
|
|
|
public <T extends ChannelHandler> T remove(Class<T> handlerType) {
|
2012-05-01 17:19:41 +09:00
|
|
|
return (T) remove(getContextOrDie(handlerType)).handler();
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 20:34:09 +02:00
|
|
|
private DefaultChannelHandlerContext remove(final DefaultChannelHandlerContext ctx) {
|
2012-06-05 11:21:44 +02:00
|
|
|
try {
|
|
|
|
DefaultChannelHandlerContext context;
|
|
|
|
Future<?> future;
|
|
|
|
synchronized (this) {
|
|
|
|
if (head == tail) {
|
|
|
|
return null;
|
|
|
|
} else if (ctx == head) {
|
|
|
|
throw new Error(); // Should never happen.
|
|
|
|
} else if (ctx == tail) {
|
|
|
|
if (head == tail) {
|
|
|
|
throw new NoSuchElementException();
|
|
|
|
}
|
|
|
|
|
|
|
|
final DefaultChannelHandlerContext oldTail = tail;
|
|
|
|
if (!oldTail.channel().isRegistered() || oldTail.executor().inEventLoop()) {
|
|
|
|
removeLast0(oldTail);
|
|
|
|
return oldTail;
|
|
|
|
} else {
|
|
|
|
future = oldTail.executor().submit(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
synchronized (oldTail) {
|
|
|
|
removeLast0(oldTail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
context = oldTail;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (!ctx.channel().isRegistered() || ctx.executor().inEventLoop()) {
|
|
|
|
remove0(ctx);
|
|
|
|
return ctx;
|
|
|
|
} else {
|
|
|
|
future = ctx.executor().submit(new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
synchronized (DefaultChannelPipeline.this) {
|
|
|
|
remove0(ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
context = ctx;
|
|
|
|
}
|
2012-06-04 20:49:31 +02:00
|
|
|
}
|
2012-06-04 20:34:09 +02:00
|
|
|
}
|
2012-06-05 11:21:44 +02:00
|
|
|
|
|
|
|
// call the Future.get() outside of the synchronization block to prevent from dead-lock
|
|
|
|
future.get();
|
|
|
|
return context;
|
|
|
|
} catch (RuntimeException e) {
|
|
|
|
throw e;
|
|
|
|
} catch (Error e) {
|
|
|
|
throw e;
|
|
|
|
} catch (Throwable t) {
|
|
|
|
throw new ChannelPipelineException(t);
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
2012-06-05 11:21:44 +02:00
|
|
|
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
2012-06-04 11:56:00 -07:00
|
|
|
|
2012-06-04 20:34:09 +02:00
|
|
|
private void remove0(DefaultChannelHandlerContext ctx) {
|
|
|
|
callBeforeRemove(ctx);
|
|
|
|
|
|
|
|
DefaultChannelHandlerContext prev = ctx.prev;
|
|
|
|
DefaultChannelHandlerContext next = ctx.next;
|
|
|
|
prev.next = next;
|
|
|
|
next.prev = prev;
|
|
|
|
name2ctx.remove(ctx.name());
|
|
|
|
|
|
|
|
callAfterRemove(ctx);
|
|
|
|
}
|
2008-08-08 00:37:18 +00:00
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-06-05 11:21:44 +02:00
|
|
|
public ChannelHandler removeFirst() {
|
2012-06-03 18:51:42 -07:00
|
|
|
if (head == tail) {
|
2008-08-18 02:38:54 +00:00
|
|
|
throw new NoSuchElementException();
|
|
|
|
}
|
2012-06-03 18:51:42 -07:00
|
|
|
return remove(head.next).handler();
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-06-05 11:21:44 +02:00
|
|
|
public ChannelHandler removeLast() {
|
|
|
|
try {
|
|
|
|
Future<?> future;
|
|
|
|
final DefaultChannelHandlerContext oldTail;
|
|
|
|
synchronized (this) {
|
|
|
|
if (head == tail) {
|
|
|
|
throw new NoSuchElementException();
|
|
|
|
}
|
|
|
|
oldTail = tail;
|
|
|
|
if (!oldTail.channel().isRegistered() || oldTail.executor().inEventLoop()) {
|
|
|
|
removeLast0(oldTail);
|
|
|
|
return oldTail.handler();
|
|
|
|
} else {
|
|
|
|
future = oldTail.executor().submit(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
synchronized (DefaultChannelPipeline.this) {
|
|
|
|
removeLast0(oldTail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2012-06-04 20:49:31 +02:00
|
|
|
}
|
2012-06-05 11:21:44 +02:00
|
|
|
// call Future.get() outside of the synchronized block to prevent deadlock
|
|
|
|
future.get();
|
|
|
|
return oldTail.handler();
|
|
|
|
} catch (RuntimeException e) {
|
|
|
|
throw e;
|
|
|
|
} catch (Error e) {
|
|
|
|
throw e;
|
|
|
|
} catch (Throwable t) {
|
|
|
|
throw new ChannelPipelineException(t);
|
2012-06-04 20:34:09 +02:00
|
|
|
}
|
2012-06-05 11:21:44 +02:00
|
|
|
|
|
|
|
|
2012-06-04 20:34:09 +02:00
|
|
|
}
|
2012-06-04 11:56:00 -07:00
|
|
|
|
2012-06-04 20:34:09 +02:00
|
|
|
private void removeLast0(DefaultChannelHandlerContext oldTail) {
|
2008-12-01 10:07:54 +00:00
|
|
|
callBeforeRemove(oldTail);
|
|
|
|
|
2012-06-03 18:51:42 -07:00
|
|
|
oldTail.prev.next = null;
|
|
|
|
tail = oldTail.prev;
|
|
|
|
name2ctx.remove(oldTail.name());
|
2008-12-01 10:07:54 +00:00
|
|
|
|
|
|
|
callBeforeRemove(oldTail);
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-06-05 11:21:44 +02:00
|
|
|
public void replace(ChannelHandler oldHandler, String newName, ChannelHandler newHandler) {
|
2008-08-08 00:37:18 +00:00
|
|
|
replace(getContextOrDie(oldHandler), newName, newHandler);
|
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-06-05 11:21:44 +02:00
|
|
|
public ChannelHandler replace(String oldName, String newName, ChannelHandler newHandler) {
|
2008-08-08 00:37:18 +00:00
|
|
|
return replace(getContextOrDie(oldName), newName, newHandler);
|
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2008-08-08 00:37:18 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
2012-06-05 11:21:44 +02:00
|
|
|
public <T extends ChannelHandler> T replace(
|
2008-08-08 00:37:18 +00:00
|
|
|
Class<T> oldHandlerType, String newName, ChannelHandler newHandler) {
|
|
|
|
return (T) replace(getContextOrDie(oldHandlerType), newName, newHandler);
|
|
|
|
}
|
|
|
|
|
2012-06-04 20:34:09 +02:00
|
|
|
private ChannelHandler replace(final DefaultChannelHandlerContext ctx, final String newName, final ChannelHandler newHandler) {
|
2012-06-05 11:21:44 +02:00
|
|
|
try {
|
|
|
|
Future<?> future;
|
|
|
|
synchronized (this) {
|
|
|
|
if (ctx == head) {
|
|
|
|
throw new IllegalArgumentException();
|
|
|
|
} else if (ctx == tail) {
|
|
|
|
if (head == tail) {
|
|
|
|
throw new NoSuchElementException();
|
|
|
|
}
|
|
|
|
final DefaultChannelHandlerContext oldTail = tail;
|
|
|
|
final DefaultChannelHandlerContext newTail = new DefaultChannelHandlerContext(this, null, oldTail, null, newName, newHandler);
|
|
|
|
|
|
|
|
if (!oldTail.channel().isRegistered() || oldTail.executor().inEventLoop()) {
|
|
|
|
removeLast0(oldTail);
|
|
|
|
checkDuplicateName(newName);
|
|
|
|
addLast0(newName, tail, newTail);
|
|
|
|
return ctx.handler();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
future = oldTail.executor().submit(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
synchronized (DefaultChannelPipeline.this) {
|
|
|
|
removeLast0(oldTail);
|
|
|
|
checkDuplicateName(newName);
|
|
|
|
addLast0(newName, tail, newTail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
boolean sameName = ctx.name().equals(newName);
|
|
|
|
if (!sameName) {
|
|
|
|
checkDuplicateName(newName);
|
|
|
|
}
|
2008-12-01 10:07:54 +00:00
|
|
|
|
2012-06-05 11:21:44 +02:00
|
|
|
DefaultChannelHandlerContext prev = ctx.prev;
|
|
|
|
DefaultChannelHandlerContext next = ctx.next;
|
|
|
|
|
|
|
|
final DefaultChannelHandlerContext newCtx = new DefaultChannelHandlerContext(this, ctx.executor, prev, next, newName, newHandler);
|
|
|
|
|
|
|
|
if (!newCtx.channel().isRegistered() || newCtx.executor().inEventLoop()) {
|
|
|
|
replace0(ctx, newName, newCtx);
|
|
|
|
return ctx.handler();
|
|
|
|
} else {
|
|
|
|
future = newCtx.executor().submit(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
synchronized (DefaultChannelPipeline.this) {
|
|
|
|
replace0(ctx, newName, newCtx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2012-06-04 20:49:31 +02:00
|
|
|
}
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
2012-06-05 11:21:44 +02:00
|
|
|
future.get();
|
|
|
|
return ctx.handler();
|
|
|
|
|
|
|
|
} catch (RuntimeException e) {
|
|
|
|
throw e;
|
|
|
|
} catch (Error e) {
|
|
|
|
throw e;
|
|
|
|
} catch (Throwable t) {
|
|
|
|
throw new ChannelPipelineException(t);
|
2012-06-04 20:34:09 +02:00
|
|
|
}
|
|
|
|
}
|
2008-12-01 10:07:54 +00:00
|
|
|
|
2012-06-04 11:56:00 -07:00
|
|
|
private void replace0(DefaultChannelHandlerContext ctx, String newName, DefaultChannelHandlerContext newCtx) {
|
2012-06-04 20:34:09 +02:00
|
|
|
boolean sameName = ctx.name().equals(newName);
|
2008-12-01 10:07:54 +00:00
|
|
|
|
2012-06-04 20:34:09 +02:00
|
|
|
DefaultChannelHandlerContext prev = ctx.prev;
|
|
|
|
DefaultChannelHandlerContext next = ctx.next;
|
2012-06-04 11:56:00 -07:00
|
|
|
|
2012-06-04 20:34:09 +02:00
|
|
|
callBeforeRemove(ctx);
|
|
|
|
callBeforeAdd(newCtx);
|
|
|
|
|
|
|
|
prev.next = newCtx;
|
|
|
|
next.prev = newCtx;
|
|
|
|
|
|
|
|
if (!sameName) {
|
|
|
|
name2ctx.remove(ctx.name());
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
2012-06-04 20:34:09 +02:00
|
|
|
name2ctx.put(newName, newCtx);
|
2008-12-01 10:07:54 +00:00
|
|
|
|
2012-06-04 20:34:09 +02:00
|
|
|
ChannelHandlerLifeCycleException removeException = null;
|
|
|
|
ChannelHandlerLifeCycleException addException = null;
|
|
|
|
boolean removed = false;
|
|
|
|
try {
|
|
|
|
callAfterRemove(ctx);
|
|
|
|
removed = true;
|
|
|
|
} catch (ChannelHandlerLifeCycleException e) {
|
|
|
|
removeException = e;
|
|
|
|
}
|
2008-08-08 00:37:18 +00:00
|
|
|
|
2012-06-04 20:34:09 +02:00
|
|
|
boolean added = false;
|
|
|
|
try {
|
|
|
|
callAfterAdd(newCtx);
|
|
|
|
added = true;
|
|
|
|
} catch (ChannelHandlerLifeCycleException e) {
|
|
|
|
addException = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!removed && !added) {
|
|
|
|
logger.warn(removeException.getMessage(), removeException);
|
|
|
|
logger.warn(addException.getMessage(), addException);
|
|
|
|
throw new ChannelHandlerLifeCycleException(
|
|
|
|
"Both " + ctx.handler().getClass().getName() +
|
|
|
|
".afterRemove() and " + newCtx.handler().getClass().getName() +
|
|
|
|
".afterAdd() failed; see logs.");
|
|
|
|
} else if (!removed) {
|
|
|
|
throw removeException;
|
|
|
|
} else if (!added) {
|
|
|
|
throw addException;
|
|
|
|
}
|
|
|
|
}
|
2012-06-04 11:56:00 -07:00
|
|
|
|
2012-05-01 17:19:41 +09:00
|
|
|
private static void callBeforeAdd(ChannelHandlerContext ctx) {
|
2012-05-31 14:54:48 -07:00
|
|
|
ChannelHandler handler = ctx.handler();
|
|
|
|
if (handler instanceof AbstractChannelHandler) {
|
|
|
|
AbstractChannelHandler h = (AbstractChannelHandler) handler;
|
|
|
|
if (!h.isSharable() && h.added) {
|
|
|
|
throw new ChannelHandlerLifeCycleException(
|
|
|
|
"Only a @Sharable handler can be added or removed multiple times.");
|
|
|
|
}
|
|
|
|
h.added = true;
|
|
|
|
}
|
2008-12-01 10:07:54 +00:00
|
|
|
try {
|
2012-05-31 14:54:48 -07:00
|
|
|
handler.beforeAdd(ctx);
|
2008-12-01 10:07:54 +00:00
|
|
|
} catch (Throwable t) {
|
|
|
|
throw new ChannelHandlerLifeCycleException(
|
2012-05-31 14:54:48 -07:00
|
|
|
handler.getClass().getName() +
|
2008-12-01 10:07:54 +00:00
|
|
|
".beforeAdd() has thrown an exception; not adding.", t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void callAfterAdd(ChannelHandlerContext ctx) {
|
|
|
|
try {
|
2012-05-01 17:19:41 +09:00
|
|
|
ctx.handler().afterAdd(ctx);
|
2008-12-01 10:07:54 +00:00
|
|
|
} catch (Throwable t) {
|
|
|
|
boolean removed = false;
|
|
|
|
try {
|
|
|
|
remove((DefaultChannelHandlerContext) ctx);
|
|
|
|
removed = true;
|
|
|
|
} catch (Throwable t2) {
|
2012-02-17 10:37:41 +01:00
|
|
|
if (logger.isWarnEnabled()) {
|
2012-05-01 17:19:41 +09:00
|
|
|
logger.warn("Failed to remove a handler: " + ctx.name(), t2);
|
2012-02-17 10:37:41 +01:00
|
|
|
}
|
2008-12-01 10:07:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (removed) {
|
|
|
|
throw new ChannelHandlerLifeCycleException(
|
2012-05-01 17:19:41 +09:00
|
|
|
ctx.handler().getClass().getName() +
|
2008-12-01 10:07:54 +00:00
|
|
|
".afterAdd() has thrown an exception; removed.", t);
|
|
|
|
} else {
|
|
|
|
throw new ChannelHandlerLifeCycleException(
|
2012-05-01 17:19:41 +09:00
|
|
|
ctx.handler().getClass().getName() +
|
2008-12-01 10:07:54 +00:00
|
|
|
".afterAdd() has thrown an exception; also failed to remove.", t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-01 17:19:41 +09:00
|
|
|
private static void callBeforeRemove(ChannelHandlerContext ctx) {
|
2008-12-01 10:07:54 +00:00
|
|
|
try {
|
2012-05-01 17:19:41 +09:00
|
|
|
ctx.handler().beforeRemove(ctx);
|
2008-12-01 10:07:54 +00:00
|
|
|
} catch (Throwable t) {
|
|
|
|
throw new ChannelHandlerLifeCycleException(
|
2012-05-01 17:19:41 +09:00
|
|
|
ctx.handler().getClass().getName() +
|
2008-12-01 10:07:54 +00:00
|
|
|
".beforeRemove() has thrown an exception; not removing.", t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-01 17:19:41 +09:00
|
|
|
private static void callAfterRemove(ChannelHandlerContext ctx) {
|
2008-12-01 10:07:54 +00:00
|
|
|
try {
|
2012-05-01 17:19:41 +09:00
|
|
|
ctx.handler().afterRemove(ctx);
|
2008-12-01 10:07:54 +00:00
|
|
|
} catch (Throwable t) {
|
|
|
|
throw new ChannelHandlerLifeCycleException(
|
2012-05-01 17:19:41 +09:00
|
|
|
ctx.handler().getClass().getName() +
|
2008-12-01 10:07:54 +00:00
|
|
|
".afterRemove() has thrown an exception.", t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-05-01 17:19:41 +09:00
|
|
|
public synchronized ChannelHandler first() {
|
2012-06-03 18:51:42 -07:00
|
|
|
DefaultChannelHandlerContext first = head.next;
|
|
|
|
if (first == null) {
|
2008-08-18 02:27:11 +00:00
|
|
|
return null;
|
|
|
|
}
|
2012-06-03 18:51:42 -07:00
|
|
|
return first.handler();
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-05-01 17:19:41 +09:00
|
|
|
public synchronized ChannelHandler last() {
|
2012-06-03 18:51:42 -07:00
|
|
|
DefaultChannelHandlerContext last = tail;
|
|
|
|
if (last == head || last == null) {
|
2008-08-18 02:27:11 +00:00
|
|
|
return null;
|
|
|
|
}
|
2012-06-03 18:51:42 -07:00
|
|
|
return last.handler();
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2008-08-08 00:37:18 +00:00
|
|
|
public synchronized ChannelHandler get(String name) {
|
|
|
|
DefaultChannelHandlerContext ctx = name2ctx.get(name);
|
|
|
|
if (ctx == null) {
|
|
|
|
return null;
|
|
|
|
} else {
|
2012-05-01 17:19:41 +09:00
|
|
|
return ctx.handler();
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2008-08-08 00:37:18 +00:00
|
|
|
public synchronized <T extends ChannelHandler> T get(Class<T> handlerType) {
|
2012-05-01 17:19:41 +09:00
|
|
|
ChannelHandlerContext ctx = context(handlerType);
|
2008-08-08 00:37:18 +00:00
|
|
|
if (ctx == null) {
|
|
|
|
return null;
|
|
|
|
} else {
|
2012-05-01 17:19:41 +09:00
|
|
|
return (T) ctx.handler();
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-05-01 17:19:41 +09:00
|
|
|
public synchronized ChannelHandlerContext context(String name) {
|
2008-08-08 00:37:18 +00:00
|
|
|
if (name == null) {
|
|
|
|
throw new NullPointerException("name");
|
|
|
|
}
|
|
|
|
return name2ctx.get(name);
|
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-05-01 17:19:41 +09:00
|
|
|
public synchronized ChannelHandlerContext context(ChannelHandler handler) {
|
2008-08-08 00:37:18 +00:00
|
|
|
if (handler == null) {
|
|
|
|
throw new NullPointerException("handler");
|
|
|
|
}
|
|
|
|
if (name2ctx.isEmpty()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
DefaultChannelHandlerContext ctx = head;
|
|
|
|
for (;;) {
|
2012-05-01 17:19:41 +09:00
|
|
|
if (ctx.handler() == handler) {
|
2008-08-08 00:37:18 +00:00
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx = ctx.next;
|
|
|
|
if (ctx == null) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-05-01 17:19:41 +09:00
|
|
|
public synchronized ChannelHandlerContext context(
|
2008-08-08 00:37:18 +00:00
|
|
|
Class<? extends ChannelHandler> handlerType) {
|
2009-12-17 10:57:57 +00:00
|
|
|
if (handlerType == null) {
|
|
|
|
throw new NullPointerException("handlerType");
|
|
|
|
}
|
|
|
|
|
2008-08-08 00:37:18 +00:00
|
|
|
if (name2ctx.isEmpty()) {
|
|
|
|
return null;
|
|
|
|
}
|
2012-06-03 18:51:42 -07:00
|
|
|
DefaultChannelHandlerContext ctx = head.next;
|
2008-08-08 00:37:18 +00:00
|
|
|
for (;;) {
|
2012-05-01 17:19:41 +09:00
|
|
|
if (handlerType.isAssignableFrom(ctx.handler().getClass())) {
|
2008-08-08 00:37:18 +00:00
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx = ctx.next;
|
|
|
|
if (ctx == null) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2011-08-02 08:43:10 +09:00
|
|
|
@Override
|
2012-05-01 17:19:41 +09:00
|
|
|
public List<String> names() {
|
2011-08-02 08:43:10 +09:00
|
|
|
List<String> list = new ArrayList<String>();
|
|
|
|
if (name2ctx.isEmpty()) {
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2012-06-03 18:51:42 -07:00
|
|
|
DefaultChannelHandlerContext ctx = head.next;
|
2011-08-02 08:43:10 +09:00
|
|
|
for (;;) {
|
2012-05-01 17:19:41 +09:00
|
|
|
list.add(ctx.name());
|
2011-08-02 08:43:10 +09:00
|
|
|
ctx = ctx.next;
|
|
|
|
if (ctx == null) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2008-08-08 00:37:18 +00:00
|
|
|
public Map<String, ChannelHandler> toMap() {
|
|
|
|
Map<String, ChannelHandler> map = new LinkedHashMap<String, ChannelHandler>();
|
|
|
|
if (name2ctx.isEmpty()) {
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
2012-06-03 18:51:42 -07:00
|
|
|
DefaultChannelHandlerContext ctx = head.next;
|
2008-08-08 00:37:18 +00:00
|
|
|
for (;;) {
|
2012-05-01 17:19:41 +09:00
|
|
|
map.put(ctx.name(), ctx.handler());
|
2008-08-08 00:37:18 +00:00
|
|
|
ctx = ctx.next;
|
|
|
|
if (ctx == null) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
2008-09-03 04:09:46 +00:00
|
|
|
/**
|
|
|
|
* Returns the {@link String} representation of this pipeline.
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
StringBuilder buf = new StringBuilder();
|
|
|
|
buf.append(getClass().getSimpleName());
|
|
|
|
buf.append('{');
|
2012-06-03 18:51:42 -07:00
|
|
|
DefaultChannelHandlerContext ctx = head.next;
|
2008-09-03 04:09:46 +00:00
|
|
|
for (;;) {
|
|
|
|
buf.append('(');
|
2012-05-01 17:19:41 +09:00
|
|
|
buf.append(ctx.name());
|
2008-09-03 04:09:46 +00:00
|
|
|
buf.append(" = ");
|
2012-05-01 17:19:41 +09:00
|
|
|
buf.append(ctx.handler().getClass().getName());
|
2008-09-03 04:09:46 +00:00
|
|
|
buf.append(')');
|
|
|
|
ctx = ctx.next;
|
|
|
|
if (ctx == null) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
buf.append(", ");
|
|
|
|
}
|
|
|
|
buf.append('}');
|
|
|
|
return buf.toString();
|
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-06-01 17:51:19 -07:00
|
|
|
public Queue<Object> inboundMessageBuffer() {
|
2012-06-02 01:58:15 -07:00
|
|
|
if (channel.type() != ChannelType.MESSAGE) {
|
|
|
|
throw new NoSuchBufferException(
|
|
|
|
"The first inbound buffer of this channel must be a message buffer.");
|
|
|
|
}
|
2012-06-04 00:24:34 -07:00
|
|
|
return nextInboundMessageBuffer(SingleThreadEventExecutor.currentEventLoop(), head.next);
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-06-01 17:51:19 -07:00
|
|
|
public ChannelBuffer inboundByteBuffer() {
|
2012-06-02 01:58:15 -07:00
|
|
|
if (channel.type() != ChannelType.STREAM) {
|
|
|
|
throw new NoSuchBufferException(
|
|
|
|
"The first inbound buffer of this channel must be a byte buffer.");
|
|
|
|
}
|
2012-06-04 00:24:34 -07:00
|
|
|
return nextInboundByteBuffer(SingleThreadEventExecutor.currentEventLoop(), head.next);
|
2012-06-01 17:51:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Queue<Object> outboundMessageBuffer() {
|
2012-06-04 00:24:34 -07:00
|
|
|
return nextOutboundMessageBuffer(SingleThreadEventExecutor.currentEventLoop(), tail);
|
2012-06-01 17:51:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelBuffer outboundByteBuffer() {
|
2012-06-04 00:24:34 -07:00
|
|
|
return nextOutboundByteBuffer(SingleThreadEventExecutor.currentEventLoop(), tail);
|
2012-06-01 17:51:19 -07:00
|
|
|
}
|
|
|
|
|
2012-06-03 04:35:38 -07:00
|
|
|
static boolean hasNextInboundByteBuffer(DefaultChannelHandlerContext ctx) {
|
|
|
|
for (;;) {
|
|
|
|
if (ctx == null) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-06-04 11:18:48 -07:00
|
|
|
if (ctx.inByteBridge != null) {
|
2012-06-03 04:35:38 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
ctx = ctx.next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static boolean hasNextInboundMessageBuffer(DefaultChannelHandlerContext ctx) {
|
|
|
|
for (;;) {
|
|
|
|
if (ctx == null) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-06-04 11:18:48 -07:00
|
|
|
if (ctx.inMsgBridge != null) {
|
2012-06-03 04:35:38 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
ctx = ctx.next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-04 00:24:34 -07:00
|
|
|
static ChannelBuffer nextInboundByteBuffer(Executor currentExecutor, DefaultChannelHandlerContext ctx) {
|
2012-06-01 17:51:19 -07:00
|
|
|
for (;;) {
|
|
|
|
if (ctx == null) {
|
2012-06-03 04:10:32 -07:00
|
|
|
throw new NoSuchBufferException();
|
2012-06-01 17:51:19 -07:00
|
|
|
}
|
2012-06-04 00:24:34 -07:00
|
|
|
if (ctx.inByteBridge != null) {
|
|
|
|
if (currentExecutor == ctx.executor()) {
|
|
|
|
return ctx.in.byteBuffer();
|
|
|
|
} else {
|
|
|
|
StreamBridge bridge = ctx.inByteBridge.get();
|
|
|
|
if (bridge == null) {
|
|
|
|
bridge = new StreamBridge();
|
|
|
|
if (!ctx.inByteBridge.compareAndSet(null, bridge)) {
|
|
|
|
bridge = ctx.inByteBridge.get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bridge.byteBuf;
|
|
|
|
}
|
|
|
|
}
|
2012-06-04 11:56:00 -07:00
|
|
|
if (ctx.inByteBridge != null) {
|
|
|
|
return ctx.in.byteBuffer();
|
2012-06-01 17:51:19 -07:00
|
|
|
}
|
|
|
|
ctx = ctx.next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-04 00:24:34 -07:00
|
|
|
static Queue<Object> nextInboundMessageBuffer(Executor currentExecutor, DefaultChannelHandlerContext ctx) {
|
2012-06-01 17:51:19 -07:00
|
|
|
for (;;) {
|
|
|
|
if (ctx == null) {
|
2012-06-03 04:10:32 -07:00
|
|
|
throw new NoSuchBufferException();
|
2012-06-01 17:51:19 -07:00
|
|
|
}
|
2012-06-03 18:51:42 -07:00
|
|
|
|
2012-06-04 00:24:34 -07:00
|
|
|
if (ctx.inMsgBridge != null) {
|
2012-06-03 18:51:42 -07:00
|
|
|
if (currentExecutor == ctx.executor()) {
|
|
|
|
return ctx.in.messageBuffer();
|
|
|
|
} else {
|
2012-06-04 00:24:34 -07:00
|
|
|
MessageBridge bridge = ctx.inMsgBridge.get();
|
|
|
|
if (bridge == null) {
|
|
|
|
bridge = new MessageBridge();
|
|
|
|
if (!ctx.inMsgBridge.compareAndSet(null, bridge)) {
|
|
|
|
bridge = ctx.inMsgBridge.get();
|
2012-06-03 18:51:42 -07:00
|
|
|
}
|
|
|
|
}
|
2012-06-04 00:24:34 -07:00
|
|
|
return bridge.msgBuf;
|
2012-06-03 18:51:42 -07:00
|
|
|
}
|
2012-06-01 17:51:19 -07:00
|
|
|
}
|
|
|
|
ctx = ctx.next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-03 04:35:38 -07:00
|
|
|
boolean hasNextOutboundByteBuffer(DefaultChannelHandlerContext ctx) {
|
|
|
|
for (;;) {
|
|
|
|
if (ctx == null) {
|
2012-06-03 18:51:42 -07:00
|
|
|
return false;
|
2012-06-03 04:35:38 -07:00
|
|
|
}
|
|
|
|
|
2012-06-04 11:18:48 -07:00
|
|
|
if (ctx.outByteBridge != null) {
|
2012-06-03 04:35:38 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
ctx = ctx.prev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean hasNextOutboundMessageBuffer(DefaultChannelHandlerContext ctx) {
|
|
|
|
for (;;) {
|
|
|
|
if (ctx == null) {
|
2012-06-03 18:51:42 -07:00
|
|
|
return false;
|
2012-06-03 04:35:38 -07:00
|
|
|
}
|
|
|
|
|
2012-06-04 11:18:48 -07:00
|
|
|
if (ctx.outMsgBridge != null) {
|
2012-06-03 04:35:38 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
ctx = ctx.prev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-04 00:24:34 -07:00
|
|
|
ChannelBuffer nextOutboundByteBuffer(Executor currentExecutor, DefaultChannelHandlerContext ctx) {
|
2012-06-01 17:51:19 -07:00
|
|
|
for (;;) {
|
|
|
|
if (ctx == null) {
|
2012-06-03 18:51:42 -07:00
|
|
|
throw new NoSuchBufferException();
|
2012-06-01 17:51:19 -07:00
|
|
|
}
|
|
|
|
|
2012-06-04 00:24:34 -07:00
|
|
|
if (ctx.outByteBridge != null) {
|
|
|
|
if (currentExecutor == ctx.executor()) {
|
|
|
|
return ctx.out.byteBuffer();
|
|
|
|
} else {
|
|
|
|
StreamBridge bridge = ctx.outByteBridge.get();
|
|
|
|
if (bridge == null) {
|
|
|
|
bridge = new StreamBridge();
|
|
|
|
if (!ctx.outByteBridge.compareAndSet(null, bridge)) {
|
|
|
|
bridge = ctx.outByteBridge.get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bridge.byteBuf;
|
|
|
|
}
|
2012-06-01 17:51:19 -07:00
|
|
|
}
|
|
|
|
ctx = ctx.prev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-03 18:51:42 -07:00
|
|
|
Queue<Object> nextOutboundMessageBuffer(Executor currentExecutor, DefaultChannelHandlerContext ctx) {
|
2012-06-01 17:51:19 -07:00
|
|
|
for (;;) {
|
|
|
|
if (ctx == null) {
|
2012-06-03 18:51:42 -07:00
|
|
|
throw new NoSuchBufferException();
|
|
|
|
}
|
|
|
|
|
2012-06-04 00:24:34 -07:00
|
|
|
if (ctx.outMsgBridge != null) {
|
2012-06-03 18:51:42 -07:00
|
|
|
if (currentExecutor == ctx.executor()) {
|
|
|
|
return ctx.out.messageBuffer();
|
2012-06-01 17:51:19 -07:00
|
|
|
} else {
|
2012-06-04 00:24:34 -07:00
|
|
|
MessageBridge bridge = ctx.outMsgBridge.get();
|
|
|
|
if (bridge == null) {
|
|
|
|
bridge = new MessageBridge();
|
|
|
|
if (!ctx.outMsgBridge.compareAndSet(null, bridge)) {
|
|
|
|
bridge = ctx.outMsgBridge.get();
|
2012-06-03 18:51:42 -07:00
|
|
|
}
|
|
|
|
}
|
2012-06-04 00:24:34 -07:00
|
|
|
return bridge.msgBuf;
|
2012-06-01 17:51:19 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ctx = ctx.prev;
|
2012-05-16 23:02:06 +09:00
|
|
|
}
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void fireChannelRegistered() {
|
|
|
|
DefaultChannelHandlerContext ctx = firstInboundContext();
|
|
|
|
if (ctx != null) {
|
|
|
|
fireChannelRegistered(ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-01 17:51:19 -07:00
|
|
|
static void fireChannelRegistered(DefaultChannelHandlerContext ctx) {
|
|
|
|
EventExecutor executor = ctx.executor();
|
|
|
|
if (executor.inEventLoop()) {
|
|
|
|
ctx.fireChannelRegisteredTask.run();
|
|
|
|
} else {
|
|
|
|
executor.execute(ctx.fireChannelRegisteredTask);
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void fireChannelUnregistered() {
|
|
|
|
DefaultChannelHandlerContext ctx = firstInboundContext();
|
|
|
|
if (ctx != null) {
|
|
|
|
fireChannelUnregistered(ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-01 17:51:19 -07:00
|
|
|
static void fireChannelUnregistered(DefaultChannelHandlerContext ctx) {
|
|
|
|
EventExecutor executor = ctx.executor();
|
|
|
|
if (executor.inEventLoop()) {
|
|
|
|
ctx.fireChannelUnregisteredTask.run();
|
|
|
|
} else {
|
|
|
|
executor.execute(ctx.fireChannelUnregisteredTask);
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void fireChannelActive() {
|
|
|
|
DefaultChannelHandlerContext ctx = firstInboundContext();
|
|
|
|
if (ctx != null) {
|
2012-05-30 11:32:39 -07:00
|
|
|
firedChannelActive = true;
|
2012-05-01 17:19:41 +09:00
|
|
|
fireChannelActive(ctx);
|
2012-05-30 11:32:39 -07:00
|
|
|
if (fireInboundBufferUpdatedOnActivation) {
|
|
|
|
fireInboundBufferUpdatedOnActivation = false;
|
|
|
|
fireInboundBufferUpdated(ctx);
|
|
|
|
}
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-01 17:51:19 -07:00
|
|
|
static void fireChannelActive(DefaultChannelHandlerContext ctx) {
|
|
|
|
EventExecutor executor = ctx.executor();
|
|
|
|
if (executor.inEventLoop()) {
|
|
|
|
ctx.fireChannelActiveTask.run();
|
|
|
|
} else {
|
|
|
|
executor.execute(ctx.fireChannelActiveTask);
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
}
|
2012-06-01 17:51:19 -07:00
|
|
|
|
2012-05-01 17:19:41 +09:00
|
|
|
@Override
|
|
|
|
public void fireChannelInactive() {
|
|
|
|
DefaultChannelHandlerContext ctx = firstInboundContext();
|
|
|
|
if (ctx != null) {
|
2012-05-31 01:53:58 -07:00
|
|
|
// Some implementations such as EmbeddedChannel can trigger inboundBufferUpdated()
|
|
|
|
// after deactivation, so it's safe not to revert the firedChannelActive flag here.
|
|
|
|
// Also, all known transports never get re-activated.
|
|
|
|
//firedChannelActive = false;
|
2012-05-01 17:19:41 +09:00
|
|
|
fireChannelInactive(ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-01 17:51:19 -07:00
|
|
|
static void fireChannelInactive(DefaultChannelHandlerContext ctx) {
|
|
|
|
EventExecutor executor = ctx.executor();
|
|
|
|
if (executor.inEventLoop()) {
|
|
|
|
ctx.fireChannelInactiveTask.run();
|
|
|
|
} else {
|
|
|
|
executor.execute(ctx.fireChannelInactiveTask);
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void fireExceptionCaught(Throwable cause) {
|
|
|
|
DefaultChannelHandlerContext ctx = firstInboundContext();
|
|
|
|
if (ctx != null) {
|
|
|
|
fireExceptionCaught(ctx, cause);
|
2012-05-30 11:48:04 -07:00
|
|
|
} else {
|
|
|
|
logTerminalException(cause);
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-01 17:51:19 -07:00
|
|
|
static void logTerminalException(Throwable cause) {
|
2012-05-30 11:48:04 -07:00
|
|
|
logger.warn(
|
|
|
|
"An exceptionCaught() event was fired, and it reached at the end of the " +
|
|
|
|
"pipeline. It usually means the last inbound handler in the pipeline did not " +
|
|
|
|
"handle the exception.", cause);
|
|
|
|
}
|
|
|
|
|
2012-06-01 17:51:19 -07:00
|
|
|
void fireExceptionCaught(final DefaultChannelHandlerContext ctx, final Throwable cause) {
|
2012-05-01 17:19:41 +09:00
|
|
|
if (cause == null) {
|
|
|
|
throw new NullPointerException("cause");
|
|
|
|
}
|
|
|
|
|
2012-06-01 17:51:19 -07:00
|
|
|
EventExecutor executor = ctx.executor();
|
|
|
|
if (executor.inEventLoop()) {
|
|
|
|
try {
|
|
|
|
((ChannelInboundHandler<Object>) ctx.handler()).exceptionCaught(ctx, cause);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
if (logger.isWarnEnabled()) {
|
|
|
|
logger.warn(
|
|
|
|
"An exception was thrown by a user handler's " +
|
|
|
|
"exceptionCaught() method while handling the following exception:", cause);
|
|
|
|
}
|
|
|
|
notifyHandlerException(t);
|
2012-02-17 10:37:41 +01:00
|
|
|
}
|
2012-06-01 17:51:19 -07:00
|
|
|
} else {
|
|
|
|
executor.execute(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
fireExceptionCaught(ctx, cause);
|
|
|
|
}
|
|
|
|
});
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
2008-08-08 00:37:18 +00:00
|
|
|
|
2012-05-01 17:19:41 +09:00
|
|
|
@Override
|
|
|
|
public void fireUserEventTriggered(Object event) {
|
|
|
|
DefaultChannelHandlerContext ctx = firstInboundContext();
|
|
|
|
if (ctx != null) {
|
|
|
|
fireUserEventTriggered(ctx, event);
|
|
|
|
}
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
|
2012-06-01 17:51:19 -07:00
|
|
|
void fireUserEventTriggered(final DefaultChannelHandlerContext ctx, final Object event) {
|
2012-05-01 17:19:41 +09:00
|
|
|
if (event == null) {
|
|
|
|
throw new NullPointerException("event");
|
|
|
|
}
|
|
|
|
|
2012-06-01 17:51:19 -07:00
|
|
|
EventExecutor executor = ctx.executor();
|
|
|
|
if (executor.inEventLoop()) {
|
|
|
|
try {
|
|
|
|
((ChannelInboundHandler<Object>) ctx.handler()).userEventTriggered(ctx, event);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
notifyHandlerException(t);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
executor.execute(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
fireUserEventTriggered(ctx, event);
|
|
|
|
}
|
|
|
|
});
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-05-01 17:19:41 +09:00
|
|
|
public void fireInboundBufferUpdated() {
|
2012-05-30 11:32:39 -07:00
|
|
|
if (!firedChannelActive) {
|
|
|
|
fireInboundBufferUpdatedOnActivation = true;
|
|
|
|
return;
|
|
|
|
}
|
2012-05-01 17:19:41 +09:00
|
|
|
DefaultChannelHandlerContext ctx = firstInboundContext();
|
|
|
|
if (ctx != null) {
|
|
|
|
fireInboundBufferUpdated(ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-01 17:51:19 -07:00
|
|
|
static void fireInboundBufferUpdated(DefaultChannelHandlerContext ctx) {
|
|
|
|
EventExecutor executor = ctx.executor();
|
|
|
|
if (executor.inEventLoop()) {
|
2012-06-04 00:24:34 -07:00
|
|
|
ctx.curCtxFireInboundBufferUpdatedTask.run();
|
2012-06-01 17:51:19 -07:00
|
|
|
} else {
|
2012-06-04 00:24:34 -07:00
|
|
|
executor.execute(ctx.curCtxFireInboundBufferUpdatedTask);
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-05-09 22:09:06 +09:00
|
|
|
public ChannelFuture bind(SocketAddress localAddress) {
|
2012-06-03 04:25:03 -07:00
|
|
|
return bind(localAddress, channel.newFuture());
|
2012-05-09 22:09:06 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture connect(SocketAddress remoteAddress) {
|
2012-06-03 04:25:03 -07:00
|
|
|
return connect(remoteAddress, channel.newFuture());
|
2012-05-09 22:09:06 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress) {
|
2012-06-03 04:25:03 -07:00
|
|
|
return connect(remoteAddress, localAddress, channel.newFuture());
|
2012-05-09 22:09:06 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture disconnect() {
|
2012-06-03 04:25:03 -07:00
|
|
|
return disconnect(channel.newFuture());
|
2012-05-09 22:09:06 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture close() {
|
2012-06-03 04:25:03 -07:00
|
|
|
return close(channel.newFuture());
|
2012-05-09 22:09:06 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture deregister() {
|
2012-06-03 04:25:03 -07:00
|
|
|
return deregister(channel.newFuture());
|
2012-05-09 22:09:06 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture flush() {
|
2012-06-03 04:25:03 -07:00
|
|
|
return flush(channel.newFuture());
|
2012-05-09 22:09:06 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture write(Object message) {
|
2012-06-03 04:25:03 -07:00
|
|
|
return write(message, channel.newFuture());
|
2012-05-09 22:09:06 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture bind(SocketAddress localAddress, ChannelFuture future) {
|
|
|
|
return bind(firstOutboundContext(), localAddress, future);
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
|
2012-06-01 17:51:19 -07:00
|
|
|
ChannelFuture bind(final DefaultChannelHandlerContext ctx, final SocketAddress localAddress, final ChannelFuture future) {
|
2012-05-01 17:19:41 +09:00
|
|
|
if (localAddress == null) {
|
|
|
|
throw new NullPointerException("localAddress");
|
|
|
|
}
|
2012-05-11 09:00:35 +09:00
|
|
|
validateFuture(future);
|
|
|
|
|
2012-06-03 18:51:42 -07:00
|
|
|
EventExecutor executor = ctx.executor();
|
|
|
|
if (executor.inEventLoop()) {
|
|
|
|
try {
|
|
|
|
((ChannelOutboundHandler<Object>) ctx.handler()).bind(ctx, localAddress, future);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
notifyHandlerException(t);
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
} else {
|
2012-06-03 18:51:42 -07:00
|
|
|
executor.execute(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
bind(ctx, localAddress, future);
|
|
|
|
}
|
|
|
|
});
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
2012-05-09 22:09:06 +09:00
|
|
|
return future;
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-05-09 22:09:06 +09:00
|
|
|
public ChannelFuture connect(SocketAddress remoteAddress, ChannelFuture future) {
|
|
|
|
return connect(remoteAddress, null, future);
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-05-09 22:09:06 +09:00
|
|
|
public ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelFuture future) {
|
|
|
|
return connect(firstOutboundContext(), remoteAddress, localAddress, future);
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
|
2012-06-01 17:51:19 -07:00
|
|
|
ChannelFuture connect(final DefaultChannelHandlerContext ctx, final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelFuture future) {
|
2012-05-01 17:19:41 +09:00
|
|
|
if (remoteAddress == null) {
|
|
|
|
throw new NullPointerException("remoteAddress");
|
|
|
|
}
|
2012-05-11 09:00:35 +09:00
|
|
|
validateFuture(future);
|
2012-05-01 17:19:41 +09:00
|
|
|
|
2012-06-03 18:51:42 -07:00
|
|
|
EventExecutor executor = ctx.executor();
|
|
|
|
if (executor.inEventLoop()) {
|
|
|
|
try {
|
|
|
|
((ChannelOutboundHandler<Object>) ctx.handler()).connect(ctx, remoteAddress, localAddress, future);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
notifyHandlerException(t);
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
} else {
|
2012-06-03 18:51:42 -07:00
|
|
|
executor.execute(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
connect(ctx, remoteAddress, localAddress, future);
|
|
|
|
}
|
|
|
|
});
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
2012-05-09 22:09:06 +09:00
|
|
|
|
|
|
|
return future;
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-05-09 22:09:06 +09:00
|
|
|
public ChannelFuture disconnect(ChannelFuture future) {
|
|
|
|
return disconnect(firstOutboundContext(), future);
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
|
2012-06-01 17:51:19 -07:00
|
|
|
ChannelFuture disconnect(final DefaultChannelHandlerContext ctx, final ChannelFuture future) {
|
2012-05-11 09:00:35 +09:00
|
|
|
validateFuture(future);
|
2012-06-03 18:51:42 -07:00
|
|
|
EventExecutor executor = ctx.executor();
|
|
|
|
if (executor.inEventLoop()) {
|
|
|
|
try {
|
|
|
|
((ChannelOutboundHandler<Object>) ctx.handler()).disconnect(ctx, future);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
notifyHandlerException(t);
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
} else {
|
2012-06-03 18:51:42 -07:00
|
|
|
executor.execute(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
disconnect(ctx, future);
|
|
|
|
}
|
|
|
|
});
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
2012-05-09 22:09:06 +09:00
|
|
|
|
|
|
|
return future;
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-05-09 22:09:06 +09:00
|
|
|
public ChannelFuture close(ChannelFuture future) {
|
|
|
|
return close(firstOutboundContext(), future);
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
|
2012-06-01 17:51:19 -07:00
|
|
|
ChannelFuture close(final DefaultChannelHandlerContext ctx, final ChannelFuture future) {
|
2012-05-11 09:00:35 +09:00
|
|
|
validateFuture(future);
|
2012-06-03 18:51:42 -07:00
|
|
|
EventExecutor executor = ctx.executor();
|
|
|
|
if (executor.inEventLoop()) {
|
|
|
|
try {
|
|
|
|
((ChannelOutboundHandler<Object>) ctx.handler()).close(ctx, future);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
notifyHandlerException(t);
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
2012-05-01 17:19:41 +09:00
|
|
|
} else {
|
2012-06-03 18:51:42 -07:00
|
|
|
executor.execute(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
close(ctx, future);
|
|
|
|
}
|
|
|
|
});
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
2012-05-09 22:09:06 +09:00
|
|
|
|
|
|
|
return future;
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
2008-08-08 00:37:18 +00:00
|
|
|
|
2012-05-01 17:19:41 +09:00
|
|
|
@Override
|
2012-05-09 22:09:06 +09:00
|
|
|
public ChannelFuture deregister(final ChannelFuture future) {
|
|
|
|
return deregister(firstOutboundContext(), future);
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
|
2012-06-01 17:51:19 -07:00
|
|
|
ChannelFuture deregister(final DefaultChannelHandlerContext ctx, final ChannelFuture future) {
|
2012-05-11 09:00:35 +09:00
|
|
|
validateFuture(future);
|
2012-06-03 18:51:42 -07:00
|
|
|
EventExecutor executor = ctx.executor();
|
|
|
|
if (executor.inEventLoop()) {
|
|
|
|
try {
|
|
|
|
((ChannelOutboundHandler<Object>) ctx.handler()).deregister(ctx, future);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
notifyHandlerException(t);
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
} else {
|
2012-06-03 18:51:42 -07:00
|
|
|
executor.execute(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
deregister(ctx, future);
|
|
|
|
}
|
|
|
|
});
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
2012-05-09 22:09:06 +09:00
|
|
|
|
|
|
|
return future;
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-05-09 22:09:06 +09:00
|
|
|
public ChannelFuture flush(ChannelFuture future) {
|
|
|
|
return flush(firstOutboundContext(), future);
|
|
|
|
}
|
|
|
|
|
2012-06-01 17:51:19 -07:00
|
|
|
ChannelFuture flush(final DefaultChannelHandlerContext ctx, final ChannelFuture future) {
|
2012-05-11 09:00:35 +09:00
|
|
|
validateFuture(future);
|
2012-06-03 18:51:42 -07:00
|
|
|
EventExecutor executor = ctx.executor();
|
|
|
|
if (executor.inEventLoop()) {
|
|
|
|
flush0(ctx, future);
|
2012-05-01 17:19:41 +09:00
|
|
|
} else {
|
2012-06-03 18:51:42 -07:00
|
|
|
executor.execute(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
flush(ctx, future);
|
|
|
|
}
|
|
|
|
});
|
2011-08-01 04:16:02 +09:00
|
|
|
}
|
2012-05-01 17:19:41 +09:00
|
|
|
|
2012-05-09 22:09:06 +09:00
|
|
|
return future;
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
|
2012-06-01 18:34:19 -07:00
|
|
|
private void flush0(final DefaultChannelHandlerContext ctx, ChannelFuture future) {
|
|
|
|
try {
|
2012-06-03 18:51:42 -07:00
|
|
|
ctx.flushBridge();
|
2012-06-01 18:34:19 -07:00
|
|
|
((ChannelOutboundHandler<Object>) ctx.handler()).flush(ctx, future);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
notifyHandlerException(t);
|
|
|
|
} finally {
|
2012-06-04 11:56:00 -07:00
|
|
|
if (ctx.outByteBridge != null) {
|
|
|
|
ChannelBuffer buf = ctx.out.byteBuffer();
|
|
|
|
if (!buf.readable()) {
|
|
|
|
buf.discardReadBytes();
|
|
|
|
}
|
2012-06-01 18:34:19 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-01 17:19:41 +09:00
|
|
|
@Override
|
2012-05-09 22:09:06 +09:00
|
|
|
public ChannelFuture write(Object message, ChannelFuture future) {
|
2012-06-03 04:25:03 -07:00
|
|
|
return write(tail, message, future);
|
2012-06-01 17:51:19 -07:00
|
|
|
}
|
|
|
|
|
2012-06-03 04:10:32 -07:00
|
|
|
ChannelFuture write(DefaultChannelHandlerContext ctx, final Object message, final ChannelFuture future) {
|
2012-05-11 09:00:35 +09:00
|
|
|
if (message == null) {
|
|
|
|
throw new NullPointerException("message");
|
|
|
|
}
|
|
|
|
validateFuture(future);
|
|
|
|
|
2012-06-01 17:51:19 -07:00
|
|
|
EventExecutor executor;
|
|
|
|
ChannelBufferHolder<Object> out;
|
2012-06-03 04:10:32 -07:00
|
|
|
boolean msgBuf = false;
|
|
|
|
for (;;) {
|
|
|
|
if (ctx == null) {
|
2012-06-03 18:51:42 -07:00
|
|
|
throw new NoSuchBufferException();
|
2012-06-03 04:10:32 -07:00
|
|
|
}
|
|
|
|
|
2012-06-03 04:25:03 -07:00
|
|
|
if (ctx.canHandleOutbound()) {
|
|
|
|
out = ctx.outbound();
|
|
|
|
if (out.hasMessageBuffer()) {
|
|
|
|
msgBuf = true;
|
|
|
|
executor = ctx.executor();
|
|
|
|
break;
|
|
|
|
} else if (message instanceof ChannelBuffer) {
|
|
|
|
executor = ctx.executor();
|
|
|
|
break;
|
|
|
|
}
|
2012-06-03 04:10:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx = ctx.prev;
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
2012-05-16 23:02:06 +09:00
|
|
|
|
2012-06-01 17:51:19 -07:00
|
|
|
if (executor.inEventLoop()) {
|
2012-06-03 04:10:32 -07:00
|
|
|
if (msgBuf) {
|
2012-06-01 17:51:19 -07:00
|
|
|
out.messageBuffer().add(message);
|
|
|
|
} else {
|
2012-06-03 04:10:32 -07:00
|
|
|
ChannelBuffer buf = (ChannelBuffer) message;
|
|
|
|
out.byteBuffer().writeBytes(buf, buf.readerIndex(), buf.readableBytes());
|
2012-06-01 17:51:19 -07:00
|
|
|
}
|
2012-06-03 18:51:42 -07:00
|
|
|
flush0(ctx, future);
|
2012-06-01 18:34:19 -07:00
|
|
|
return future;
|
2012-06-01 17:51:19 -07:00
|
|
|
} else {
|
2012-06-03 04:10:32 -07:00
|
|
|
final DefaultChannelHandlerContext ctx0 = ctx;
|
2012-06-01 17:51:19 -07:00
|
|
|
executor.execute(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2012-06-03 04:10:32 -07:00
|
|
|
write(ctx0, message, future);
|
2012-06-01 17:51:19 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return future;
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
|
2012-05-11 09:00:35 +09:00
|
|
|
private void validateFuture(ChannelFuture future) {
|
|
|
|
if (future == null) {
|
|
|
|
throw new NullPointerException("future");
|
|
|
|
}
|
2012-06-03 04:25:03 -07:00
|
|
|
if (future.channel() != channel) {
|
2012-05-11 09:00:35 +09:00
|
|
|
throw new IllegalArgumentException(String.format(
|
2012-06-03 04:25:03 -07:00
|
|
|
"future.channel does not match: %s (expected: %s)", future.channel(), channel));
|
2012-05-11 09:00:35 +09:00
|
|
|
}
|
2012-05-13 01:35:43 +09:00
|
|
|
if (future.isDone()) {
|
|
|
|
throw new IllegalArgumentException("future already done");
|
|
|
|
}
|
|
|
|
if (future instanceof ChannelFuture.Unsafe) {
|
|
|
|
throw new IllegalArgumentException("internal use only future not allowed");
|
|
|
|
}
|
2012-05-11 09:00:35 +09:00
|
|
|
}
|
|
|
|
|
2012-05-01 17:19:41 +09:00
|
|
|
private DefaultChannelHandlerContext firstInboundContext() {
|
2012-06-03 18:51:42 -07:00
|
|
|
return nextInboundContext(head.next);
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
private DefaultChannelHandlerContext firstOutboundContext() {
|
|
|
|
return nextOutboundContext(tail);
|
|
|
|
}
|
|
|
|
|
2012-06-01 17:51:19 -07:00
|
|
|
static DefaultChannelHandlerContext nextInboundContext(DefaultChannelHandlerContext ctx) {
|
2008-08-08 00:37:18 +00:00
|
|
|
if (ctx == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
DefaultChannelHandlerContext realCtx = ctx;
|
2012-05-01 17:19:41 +09:00
|
|
|
while (!realCtx.canHandleInbound()) {
|
2008-08-08 00:37:18 +00:00
|
|
|
realCtx = realCtx.next;
|
|
|
|
if (realCtx == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return realCtx;
|
|
|
|
}
|
|
|
|
|
2012-06-01 17:51:19 -07:00
|
|
|
static DefaultChannelHandlerContext nextOutboundContext(DefaultChannelHandlerContext ctx) {
|
2008-08-08 00:37:18 +00:00
|
|
|
if (ctx == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
DefaultChannelHandlerContext realCtx = ctx;
|
2012-05-01 17:19:41 +09:00
|
|
|
while (!realCtx.canHandleOutbound()) {
|
2008-08-08 00:37:18 +00:00
|
|
|
realCtx = realCtx.prev;
|
|
|
|
if (realCtx == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return realCtx;
|
|
|
|
}
|
|
|
|
|
2012-05-01 17:19:41 +09:00
|
|
|
protected void notifyHandlerException(Throwable cause) {
|
|
|
|
if (!(cause instanceof ChannelPipelineException)) {
|
|
|
|
cause = new ChannelPipelineException(cause);
|
|
|
|
}
|
2012-02-29 13:53:26 -08:00
|
|
|
|
2012-05-01 17:19:41 +09:00
|
|
|
if (inExceptionCaught(cause)) {
|
2012-02-17 10:37:41 +01:00
|
|
|
if (logger.isWarnEnabled()) {
|
|
|
|
logger.warn(
|
|
|
|
"An exception was thrown by a user handler " +
|
2012-05-01 17:19:41 +09:00
|
|
|
"while handling an exceptionCaught event", cause);
|
2012-02-17 10:37:41 +01:00
|
|
|
}
|
2008-08-18 11:11:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-01 17:19:41 +09:00
|
|
|
fireExceptionCaught(cause);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean inExceptionCaught(Throwable cause) {
|
|
|
|
if (cause == null) {
|
|
|
|
return false;
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
|
2012-05-01 17:19:41 +09:00
|
|
|
StackTraceElement[] trace = cause.getStackTrace();
|
|
|
|
if (trace != null) {
|
|
|
|
for (StackTraceElement t: trace) {
|
|
|
|
if ("exceptionCaught".equals(t.getMethodName())) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-02-17 10:37:41 +01:00
|
|
|
}
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
2012-05-01 17:19:41 +09:00
|
|
|
|
|
|
|
return inExceptionCaught(cause.getCause());
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void checkDuplicateName(String name) {
|
|
|
|
if (name2ctx.containsKey(name)) {
|
2011-11-23 14:07:26 +09:00
|
|
|
throw new IllegalArgumentException("Duplicate handler name: " + name);
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private DefaultChannelHandlerContext getContextOrDie(String name) {
|
2012-05-01 17:19:41 +09:00
|
|
|
DefaultChannelHandlerContext ctx = (DefaultChannelHandlerContext) context(name);
|
2012-06-03 18:51:42 -07:00
|
|
|
if (ctx == null || ctx == head) {
|
2008-08-08 00:37:18 +00:00
|
|
|
throw new NoSuchElementException(name);
|
|
|
|
} else {
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private DefaultChannelHandlerContext getContextOrDie(ChannelHandler handler) {
|
2012-05-01 17:19:41 +09:00
|
|
|
DefaultChannelHandlerContext ctx = (DefaultChannelHandlerContext) context(handler);
|
2012-06-03 18:51:42 -07:00
|
|
|
if (ctx == null || ctx == head) {
|
2008-08-08 00:37:18 +00:00
|
|
|
throw new NoSuchElementException(handler.getClass().getName());
|
|
|
|
} else {
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private DefaultChannelHandlerContext getContextOrDie(Class<? extends ChannelHandler> handlerType) {
|
2012-05-01 17:19:41 +09:00
|
|
|
DefaultChannelHandlerContext ctx = (DefaultChannelHandlerContext) context(handlerType);
|
2012-06-03 18:51:42 -07:00
|
|
|
if (ctx == null || ctx == head) {
|
2008-08-08 00:37:18 +00:00
|
|
|
throw new NoSuchElementException(handlerType.getName());
|
|
|
|
} else {
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
}
|
2012-06-03 18:51:42 -07:00
|
|
|
|
|
|
|
@SuppressWarnings("rawtypes")
|
|
|
|
private final class HeadHandler implements ChannelOutboundHandler {
|
|
|
|
@Override
|
|
|
|
public ChannelBufferHolder newOutboundBuffer(
|
|
|
|
ChannelOutboundHandlerContext ctx) throws Exception {
|
|
|
|
switch (channel.type()) {
|
|
|
|
case STREAM:
|
|
|
|
return ChannelBufferHolders.byteBuffer();
|
|
|
|
case MESSAGE:
|
|
|
|
return ChannelBufferHolders.messageBuffer();
|
|
|
|
default:
|
|
|
|
throw new Error();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void beforeAdd(ChannelHandlerContext ctx) throws Exception {
|
|
|
|
// NOOP
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void afterAdd(ChannelHandlerContext ctx) throws Exception {
|
|
|
|
// NOOP
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void beforeRemove(ChannelHandlerContext ctx) throws Exception {
|
|
|
|
// NOOP
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void afterRemove(ChannelHandlerContext ctx) throws Exception {
|
|
|
|
// NOOP
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void bind(ChannelOutboundHandlerContext ctx,
|
|
|
|
SocketAddress localAddress, ChannelFuture future)
|
|
|
|
throws Exception {
|
|
|
|
unsafe.bind(localAddress, future);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void connect(ChannelOutboundHandlerContext ctx,
|
|
|
|
SocketAddress remoteAddress, SocketAddress localAddress,
|
|
|
|
ChannelFuture future) throws Exception {
|
|
|
|
unsafe.connect(remoteAddress, localAddress, future);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void disconnect(ChannelOutboundHandlerContext ctx,
|
|
|
|
ChannelFuture future) throws Exception {
|
|
|
|
unsafe.disconnect(future);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void close(ChannelOutboundHandlerContext ctx,
|
|
|
|
ChannelFuture future) throws Exception {
|
|
|
|
unsafe.close(future);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void deregister(ChannelOutboundHandlerContext ctx,
|
|
|
|
ChannelFuture future) throws Exception {
|
|
|
|
unsafe.deregister(future);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void flush(ChannelOutboundHandlerContext ctx,
|
|
|
|
ChannelFuture future) throws Exception {
|
|
|
|
unsafe.flush(future);
|
|
|
|
}
|
|
|
|
}
|
2009-08-28 07:15:49 +00:00
|
|
|
}
|