org.jboss.netty.bootstrap
Class Bootstrap

java.lang.Object
  extended by org.jboss.netty.bootstrap.Bootstrap
All Implemented Interfaces:
ExternalResourceReleasable
Direct Known Subclasses:
ClientBootstrap, ConnectionlessBootstrap, ServerBootstrap

public class Bootstrap
extends Object
implements ExternalResourceReleasable

A helper class which initializes a 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.

Version:
$Rev: 1685 $, $Date: 2009-08-28 16:15:49 +0900 (금, 28 8 2009) $
Author:
The Netty Project (netty-dev@lists.jboss.org), Trustin Lee (tlee@redhat.com)

Constructor Summary
protected Bootstrap()
          Creates a new instance with no ChannelFactory set.
protected Bootstrap(ChannelFactory channelFactory)
          Creates a new instance with the specified initial ChannelFactory.
 
Method Summary
 ChannelFactory getFactory()
          Returns the ChannelFactory that will be used to perform an I/O operation.
 Object getOption(String key)
          Returns the value of the option with the specified key.
 Map<String,Object> getOptions()
          Returns the options which configures a new Channel and its child Channels.
 ChannelPipeline getPipeline()
          Returns the default ChannelPipeline which is cloned when a new Channel is created.
 Map<String,ChannelHandler> getPipelineAsMap()
          Dependency injection friendly convenience method for getPipeline() which returns the default pipeline of this bootstrap as an ordered map.
 ChannelPipelineFactory getPipelineFactory()
          Returns the ChannelPipelineFactory which creates a new ChannelPipeline for a new Channel.
 void releaseExternalResources()
          Releases the external resources that this object depends on.
 void setFactory(ChannelFactory factory)
          Sets the ChannelFactory that will be used to perform an I/O operation.
 void setOption(String key, Object value)
          Sets an option with the specified key and value.
 void setOptions(Map<String,Object> options)
          Sets the options which configures a new Channel and its child Channels.
 void setPipeline(ChannelPipeline pipeline)
          Sets the default ChannelPipeline which is cloned when a new Channel is created.
 void setPipelineAsMap(Map<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)
          Sets the ChannelPipelineFactory which creates a new ChannelPipeline for a new Channel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Bootstrap

protected Bootstrap()
Creates a new instance with no ChannelFactory 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 initial ChannelFactory.

Method Detail

getFactory

public ChannelFactory getFactory()
Returns the ChannelFactory 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 or setFactory(ChannelFactory).

setFactory

public void setFactory(ChannelFactory factory)
Sets the 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.

Throws:
IllegalStateException - if the factory is already set

getPipeline

public ChannelPipeline getPipeline()
Returns the default 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.

Returns:
the default ChannelPipeline
Throws:
IllegalStateException - if setPipelineFactory(ChannelPipelineFactory) was called by a user last time.

setPipeline

public void setPipeline(ChannelPipeline pipeline)
Sets the default 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) the ChannelPipelineCoverage of all handlers in the pipeline is "all". You have to use setPipelineFactory(ChannelPipelineFactory) if 1) your pipeline contains a ChannelHandler whose ChannelPipelineCoverage is "one" and 2) one or more channels are going to be created by this bootstrap (e.g. server-side channels).


getPipelineAsMap

public Map<String,ChannelHandler> getPipelineAsMap()
Dependency injection friendly convenience method for getPipeline() which returns the default pipeline of this bootstrap as an ordered map.

Throws:
IllegalStateException - if setPipelineFactory(ChannelPipelineFactory) was called by a user last time.

setPipelineAsMap

public void setPipelineAsMap(Map<String,ChannelHandler> pipelineMap)
Dependency injection friendly convenience method for setPipeline(ChannelPipeline) which sets the default pipeline of this bootstrap from an ordered map.

Throws:
IllegalArgumentException - if the specified map is not an ordered map

getPipelineFactory

public ChannelPipelineFactory getPipelineFactory()
Returns the ChannelPipelineFactory which creates a new ChannelPipeline for a new Channel.

See Also:
getPipeline()

setPipelineFactory

public void setPipelineFactory(ChannelPipelineFactory pipelineFactory)
Sets the ChannelPipelineFactory which creates a new ChannelPipeline for a new Channel. Calling this method invalidates the current pipeline property of this bootstrap. Subsequent getPipeline() and getPipelineAsMap() calls will raise IllegalStateException.

See Also:
setPipeline(ChannelPipeline), setPipelineAsMap(Map)

getOptions

public Map<String,Object> getOptions()
Returns the options which configures a new Channel and its child Channels. The names of the child Channel options are prepended with "child." (e.g. "child.keepAlive").


setOptions

public void setOptions(Map<String,Object> options)
Sets the options which configures a new Channel and its child Channels. To set the options of a child Channel, prepend "child." to the option name (e.g. "child.keepAlive").


getOption

public Object getOption(String key)
Returns the value of the option with the specified key. To retrieve the option value of a child Channel, 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(String key,
                      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 is 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").

Parameters:
key - the option name
value - the option value

releaseExternalResources

public void releaseExternalResources()
Releases the external resources that this object depends on. You should not call this method if the external resources (e.g. thread pool) are in use by other objects. This method simply delegates the call to ChannelFactory.releaseExternalResources().

Specified by:
releaseExternalResources in interface ExternalResourceReleasable


Copyright © 2008-2009 JBoss, by Red Hat. All Rights Reserved.