Skip to content

Commit

Permalink
Remove support from deregister a Channel from a EventLoop manually
Browse files Browse the repository at this point in the history
  • Loading branch information
bgallagher authored and Norman Maurer committed Aug 29, 2013
1 parent 2ffdd92 commit c149f4b
Show file tree
Hide file tree
Showing 26 changed files with 188 additions and 363 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public class HttpUploadServerHandler extends SimpleChannelInboundHandler<HttpObj
}

@Override
public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
if (decoder != null) {
decoder.cleanFiles();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,9 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc
}

@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
public void channelInactive(final ChannelHandlerContext ctx) throws Exception {
println("Disconnected from: " + ctx.channel().remoteAddress());
}

@Override
public void channelUnregistered(final ChannelHandlerContext ctx)
throws Exception {
println("Sleeping for: " + UptimeClient.RECONNECT_DELAY + 's');

final EventLoop loop = ctx.channel().eventLoop();
Expand Down
18 changes: 0 additions & 18 deletions handler/src/main/java/io/netty/handler/logging/LoggingHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,6 @@ public void channelRegistered(ChannelHandlerContext ctx)
super.channelRegistered(ctx);
}

@Override
public void channelUnregistered(ChannelHandlerContext ctx)
throws Exception {
if (logger.isEnabled(internalLevel)) {
logger.log(internalLevel, format(ctx, "UNREGISTERED"));
}
super.channelUnregistered(ctx);
}

@Override
public void channelActive(ChannelHandlerContext ctx)
throws Exception {
Expand Down Expand Up @@ -282,15 +273,6 @@ public void close(ChannelHandlerContext ctx,
super.close(ctx, promise);
}

@Override
public void deregister(ChannelHandlerContext ctx,
ChannelPromise promise) throws Exception {
if (logger.isEnabled(internalLevel)) {
logger.log(internalLevel, format(ctx, "DEREGISTER()"));
}
super.deregister(ctx, promise);
}

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
logMessage(ctx, "RECEIVED", msg);
Expand Down
7 changes: 2 additions & 5 deletions handler/src/main/java/io/netty/handler/ssl/SslHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import javax.net.ssl.SSLEngineResult;
import javax.net.ssl.SSLEngineResult.Status;
import javax.net.ssl.SSLException;

import java.io.IOException;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
Expand All @@ -58,6 +59,7 @@
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;


/**
* Adds <a href="http://en.wikipedia.org/wiki/Transport_Layer_Security">SSL
* &middot; TLS</a> and StartTLS support to a {@link Channel}. Please refer
Expand Down Expand Up @@ -370,11 +372,6 @@ public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, Sock
ctx.connect(remoteAddress, localAddress, promise);
}

@Override
public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
ctx.deregister(promise);
}

@Override
public void disconnect(final ChannelHandlerContext ctx,
final ChannelPromise promise) throws Exception {
Expand Down
45 changes: 12 additions & 33 deletions transport/src/main/java/io/netty/channel/AbstractChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.net.SocketAddress;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.NotYetConnectedException;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

/**
* A skeletal {@link Channel} implementation.
Expand Down Expand Up @@ -66,6 +67,9 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
private boolean strValActive;
private String strVal;

private static final AtomicReferenceFieldUpdater<AbstractChannel, EventLoop> EVENT_LOOP_UPDATER =
AtomicReferenceFieldUpdater.newUpdater(AbstractChannel.class, EventLoop.class, "eventLoop");

/**
* Creates a new instance.
*
Expand Down Expand Up @@ -177,11 +181,6 @@ public ChannelFuture close() {
return pipeline.close();
}

@Override
public ChannelFuture deregister() {
return pipeline.deregister();
}

@Override
public Channel flush() {
pipeline.flush();
Expand Down Expand Up @@ -213,11 +212,6 @@ public ChannelFuture close(ChannelPromise promise) {
return pipeline.close(promise);
}

@Override
public ChannelFuture deregister(ChannelPromise promise) {
return pipeline.deregister(promise);
}

@Override
public Channel read() {
pipeline.read();
Expand Down Expand Up @@ -395,17 +389,16 @@ public final void register(EventLoop eventLoop, final ChannelPromise promise) {
if (eventLoop == null) {
throw new NullPointerException("eventLoop");
}
if (isRegistered()) {
promise.setFailure(new IllegalStateException("registered to an event loop already"));
return;
}

if (!isCompatible(eventLoop)) {
promise.setFailure(
new IllegalStateException("incompatible event loop type: " + eventLoop.getClass().getName()));
promise.setFailure(new IllegalStateException("incompatible event loop type: " +
eventLoop.getClass().getName()));
return;
}

AbstractChannel.this.eventLoop = eventLoop;
if (!AbstractChannel.EVENT_LOOP_UPDATER.compareAndSet(AbstractChannel.this, null, eventLoop)) {
return;
}

if (eventLoop.inEventLoop()) {
register0(promise);
Expand Down Expand Up @@ -560,7 +553,7 @@ public void run() {
});
}

deregister(voidPromise());
deregister();
}
}

Expand All @@ -573,10 +566,8 @@ public final void closeForcibly() {
}
}

@Override
public final void deregister(final ChannelPromise promise) {
private void deregister() {
if (!registered) {
promise.setSuccess();
return;
}

Expand All @@ -587,18 +578,6 @@ public final void deregister(final ChannelPromise promise) {
} finally {
if (registered) {
registered = false;
promise.setSuccess();
invokeLater(new Runnable() {
@Override
public void run() {
pipeline.fireChannelUnregistered();
}
});
} 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.
promise.setSuccess();
}
}
}
Expand Down
7 changes: 0 additions & 7 deletions transport/src/main/java/io/netty/channel/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,6 @@ interface Unsafe {
*/
void closeForcibly();

/**
* Deregister the {@link Channel} of the {@link ChannelPromise} from {@link EventLoop} and notify the
* {@link ChannelPromise} once the operation was complete.
*/
@Deprecated
void deregister(ChannelPromise promise);

/**
* Schedules a read operation that fills the inbound buffer of the first {@link ChannelInboundHandler} in the
* {@link ChannelPipeline}. If there's already a pending read operation, this method does nothing.
Expand Down
11 changes: 0 additions & 11 deletions transport/src/main/java/io/netty/channel/ChannelDuplexHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,6 @@ public void close(ChannelHandlerContext ctx, ChannelPromise future) throws Excep
ctx.close(future);
}

/**
* Calls {@link ChannelHandlerContext#close(ChannelPromise)} to forward
* to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override
public void deregister(ChannelHandlerContext ctx, ChannelPromise future) throws Exception {
ctx.deregister(future);
}

/**
* Calls {@link ChannelHandlerContext#read()} to forward
* to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,6 @@ public interface ChannelHandlerContext
@Override
ChannelHandlerContext fireChannelRegistered();

@Override
@Deprecated
ChannelHandlerContext fireChannelUnregistered();

@Override
ChannelHandlerContext fireChannelActive();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package io.netty.channel;

/**
* {@link ChannelHandler} which adds callbacks for state changes. This allows the user
* to hook in to state changes easily.
* {@link ChannelHandler} which adds callbacks for state changes. This allows the user to hook in to state changes
* easily.
*/
public interface ChannelInboundHandler extends ChannelHandler {

Expand All @@ -26,14 +26,6 @@ public interface ChannelInboundHandler extends ChannelHandler {
*/
void channelRegistered(ChannelHandlerContext ctx) throws Exception;

/**
* The {@link Channel} of the {@link ChannelHandlerContext} was unregistered from its {@link EventLoop}
*
* @deprecated use {@link #channelInactive(ChannelHandlerContext)}
*/
@Deprecated
void channelUnregistered(ChannelHandlerContext ctx) throws Exception;

/**
* The {@link Channel} of the {@link ChannelHandlerContext} is now active
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package io.netty.channel;

/**
* Abstract base class for {@link ChannelInboundHandler} implementations which provide
* Abstract base class for {@link ChannelInboundHandler} implementations that provides
* implementations of all of their methods.
*
* <p>
Expand All @@ -42,17 +42,6 @@ public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelRegistered();
}

/**
* Calls {@link ChannelHandlerContext#fireChannelUnregistered()} to forward
* to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override
public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelUnregistered();
}

/**
* Calls {@link ChannelHandlerContext#fireChannelActive()} to forward
* to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ interface ChannelInboundInvoker {
*/
ChannelInboundInvoker fireChannelRegistered();

/**
* A {@link Channel} was unregistered from its {@link EventLoop}.
*
* This will result in having the {@link ChannelInboundHandler#channelUnregistered(ChannelHandlerContext)} method
* called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the
* {@link Channel}.
*/
@Deprecated
ChannelInboundInvoker fireChannelUnregistered();

/**
* A {@link Channel} is active now, which means it is connected.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,6 @@ void connect(
*/
void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception;

/**
* Called once a deregister operation is made from the current registered {@link EventLoop}.
*
* @param ctx the {@link ChannelHandlerContext} for which the close operation is made
* @param promise the {@link ChannelPromise} to notify once the operation completes
* @throws Exception thrown if an error accour
*/
void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception;

/**
* Intercepts {@link ChannelHandlerContext#read()}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,6 @@ public void close(ChannelHandlerContext ctx, ChannelPromise promise)
ctx.close(promise);
}

/**
* Calls {@link ChannelHandlerContext#close(ChannelPromise)} to forward
* to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override
public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
ctx.deregister(promise);
}

/**
* Calls {@link ChannelHandlerContext#read()} to forward
* to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package io.netty.channel;

import io.netty.util.concurrent.EventExecutor;

import java.net.ConnectException;
import java.net.SocketAddress;

Expand Down Expand Up @@ -88,20 +86,6 @@ interface ChannelOutboundInvoker {
*/
ChannelFuture close();

/**
* Request to deregister this ChannelOutboundInvoker from the previous assigned {@link EventExecutor} and notify the
* {@link ChannelFuture} once the operation completes, either because the operation was successful or because of
* an error.
* <p>
* This will result in having the
* {@link ChannelOutboundHandler#deregister(ChannelHandlerContext, ChannelPromise)}
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
* {@link Channel}.
*
*/
@Deprecated
ChannelFuture deregister();

/**
* Request to bind to the given {@link SocketAddress} and notify the {@link ChannelFuture} once the operation
* completes, either because the operation was successful or because of an error.
Expand Down Expand Up @@ -175,21 +159,6 @@ interface ChannelOutboundInvoker {
*/
ChannelFuture close(ChannelPromise promise);

/**
* Request to deregister this ChannelOutboundInvoker from the previous assigned {@link EventExecutor} and notify the
* {@link ChannelFuture} once the operation completes, either because the operation was successful or because of
* an error.
*
* The given {@link ChannelPromise} will be notified.
* <p>
* This will result in having the
* {@link ChannelOutboundHandler#deregister(ChannelHandlerContext, ChannelPromise)}
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the
* {@link Channel}.
*/
@Deprecated
ChannelFuture deregister(ChannelPromise promise);

/**
* Request to Read data from the {@link Channel} into the first inbound buffer, triggers an
* {@link ChannelInboundHandler#channelRead(ChannelHandlerContext, Object)} event if data was
Expand Down
Loading

0 comments on commit c149f4b

Please sign in to comment.