2008-08-08 00:37:18 +00:00
|
|
|
/*
|
2011-12-09 14:18:34 +09:00
|
|
|
* Copyright 2011 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
|
|
|
*
|
2011-12-09 14:18:34 +09: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;
|
|
|
|
import io.netty.logging.InternalLogger;
|
|
|
|
import io.netty.logging.InternalLoggerFactory;
|
|
|
|
import io.netty.util.DefaultAttributeMap;
|
|
|
|
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
|
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-05-01 17:19:41 +09:00
|
|
|
private final Channel channel;
|
2008-08-08 00:37:18 +00:00
|
|
|
private volatile DefaultChannelHandlerContext head;
|
|
|
|
private volatile DefaultChannelHandlerContext tail;
|
|
|
|
private final Map<String, DefaultChannelHandlerContext> name2ctx =
|
|
|
|
new HashMap<String, DefaultChannelHandlerContext>(4);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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-05-15 14:08:42 +09:00
|
|
|
public synchronized ChannelPipeline addFirst(String name, ChannelHandler handler) {
|
2008-08-08 00:37:18 +00:00
|
|
|
if (name2ctx.isEmpty()) {
|
|
|
|
init(name, handler);
|
|
|
|
} else {
|
|
|
|
checkDuplicateName(name);
|
|
|
|
DefaultChannelHandlerContext oldHead = head;
|
|
|
|
DefaultChannelHandlerContext newHead = new DefaultChannelHandlerContext(null, oldHead, name, handler);
|
2008-12-01 10:07:54 +00:00
|
|
|
|
|
|
|
callBeforeAdd(newHead);
|
|
|
|
|
2008-08-08 00:37:18 +00:00
|
|
|
oldHead.prev = newHead;
|
|
|
|
head = newHead;
|
|
|
|
name2ctx.put(name, newHead);
|
2008-12-01 10:07:54 +00:00
|
|
|
|
|
|
|
callAfterAdd(newHead);
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
2012-05-15 14:08:42 +09:00
|
|
|
|
|
|
|
return this;
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-05-15 14:08:42 +09:00
|
|
|
public synchronized ChannelPipeline addLast(String name, ChannelHandler handler) {
|
2008-08-08 00:37:18 +00:00
|
|
|
if (name2ctx.isEmpty()) {
|
|
|
|
init(name, handler);
|
|
|
|
} else {
|
|
|
|
checkDuplicateName(name);
|
|
|
|
DefaultChannelHandlerContext oldTail = tail;
|
|
|
|
DefaultChannelHandlerContext newTail = new DefaultChannelHandlerContext(oldTail, null, name, handler);
|
2008-12-01 10:07:54 +00:00
|
|
|
|
|
|
|
callBeforeAdd(newTail);
|
|
|
|
|
2008-08-08 00:37:18 +00:00
|
|
|
oldTail.next = newTail;
|
|
|
|
tail = newTail;
|
|
|
|
name2ctx.put(name, newTail);
|
2008-12-01 10:07:54 +00:00
|
|
|
|
|
|
|
callAfterAdd(newTail);
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
2012-05-15 14:08:42 +09:00
|
|
|
|
|
|
|
return this;
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-05-15 14:08:42 +09:00
|
|
|
public synchronized ChannelPipeline addBefore(String baseName, String name, ChannelHandler handler) {
|
2008-08-08 00:37:18 +00:00
|
|
|
DefaultChannelHandlerContext ctx = getContextOrDie(baseName);
|
|
|
|
if (ctx == head) {
|
|
|
|
addFirst(name, handler);
|
|
|
|
} else {
|
|
|
|
checkDuplicateName(name);
|
|
|
|
DefaultChannelHandlerContext newCtx = new DefaultChannelHandlerContext(ctx.prev, ctx, name, handler);
|
2008-12-01 10:07:54 +00:00
|
|
|
|
|
|
|
callBeforeAdd(newCtx);
|
|
|
|
|
2008-08-08 00:37:18 +00:00
|
|
|
ctx.prev.next = newCtx;
|
|
|
|
ctx.prev = newCtx;
|
|
|
|
name2ctx.put(name, newCtx);
|
2008-12-01 10:07:54 +00:00
|
|
|
|
|
|
|
callAfterAdd(newCtx);
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
2012-05-15 14:08:42 +09:00
|
|
|
|
|
|
|
return this;
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-05-15 14:08:42 +09:00
|
|
|
public synchronized ChannelPipeline addAfter(String baseName, String name, ChannelHandler handler) {
|
2008-08-08 00:37:18 +00:00
|
|
|
DefaultChannelHandlerContext ctx = getContextOrDie(baseName);
|
|
|
|
if (ctx == tail) {
|
|
|
|
addLast(name, handler);
|
|
|
|
} else {
|
|
|
|
checkDuplicateName(name);
|
|
|
|
DefaultChannelHandlerContext newCtx = new DefaultChannelHandlerContext(ctx, ctx.next, name, handler);
|
2008-12-01 10:07:54 +00:00
|
|
|
|
|
|
|
callBeforeAdd(newCtx);
|
|
|
|
|
2008-08-08 00:37:18 +00:00
|
|
|
ctx.next.prev = newCtx;
|
|
|
|
ctx.next = newCtx;
|
|
|
|
name2ctx.put(name, newCtx);
|
2008-12-01 10:07:54 +00:00
|
|
|
|
|
|
|
callAfterAdd(newCtx);
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
2012-05-15 14:08:42 +09:00
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelPipeline addFirst(ChannelHandler... handlers) {
|
|
|
|
if (handlers == null) {
|
|
|
|
throw new NullPointerException("handlers");
|
|
|
|
}
|
|
|
|
if (handlers[0] == null) {
|
|
|
|
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];
|
|
|
|
addFirst(generateName(h), h);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelPipeline addLast(ChannelHandler... handlers) {
|
|
|
|
if (handlers == null) {
|
|
|
|
throw new NullPointerException("handlers");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (ChannelHandler h: handlers) {
|
|
|
|
if (h == null) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
addLast(generateName(h), h);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
static String generateName(ChannelHandler handler) {
|
|
|
|
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
|
2008-08-08 00:37:18 +00:00
|
|
|
public synchronized void remove(ChannelHandler handler) {
|
|
|
|
remove(getContextOrDie(handler));
|
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2008-08-08 00:37:18 +00:00
|
|
|
public synchronized 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
|
2008-08-08 00:37:18 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public synchronized <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
|
|
|
}
|
|
|
|
|
|
|
|
private DefaultChannelHandlerContext remove(DefaultChannelHandlerContext ctx) {
|
|
|
|
if (head == tail) {
|
|
|
|
head = tail = null;
|
|
|
|
name2ctx.clear();
|
|
|
|
} else if (ctx == head) {
|
|
|
|
removeFirst();
|
|
|
|
} else if (ctx == tail) {
|
|
|
|
removeLast();
|
|
|
|
} else {
|
2008-12-01 10:07:54 +00:00
|
|
|
callBeforeRemove(ctx);
|
|
|
|
|
2008-08-08 00:37:18 +00:00
|
|
|
DefaultChannelHandlerContext prev = ctx.prev;
|
|
|
|
DefaultChannelHandlerContext next = ctx.next;
|
|
|
|
prev.next = next;
|
|
|
|
next.prev = prev;
|
2012-05-01 17:19:41 +09:00
|
|
|
name2ctx.remove(ctx.name());
|
2008-12-01 10:07:54 +00:00
|
|
|
|
|
|
|
callAfterRemove(ctx);
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2008-08-08 00:37:18 +00:00
|
|
|
public synchronized ChannelHandler removeFirst() {
|
|
|
|
if (name2ctx.isEmpty()) {
|
|
|
|
throw new NoSuchElementException();
|
|
|
|
}
|
|
|
|
|
|
|
|
DefaultChannelHandlerContext oldHead = head;
|
2008-08-18 02:38:54 +00:00
|
|
|
if (oldHead == null) {
|
|
|
|
throw new NoSuchElementException();
|
|
|
|
}
|
2008-12-01 10:07:54 +00:00
|
|
|
|
|
|
|
callBeforeRemove(oldHead);
|
|
|
|
|
2008-08-18 02:38:54 +00:00
|
|
|
if (oldHead.next == null) {
|
|
|
|
head = tail = null;
|
|
|
|
name2ctx.clear();
|
|
|
|
} else {
|
|
|
|
oldHead.next.prev = null;
|
|
|
|
head = oldHead.next;
|
2012-05-01 17:19:41 +09:00
|
|
|
name2ctx.remove(oldHead.name());
|
2008-08-18 02:38:54 +00:00
|
|
|
}
|
2008-12-01 10:07:54 +00:00
|
|
|
|
|
|
|
callAfterRemove(oldHead);
|
|
|
|
|
2012-05-01 17:19:41 +09:00
|
|
|
return oldHead.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 removeLast() {
|
|
|
|
if (name2ctx.isEmpty()) {
|
|
|
|
throw new NoSuchElementException();
|
|
|
|
}
|
|
|
|
|
|
|
|
DefaultChannelHandlerContext oldTail = tail;
|
2008-08-18 02:38:54 +00:00
|
|
|
if (oldTail == null) {
|
|
|
|
throw new NoSuchElementException();
|
|
|
|
}
|
2008-12-01 10:07:54 +00:00
|
|
|
|
|
|
|
callBeforeRemove(oldTail);
|
|
|
|
|
2008-08-18 02:38:54 +00:00
|
|
|
if (oldTail.prev == null) {
|
|
|
|
head = tail = null;
|
|
|
|
name2ctx.clear();
|
|
|
|
} else {
|
|
|
|
oldTail.prev.next = null;
|
|
|
|
tail = oldTail.prev;
|
2012-05-01 17:19:41 +09:00
|
|
|
name2ctx.remove(oldTail.name());
|
2008-08-18 02:38:54 +00:00
|
|
|
}
|
2008-12-01 10:07:54 +00:00
|
|
|
|
|
|
|
callBeforeRemove(oldTail);
|
|
|
|
|
2012-05-01 17:19:41 +09:00
|
|
|
return oldTail.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 void replace(ChannelHandler oldHandler, String newName, ChannelHandler newHandler) {
|
|
|
|
replace(getContextOrDie(oldHandler), newName, newHandler);
|
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2008-08-08 00:37:18 +00:00
|
|
|
public synchronized ChannelHandler replace(String oldName, String newName, ChannelHandler newHandler) {
|
|
|
|
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")
|
|
|
|
public synchronized <T extends ChannelHandler> T replace(
|
|
|
|
Class<T> oldHandlerType, String newName, ChannelHandler newHandler) {
|
|
|
|
return (T) replace(getContextOrDie(oldHandlerType), newName, newHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
private ChannelHandler replace(DefaultChannelHandlerContext ctx, String newName, ChannelHandler newHandler) {
|
|
|
|
if (ctx == head) {
|
|
|
|
removeFirst();
|
|
|
|
addFirst(newName, newHandler);
|
|
|
|
} else if (ctx == tail) {
|
|
|
|
removeLast();
|
|
|
|
addLast(newName, newHandler);
|
|
|
|
} else {
|
2012-05-01 17:19:41 +09:00
|
|
|
boolean sameName = ctx.name().equals(newName);
|
2008-08-08 00:37:18 +00:00
|
|
|
if (!sameName) {
|
|
|
|
checkDuplicateName(newName);
|
|
|
|
}
|
2008-12-01 10:07:54 +00:00
|
|
|
|
2008-08-08 00:37:18 +00:00
|
|
|
DefaultChannelHandlerContext prev = ctx.prev;
|
|
|
|
DefaultChannelHandlerContext next = ctx.next;
|
|
|
|
DefaultChannelHandlerContext newCtx = new DefaultChannelHandlerContext(prev, next, newName, newHandler);
|
2008-12-01 10:07:54 +00:00
|
|
|
|
|
|
|
callBeforeRemove(ctx);
|
|
|
|
callBeforeAdd(newCtx);
|
|
|
|
|
2008-08-08 00:37:18 +00:00
|
|
|
prev.next = newCtx;
|
|
|
|
next.prev = newCtx;
|
2008-12-01 10:07:54 +00:00
|
|
|
|
2008-08-08 00:37:18 +00:00
|
|
|
if (!sameName) {
|
2012-05-01 17:19:41 +09:00
|
|
|
name2ctx.remove(ctx.name());
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
2011-12-11 09:21:29 +01:00
|
|
|
name2ctx.put(newName, newCtx);
|
2008-12-01 10:07:54 +00:00
|
|
|
|
|
|
|
ChannelHandlerLifeCycleException removeException = null;
|
|
|
|
ChannelHandlerLifeCycleException addException = null;
|
|
|
|
boolean removed = false;
|
|
|
|
try {
|
|
|
|
callAfterRemove(ctx);
|
|
|
|
removed = true;
|
|
|
|
} catch (ChannelHandlerLifeCycleException e) {
|
|
|
|
removeException = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
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(
|
2012-05-01 17:19:41 +09:00
|
|
|
"Both " + ctx.handler().getClass().getName() +
|
|
|
|
".afterRemove() and " + newCtx.handler().getClass().getName() +
|
2008-12-01 10:07:54 +00:00
|
|
|
".afterAdd() failed; see logs.");
|
|
|
|
} else if (!removed) {
|
|
|
|
throw removeException;
|
|
|
|
} else if (!added) {
|
|
|
|
throw addException;
|
|
|
|
}
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
2008-12-01 10:07:54 +00:00
|
|
|
|
2012-05-01 17:19:41 +09:00
|
|
|
return ctx.handler();
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
|
2012-05-01 17:19:41 +09:00
|
|
|
private static void callBeforeAdd(ChannelHandlerContext ctx) {
|
2008-12-01 10:07:54 +00:00
|
|
|
try {
|
2012-05-01 17:19:41 +09:00
|
|
|
ctx.handler().beforeAdd(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
|
|
|
".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() {
|
2008-08-18 02:27:11 +00:00
|
|
|
DefaultChannelHandlerContext head = this.head;
|
|
|
|
if (head == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2012-05-01 17:19:41 +09:00
|
|
|
return head.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() {
|
2008-08-18 02:27:11 +00:00
|
|
|
DefaultChannelHandlerContext tail = this.tail;
|
|
|
|
if (tail == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2012-05-01 17:19:41 +09:00
|
|
|
return tail.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;
|
|
|
|
}
|
|
|
|
DefaultChannelHandlerContext ctx = head;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
DefaultChannelHandlerContext ctx = head;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
DefaultChannelHandlerContext ctx = head;
|
|
|
|
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('{');
|
|
|
|
DefaultChannelHandlerContext ctx = head;
|
|
|
|
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-05-01 17:19:41 +09:00
|
|
|
public ChannelBufferHolder<Object> nextIn() {
|
|
|
|
DefaultChannelHandlerContext ctx = firstInboundContext();
|
|
|
|
if (ctx != null) {
|
|
|
|
return ctx.in();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-05-09 22:09:06 +09:00
|
|
|
public ChannelBufferHolder<Object> out() {
|
2012-05-01 17:19:41 +09:00
|
|
|
return channel().unsafe().out();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void fireChannelRegistered() {
|
|
|
|
DefaultChannelHandlerContext ctx = firstInboundContext();
|
|
|
|
if (ctx != null) {
|
|
|
|
fireChannelRegistered(ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
private void fireChannelRegistered(DefaultChannelHandlerContext ctx) {
|
|
|
|
try {
|
|
|
|
((ChannelInboundHandler<Object>) ctx.handler()).channelRegistered(ctx);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
notifyHandlerException(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void fireChannelUnregistered() {
|
|
|
|
DefaultChannelHandlerContext ctx = firstInboundContext();
|
|
|
|
if (ctx != null) {
|
|
|
|
fireChannelUnregistered(ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
private void fireChannelUnregistered(DefaultChannelHandlerContext ctx) {
|
|
|
|
try {
|
|
|
|
((ChannelInboundHandler<Object>) ctx.handler()).channelUnregistered(ctx);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
notifyHandlerException(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void fireChannelActive() {
|
|
|
|
DefaultChannelHandlerContext ctx = firstInboundContext();
|
|
|
|
if (ctx != null) {
|
|
|
|
fireChannelActive(ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
private void fireChannelActive(DefaultChannelHandlerContext ctx) {
|
|
|
|
try {
|
|
|
|
((ChannelInboundHandler<Object>) ctx.handler()).channelActive(ctx);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
notifyHandlerException(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void fireChannelInactive() {
|
|
|
|
DefaultChannelHandlerContext ctx = firstInboundContext();
|
|
|
|
if (ctx != null) {
|
|
|
|
fireChannelInactive(ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
private void fireChannelInactive(DefaultChannelHandlerContext ctx) {
|
|
|
|
try {
|
|
|
|
((ChannelInboundHandler<Object>) ctx.handler()).channelInactive(ctx);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
notifyHandlerException(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void fireExceptionCaught(Throwable cause) {
|
|
|
|
DefaultChannelHandlerContext ctx = firstInboundContext();
|
|
|
|
if (ctx != null) {
|
|
|
|
fireExceptionCaught(ctx, cause);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
private void fireExceptionCaught(DefaultChannelHandlerContext ctx, Throwable cause) {
|
|
|
|
if (cause == null) {
|
|
|
|
throw new NullPointerException("cause");
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
((ChannelInboundHandler<Object>) ctx.handler()).exceptionCaught(ctx, cause);
|
|
|
|
} catch (Throwable t) {
|
2012-02-17 10:37:41 +01:00
|
|
|
if (logger.isWarnEnabled()) {
|
2012-05-01 17:19:41 +09:00
|
|
|
logger.warn(
|
|
|
|
"An exception was thrown by a user handler's " +
|
|
|
|
"exceptionCaught() method while handling the following exception:", cause);
|
2012-02-17 10:37:41 +01:00
|
|
|
}
|
2012-05-01 17:19:41 +09:00
|
|
|
notifyHandlerException(t);
|
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-05-01 17:19:41 +09:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
private void fireUserEventTriggered(DefaultChannelHandlerContext ctx, Object event) {
|
|
|
|
if (event == null) {
|
|
|
|
throw new NullPointerException("event");
|
|
|
|
}
|
|
|
|
|
2008-08-08 00:37:18 +00:00
|
|
|
try {
|
2012-05-01 17:19:41 +09:00
|
|
|
((ChannelInboundHandler<Object>) ctx.handler()).userEventTriggered(ctx, event);
|
2008-08-08 00:37:18 +00:00
|
|
|
} catch (Throwable t) {
|
2012-05-01 17:19:41 +09:00
|
|
|
notifyHandlerException(t);
|
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() {
|
|
|
|
DefaultChannelHandlerContext ctx = firstInboundContext();
|
|
|
|
if (ctx != null) {
|
|
|
|
fireInboundBufferUpdated(ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
private void fireInboundBufferUpdated(DefaultChannelHandlerContext ctx) {
|
|
|
|
try {
|
|
|
|
((ChannelInboundHandler<Object>) ctx.handler()).inboundBufferUpdated(ctx);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
notifyHandlerException(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-05-09 22:09:06 +09:00
|
|
|
public ChannelFuture bind(SocketAddress localAddress) {
|
2012-05-11 00:57:42 +09:00
|
|
|
return bind(localAddress, channel().newFuture());
|
2012-05-09 22:09:06 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture connect(SocketAddress remoteAddress) {
|
2012-05-11 00:57:42 +09:00
|
|
|
return connect(remoteAddress, channel().newFuture());
|
2012-05-09 22:09:06 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress) {
|
2012-05-11 00:57:42 +09:00
|
|
|
return connect(remoteAddress, localAddress, channel().newFuture());
|
2012-05-09 22:09:06 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture disconnect() {
|
2012-05-11 00:57:42 +09:00
|
|
|
return disconnect(channel().newFuture());
|
2012-05-09 22:09:06 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture close() {
|
2012-05-11 00:57:42 +09:00
|
|
|
return close(channel().newFuture());
|
2012-05-09 22:09:06 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture deregister() {
|
2012-05-11 00:57:42 +09:00
|
|
|
return deregister(channel().newFuture());
|
2012-05-09 22:09:06 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture flush() {
|
2012-05-11 00:57:42 +09:00
|
|
|
return flush(channel().newFuture());
|
2012-05-09 22:09:06 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture write(Object message) {
|
2012-05-11 00:57:42 +09: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
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2012-05-09 22:09:06 +09:00
|
|
|
private ChannelFuture bind(DefaultChannelHandlerContext ctx, SocketAddress localAddress, 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-05-01 17:19:41 +09:00
|
|
|
if (ctx != null) {
|
|
|
|
try {
|
|
|
|
((ChannelOutboundHandler<Object>) ctx.handler()).bind(ctx, localAddress, future);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
notifyHandlerException(t);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
channel().unsafe().bind(localAddress, future);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2012-05-09 22:09:06 +09:00
|
|
|
private ChannelFuture connect(DefaultChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, 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
|
|
|
|
|
|
|
if (ctx != null) {
|
|
|
|
try {
|
|
|
|
((ChannelOutboundHandler<Object>) ctx.handler()).connect(ctx, remoteAddress, localAddress, future);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
notifyHandlerException(t);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
channel().unsafe().connect(remoteAddress, localAddress, future);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2012-05-09 22:09:06 +09:00
|
|
|
private ChannelFuture disconnect(DefaultChannelHandlerContext ctx, ChannelFuture future) {
|
2012-05-11 09:00:35 +09:00
|
|
|
validateFuture(future);
|
2012-05-01 17:19:41 +09:00
|
|
|
if (ctx != null) {
|
|
|
|
try {
|
|
|
|
((ChannelOutboundHandler<Object>) ctx.handler()).disconnect(ctx, future);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
notifyHandlerException(t);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
channel().unsafe().disconnect(future);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2012-05-09 22:09:06 +09:00
|
|
|
private ChannelFuture close(DefaultChannelHandlerContext ctx, ChannelFuture future) {
|
2012-05-11 09:00:35 +09:00
|
|
|
validateFuture(future);
|
2012-05-01 17:19:41 +09:00
|
|
|
if (ctx != null) {
|
2008-08-08 00:37:18 +00:00
|
|
|
try {
|
2012-05-01 17:19:41 +09:00
|
|
|
((ChannelOutboundHandler<Object>) ctx.handler()).close(ctx, future);
|
2008-08-08 00:37:18 +00:00
|
|
|
} catch (Throwable t) {
|
2012-05-01 17:19:41 +09:00
|
|
|
notifyHandlerException(t);
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
2012-05-01 17:19:41 +09:00
|
|
|
} else {
|
|
|
|
channel().unsafe().close(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-05-01 17:19:41 +09:00
|
|
|
@SuppressWarnings("unchecked")
|
2012-05-09 22:09:06 +09:00
|
|
|
private ChannelFuture deregister(DefaultChannelHandlerContext ctx, ChannelFuture future) {
|
2012-05-11 09:00:35 +09:00
|
|
|
validateFuture(future);
|
2012-05-01 17:19:41 +09:00
|
|
|
if (ctx != null) {
|
|
|
|
try {
|
|
|
|
((ChannelOutboundHandler<Object>) ctx.handler()).deregister(ctx, future);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
notifyHandlerException(t);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
channel().unsafe().deregister(future);
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
private ChannelFuture flush(DefaultChannelHandlerContext ctx, ChannelFuture future) {
|
2012-05-11 09:00:35 +09:00
|
|
|
validateFuture(future);
|
2012-05-01 17:19:41 +09:00
|
|
|
if (ctx != null) {
|
2012-05-09 22:09:06 +09:00
|
|
|
try {
|
|
|
|
((ChannelOutboundHandler<Object>) ctx.handler()).flush(ctx, future);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
notifyHandlerException(t);
|
|
|
|
}
|
2012-05-01 17:19:41 +09:00
|
|
|
} else {
|
|
|
|
channel().unsafe().flush(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-05-01 17:19:41 +09:00
|
|
|
@Override
|
2012-05-09 22:09:06 +09:00
|
|
|
public ChannelFuture write(Object message, ChannelFuture future) {
|
2012-05-11 09:00:35 +09:00
|
|
|
if (message == null) {
|
|
|
|
throw new NullPointerException("message");
|
|
|
|
}
|
|
|
|
validateFuture(future);
|
|
|
|
|
2012-05-01 17:19:41 +09:00
|
|
|
if (message instanceof ChannelBuffer) {
|
|
|
|
ChannelBuffer m = (ChannelBuffer) message;
|
2012-05-09 22:09:06 +09:00
|
|
|
out().byteBuffer().writeBytes(m, m.readerIndex(), m.readableBytes());
|
2012-05-01 17:19:41 +09:00
|
|
|
} else {
|
2012-05-09 22:09:06 +09:00
|
|
|
out().messageBuffer().add(message);
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
2012-05-09 22:09:06 +09:00
|
|
|
return flush(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");
|
|
|
|
}
|
|
|
|
if (future.channel() != channel()) {
|
|
|
|
throw new IllegalArgumentException(String.format(
|
|
|
|
"future.channel does not match: %s (expected: %s)", future.channel(), channel()));
|
|
|
|
}
|
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() {
|
|
|
|
return nextInboundContext(head);
|
|
|
|
}
|
|
|
|
|
|
|
|
private DefaultChannelHandlerContext firstOutboundContext() {
|
|
|
|
return nextOutboundContext(tail);
|
|
|
|
}
|
|
|
|
|
|
|
|
private 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-05-01 17:19:41 +09:00
|
|
|
private 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 init(String name, ChannelHandler handler) {
|
|
|
|
DefaultChannelHandlerContext ctx = new DefaultChannelHandlerContext(null, null, name, handler);
|
2009-12-17 09:05:46 +00:00
|
|
|
callBeforeAdd(ctx);
|
2008-08-08 00:37:18 +00:00
|
|
|
head = tail = ctx;
|
|
|
|
name2ctx.clear();
|
|
|
|
name2ctx.put(name, ctx);
|
2009-12-17 09:05:46 +00:00
|
|
|
callAfterAdd(ctx);
|
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);
|
2008-08-08 00:37:18 +00:00
|
|
|
if (ctx == null) {
|
|
|
|
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);
|
2008-08-08 00:37:18 +00:00
|
|
|
if (ctx == null) {
|
|
|
|
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);
|
2008-08-08 00:37:18 +00:00
|
|
|
if (ctx == null) {
|
|
|
|
throw new NoSuchElementException(handlerType.getName());
|
|
|
|
} else {
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-01 17:19:41 +09:00
|
|
|
private final class DefaultChannelHandlerContext extends DefaultAttributeMap implements ChannelInboundHandlerContext<Object>, ChannelOutboundHandlerContext<Object> {
|
2009-03-11 10:45:55 +00:00
|
|
|
volatile DefaultChannelHandlerContext next;
|
|
|
|
volatile DefaultChannelHandlerContext prev;
|
|
|
|
private final String name;
|
|
|
|
private final ChannelHandler handler;
|
2012-05-01 17:19:41 +09:00
|
|
|
private final boolean canHandleInbound;
|
|
|
|
private final boolean canHandleOutbound;
|
|
|
|
private final ChannelBufferHolder<Object> in;
|
2012-05-09 22:09:06 +09:00
|
|
|
private final ChannelBufferHolder<Object> prevOut;
|
2009-03-11 10:45:55 +00:00
|
|
|
|
2012-05-01 17:19:41 +09:00
|
|
|
@SuppressWarnings("unchecked")
|
2009-03-11 10:45:55 +00:00
|
|
|
DefaultChannelHandlerContext(
|
|
|
|
DefaultChannelHandlerContext prev, DefaultChannelHandlerContext next,
|
|
|
|
String name, ChannelHandler handler) {
|
|
|
|
|
|
|
|
if (name == null) {
|
|
|
|
throw new NullPointerException("name");
|
|
|
|
}
|
|
|
|
if (handler == null) {
|
|
|
|
throw new NullPointerException("handler");
|
|
|
|
}
|
2012-05-01 17:19:41 +09:00
|
|
|
canHandleInbound = handler instanceof ChannelInboundHandler;
|
|
|
|
canHandleOutbound = handler instanceof ChannelOutboundHandler;
|
2009-03-11 10:45:55 +00:00
|
|
|
|
2012-05-01 17:19:41 +09:00
|
|
|
if (!canHandleInbound && !canHandleOutbound) {
|
2009-03-11 10:45:55 +00:00
|
|
|
throw new IllegalArgumentException(
|
|
|
|
"handler must be either " +
|
2012-05-01 17:19:41 +09:00
|
|
|
ChannelInboundHandler.class.getName() + " or " +
|
|
|
|
ChannelOutboundHandler.class.getName() + '.');
|
2009-03-11 10:45:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.prev = prev;
|
|
|
|
this.next = next;
|
|
|
|
this.name = name;
|
|
|
|
this.handler = handler;
|
2012-05-01 17:19:41 +09:00
|
|
|
|
|
|
|
if (canHandleInbound) {
|
|
|
|
try {
|
|
|
|
in = ((ChannelInboundHandler<Object>) handler).newInboundBuffer(this);
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new ChannelPipelineException("A user handler failed to create a new inbound buffer.", e);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
in = null;
|
|
|
|
}
|
|
|
|
if (canHandleOutbound) {
|
|
|
|
try {
|
2012-05-09 22:09:06 +09:00
|
|
|
prevOut = ((ChannelOutboundHandler<Object>) handler).newOutboundBuffer(this);
|
2012-05-01 17:19:41 +09:00
|
|
|
} catch (Exception e) {
|
|
|
|
throw new ChannelPipelineException("A user handler failed to create a new outbound buffer.", e);
|
|
|
|
} finally {
|
|
|
|
if (in != null) {
|
|
|
|
// TODO Release the inbound buffer once pooling is implemented.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2012-05-09 22:09:06 +09:00
|
|
|
prevOut = null;
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
2009-03-11 10:45:55 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-05-01 17:19:41 +09:00
|
|
|
public Channel channel() {
|
|
|
|
return DefaultChannelPipeline.this.channel();
|
2009-03-11 10:45:55 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-05-01 17:19:41 +09:00
|
|
|
public ChannelPipeline pipeline() {
|
2009-03-11 10:45:55 +00:00
|
|
|
return DefaultChannelPipeline.this;
|
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-05-01 17:19:41 +09:00
|
|
|
public ChannelHandler handler() {
|
|
|
|
return handler;
|
2009-03-11 10:45:55 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-05-01 17:19:41 +09:00
|
|
|
public String name() {
|
|
|
|
return name;
|
2009-03-11 10:45:55 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-05-01 17:19:41 +09:00
|
|
|
public boolean canHandleInbound() {
|
|
|
|
return canHandleInbound;
|
2009-03-11 10:45:55 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-05-01 17:19:41 +09:00
|
|
|
public boolean canHandleOutbound() {
|
|
|
|
return canHandleOutbound;
|
2009-03-11 10:45:55 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-05-01 17:19:41 +09:00
|
|
|
public ChannelBufferHolder<Object> in() {
|
|
|
|
return in;
|
2009-03-11 10:53:52 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-05-09 22:09:06 +09:00
|
|
|
public ChannelBufferHolder<Object> prevOut() {
|
|
|
|
return prevOut;
|
2009-03-11 10:53:52 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-05-01 17:19:41 +09:00
|
|
|
public ChannelBufferHolder<Object> nextIn() {
|
|
|
|
DefaultChannelHandlerContext next = nextInboundContext(this.next);
|
|
|
|
if (next != null) {
|
|
|
|
return next.in();
|
2009-03-11 10:45:55 +00:00
|
|
|
} else {
|
2012-05-01 17:19:41 +09:00
|
|
|
throw new NoSuchElementException("no inbound buffer in the rest of the pipeline");
|
2009-03-11 10:45:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-05-09 22:09:06 +09:00
|
|
|
public ChannelBufferHolder<Object> out() {
|
2012-05-01 17:19:41 +09:00
|
|
|
DefaultChannelHandlerContext next = nextOutboundContext(prev);
|
2009-03-11 10:45:55 +00:00
|
|
|
if (next != null) {
|
2012-05-09 22:09:06 +09:00
|
|
|
return next.prevOut();
|
2012-05-01 17:19:41 +09:00
|
|
|
} else {
|
|
|
|
return channel().unsafe().out();
|
2009-03-11 10:45:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-01 17:19:41 +09:00
|
|
|
@Override
|
|
|
|
public void fireChannelRegistered() {
|
|
|
|
DefaultChannelHandlerContext next = nextInboundContext(this.next);
|
|
|
|
if (next != null) {
|
|
|
|
DefaultChannelPipeline.this.fireChannelRegistered(next);
|
|
|
|
}
|
2009-03-11 10:45:55 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2012-05-01 17:19:41 +09:00
|
|
|
public void fireChannelUnregistered() {
|
|
|
|
DefaultChannelHandlerContext next = nextInboundContext(this.next);
|
|
|
|
if (next != null) {
|
|
|
|
DefaultChannelPipeline.this.fireChannelUnregistered(next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void fireChannelActive() {
|
|
|
|
DefaultChannelHandlerContext next = nextInboundContext(this.next);
|
|
|
|
if (next != null) {
|
|
|
|
DefaultChannelPipeline.this.fireChannelActive(next);
|
2012-02-17 10:37:41 +01:00
|
|
|
}
|
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 fireChannelInactive() {
|
|
|
|
DefaultChannelHandlerContext next = nextInboundContext(this.next);
|
|
|
|
if (next != null) {
|
|
|
|
DefaultChannelPipeline.this.fireChannelInactive(next);
|
|
|
|
}
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
2012-02-24 20:26:50 +01:00
|
|
|
|
|
|
|
@Override
|
2012-05-01 17:19:41 +09:00
|
|
|
public void fireExceptionCaught(Throwable cause) {
|
|
|
|
DefaultChannelHandlerContext next = nextInboundContext(this.next);
|
|
|
|
if (next != null) {
|
|
|
|
DefaultChannelPipeline.this.fireExceptionCaught(next, cause);
|
2012-02-24 20:26:50 +01:00
|
|
|
}
|
|
|
|
}
|
2012-02-29 21:07:02 +01:00
|
|
|
|
2012-05-01 17:19:41 +09:00
|
|
|
@Override
|
|
|
|
public void fireUserEventTriggered(Object event) {
|
|
|
|
DefaultChannelHandlerContext next = nextInboundContext(this.next);
|
|
|
|
if (next != null) {
|
|
|
|
DefaultChannelPipeline.this.fireUserEventTriggered(next, event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void fireInboundBufferUpdated() {
|
|
|
|
DefaultChannelHandlerContext next = nextInboundContext(this.next);
|
|
|
|
if (next != null) {
|
|
|
|
DefaultChannelPipeline.this.fireInboundBufferUpdated(next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-05-09 22:09:06 +09:00
|
|
|
public ChannelFuture bind(SocketAddress localAddress) {
|
2012-05-11 00:57:42 +09:00
|
|
|
return bind(localAddress, newFuture());
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-05-09 22:09:06 +09:00
|
|
|
public ChannelFuture connect(SocketAddress remoteAddress) {
|
2012-05-11 00:57:42 +09:00
|
|
|
return connect(remoteAddress, newFuture());
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-05-09 22:09:06 +09:00
|
|
|
public ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress) {
|
2012-05-11 00:57:42 +09:00
|
|
|
return connect(remoteAddress, localAddress, newFuture());
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-05-09 22:09:06 +09:00
|
|
|
public ChannelFuture disconnect() {
|
2012-05-11 00:57:42 +09:00
|
|
|
return disconnect(newFuture());
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-05-09 22:09:06 +09:00
|
|
|
public ChannelFuture close() {
|
2012-05-11 00:57:42 +09:00
|
|
|
return close(newFuture());
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-05-09 22:09:06 +09:00
|
|
|
public ChannelFuture deregister() {
|
2012-05-11 00:57:42 +09:00
|
|
|
return deregister(newFuture());
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-05-09 22:09:06 +09:00
|
|
|
public ChannelFuture flush() {
|
2012-05-11 00:57:42 +09:00
|
|
|
return flush(newFuture());
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-05-09 22:09:06 +09:00
|
|
|
public ChannelFuture write(Object message) {
|
2012-05-11 00:57:42 +09:00
|
|
|
return write(message, newFuture());
|
2012-05-09 22:09:06 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture bind(SocketAddress localAddress, ChannelFuture future) {
|
|
|
|
return DefaultChannelPipeline.this.bind(nextOutboundContext(prev), localAddress, future);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture connect(SocketAddress remoteAddress, ChannelFuture future) {
|
|
|
|
return connect(remoteAddress, null, future);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelFuture future) {
|
|
|
|
return DefaultChannelPipeline.this.connect(nextOutboundContext(prev), remoteAddress, localAddress, future);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture disconnect(ChannelFuture future) {
|
|
|
|
return DefaultChannelPipeline.this.disconnect(nextOutboundContext(prev), future);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture close(ChannelFuture future) {
|
|
|
|
return DefaultChannelPipeline.this.close(nextOutboundContext(prev), future);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture deregister(ChannelFuture future) {
|
|
|
|
return DefaultChannelPipeline.this.deregister(nextOutboundContext(prev), future);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture flush(ChannelFuture future) {
|
|
|
|
return DefaultChannelPipeline.this.flush(nextOutboundContext(prev), future);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture write(Object message, ChannelFuture future) {
|
|
|
|
if (message instanceof ChannelBuffer) {
|
|
|
|
ChannelBuffer m = (ChannelBuffer) message;
|
|
|
|
out().byteBuffer().writeBytes(m, m.readerIndex(), m.readableBytes());
|
|
|
|
} else {
|
|
|
|
out().messageBuffer().add(message);
|
|
|
|
}
|
|
|
|
return flush(future);
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture newFuture() {
|
2012-05-01 17:48:06 +09:00
|
|
|
return channel().newFuture();
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture newSucceededFuture() {
|
2012-05-01 17:48:06 +09:00
|
|
|
return channel().newSucceededFuture();
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture newFailedFuture(Throwable cause) {
|
2012-05-01 17:48:06 +09:00
|
|
|
return channel().newFailedFuture(cause);
|
2012-05-01 17:19:41 +09:00
|
|
|
}
|
2009-03-11 10:45:55 +00:00
|
|
|
}
|
2009-08-28 07:15:49 +00:00
|
|
|
}
|