2008-08-08 02:37:18 +02:00
|
|
|
/*
|
2012-06-04 22:31:44 +02:00
|
|
|
* Copyright 2012 The Netty Project
|
2008-08-08 02:37:18 +02:00
|
|
|
*
|
2011-12-09 06:18:34 +01: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 02:37:18 +02:00
|
|
|
*
|
2012-06-04 22:31:44 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2008-08-08 03:27:24 +02:00
|
|
|
*
|
2009-08-28 09:15:49 +02: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 06:18:34 +01:00
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
2009-08-28 09:15:49 +02:00
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2008-08-08 02:37:18 +02:00
|
|
|
*/
|
2011-12-09 04:38:59 +01:00
|
|
|
package io.netty.channel;
|
2008-08-08 02:37:18 +02:00
|
|
|
|
2012-06-10 04:08:43 +02:00
|
|
|
import io.netty.buffer.ByteBuf;
|
2012-06-11 03:43:47 +02:00
|
|
|
import io.netty.buffer.MessageBuf;
|
2012-05-01 10:19:41 +02:00
|
|
|
import io.netty.logging.InternalLogger;
|
|
|
|
import io.netty.logging.InternalLoggerFactory;
|
|
|
|
import io.netty.util.DefaultAttributeMap;
|
|
|
|
|
2012-05-09 16:42:01 +02:00
|
|
|
import java.io.IOException;
|
2008-08-08 02:37:18 +02:00
|
|
|
import java.net.SocketAddress;
|
2012-05-09 15:09:06 +02:00
|
|
|
import java.nio.channels.ClosedChannelException;
|
2012-05-25 15:16:25 +02:00
|
|
|
import java.util.ArrayDeque;
|
|
|
|
import java.util.Deque;
|
2012-06-02 02:51:19 +02:00
|
|
|
import java.util.Queue;
|
2012-05-15 10:10:54 +02:00
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
2009-02-16 12:59:33 +01:00
|
|
|
import java.util.concurrent.ConcurrentMap;
|
2008-08-08 02:37:18 +02:00
|
|
|
|
|
|
|
/**
|
2008-09-02 09:13:20 +02:00
|
|
|
* A skeletal {@link Channel} implementation.
|
2008-08-08 02:37:18 +02:00
|
|
|
*/
|
2012-05-01 10:19:41 +02:00
|
|
|
public abstract class AbstractChannel extends DefaultAttributeMap implements Channel {
|
|
|
|
|
|
|
|
private static final InternalLogger logger = InternalLoggerFactory.getInstance(AbstractChannel.class);
|
2008-08-08 02:37:18 +02:00
|
|
|
|
2009-02-16 12:59:33 +01:00
|
|
|
static final ConcurrentMap<Integer, Channel> allChannels = new ConcurrentHashMap<Integer, Channel>();
|
|
|
|
|
2012-05-09 15:09:06 +02:00
|
|
|
/**
|
|
|
|
* Generates a negative unique integer ID. This method generates only
|
|
|
|
* negative integers to avoid conflicts with user-specified IDs where only
|
|
|
|
* non-negative integers are allowed.
|
|
|
|
*/
|
2009-02-16 12:59:33 +01:00
|
|
|
private static Integer allocateId(Channel channel) {
|
2012-05-10 14:56:10 +02:00
|
|
|
int idVal = System.identityHashCode(channel);
|
|
|
|
if (idVal > 0) {
|
|
|
|
idVal = -idVal;
|
|
|
|
} else if (idVal == 0) {
|
2012-05-09 15:09:06 +02:00
|
|
|
idVal = -1;
|
|
|
|
}
|
2012-05-10 14:56:10 +02:00
|
|
|
|
2012-05-09 15:09:06 +02:00
|
|
|
Integer id;
|
2009-02-16 12:59:33 +01:00
|
|
|
for (;;) {
|
2012-05-09 15:09:06 +02:00
|
|
|
id = Integer.valueOf(idVal);
|
2009-02-16 12:59:33 +01:00
|
|
|
// Loop until a unique ID is acquired.
|
|
|
|
// It should be found in one loop practically.
|
|
|
|
if (allChannels.putIfAbsent(id, channel) == null) {
|
|
|
|
// Successfully acquired.
|
|
|
|
return id;
|
|
|
|
} else {
|
|
|
|
// Taken by other channel at almost the same moment.
|
2012-05-09 15:09:06 +02:00
|
|
|
idVal --;
|
|
|
|
if (idVal >= 0) {
|
|
|
|
idVal = -1;
|
|
|
|
}
|
2009-02-16 12:59:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-08 02:37:18 +02:00
|
|
|
private final Channel parent;
|
2012-05-09 15:09:06 +02:00
|
|
|
private final Integer id;
|
2012-05-01 10:19:41 +02:00
|
|
|
private final Unsafe unsafe;
|
2012-06-04 03:51:42 +02:00
|
|
|
private final DefaultChannelPipeline pipeline;
|
2012-05-01 10:48:06 +02:00
|
|
|
private final ChannelFuture succeededFuture = new SucceededChannelFuture(this);
|
2012-05-12 18:37:16 +02:00
|
|
|
private final ChannelFuture voidFuture = new VoidChannelFuture(this);
|
|
|
|
private final CloseFuture closeFuture = new CloseFuture(this);
|
2012-05-01 10:19:41 +02:00
|
|
|
|
2012-05-16 16:02:06 +02:00
|
|
|
private volatile SocketAddress localAddress;
|
|
|
|
private volatile SocketAddress remoteAddress;
|
2012-05-01 10:19:41 +02:00
|
|
|
private volatile EventLoop eventLoop;
|
2012-05-02 14:05:53 +02:00
|
|
|
private volatile boolean registered;
|
2012-05-09 15:09:06 +02:00
|
|
|
|
2012-05-12 17:40:28 +02:00
|
|
|
private ClosedChannelException closedChannelException;
|
2012-05-27 07:48:48 +02:00
|
|
|
private final Deque<FlushCheckpoint> flushCheckpoints = new ArrayDeque<FlushCheckpoint>();
|
2012-05-28 14:05:49 +02:00
|
|
|
private long writeCounter;
|
|
|
|
private boolean inFlushNow;
|
|
|
|
private boolean flushNowPending;
|
2008-08-08 02:37:18 +02:00
|
|
|
|
|
|
|
/** Cache for the string representation of this channel */
|
2012-05-01 10:19:41 +02:00
|
|
|
private boolean strValActive;
|
2008-08-08 02:37:18 +02:00
|
|
|
private String strVal;
|
2012-05-01 10:19:41 +02:00
|
|
|
|
2008-09-02 09:13:20 +02:00
|
|
|
/**
|
|
|
|
* Creates a new instance.
|
|
|
|
*
|
2012-05-09 15:09:06 +02:00
|
|
|
* @param id
|
|
|
|
* the unique non-negative integer ID of this channel.
|
|
|
|
* Specify {@code null} to auto-generate a unique negative integer
|
|
|
|
* ID.
|
2008-09-02 09:13:20 +02:00
|
|
|
* @param parent
|
|
|
|
* the parent of this channel. {@code null} if there's no parent.
|
|
|
|
*/
|
2012-06-07 14:06:56 +02:00
|
|
|
protected AbstractChannel(Channel parent, Integer id) {
|
2012-05-09 15:09:06 +02:00
|
|
|
if (id == null) {
|
|
|
|
id = allocateId(this);
|
|
|
|
} else {
|
|
|
|
if (id.intValue() < 0) {
|
|
|
|
throw new IllegalArgumentException("id: " + id + " (expected: >= 0)");
|
|
|
|
}
|
|
|
|
if (allChannels.putIfAbsent(id, this) != null) {
|
|
|
|
throw new IllegalArgumentException("duplicate ID: " + id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-01 10:19:41 +02:00
|
|
|
this.parent = parent;
|
2012-05-09 15:09:06 +02:00
|
|
|
this.id = id;
|
2012-05-27 07:48:48 +02:00
|
|
|
unsafe = newUnsafe();
|
2012-06-04 03:51:42 +02:00
|
|
|
pipeline = new DefaultChannelPipeline(this);
|
2010-05-19 08:29:43 +02:00
|
|
|
|
2012-05-12 18:37:16 +02:00
|
|
|
closeFuture().addListener(new ChannelFutureListener() {
|
2012-05-01 10:19:41 +02:00
|
|
|
@Override
|
|
|
|
public void operationComplete(ChannelFuture future) {
|
|
|
|
allChannels.remove(id());
|
|
|
|
}
|
|
|
|
});
|
2012-06-02 03:34:19 +02:00
|
|
|
|
2010-05-19 08:29:43 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-05-01 10:19:41 +02:00
|
|
|
public final Integer id() {
|
2008-08-08 02:37:18 +02:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-05-01 10:19:41 +02:00
|
|
|
public Channel parent() {
|
2008-08-08 02:37:18 +02:00
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-05-01 10:19:41 +02:00
|
|
|
public ChannelPipeline pipeline() {
|
2008-08-08 02:37:18 +02:00
|
|
|
return pipeline;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-05-01 10:19:41 +02:00
|
|
|
public EventLoop eventLoop() {
|
2012-06-02 03:34:19 +02:00
|
|
|
EventLoop eventLoop = this.eventLoop;
|
2012-05-09 15:09:06 +02:00
|
|
|
if (eventLoop == null) {
|
|
|
|
throw new IllegalStateException("channel not registered to an event loop");
|
|
|
|
}
|
2012-05-01 10:19:41 +02:00
|
|
|
return eventLoop;
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2012-05-16 16:02:06 +02:00
|
|
|
@Override
|
|
|
|
public SocketAddress localAddress() {
|
|
|
|
SocketAddress localAddress = this.localAddress;
|
|
|
|
if (localAddress == null) {
|
|
|
|
try {
|
|
|
|
this.localAddress = localAddress = unsafe().localAddress();
|
|
|
|
} catch (Throwable t) {
|
|
|
|
// Sometimes fails on a closed socket in Windows.
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return localAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void invalidateLocalAddress() {
|
|
|
|
localAddress = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public SocketAddress remoteAddress() {
|
|
|
|
SocketAddress remoteAddress = this.remoteAddress;
|
|
|
|
if (remoteAddress == null) {
|
|
|
|
try {
|
|
|
|
this.remoteAddress = remoteAddress = unsafe().remoteAddress();
|
|
|
|
} catch (Throwable t) {
|
|
|
|
// Sometimes fails on a closed socket in Windows.
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return remoteAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void invalidateRemoteAddress() {
|
|
|
|
remoteAddress = null;
|
|
|
|
}
|
|
|
|
|
2012-05-02 14:05:53 +02:00
|
|
|
@Override
|
|
|
|
public boolean isRegistered() {
|
|
|
|
return registered;
|
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-05-09 15:09:06 +02:00
|
|
|
public ChannelFuture bind(SocketAddress localAddress) {
|
2012-06-03 13:25:03 +02:00
|
|
|
return pipeline.bind(localAddress);
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-05-09 15:09:06 +02:00
|
|
|
public ChannelFuture connect(SocketAddress remoteAddress) {
|
2012-06-03 13:25:03 +02:00
|
|
|
return pipeline.connect(remoteAddress);
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-05-09 15:09:06 +02:00
|
|
|
public ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress) {
|
2012-06-03 13:25:03 +02:00
|
|
|
return pipeline.connect(remoteAddress, localAddress);
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-05-09 15:09:06 +02:00
|
|
|
public ChannelFuture disconnect() {
|
2012-06-03 13:25:03 +02:00
|
|
|
return pipeline.disconnect();
|
2008-10-02 06:40:46 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-05-09 15:09:06 +02:00
|
|
|
public ChannelFuture close() {
|
2012-06-03 13:25:03 +02:00
|
|
|
return pipeline.close();
|
2008-11-26 10:21:00 +01:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-05-09 15:09:06 +02:00
|
|
|
public ChannelFuture deregister() {
|
2012-06-03 13:25:03 +02:00
|
|
|
return pipeline.deregister();
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-05-09 15:09:06 +02:00
|
|
|
public ChannelFuture flush() {
|
2012-06-03 13:25:03 +02:00
|
|
|
return pipeline.flush();
|
2012-05-09 15:09:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture write(Object message) {
|
2012-06-03 13:25:03 +02:00
|
|
|
return pipeline.write(message);
|
2012-05-09 15:09:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture bind(SocketAddress localAddress, ChannelFuture future) {
|
2012-06-03 13:25:03 +02:00
|
|
|
return pipeline.bind(localAddress, future);
|
2012-05-09 15:09:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture connect(SocketAddress remoteAddress, ChannelFuture future) {
|
2012-06-03 13:25:03 +02:00
|
|
|
return pipeline.connect(remoteAddress, future);
|
2012-05-09 15:09:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelFuture future) {
|
2012-06-03 13:25:03 +02:00
|
|
|
return pipeline.connect(remoteAddress, localAddress, future);
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-05-09 15:09:06 +02:00
|
|
|
public ChannelFuture disconnect(ChannelFuture future) {
|
2012-06-03 13:25:03 +02:00
|
|
|
return pipeline.disconnect(future);
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-05-09 15:09:06 +02:00
|
|
|
public ChannelFuture close(ChannelFuture future) {
|
2012-06-03 13:25:03 +02:00
|
|
|
return pipeline.close(future);
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2012-05-09 15:09:06 +02:00
|
|
|
@Override
|
|
|
|
public ChannelFuture deregister(ChannelFuture future) {
|
2012-06-03 13:25:03 +02:00
|
|
|
return pipeline.deregister(future);
|
2012-05-09 15:09:06 +02:00
|
|
|
}
|
2012-05-01 10:48:06 +02:00
|
|
|
|
2012-05-09 15:09:06 +02:00
|
|
|
@Override
|
2012-06-10 04:08:43 +02:00
|
|
|
public ByteBuf outboundByteBuffer() {
|
2012-06-03 13:25:03 +02:00
|
|
|
return pipeline.outboundByteBuffer();
|
2012-06-02 02:51:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-06-11 03:43:47 +02:00
|
|
|
public MessageBuf<Object> outboundMessageBuffer() {
|
2012-06-03 13:25:03 +02:00
|
|
|
return pipeline.outboundMessageBuffer();
|
2012-05-09 15:09:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture flush(ChannelFuture future) {
|
2012-06-03 13:25:03 +02:00
|
|
|
return pipeline.flush(future);
|
2012-05-09 15:09:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture write(Object message, ChannelFuture future) {
|
|
|
|
return pipeline.write(message, future);
|
|
|
|
}
|
2012-05-01 10:48:06 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture newFuture() {
|
|
|
|
return new DefaultChannelFuture(this, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture newSucceededFuture() {
|
|
|
|
return succeededFuture;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ChannelFuture newFailedFuture(Throwable cause) {
|
|
|
|
return new FailedChannelFuture(this, cause);
|
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-05-12 18:37:16 +02:00
|
|
|
public ChannelFuture closeFuture() {
|
|
|
|
return closeFuture;
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-05-01 10:19:41 +02:00
|
|
|
public Unsafe unsafe() {
|
|
|
|
return unsafe;
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2012-05-27 07:48:48 +02:00
|
|
|
protected abstract Unsafe newUnsafe();
|
|
|
|
|
2012-05-01 10:19:41 +02:00
|
|
|
/**
|
|
|
|
* Returns the {@linkplain System#identityHashCode(Object) identity hash code}
|
|
|
|
* of this channel.
|
|
|
|
*/
|
2010-11-12 01:45:39 +01:00
|
|
|
@Override
|
2012-05-01 10:19:41 +02:00
|
|
|
public final int hashCode() {
|
|
|
|
return System.identityHashCode(this);
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2012-05-01 10:19:41 +02:00
|
|
|
/**
|
|
|
|
* Returns {@code true} if and only if the specified object is identical
|
|
|
|
* with this channel (i.e: {@code this == o}).
|
|
|
|
*/
|
2011-12-07 07:54:15 +01:00
|
|
|
@Override
|
2012-05-01 10:19:41 +02:00
|
|
|
public final boolean equals(Object o) {
|
|
|
|
return this == o;
|
2011-12-07 07:54:15 +01:00
|
|
|
}
|
|
|
|
|
2012-05-01 10:19:41 +02:00
|
|
|
/**
|
|
|
|
* Compares the {@linkplain #id() ID} of the two channels.
|
|
|
|
*/
|
2011-12-07 07:54:15 +01:00
|
|
|
@Override
|
2012-05-01 10:19:41 +02:00
|
|
|
public final int compareTo(Channel o) {
|
|
|
|
return id().compareTo(o.id());
|
2011-12-07 07:54:15 +01:00
|
|
|
}
|
2012-05-01 10:19:41 +02:00
|
|
|
|
2008-09-02 09:13:20 +02:00
|
|
|
/**
|
|
|
|
* Returns the {@link String} representation of this channel. The returned
|
2012-05-01 10:19:41 +02:00
|
|
|
* string contains the {@linkplain #id() ID}, {@linkplain #localAddress() local address},
|
|
|
|
* and {@linkplain #remoteAddress() remote address} of this channel for
|
2008-09-02 09:13:20 +02:00
|
|
|
* easier identification.
|
|
|
|
*/
|
2008-08-08 02:37:18 +02:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
2012-05-01 10:19:41 +02:00
|
|
|
boolean active = isActive();
|
|
|
|
if (strValActive == active && strVal != null) {
|
2008-08-08 02:37:18 +02:00
|
|
|
return strVal;
|
|
|
|
}
|
|
|
|
|
2012-05-11 03:47:45 +02:00
|
|
|
SocketAddress remoteAddr = remoteAddress();
|
|
|
|
SocketAddress localAddr = localAddress();
|
|
|
|
if (remoteAddr != null) {
|
|
|
|
SocketAddress srcAddr;
|
|
|
|
SocketAddress dstAddr;
|
|
|
|
if (parent == null) {
|
|
|
|
srcAddr = localAddr;
|
|
|
|
dstAddr = remoteAddr;
|
2008-08-08 02:37:18 +02:00
|
|
|
} else {
|
2012-05-11 03:47:45 +02:00
|
|
|
srcAddr = remoteAddr;
|
|
|
|
dstAddr = localAddr;
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
2012-05-11 03:47:45 +02:00
|
|
|
strVal = String.format("[id: 0x%08x, %s %s %s]", id, srcAddr, active? "=>" : ":>", dstAddr);
|
|
|
|
} else if (localAddr != null) {
|
|
|
|
strVal = String.format("[id: 0x%08x, %s]", id, localAddr);
|
|
|
|
} else {
|
|
|
|
strVal = String.format("[id: 0x%08x]", id);
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
|
|
|
|
2012-05-01 10:19:41 +02:00
|
|
|
strValActive = active;
|
2009-02-09 09:00:26 +01:00
|
|
|
return strVal;
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|
2009-02-16 15:32:40 +01:00
|
|
|
|
2012-05-27 07:48:48 +02:00
|
|
|
protected abstract class AbstractUnsafe implements Unsafe {
|
2010-01-09 06:40:40 +01:00
|
|
|
|
2012-05-28 14:05:49 +02:00
|
|
|
private final Runnable flushLaterTask = new FlushLater();
|
|
|
|
|
2010-01-09 06:40:40 +01:00
|
|
|
@Override
|
2012-06-07 07:52:33 +02:00
|
|
|
public final ChannelHandlerContext directOutboundContext() {
|
|
|
|
return pipeline.head;
|
2010-01-09 06:40:40 +01:00
|
|
|
}
|
|
|
|
|
2012-05-10 17:57:42 +02:00
|
|
|
@Override
|
2012-05-30 12:58:14 +02:00
|
|
|
public final ChannelFuture voidFuture() {
|
2012-05-10 17:57:42 +02:00
|
|
|
return voidFuture;
|
|
|
|
}
|
|
|
|
|
2012-05-02 08:01:58 +02:00
|
|
|
@Override
|
2012-05-30 12:58:14 +02:00
|
|
|
public final SocketAddress localAddress() {
|
2012-05-02 08:01:58 +02:00
|
|
|
return localAddress0();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-05-30 12:58:14 +02:00
|
|
|
public final SocketAddress remoteAddress() {
|
2012-05-02 08:01:58 +02:00
|
|
|
return remoteAddress0();
|
|
|
|
}
|
|
|
|
|
2012-05-01 16:18:29 +02:00
|
|
|
@Override
|
2012-05-30 12:58:14 +02:00
|
|
|
public final void register(EventLoop eventLoop, ChannelFuture future) {
|
2012-05-01 16:18:29 +02:00
|
|
|
if (eventLoop == null) {
|
|
|
|
throw new NullPointerException("eventLoop");
|
|
|
|
}
|
2012-05-14 16:57:23 +02:00
|
|
|
if (isRegistered()) {
|
2012-05-01 16:18:29 +02:00
|
|
|
throw new IllegalStateException("registered to an event loop already");
|
|
|
|
}
|
2012-05-12 17:40:28 +02:00
|
|
|
if (!isCompatible(eventLoop)) {
|
|
|
|
throw new IllegalStateException("incompatible event loop type: " + eventLoop.getClass().getName());
|
|
|
|
}
|
|
|
|
|
2012-05-01 16:18:29 +02:00
|
|
|
AbstractChannel.this.eventLoop = eventLoop;
|
|
|
|
|
|
|
|
assert eventLoop().inEventLoop();
|
2012-05-09 15:09:06 +02:00
|
|
|
|
|
|
|
if (!ensureOpen(future)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2012-06-03 21:54:26 +02:00
|
|
|
Runnable postRegisterTask = doRegister();
|
2012-05-09 15:09:06 +02:00
|
|
|
registered = true;
|
|
|
|
future.setSuccess();
|
2012-06-03 13:25:03 +02:00
|
|
|
pipeline.fireChannelRegistered();
|
2012-06-03 21:54:26 +02:00
|
|
|
if (postRegisterTask != null) {
|
|
|
|
postRegisterTask.run();
|
|
|
|
}
|
2012-05-10 16:19:59 +02:00
|
|
|
if (isActive()) {
|
2012-06-03 13:25:03 +02:00
|
|
|
pipeline.fireChannelActive();
|
2012-05-10 16:19:59 +02:00
|
|
|
}
|
2012-05-09 15:09:06 +02:00
|
|
|
} catch (Throwable t) {
|
|
|
|
// Close the channel directly to avoid FD leak.
|
|
|
|
try {
|
|
|
|
doClose();
|
|
|
|
} catch (Throwable t2) {
|
|
|
|
logger.warn("Failed to close a channel", t2);
|
|
|
|
}
|
|
|
|
|
|
|
|
future.setFailure(t);
|
2012-06-03 13:25:03 +02:00
|
|
|
pipeline.fireExceptionCaught(t);
|
2012-05-14 07:17:40 +02:00
|
|
|
closeFuture().setSuccess();
|
2012-05-02 14:05:53 +02:00
|
|
|
}
|
2012-05-01 16:18:29 +02:00
|
|
|
}
|
|
|
|
|
2012-05-01 10:19:41 +02:00
|
|
|
@Override
|
2012-05-30 12:58:14 +02:00
|
|
|
public final void bind(final SocketAddress localAddress, final ChannelFuture future) {
|
2012-05-01 10:19:41 +02:00
|
|
|
if (eventLoop().inEventLoop()) {
|
2012-05-09 15:09:06 +02:00
|
|
|
if (!ensureOpen(future)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
boolean wasActive = isActive();
|
|
|
|
doBind(localAddress);
|
|
|
|
future.setSuccess();
|
|
|
|
if (!wasActive && isActive()) {
|
2012-06-03 13:25:03 +02:00
|
|
|
pipeline.fireChannelActive();
|
2012-05-09 15:09:06 +02:00
|
|
|
}
|
|
|
|
} catch (Throwable t) {
|
|
|
|
future.setFailure(t);
|
2012-06-03 13:25:03 +02:00
|
|
|
pipeline.fireExceptionCaught(t);
|
2012-05-09 15:09:06 +02:00
|
|
|
closeIfClosed();
|
|
|
|
}
|
2012-05-01 10:19:41 +02:00
|
|
|
} else {
|
|
|
|
eventLoop().execute(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2012-05-09 15:09:06 +02:00
|
|
|
bind(localAddress, future);
|
2012-05-01 10:19:41 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-05-30 12:58:14 +02:00
|
|
|
public final void disconnect(final ChannelFuture future) {
|
2012-05-01 10:19:41 +02:00
|
|
|
if (eventLoop().inEventLoop()) {
|
2012-05-09 15:09:06 +02:00
|
|
|
try {
|
|
|
|
boolean wasActive = isActive();
|
|
|
|
doDisconnect();
|
|
|
|
future.setSuccess();
|
|
|
|
if (wasActive && !isActive()) {
|
2012-06-03 13:25:03 +02:00
|
|
|
pipeline.fireChannelInactive();
|
2012-05-09 15:09:06 +02:00
|
|
|
}
|
|
|
|
} catch (Throwable t) {
|
|
|
|
future.setFailure(t);
|
|
|
|
closeIfClosed();
|
|
|
|
}
|
2012-05-01 10:19:41 +02:00
|
|
|
} else {
|
|
|
|
eventLoop().execute(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2012-05-09 15:09:06 +02:00
|
|
|
disconnect(future);
|
2012-05-01 10:19:41 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-05-30 12:58:14 +02:00
|
|
|
public final void close(final ChannelFuture future) {
|
2012-05-01 10:19:41 +02:00
|
|
|
if (eventLoop().inEventLoop()) {
|
2012-05-14 07:17:40 +02:00
|
|
|
if (closeFuture.setClosed()) {
|
2012-05-09 15:09:06 +02:00
|
|
|
boolean wasActive = isActive();
|
|
|
|
try {
|
|
|
|
doClose();
|
|
|
|
future.setSuccess();
|
|
|
|
} catch (Throwable t) {
|
|
|
|
future.setFailure(t);
|
|
|
|
}
|
2012-05-10 16:19:59 +02:00
|
|
|
|
2012-05-12 17:40:28 +02:00
|
|
|
if (closedChannelException != null) {
|
|
|
|
closedChannelException = new ClosedChannelException();
|
|
|
|
}
|
|
|
|
|
|
|
|
notifyFlushFutures(closedChannelException);
|
|
|
|
|
2012-05-09 15:09:06 +02:00
|
|
|
if (wasActive && !isActive()) {
|
2012-06-03 13:25:03 +02:00
|
|
|
pipeline.fireChannelInactive();
|
2012-05-09 15:09:06 +02:00
|
|
|
}
|
2012-05-10 16:19:59 +02:00
|
|
|
|
2012-05-10 17:57:42 +02:00
|
|
|
deregister(voidFuture());
|
2012-05-09 15:09:06 +02:00
|
|
|
} else {
|
|
|
|
// Closed already.
|
|
|
|
future.setSuccess();
|
|
|
|
}
|
2012-05-01 10:19:41 +02:00
|
|
|
} else {
|
|
|
|
eventLoop().execute(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2012-05-09 15:09:06 +02:00
|
|
|
close(future);
|
2012-05-01 10:19:41 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-05-30 12:58:14 +02:00
|
|
|
public final void deregister(final ChannelFuture future) {
|
2012-05-01 10:19:41 +02:00
|
|
|
if (eventLoop().inEventLoop()) {
|
2012-05-30 12:58:14 +02:00
|
|
|
if (!registered) {
|
|
|
|
future.setSuccess();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-01 16:19:31 +02:00
|
|
|
try {
|
2012-05-09 15:09:06 +02:00
|
|
|
doDeregister();
|
|
|
|
} catch (Throwable t) {
|
|
|
|
logger.warn("Unexpected exception occurred while deregistering a channel.", t);
|
2012-05-01 16:19:31 +02:00
|
|
|
} finally {
|
2012-05-30 12:58:14 +02:00
|
|
|
if (registered) {
|
|
|
|
registered = false;
|
|
|
|
future.setSuccess();
|
2012-06-03 13:25:03 +02:00
|
|
|
pipeline.fireChannelUnregistered();
|
2012-05-30 12:58:14 +02:00
|
|
|
} else {
|
|
|
|
// Some transports like local and AIO does not allow the deregistration of
|
|
|
|
// an open channel. Their doDeregister() calls close(). Consequently,
|
|
|
|
// close() calls deregister() again - no need to fire channelUnregistered.
|
|
|
|
future.setSuccess();
|
|
|
|
}
|
2012-05-01 16:19:31 +02:00
|
|
|
}
|
2012-05-01 10:19:41 +02:00
|
|
|
} else {
|
|
|
|
eventLoop().execute(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2012-05-09 15:09:06 +02:00
|
|
|
deregister(future);
|
2012-05-01 10:19:41 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-05-09 15:09:06 +02:00
|
|
|
public void flush(final ChannelFuture future) {
|
2012-05-01 10:19:41 +02:00
|
|
|
if (eventLoop().inEventLoop()) {
|
2012-05-12 17:40:28 +02:00
|
|
|
// Append flush future to the notification list.
|
2012-05-12 22:09:05 +02:00
|
|
|
if (future != voidFuture) {
|
2012-06-07 07:52:33 +02:00
|
|
|
final int bufSize;
|
|
|
|
final ChannelHandlerContext ctx = directOutboundContext();
|
|
|
|
if (ctx.hasOutboundByteBuffer()) {
|
|
|
|
bufSize = ctx.outboundByteBuffer().readableBytes();
|
|
|
|
} else {
|
|
|
|
bufSize = ctx.outboundMessageBuffer().size();
|
|
|
|
}
|
|
|
|
|
|
|
|
long checkpoint = writeCounter + bufSize;
|
2012-05-25 15:16:25 +02:00
|
|
|
if (future instanceof FlushCheckpoint) {
|
|
|
|
FlushCheckpoint cp = (FlushCheckpoint) future;
|
|
|
|
cp.flushCheckpoint(checkpoint);
|
|
|
|
flushCheckpoints.add(cp);
|
2012-05-12 17:40:28 +02:00
|
|
|
} else {
|
2012-05-25 15:16:25 +02:00
|
|
|
flushCheckpoints.add(new DefaultFlushCheckpoint(checkpoint, future));
|
2012-05-12 17:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-02 03:34:19 +02:00
|
|
|
if (!inFlushNow) { // Avoid re-entrance
|
2012-05-28 14:05:49 +02:00
|
|
|
try {
|
2012-06-02 03:34:19 +02:00
|
|
|
if (!isFlushPending()) {
|
2012-05-28 14:05:49 +02:00
|
|
|
flushNow();
|
2012-06-02 03:34:19 +02:00
|
|
|
} else {
|
|
|
|
// Event loop will call flushNow() later by itself.
|
2012-05-28 14:05:49 +02:00
|
|
|
}
|
|
|
|
} catch (Throwable t) {
|
|
|
|
notifyFlushFutures(t);
|
2012-06-03 13:25:03 +02:00
|
|
|
pipeline.fireExceptionCaught(t);
|
2012-05-28 14:05:49 +02:00
|
|
|
if (t instanceof IOException) {
|
|
|
|
close(voidFuture());
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
if (!isActive()) {
|
|
|
|
close(unsafe().voidFuture());
|
|
|
|
}
|
2012-05-27 07:48:48 +02:00
|
|
|
}
|
2012-05-28 14:05:49 +02:00
|
|
|
} else {
|
|
|
|
if (!flushNowPending) {
|
|
|
|
flushNowPending = true;
|
|
|
|
eventLoop().execute(flushLaterTask);
|
2012-05-27 07:48:48 +02:00
|
|
|
}
|
2012-05-09 15:09:06 +02:00
|
|
|
}
|
2012-05-01 10:19:41 +02:00
|
|
|
} else {
|
|
|
|
eventLoop().execute(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2012-05-12 17:40:28 +02:00
|
|
|
flush(future);
|
2012-05-01 10:19:41 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2010-01-09 06:40:40 +01:00
|
|
|
}
|
2012-05-09 15:09:06 +02:00
|
|
|
|
2012-05-27 14:07:23 +02:00
|
|
|
@Override
|
2012-05-30 12:58:14 +02:00
|
|
|
public final void flushNow() {
|
2012-05-28 14:05:49 +02:00
|
|
|
if (inFlushNow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
inFlushNow = true;
|
2012-06-07 07:52:33 +02:00
|
|
|
ChannelHandlerContext ctx = directOutboundContext();
|
|
|
|
Throwable cause = null;
|
2012-05-12 22:09:05 +02:00
|
|
|
try {
|
2012-06-07 07:52:33 +02:00
|
|
|
if (ctx.hasOutboundByteBuffer()) {
|
2012-06-10 04:08:43 +02:00
|
|
|
ByteBuf out = ctx.outboundByteBuffer();
|
2012-06-07 07:52:33 +02:00
|
|
|
int oldSize = out.readableBytes();
|
|
|
|
try {
|
|
|
|
doFlushByteBuffer(out);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
cause = t;
|
|
|
|
} finally {
|
|
|
|
final int newSize = out.readableBytes();
|
|
|
|
writeCounter += oldSize - newSize;
|
|
|
|
if (newSize == 0) {
|
|
|
|
out.discardReadBytes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Queue<Object> out = ctx.outboundMessageBuffer();
|
|
|
|
int oldSize = out.size();
|
|
|
|
try {
|
|
|
|
doFlushMessageBuffer(out);
|
|
|
|
} catch (Throwable t) {
|
|
|
|
cause = t;
|
|
|
|
} finally {
|
|
|
|
writeCounter += oldSize - out.size();
|
2012-06-01 01:59:54 +02:00
|
|
|
}
|
2012-05-27 07:48:48 +02:00
|
|
|
}
|
2012-05-28 14:05:49 +02:00
|
|
|
|
|
|
|
if (cause == null) {
|
|
|
|
notifyFlushFutures();
|
|
|
|
} else {
|
|
|
|
notifyFlushFutures(cause);
|
2012-06-03 13:25:03 +02:00
|
|
|
pipeline.fireExceptionCaught(cause);
|
2012-05-28 14:05:49 +02:00
|
|
|
if (cause instanceof IOException) {
|
|
|
|
close(voidFuture());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
inFlushNow = false;
|
2012-05-12 22:09:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:58:14 +02:00
|
|
|
protected final boolean ensureOpen(ChannelFuture future) {
|
2012-05-27 07:48:48 +02:00
|
|
|
if (isOpen()) {
|
|
|
|
return true;
|
2012-05-26 00:32:28 +02:00
|
|
|
}
|
|
|
|
|
2012-05-27 07:48:48 +02:00
|
|
|
Exception e = new ClosedChannelException();
|
|
|
|
future.setFailure(e);
|
2012-06-03 13:25:03 +02:00
|
|
|
pipeline.fireExceptionCaught(e);
|
2012-05-27 07:48:48 +02:00
|
|
|
return false;
|
2012-05-24 17:57:10 +02:00
|
|
|
}
|
|
|
|
|
2012-05-30 12:58:14 +02:00
|
|
|
protected final void closeIfClosed() {
|
2012-05-27 07:48:48 +02:00
|
|
|
if (isOpen()) {
|
|
|
|
return;
|
2012-05-24 17:57:10 +02:00
|
|
|
}
|
2012-05-27 07:48:48 +02:00
|
|
|
close(voidFuture());
|
2012-05-24 17:57:10 +02:00
|
|
|
}
|
2012-05-27 07:48:48 +02:00
|
|
|
}
|
2012-05-24 17:57:10 +02:00
|
|
|
|
2012-05-28 14:05:49 +02:00
|
|
|
private class FlushLater implements Runnable {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
flushNowPending = false;
|
|
|
|
unsafe().flush(voidFuture);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-27 07:48:48 +02:00
|
|
|
protected abstract boolean isCompatible(EventLoop loop);
|
2012-05-12 17:40:28 +02:00
|
|
|
|
2012-05-27 07:48:48 +02:00
|
|
|
protected abstract SocketAddress localAddress0();
|
|
|
|
protected abstract SocketAddress remoteAddress0();
|
2012-05-12 17:40:28 +02:00
|
|
|
|
2012-06-03 21:54:26 +02:00
|
|
|
protected abstract Runnable doRegister() throws Exception;
|
2012-05-27 07:48:48 +02:00
|
|
|
protected abstract void doBind(SocketAddress localAddress) throws Exception;
|
|
|
|
protected abstract void doDisconnect() throws Exception;
|
|
|
|
protected abstract void doClose() throws Exception;
|
|
|
|
protected abstract void doDeregister() throws Exception;
|
2012-06-10 04:08:43 +02:00
|
|
|
protected void doFlushByteBuffer(ByteBuf buf) throws Exception {
|
2012-06-07 07:52:33 +02:00
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
protected void doFlushMessageBuffer(Queue<Object> buf) throws Exception {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
2012-05-27 07:48:48 +02:00
|
|
|
|
|
|
|
protected abstract boolean isFlushPending();
|
|
|
|
|
2012-05-28 14:05:49 +02:00
|
|
|
private void notifyFlushFutures() {
|
2012-05-27 07:48:48 +02:00
|
|
|
if (flushCheckpoints.isEmpty()) {
|
|
|
|
return;
|
2012-05-12 17:40:28 +02:00
|
|
|
}
|
|
|
|
|
2012-05-28 14:05:49 +02:00
|
|
|
final long writeCounter = AbstractChannel.this.writeCounter;
|
2012-05-27 07:48:48 +02:00
|
|
|
for (;;) {
|
2012-05-28 14:05:49 +02:00
|
|
|
FlushCheckpoint cp = flushCheckpoints.peek();
|
2012-05-27 07:48:48 +02:00
|
|
|
if (cp == null) {
|
2012-05-28 14:05:49 +02:00
|
|
|
// Reset the counter if there's nothing in the notification list.
|
|
|
|
AbstractChannel.this.writeCounter = 0;
|
2012-05-27 07:48:48 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-05-28 14:05:49 +02:00
|
|
|
|
|
|
|
if (cp.flushCheckpoint() > writeCounter) {
|
|
|
|
if (writeCounter > 0 && flushCheckpoints.size() == 1) {
|
|
|
|
AbstractChannel.this.writeCounter = 0;
|
|
|
|
cp.flushCheckpoint(cp.flushCheckpoint() - writeCounter);
|
|
|
|
}
|
2012-05-27 07:48:48 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-05-28 14:05:49 +02:00
|
|
|
|
|
|
|
flushCheckpoints.remove();
|
2012-05-27 07:48:48 +02:00
|
|
|
cp.future().setSuccess();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Avoid overflow
|
2012-05-28 14:05:49 +02:00
|
|
|
final long newWriteCounter = AbstractChannel.this.writeCounter;
|
|
|
|
if (newWriteCounter >= 0x1000000000000000L) {
|
|
|
|
// Reset the counter only when the counter grew pretty large
|
2012-05-27 07:48:48 +02:00
|
|
|
// so that we can reduce the cost of updating all entries in the notification list.
|
|
|
|
AbstractChannel.this.writeCounter = 0;
|
|
|
|
for (FlushCheckpoint cp: flushCheckpoints) {
|
2012-05-28 14:05:49 +02:00
|
|
|
cp.flushCheckpoint(cp.flushCheckpoint() - newWriteCounter);
|
2012-05-09 15:09:06 +02:00
|
|
|
}
|
|
|
|
}
|
2012-05-27 07:48:48 +02:00
|
|
|
}
|
2012-05-09 15:09:06 +02:00
|
|
|
|
2012-05-28 14:05:49 +02:00
|
|
|
private void notifyFlushFutures(Throwable cause) {
|
|
|
|
notifyFlushFutures();
|
2012-05-27 07:48:48 +02:00
|
|
|
for (;;) {
|
|
|
|
FlushCheckpoint cp = flushCheckpoints.poll();
|
|
|
|
if (cp == null) {
|
|
|
|
break;
|
2012-05-09 15:09:06 +02:00
|
|
|
}
|
2012-05-27 07:48:48 +02:00
|
|
|
cp.future().setFailure(cause);
|
2012-05-09 15:09:06 +02:00
|
|
|
}
|
2010-01-09 06:40:40 +01:00
|
|
|
}
|
2012-05-01 10:19:41 +02:00
|
|
|
|
2012-06-04 22:43:02 +02:00
|
|
|
abstract static class FlushCheckpoint {
|
2012-05-25 15:16:25 +02:00
|
|
|
abstract long flushCheckpoint();
|
|
|
|
abstract void flushCheckpoint(long checkpoint);
|
|
|
|
abstract ChannelFuture future();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static class DefaultFlushCheckpoint extends FlushCheckpoint {
|
|
|
|
private long checkpoint;
|
2012-05-12 17:40:28 +02:00
|
|
|
private final ChannelFuture future;
|
|
|
|
|
2012-05-25 15:16:25 +02:00
|
|
|
DefaultFlushCheckpoint(long checkpoint, ChannelFuture future) {
|
|
|
|
this.checkpoint = checkpoint;
|
2012-05-12 17:40:28 +02:00
|
|
|
this.future = future;
|
2012-05-25 15:16:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
long flushCheckpoint() {
|
|
|
|
return checkpoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
void flushCheckpoint(long checkpoint) {
|
|
|
|
this.checkpoint = checkpoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
ChannelFuture future() {
|
|
|
|
return future;
|
2012-05-12 17:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-12 18:37:16 +02:00
|
|
|
private static final class CloseFuture extends DefaultChannelFuture implements ChannelFuture.Unsafe {
|
|
|
|
|
|
|
|
CloseFuture(AbstractChannel ch) {
|
|
|
|
super(ch, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean setSuccess() {
|
|
|
|
throw new IllegalStateException();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean setFailure(Throwable cause) {
|
|
|
|
throw new IllegalStateException();
|
|
|
|
}
|
|
|
|
|
2012-05-14 07:17:40 +02:00
|
|
|
boolean setClosed() {
|
2012-06-11 04:39:44 +02:00
|
|
|
return super.setSuccess();
|
2012-05-12 18:37:16 +02:00
|
|
|
}
|
|
|
|
}
|
2008-08-08 02:37:18 +02:00
|
|
|
}
|