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 initializeChannel
s and their childChannel
s using the common data structure. Please refer toClientBootstrap
,ServerBootstrap
, andConnectionlessBootstrap
for client side, server-side, and connectionless (e.g. UDP) channel initialization respectively.
-
-
Field Summary
Fields Modifier and Type Field Description private ChannelFactory
factory
private java.util.Map<java.lang.String,java.lang.Object>
options
private static short[]
ORDER_TEST_SAMPLES
private ChannelPipeline
pipeline
private ChannelPipelineFactory
pipelineFactory
-
Constructor Summary
Constructors Modifier Constructor Description protected
Bootstrap()
Creates a new instance with noChannelFactory
set.protected
Bootstrap(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 ChannelFactory
getFactory()
Returns theChannelFactory
that will be used to perform an I/O operation.java.lang.Object
getOption(java.lang.String key)
Returns the value of the option with the specified key.java.util.Map<java.lang.String,java.lang.Object>
getOptions()
ChannelPipeline
getPipeline()
Returns the defaultChannelPipeline
which is cloned when a newChannel
is 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.ChannelPipelineFactory
getPipelineFactory()
(package private) static boolean
isOrderedMap(java.util.Map<?,?> map)
Returnstrue
if and only if the specifiedmap
is an ordered map, likeLinkedHashMap
is.void
releaseExternalResources()
This method simply delegates the call toChannelFactory.releaseExternalResources()
.void
setFactory(ChannelFactory factory)
Sets theChannelFactory
that will be used to perform an I/O operation.void
setOption(java.lang.String key, java.lang.Object value)
Sets an option with the specified key and value.void
setOptions(java.util.Map<java.lang.String,java.lang.Object> options)
void
setPipeline(ChannelPipeline pipeline)
Sets the defaultChannelPipeline
which is cloned when a newChannel
is created.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.void
setPipelineFactory(ChannelPipelineFactory pipelineFactory)
void
shutdown()
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 noChannelFactory
set.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 theChannelFactory
that 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 theChannelFactory
that 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 defaultChannelPipeline
which is cloned when a newChannel
is created.Bootstrap
creates 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 statefulChannelHandler
and 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 defaultChannelPipeline
which is cloned when a newChannel
is created.Bootstrap
creates a new pipeline which has the same entries with the specified pipeline for a new channel.Calling this method also sets the
pipelineFactory
property to an internalChannelPipelineFactory
implementation 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 statefulChannelHandler
and 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 statefulChannelHandler
and 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 statefulChannelHandler
and 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 theChannelPipelineFactory
which creates a newChannelPipeline
for each newChannel
. Calling this method invalidates the currentpipeline
property 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.
null
otherwise.
-
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:
releaseExternalResources
in interfaceExternalResourceReleasable
-
shutdown
public void shutdown()
This method simply delegates the call toChannelFactory.shutdown()
.
-
isOrderedMap
static boolean isOrderedMap(java.util.Map<?,?> map)
Returnstrue
if and only if the specifiedmap
is an ordered map, likeLinkedHashMap
is.
-
-