Class Bootstrap
- java.lang.Object
-
- org.jboss.netty.bootstrap.Bootstrap
-
- All Implemented Interfaces:
ExternalResourceReleasable
- Direct Known Subclasses:
ClientBootstrap,ConnectionlessBootstrap,ServerBootstrap
public class Bootstrap extends java.lang.Object implements ExternalResourceReleasable
A helper class which initializes aChannel. This class provides the common data structure for its subclasses which actually initializeChannels and their childChannels using the common data structure. Please refer toClientBootstrap,ServerBootstrap, andConnectionlessBootstrapfor client side, server-side, and connectionless (e.g. UDP) channel initialization respectively.
-
-
Field Summary
Fields Modifier and Type Field Description private ChannelFactoryfactoryprivate java.util.Map<java.lang.String,java.lang.Object>optionsprivate static short[]ORDER_TEST_SAMPLESprivate ChannelPipelinepipelineprivate ChannelPipelineFactorypipelineFactory
-
Constructor Summary
Constructors Modifier Constructor Description protectedBootstrap()Creates a new instance with noChannelFactoryset.protectedBootstrap(ChannelFactory channelFactory)Creates a new instance with the specified initialChannelFactory.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ChannelFactorygetFactory()Returns theChannelFactorythat will be used to perform an I/O operation.java.lang.ObjectgetOption(java.lang.String key)Returns the value of the option with the specified key.java.util.Map<java.lang.String,java.lang.Object>getOptions()ChannelPipelinegetPipeline()Returns the defaultChannelPipelinewhich is cloned when a newChannelis created.java.util.Map<java.lang.String,ChannelHandler>getPipelineAsMap()Dependency injection friendly convenience method forgetPipeline()which returns the default pipeline of this bootstrap as an ordered map.ChannelPipelineFactorygetPipelineFactory()(package private) static booleanisOrderedMap(java.util.Map<?,?> map)Returnstrueif and only if the specifiedmapis an ordered map, likeLinkedHashMapis.voidreleaseExternalResources()This method simply delegates the call toChannelFactory.releaseExternalResources().voidsetFactory(ChannelFactory factory)Sets theChannelFactorythat will be used to perform an I/O operation.voidsetOption(java.lang.String key, java.lang.Object value)Sets an option with the specified key and value.voidsetOptions(java.util.Map<java.lang.String,java.lang.Object> options)voidsetPipeline(ChannelPipeline pipeline)Sets the defaultChannelPipelinewhich is cloned when a newChannelis created.voidsetPipelineAsMap(java.util.Map<java.lang.String,ChannelHandler> pipelineMap)Dependency injection friendly convenience method forsetPipeline(ChannelPipeline)which sets the default pipeline of this bootstrap from an ordered map.voidsetPipelineFactory(ChannelPipelineFactory pipelineFactory)voidshutdown()This method simply delegates the call toChannelFactory.shutdown().
-
-
-
Field Detail
-
factory
private volatile ChannelFactory factory
-
pipeline
private volatile ChannelPipeline pipeline
-
pipelineFactory
private volatile ChannelPipelineFactory pipelineFactory
-
options
private volatile java.util.Map<java.lang.String,java.lang.Object> options
-
ORDER_TEST_SAMPLES
private static final short[] ORDER_TEST_SAMPLES
-
-
Constructor Detail
-
Bootstrap
protected Bootstrap()
Creates a new instance with noChannelFactoryset.setFactory(ChannelFactory)must be called at once before any I/O operation is requested.
-
Bootstrap
protected Bootstrap(ChannelFactory channelFactory)
Creates a new instance with the specified initialChannelFactory.
-
-
Method Detail
-
getFactory
public ChannelFactory getFactory()
Returns theChannelFactorythat will be used to perform an I/O operation.- Throws:
java.lang.IllegalStateException- if the factory is not set for this bootstrap yet. The factory can be set in the constructor orsetFactory(ChannelFactory).
-
setFactory
public void setFactory(ChannelFactory factory)
Sets theChannelFactorythat will be used to perform an I/O operation. This method can be called only once and can't be called at all if the factory was specified in the constructor.- Throws:
java.lang.IllegalStateException- if the factory is already set
-
getPipeline
public ChannelPipeline getPipeline()
Returns the defaultChannelPipelinewhich is cloned when a newChannelis created.Bootstrapcreates a new pipeline which has the same entries with the returned pipeline for a newChannel.Please note that this method is a convenience method that works only when 1) you create only one channel from this bootstrap (e.g. one-time client-side or connectionless channel) or 2) all handlers in the pipeline is stateless. You have to use
setPipelineFactory(ChannelPipelineFactory)if 1) your pipeline contains a statefulChannelHandlerand 2) one or more channels are going to be created by this bootstrap (e.g. server-side channels).- Returns:
- the default
ChannelPipeline - Throws:
java.lang.IllegalStateException- ifsetPipelineFactory(ChannelPipelineFactory)was called by a user last time.
-
setPipeline
public void setPipeline(ChannelPipeline pipeline)
Sets the defaultChannelPipelinewhich is cloned when a newChannelis created.Bootstrapcreates a new pipeline which has the same entries with the specified pipeline for a new channel.Calling this method also sets the
pipelineFactoryproperty to an internalChannelPipelineFactoryimplementation which returns a shallow copy of the specified pipeline.Please note that this method is a convenience method that works only when 1) you create only one channel from this bootstrap (e.g. one-time client-side or connectionless channel) or 2) all handlers in the pipeline is stateless. You have to use
setPipelineFactory(ChannelPipelineFactory)if 1) your pipeline contains a statefulChannelHandlerand 2) one or more channels are going to be created by this bootstrap (e.g. server-side channels).
-
getPipelineAsMap
public java.util.Map<java.lang.String,ChannelHandler> getPipelineAsMap()
Dependency injection friendly convenience method forgetPipeline()which returns the default pipeline of this bootstrap as an ordered map.Please note that this method is a convenience method that works only when 1) you create only one channel from this bootstrap (e.g. one-time client-side or connectionless channel) or 2) all handlers in the pipeline is stateless. You have to use
setPipelineFactory(ChannelPipelineFactory)if 1) your pipeline contains a statefulChannelHandlerand 2) one or more channels are going to be created by this bootstrap (e.g. server-side channels).- Throws:
java.lang.IllegalStateException- ifsetPipelineFactory(ChannelPipelineFactory)was called by a user last time.
-
setPipelineAsMap
public void setPipelineAsMap(java.util.Map<java.lang.String,ChannelHandler> pipelineMap)
Dependency injection friendly convenience method forsetPipeline(ChannelPipeline)which sets the default pipeline of this bootstrap from an ordered map.Please note that this method is a convenience method that works only when 1) you create only one channel from this bootstrap (e.g. one-time client-side or connectionless channel) or 2) all handlers in the pipeline is stateless. You have to use
setPipelineFactory(ChannelPipelineFactory)if 1) your pipeline contains a statefulChannelHandlerand 2) one or more channels are going to be created by this bootstrap (e.g. server-side channels).- Throws:
java.lang.IllegalArgumentException- if the specified map is not an ordered map
-
getPipelineFactory
public ChannelPipelineFactory getPipelineFactory()
- See Also:
getPipeline()
-
setPipelineFactory
public void setPipelineFactory(ChannelPipelineFactory pipelineFactory)
Sets theChannelPipelineFactorywhich creates a newChannelPipelinefor each newChannel. Calling this method invalidates the currentpipelineproperty of this bootstrap. SubsequentgetPipeline()andgetPipelineAsMap()calls will raiseIllegalStateException.
-
getOptions
public java.util.Map<java.lang.String,java.lang.Object> getOptions()
-
setOptions
public void setOptions(java.util.Map<java.lang.String,java.lang.Object> options)
-
getOption
public java.lang.Object getOption(java.lang.String key)
Returns the value of the option with the specified key. To retrieve the option value of a childChannel, prepend"child."to the option name (e.g."child.keepAlive").- Parameters:
key- the option name- Returns:
- the option value if the option is found.
nullotherwise.
-
setOption
public void setOption(java.lang.String key, java.lang.Object value)Sets an option with the specified key and value. If there's already an option with the same key, it is replaced with the new value. If the specified value isnull, an existing option with the specified key is removed. To set the option value of a childChannel, prepend"child."to the option name (e.g."child.keepAlive").- Parameters:
key- the option namevalue- the option value
-
releaseExternalResources
public void releaseExternalResources()
This method simply delegates the call toChannelFactory.releaseExternalResources().- Specified by:
releaseExternalResourcesin interfaceExternalResourceReleasable
-
shutdown
public void shutdown()
This method simply delegates the call toChannelFactory.shutdown().
-
isOrderedMap
static boolean isOrderedMap(java.util.Map<?,?> map)
Returnstrueif and only if the specifiedmapis an ordered map, likeLinkedHashMapis.
-
-