public class Bootstrap extends java.lang.Object implements ExternalResourceReleasable
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.限定符 | 构造器和说明 |
---|---|
protected |
Bootstrap()
Creates a new instance with no
ChannelFactory set. |
protected |
Bootstrap(ChannelFactory channelFactory)
Creates a new instance with the specified initial
ChannelFactory . |
限定符和类型 | 方法和说明 |
---|---|
ChannelFactory |
getFactory()
Returns the
ChannelFactory 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 default
ChannelPipeline which is cloned when a new
Channel is created. |
java.util.Map<java.lang.String,ChannelHandler> |
getPipelineAsMap()
Dependency injection friendly convenience method for
getPipeline() which returns the default pipeline of this
bootstrap as an ordered map. |
ChannelPipelineFactory |
getPipelineFactory()
|
void |
releaseExternalResources()
This method simply delegates the call to
ChannelFactory.releaseExternalResources() . |
void |
setFactory(ChannelFactory factory)
Sets the
ChannelFactory 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 default
ChannelPipeline which is cloned when a new
Channel is created. |
void |
setPipelineAsMap(java.util.Map<java.lang.String,ChannelHandler> pipelineMap)
Dependency injection friendly convenience method for
setPipeline(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 to
ChannelFactory.shutdown() . |
protected Bootstrap()
ChannelFactory
set.
setFactory(ChannelFactory)
must be called at once before any
I/O operation is requested.protected Bootstrap(ChannelFactory channelFactory)
ChannelFactory
.public ChannelFactory getFactory()
ChannelFactory
that will be used to perform an
I/O operation.java.lang.IllegalStateException
- if the factory is not set for this bootstrap yet.
The factory can be set in the constructor or
setFactory(ChannelFactory)
.public void setFactory(ChannelFactory factory)
ChannelFactory
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.java.lang.IllegalStateException
- if the factory is already setpublic ChannelPipeline getPipeline()
ChannelPipeline
which is cloned when a new
Channel
is created. Bootstrap
creates a new pipeline
which has the same entries with the returned pipeline for a new
Channel
.
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 stateful ChannelHandler
and 2) one or
more channels are going to be created by this bootstrap (e.g. server-side
channels).
ChannelPipeline
java.lang.IllegalStateException
- if setPipelineFactory(ChannelPipelineFactory)
was
called by a user last time.public void setPipeline(ChannelPipeline pipeline)
ChannelPipeline
which is cloned when a new
Channel
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
internal ChannelPipelineFactory
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 stateful ChannelHandler
and 2) one or
more channels are going to be created by this bootstrap (e.g. server-side
channels).
public java.util.Map<java.lang.String,ChannelHandler> getPipelineAsMap()
getPipeline()
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 stateful ChannelHandler
and 2) one or
more channels are going to be created by this bootstrap (e.g. server-side
channels).
java.lang.IllegalStateException
- if setPipelineFactory(ChannelPipelineFactory)
was
called by a user last time.public void setPipelineAsMap(java.util.Map<java.lang.String,ChannelHandler> pipelineMap)
setPipeline(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 stateful ChannelHandler
and 2) one or
more channels are going to be created by this bootstrap (e.g. server-side
channels).
java.lang.IllegalArgumentException
- if the specified map is not an ordered mappublic ChannelPipelineFactory getPipelineFactory()
getPipeline()
public void setPipelineFactory(ChannelPipelineFactory pipelineFactory)
ChannelPipelineFactory
which creates a new
ChannelPipeline
for each new Channel
. Calling this
method invalidates the current pipeline
property of this
bootstrap. Subsequent getPipeline()
and getPipelineAsMap()
calls will raise IllegalStateException
.public java.util.Map<java.lang.String,java.lang.Object> getOptions()
public void setOptions(java.util.Map<java.lang.String,java.lang.Object> options)
public java.lang.Object getOption(java.lang.String key)
Channel
, prepend "child."
to the option name (e.g. "child.keepAlive"
).key
- the option namenull
otherwise.public void setOption(java.lang.String key, java.lang.Object value)
null
, an existing option with the specified
key is removed. To set the option value of a child Channel
,
prepend "child."
to the option name (e.g. "child.keepAlive"
).key
- the option namevalue
- the option valuepublic void releaseExternalResources()
ChannelFactory.releaseExternalResources()
.public void shutdown()
ChannelFactory.shutdown()
.