Put simplistic channel lifecycle handler method to TrafficMonitor

This commit is contained in:
Trustin Lee 2009-02-05 03:46:13 +00:00
parent 2625d10e58
commit 29d227e69e
3 changed files with 24 additions and 0 deletions

View File

@ -94,6 +94,20 @@ public abstract class AbstractChannelFactory implements ChannelFactory {
}
}
void notifyState(Channel channel) {
TrafficMonitor[] trafficMonitors = this.trafficMonitors;
for (TrafficMonitor m: trafficMonitors) {
try {
m.onState(channel);
} catch (Exception e) {
logger.warn(
"An exception was thrown by " +
TrafficMonitor.class.getSimpleName() +
".onState().", e);
}
}
}
void notifyInflow(Channel channel, int amount) {
TrafficMonitor[] trafficMonitors = this.trafficMonitors;
for (TrafficMonitor m: trafficMonitors) {

View File

@ -186,6 +186,7 @@ public class Channels {
if (channel.getParent() != null) {
fireChildChannelStateChanged(channel.getParent(), channel);
}
notifyState(channel);
channel.getPipeline().sendUpstream(
new DefaultChannelStateEvent(
channel, succeededFuture(channel),
@ -547,6 +548,7 @@ public class Channels {
new DefaultChannelStateEvent(
channel, succeededFuture(channel),
ChannelState.OPEN, Boolean.FALSE));
notifyState(channel);
if (channel.getParent() != null) {
fireChildChannelStateChanged(channel.getParent(), channel);
}
@ -1062,6 +1064,13 @@ public class Channels {
close(ctx, future);
}
private static void notifyState(Channel channel) {
ChannelFactory factory = channel.getFactory();
if (factory instanceof AbstractChannelFactory) {
((AbstractChannelFactory) factory).notifyState(channel);
}
}
public static void notifyInflow(Channel channel, int amount) {
if (amount <= 0) {
return;

View File

@ -28,6 +28,7 @@ package org.jboss.netty.channel;
* @version $Rev$, $Date$
*/
public interface TrafficMonitor {
void onState(Channel channel) throws Exception;
void onInflow(Channel channel, int amount) throws Exception;
void onOutflow(Channel channel, int amount) throws Exception;
}