org.jboss.ha.framework.server
Class JChannelFactory

java.lang.Object
  extended by org.jgroups.JChannelFactory
      extended by org.jboss.ha.framework.server.JChannelFactory
All Implemented Interfaces:
MBeanRegistration, JChannelFactoryMBean, org.jgroups.ChannelFactory

public class JChannelFactory
extends org.jgroups.JChannelFactory
implements JChannelFactoryMBean, MBeanRegistration

Extension to the JGroups JChannelFactory that supports a number of JBoss AS-specific behaviors:

Version:
$Revision: 86596 $
Author:
Brian Stansberry, Galder Zamarreno

Field Summary
protected static Logger log
           
static String UNSHARED_TRANSPORT_NAME_BASE
           
 
Constructor Summary
JChannelFactory()
           
 
Method Summary
 void create()
          Execute the create phase of the 4 step lifecycle.
 org.jgroups.Channel createChannel()
          Always throws ChannelException; this method is not supported.
 org.jgroups.Channel createChannel(Object properties)
           
 org.jgroups.Channel createChannel(String stack_name)
          Create a Channel using the specified stack.
 org.jgroups.Channel createMultiplexerChannel(String stack_name, String id)
          Creates and returns a shared transport Channel configured with the specified protocol stack configuration.
 org.jgroups.Channel createMultiplexerChannel(String stack_name, String id, boolean register_for_state_transfer, String substate_id)
          Creates and returns a shared transport Channel configured with the specified protocol stack configuration.
 void destroy()
          Execute the destroy phase of the 4 step lifecycle.
 boolean getAddMissingSingletonName()
          Gets whether createMultiplexerChannel(String, String) should create a synthetic singleton name attribute for a channel's transport protocol if one isn't configured.
 boolean getAssignLogicalAddresses()
          Gets whether this factory should create a "logical address" (or use one set via setNodeName(String) and assign it to any newly created Channel as JGroups "additional_data".
protected  ClassLoader getDefaultChannelThreadContextClassLoader()
          Gets the classloader that channel threads should be set to if #getManageNewThreadClassloader() or getManageReleasedThreadClassLoader() are true.
 boolean getManageNewThreadClassLoader()
          Gets whether this factory should update the standard JGroups thread factories to ensure application classloaders do not leak to newly created channel threads.
 boolean getManageReleasedThreadClassLoader()
          Gets whether this factory should update the standard JGroups thread pools to ensure application classloaders have not leaked to threads returned to the pool.
 int getNamingServicePort()
          Gets the port on which this server's naming service is listening.
 InetAddress getNodeAddress()
          Gets the address to which this server is bound; typically the value passed to -b when JBoss is started.
 String getNodeName()
          Get any logical name assigned to this server; if not null this value will be the value of the logical address assigned to the channels this factory creates.
 void postDeregister()
           
 void postRegister(Boolean registrationDone)
           
 void preDeregister()
           
 ObjectName preRegister(MBeanServer server, ObjectName name)
           
 void setAddMissingSingletonName(boolean addMissingSingletonName)
          Sets whether createMultiplexerChannel(String, String) should create a synthetic singleton name attribute for a channel's transport protocol if one isn't configured.
 void setAssignLogicalAddresses(boolean logicalAddresses)
          Sets whether this factory should create a "logical address" (or use one set via setNodeName(String) and assign it to any newly created Channel as JGroups "additional_data".
 void setDomain(String domain)
          Sets the domain portion of any ObjectName the factory should use when registering channels or protocols in JMX.
 void setManageNewThreadClassLoader(boolean manage)
          Sets whether this factory should update the standard JGroups thread factories to ensure application classloaders do not leak to newly created channel threads.
 void setManageReleasedThreadClassLoader(boolean manage)
          Sets whether this factory should update the standard JGroups thread pools to ensure application classloaders have not leaked to threads returned to the pool.
 void setNamingServicePort(int jndiPort)
          Sets the port on which this server's naming service is listening.
 void setNodeAddress(InetAddress nodeAddress)
          Sets the address to which this server is bound; typically the value passed to -b when JBoss is started.
 void setNodeName(String nodeName)
          Sets the logical name assigned to this server; if not null this value will be the value of the logical address assigned to the channels this factory creates.
 void start()
          Execute the start phase of the 4 step lifecycle.
 void stop()
          Execute the stop phase of the 4 step lifecycle.
 
Methods inherited from class org.jgroups.JChannelFactory
clearConfigurations, dumpChannels, dumpConfiguration, getConfig, getDomain, getMultiplexerConfig, getServer, hasMuxChannel, isExposeChannels, isExposeProtocols, removeConfig, setExposeChannels, setExposeProtocols, setMultiplexerConfig, setMultiplexerConfig, setMultiplexerConfig, setMultiplexerConfig, setMultiplexerConfig, setMultiplexerConfig, setMultiplexerConfig, setMultiplexerConfig, setMultiplexerConfig, setMultiplexerConfig, setServer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jboss.ha.framework.server.JChannelFactoryMBean
clearConfigurations, dumpChannels, dumpConfiguration, getConfig, getDomain, getMultiplexerConfig, isExposeChannels, isExposeProtocols, removeConfig, setExposeChannels, setExposeProtocols, setMultiplexerConfig, setMultiplexerConfig
 

Field Detail

log

protected static final Logger log

UNSHARED_TRANSPORT_NAME_BASE

public static final String UNSHARED_TRANSPORT_NAME_BASE
See Also:
Constant Field Values
Constructor Detail

JChannelFactory

public JChannelFactory()
Method Detail

createChannel

public org.jgroups.Channel createChannel()
                                  throws org.jgroups.ChannelException
Always throws ChannelException; this method is not supported.

Specified by:
createChannel in interface org.jgroups.ChannelFactory
Overrides:
createChannel in class org.jgroups.JChannelFactory
Throws:
org.jgroups.ChannelException

createChannel

public org.jgroups.Channel createChannel(Object properties)
                                  throws org.jgroups.ChannelException
Specified by:
createChannel in interface org.jgroups.ChannelFactory
Overrides:
createChannel in class org.jgroups.JChannelFactory
Throws:
org.jgroups.ChannelException

createChannel

public org.jgroups.Channel createChannel(String stack_name)
                                  throws Exception
Create a Channel using the specified stack. Channel will use a shared transport if the singleton-name attribute is set on the stack's transport protocol.

Specified by:
createChannel in interface JChannelFactoryMBean
Specified by:
createChannel in interface org.jgroups.ChannelFactory
Overrides:
createChannel in class org.jgroups.JChannelFactory
Parameters:
stack_name - the name of the stack
Returns:
the channel
Throws:
Exception

createMultiplexerChannel

public org.jgroups.Channel createMultiplexerChannel(String stack_name,
                                                    String id)
                                             throws Exception
Creates and returns a shared transport Channel configured with the specified protocol stack configuration.

NOTE: The implementation of this method is somewhat different from what is described in ChannelFactory.createMultiplexerChannel(String, String). The returned channel will not be an instance of org.jgroups.mux.MuxChannel; rather a channel that uses a shared transport will be returned. This will be the case whether or not the protocol stack specified by stack_name includes a singleton_name attribute in its transport protocol configuration. If no singleton_name attribute is present, this factory will create a synthetic one by prepending "unnamed_" to the provided id param and will use that for the returned channel's transport protocol. (Note this will not effect the protocol stack configuration named by stack_name; i.e. another request that passes the same stack_name will not inherit the synthetic singleton name.)

Specified by:
createMultiplexerChannel in interface JChannelFactoryMBean
Specified by:
createMultiplexerChannel in interface org.jgroups.ChannelFactory
Overrides:
createMultiplexerChannel in class org.jgroups.JChannelFactory
Parameters:
stack_name - The name of the stack to be used. All stacks are defined in the configuration with which the factory is configured (see JChannelFactory.setMultiplexerConfig(Object) for example. If clients attempt to create a Channel for an undefined stack name an Exception will be thrown.
id - Only used if the transport protocol configuration for the specified stack does not include the singleton_name attribute; then it is used to create a synthetic singleton-name for the channel's protocol stack.
Returns:
An implementation of Channel configured with a shared transport.
Throws:
IllegalStateException - if the specified protocol stack does not declare a singleton_name and getAddMissingSingletonName() returns false.
org.jgroups.ChannelException
Exception

createMultiplexerChannel

public org.jgroups.Channel createMultiplexerChannel(String stack_name,
                                                    String id,
                                                    boolean register_for_state_transfer,
                                                    String substate_id)
                                             throws Exception
Creates and returns a shared transport Channel configured with the specified protocol stack configuration. See createMultiplexerChannel(String, String); the additional attributes specified in this overloaded version of that method are ignored.

Specified by:
createMultiplexerChannel in interface JChannelFactoryMBean
Specified by:
createMultiplexerChannel in interface org.jgroups.ChannelFactory
Overrides:
createMultiplexerChannel in class org.jgroups.JChannelFactory
Parameters:
register_for_state_transfer - ignored in JBoss AS. Treated as false.
substate_id - ignored in JBoss AS
Returns:
An implementation of Channel configured with a shared transport.
Throws:
IllegalStateException - if the specified protocol stack does not declare a singleton_name and getAddMissingSingletonName() returns false.
org.jgroups.ChannelException
Exception

setDomain

public void setDomain(String domain)
Description copied from interface: JChannelFactoryMBean
Sets the domain portion of any ObjectName the factory should use when registering channels or protocols in JMX.

Specified by:
setDomain in interface JChannelFactoryMBean
Overrides:
setDomain in class org.jgroups.JChannelFactory
Parameters:
domain - the domain portion of the object name. Must conform to the rules for elements in an ObjectName.

getNodeName

public String getNodeName()
Get any logical name assigned to this server; if not null this value will be the value of the logical address assigned to the channels this factory creates.

Returns:
the logical name for this server, or null.

setNodeName

public void setNodeName(String nodeName)
Sets the logical name assigned to this server; if not null this value will be the value of the logical address assigned to the channels this factory creates.

Parameters:
nodeName - the logical name for this server, or null.

getNodeAddress

public InetAddress getNodeAddress()
Gets the address to which this server is bound; typically the value passed to -b when JBoss is started. Used in combination with the naming service port to create a logical name for this server if no node name is specified.

Returns:
the address to which this server is bound, or null if not set

setNodeAddress

public void setNodeAddress(InetAddress nodeAddress)
Sets the address to which this server is bound; typically the value passed to -b when JBoss is started. Used in combination with the naming service port to create a logical name for this server if no node name is specified.

Parameters:
nodeAddress - the address to which this server is bound, or null

getNamingServicePort

public int getNamingServicePort()
Gets the port on which this server's naming service is listening. Used in combination with the server bind address to create a logical name for this server if no node name is specified.

Returns:
the port on which JNDI is listening, or -1 if not set.

setNamingServicePort

public void setNamingServicePort(int jndiPort)
Sets the port on which this server's naming service is listening. Used in combination with the server bind address to create a logical name for this server if no node name is specified.

Parameters:
jndiPort - the port on which JNDI is listening.

getAssignLogicalAddresses

public boolean getAssignLogicalAddresses()
Gets whether this factory should create a "logical address" (or use one set via setNodeName(String) and assign it to any newly created Channel as JGroups "additional_data".

See Also:
setAssignLogicalAddresses(boolean)

setAssignLogicalAddresses

public void setAssignLogicalAddresses(boolean logicalAddresses)
Sets whether this factory should create a "logical address" (or use one set via setNodeName(String) and assign it to any newly created Channel as JGroups "additional_data".

Any such logical address will be used by HAPartition to assign a name to the ClusterNode object representing this node. If a logical address is not set, the ClusterNode will use the address and port JGroups is using to receive messages to create its name.

Default is true.


getManageNewThreadClassLoader

public boolean getManageNewThreadClassLoader()
Gets whether this factory should update the standard JGroups thread factories to ensure application classloaders do not leak to newly created channel threads.

Returns:
true if the factories should be updated. Default is true.

setManageNewThreadClassLoader

public void setManageNewThreadClassLoader(boolean manage)
Sets whether this factory should update the standard JGroups thread factories to ensure application classloaders do not leak to newly created channel threads. This should only be set to false if a JGroups release is used that itself prevents such classloader leaks.

Parameters:
manage - true if the factories should be updated.

getManageReleasedThreadClassLoader

public boolean getManageReleasedThreadClassLoader()
Gets whether this factory should update the standard JGroups thread pools to ensure application classloaders have not leaked to threads returned to the pool.

Returns:
true if the pools should be updated. Default is false.

setManageReleasedThreadClassLoader

public void setManageReleasedThreadClassLoader(boolean manage)
Sets whether this factory should update the standard JGroups thread pools to ensure application classloaders have not leaked to threads returned to the pool.

There is a small performance cost to enabling this, and applications can prevent any need to enable it by properly restoring the thread context classloader if they change it. Therefore, by default this is set to false.

Parameters:
manage - true if the factories should be updated.

getAddMissingSingletonName

public boolean getAddMissingSingletonName()
Gets whether createMultiplexerChannel(String, String) should create a synthetic singleton name attribute for a channel's transport protocol if one isn't configured. If this is false and no singleton_name is configured, createMultiplexerChannel(String, String) will throw an IllegalStateException.

Returns:
true if synthetic singleton names should be created. Default is true.

setAddMissingSingletonName

public void setAddMissingSingletonName(boolean addMissingSingletonName)
Sets whether createMultiplexerChannel(String, String) should create a synthetic singleton name attribute for a channel's transport protocol if one isn't configured.

Parameters:
addMissingSingletonName - true if synthetic singleton names should be created.

create

public void create()
            throws Exception
Description copied from interface: JChannelFactoryMBean
Execute the create phase of the 4 step lifecycle.

Specified by:
create in interface JChannelFactoryMBean
Overrides:
create in class org.jgroups.JChannelFactory
Throws:
Exception

start

public void start()
           throws Exception
Description copied from interface: JChannelFactoryMBean
Execute the start phase of the 4 step lifecycle.

Specified by:
start in interface JChannelFactoryMBean
Overrides:
start in class org.jgroups.JChannelFactory
Throws:
Exception

stop

public void stop()
Description copied from interface: JChannelFactoryMBean
Execute the stop phase of the 4 step lifecycle.

Specified by:
stop in interface JChannelFactoryMBean
Overrides:
stop in class org.jgroups.JChannelFactory

destroy

public void destroy()
Description copied from interface: JChannelFactoryMBean
Execute the destroy phase of the 4 step lifecycle.

Specified by:
destroy in interface JChannelFactoryMBean
Overrides:
destroy in class org.jgroups.JChannelFactory

preRegister

public ObjectName preRegister(MBeanServer server,
                              ObjectName name)
                       throws Exception
Specified by:
preRegister in interface MBeanRegistration
Throws:
Exception

postRegister

public void postRegister(Boolean registrationDone)
Specified by:
postRegister in interface MBeanRegistration

preDeregister

public void preDeregister()
                   throws Exception
Specified by:
preDeregister in interface MBeanRegistration
Throws:
Exception

postDeregister

public void postDeregister()
Specified by:
postDeregister in interface MBeanRegistration

getDefaultChannelThreadContextClassLoader

protected ClassLoader getDefaultChannelThreadContextClassLoader()
Gets the classloader that channel threads should be set to if #getManageNewThreadClassloader() or getManageReleasedThreadClassLoader() are true.

This implementation returns this class' classloader.

Returns:
the classloader.


Copyright © 2009 JBoss, a division of Red Hat, Inc.. All Rights Reserved.