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
Channels and their child Channels 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 ChannelFactoryprivate static final short[]private ChannelPipelineprivate ChannelPipelineFactory -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a new instance with noChannelFactoryset.protectedBootstrap(ChannelFactory channelFactory) Creates a new instance with the specified initialChannelFactory. -
Method Summary
Modifier and TypeMethodDescriptionReturns theChannelFactorythat will be used to perform an I/O operation.Returns the value of the option with the specified key.Returns the defaultChannelPipelinewhich is cloned when a newChannelis created.Dependency injection friendly convenience method forgetPipeline()which returns the default pipeline of this bootstrap as an ordered map.(package private) static booleanisOrderedMap(Map<?, ?> map) voidThis method simply delegates the call toChannelFactory.releaseExternalResources().voidsetFactory(ChannelFactory factory) Sets theChannelFactorythat will be used to perform an I/O operation.voidSets an option with the specified key and value.voidsetOptions(Map<String, Object> options) voidsetPipeline(ChannelPipeline pipeline) Sets the defaultChannelPipelinewhich is cloned when a newChannelis created.voidsetPipelineAsMap(Map<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 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 noChannelFactoryset.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 theChannelFactorythat 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 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:
IllegalStateException- if the factory is already set
-
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:
IllegalStateException- ifsetPipelineFactory(ChannelPipelineFactory)was called by a user last time.
-
setPipeline
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
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:
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 statefulChannelHandlerand 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 theChannelPipelineFactorywhich creates a newChannelPipelinefor each newChannel. Calling this method invalidates the currentpipelineproperty of this bootstrap. SubsequentgetPipeline()andgetPipelineAsMap()calls will raiseIllegalStateException.- See Also:
-
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.
nullotherwise.
-
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:
releaseExternalResourcesin interfaceExternalResourceReleasable
-
shutdown
public void shutdown()This method simply delegates the call toChannelFactory.shutdown(). -
isOrderedMap
-