* Made sure ServerBootstrap accepts only ServerChannelFactory
* Validation first, state check later
This commit is contained in:
parent
f6ee08090a
commit
547af08bc6
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user