* Made sure ServerBootstrap accepts only ServerChannelFactory

* Validation first, state check later
This commit is contained in:
Trustin Lee 2009-02-21 19:32:32 +00:00
parent f6ee08090a
commit 547af08bc6
2 changed files with 18 additions and 3 deletions

View File

@ -100,13 +100,13 @@ public class Bootstrap {
* if the factory is already set
*/
public void setFactory(ChannelFactory factory) {
if (factory == null) {
throw new NullPointerException("factory");
}
if (this.factory != null) {
throw new IllegalStateException(
"factory can't change once set.");
}
if (factory == null) {
throw new NullPointerException("factory");
}
this.factory = factory;
}

View File

@ -46,6 +46,7 @@ import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.ChildChannelStateEvent;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.ServerChannelFactory;
import org.jboss.netty.channel.SimpleChannelHandler;
/**
@ -166,6 +167,20 @@ public class ServerBootstrap extends Bootstrap {
super(channelFactory);
}
@Override
public void setFactory(ChannelFactory factory) {
if (factory == null) {
throw new NullPointerException("factory");
}
if (!(factory instanceof ServerChannelFactory)) {
throw new IllegalArgumentException(
"factory must be a " +
ServerChannelFactory.class.getSimpleName() + ": " +
factory.getClass());
}
super.setFactory(factory);
}
/**
* Returns an optional {@link ChannelHandler} which intercepts an event
* of a new bound server-side channel which accepts incoming connections.