|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jboss.netty.bootstrap.Bootstrap
org.jboss.netty.bootstrap.ClientBootstrap
public class ClientBootstrap
A helper class which creates a new client-side Channel and makes a
connection attempt.
Options are used to configure a channel:
For the detailed list of available options, please refer toClientBootstrapb = ...; // Options for a new channel b.setOption("remoteAddress", newInetSocketAddress("example.com", 8080)); b.setOption("tcpNoDelay", true); b.setOption("receiveBufferSize", 1048576);
ChannelConfig and its sub-types.
ChannelPipeline and you can configure it
in two ways.
The recommended approach is to specify a ChannelPipelineFactory by
calling Bootstrap.setPipelineFactory(ChannelPipelineFactory).
ClientBootstrapb = ...; b.setPipelineFactory(new MyPipelineFactory()); public class MyPipelineFactory implementsChannelPipelineFactory{ publicChannelPipelinegetPipeline() throws Exception { // Create and configure a new pipeline for a new channel.ChannelPipelinep =Channels.pipeline(); p.addLast("encoder", new EncodingHandler()); p.addLast("decoder", new DecodingHandler()); p.addLast("logic", new LogicHandler()); return p; } }
The alternative approach, which works only in a certain situation, is to use the default pipeline and let the bootstrap to shallow-copy the default pipeline for each new channel:
Please note 'shallow-copy' here means that the addedClientBootstrapb = ...;ChannelPipelinep = b.getPipeline(); // Add handlers to the default pipeline. p.addLast("encoder", new EncodingHandler()); p.addLast("decoder", new DecodingHandler()); p.addLast("logic", new LogicHandler());
ChannelHandlers
are not cloned but only their references are added to the new pipeline.
Therefore, you cannot use this approach if you are going to open more than
one Channels or run a server that accepts incoming connections to
create its child channels.
ChannelsClientBootstrap is just a helper class. It neither allocates nor
manages any resources. What manages the resources is the
ChannelFactory implementation you specified in the constructor of
ClientBootstrap. Therefore, it is OK to create as many
ClientBootstrap instances as you want with the same
ChannelFactory to apply different settings for different
Channels.
| Constructor Summary | |
|---|---|
ClientBootstrap()
Creates a new instance with no ChannelFactory set. |
|
ClientBootstrap(ChannelFactory channelFactory)
Creates a new instance with the specified initial ChannelFactory. |
|
| Method Summary | |
|---|---|
ChannelFuture |
connect()
Attempts a new connection with the current "remoteAddress" and
"localAddress" option. |
ChannelFuture |
connect(java.net.SocketAddress remoteAddress)
Attempts a new connection with the specified remoteAddress and
the current "localAddress" option. |
ChannelFuture |
connect(java.net.SocketAddress remoteAddress,
java.net.SocketAddress localAddress)
Attempts a new connection with the specified remoteAddress and
the specified localAddress. |
| Methods inherited from class org.jboss.netty.bootstrap.Bootstrap |
|---|
getFactory, getOption, getOptions, getPipeline, getPipelineAsMap, getPipelineFactory, releaseExternalResources, setFactory, setOption, setOptions, setPipeline, setPipelineAsMap, setPipelineFactory |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ClientBootstrap()
ChannelFactory set.
Bootstrap.setFactory(ChannelFactory) must be called before any I/O
operation is requested.
public ClientBootstrap(ChannelFactory channelFactory)
ChannelFactory.
| Method Detail |
|---|
public ChannelFuture connect()
"remoteAddress" and
"localAddress" option. If the "localAddress" option is
not set, the local address of a new channel is determined automatically.
This method is similar to the following code:
ClientBootstrap b = ...;
b.connect(b.getOption("remoteAddress"), b.getOption("localAddress"));
java.lang.IllegalStateException - if "remoteAddress" option was not set
java.lang.ClassCastException - if "remoteAddress" or "localAddress" option's
value is neither a SocketAddress nor null
ChannelPipelineException - if this bootstrap's pipelineFactory
failed to create a new ChannelPipelinepublic ChannelFuture connect(java.net.SocketAddress remoteAddress)
remoteAddress and
the current "localAddress" option. If the "localAddress"
option is not set, the local address of a new channel is determined
automatically. This method is identical with the following code:
ClientBootstrap b = ...;
b.connect(remoteAddress, b.getOption("localAddress"));
java.lang.ClassCastException - if "localAddress" option's value is
neither a SocketAddress nor null
ChannelPipelineException - if this bootstrap's pipelineFactory
failed to create a new ChannelPipeline
public ChannelFuture connect(java.net.SocketAddress remoteAddress,
java.net.SocketAddress localAddress)
remoteAddress and
the specified localAddress. If the specified local address is
null, the local address of a new channel is determined
automatically.
ChannelPipelineException - if this bootstrap's pipelineFactory
failed to create a new ChannelPipeline
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||