Class Bootstrap
- All Implemented Interfaces:
ExternalResourceReleasable
- Direct Known Subclasses:
ClientBootstrap
,ConnectionlessBootstrap
,ServerBootstrap
Channel
. This class provides
the common data structure for its subclasses which actually initialize
Channel
s and their child Channel
s using the common data
structure. Please refer to ClientBootstrap
, ServerBootstrap
,
and ConnectionlessBootstrap
for client side, server-side, and
connectionless (e.g. UDP) channel initialization respectively.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ChannelFactory
private static final short[]
private ChannelPipeline
private ChannelPipelineFactory
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Creates a new instance with noChannelFactory
set.protected
Bootstrap
(ChannelFactory channelFactory) Creates a new instance with the specified initialChannelFactory
. -
Method Summary
Modifier and TypeMethodDescriptionReturns theChannelFactory
that will be used to perform an I/O operation.Returns the value of the option with the specified key.Returns the defaultChannelPipeline
which is cloned when a newChannel
is created.Dependency injection friendly convenience method forgetPipeline()
which returns the default pipeline of this bootstrap as an ordered map.(package private) static boolean
isOrderedMap
(Map<?, ?> map) void
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
Sets an option with the specified key and value.void
setOptions
(Map<String, Object> options) void
setPipeline
(ChannelPipeline pipeline) Sets the defaultChannelPipeline
which is cloned when a newChannel
is created.void
setPipelineAsMap
(Map<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 Details
-
factory
-
pipeline
-
pipelineFactory
-
options
-
ORDER_TEST_SAMPLES
private static final short[] ORDER_TEST_SAMPLES
-
-
Constructor Details
-
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
Creates a new instance with the specified initialChannelFactory
.
-
-
Method Details
-
getFactory
Returns theChannelFactory
that will be used to perform an I/O operation.- Throws:
IllegalStateException
- if the factory is not set for this bootstrap yet. The factory can be set in the constructor orsetFactory(ChannelFactory)
.
-
setFactory
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:
IllegalStateException
- if the factory is already set
-
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:
IllegalStateException
- ifsetPipelineFactory(ChannelPipelineFactory)
was called by a user last time.
-
setPipeline
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
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:
IllegalStateException
- ifsetPipelineFactory(ChannelPipelineFactory)
was called by a user last time.
-
setPipelineAsMap
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:
IllegalArgumentException
- if the specified map is not an ordered map
-
getPipelineFactory
- See Also:
-
setPipelineFactory
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
-
setOptions
-
getOption
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
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
-