Don't attempt to inject closed channels. Fixes issue #23

This commit is contained in:
Kristian S. Stangeland 2013-12-08 19:50:59 +01:00
parent 20524c1c3c
commit 1aaf272878

View File

@ -182,13 +182,18 @@ class ChannelInjector extends ByteToMessageDecoder {
/**
* Inject the current channel.
* <p>
* Note that only active channels can be injected.
* @return TRUE if we injected the channel, false if we could not inject or it was already injected.
*/
@SuppressWarnings("unchecked")
public boolean inject() {
synchronized (networkManager) {
if (originalChannel instanceof Factory)
return false;
if (!originalChannel.isActive())
return false;
// Don't inject the same channel twice
if (findChannelHandler(originalChannel, ChannelInjector.class) != null) {
// Invalidate cache
@ -202,9 +207,9 @@ class ChannelInjector extends ByteToMessageDecoder {
vanillaEncoder = (MessageToByteEncoder<Object>) originalChannel.pipeline().get("encoder");
if (vanillaDecoder == null)
throw new IllegalArgumentException("Unable to find vanilla decoder.in " + originalChannel.pipeline() + ". " + getChannelState());
throw new IllegalArgumentException("Unable to find vanilla decoder.in " + originalChannel.pipeline() );
if (vanillaEncoder == null)
throw new IllegalArgumentException("Unable to find vanilla encoder in " + originalChannel.pipeline() + ". " + getChannelState());
throw new IllegalArgumentException("Unable to find vanilla encoder in " + originalChannel.pipeline() );
patchEncoder(vanillaEncoder);
if (DECODE_BUFFER == null)
@ -245,10 +250,6 @@ class ChannelInjector extends ByteToMessageDecoder {
}
}
private String getChannelState() {
return "Registered channel: " + originalChannel.isRegistered() + ", Active channel: " + originalChannel.isActive() + ", Open channel: " + originalChannel.isOpen();
}
/**
* Process a given message on the packet listeners.
* @param message - the message/packet.