[jboss-cvs] jbossmx/src/main/org/jboss/ha/framework/server ...
Brian Stansberry
brian.stansberry at jboss.com
Tue Jul 25 11:33:12 EDT 2006
User: bstansberry
Date: 06/07/25 11:33:12
Modified: src/main/org/jboss/ha/framework/server
ClusterPartition.java
Added: src/main/org/jboss/ha/framework/server
JChannelFactory.java
Log:
[JBAS-3424] Ensure node name "additional_data" is present in multiplexed channel
Revision Changes Path
1.49 +23 -5 jbossmx/src/main/org/jboss/ha/framework/server/ClusterPartition.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ClusterPartition.java
===================================================================
RCS file: /cvsroot/jboss/jbossmx/src/main/org/jboss/ha/framework/server/ClusterPartition.java,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -b -r1.48 -r1.49
--- ClusterPartition.java 20 Jun 2006 16:19:28 -0000 1.48
+++ ClusterPartition.java 25 Jul 2006 15:33:12 -0000 1.49
@@ -45,6 +45,7 @@
import org.jgroups.debug.Debugger;
import org.jgroups.JChannel;
import org.jgroups.jmx.JChannelFactoryMBean;
+import org.jgroups.stack.IpAddress;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
@@ -57,7 +58,7 @@
*
* @author <a href="mailto:bill at burkecentral.com">Bill Burke</a>.
* @author <a href="mailto:sacha.labourey at cogito-info.ch">Sacha Labourey</a>.
- * @version $Revision: 1.48 $
+ * @version $Revision: 1.49 $
*/
public class ClusterPartition
extends ServiceMBeanSupport
@@ -343,12 +344,29 @@
throws Exception
{
// We push the independent name in the protocol stack before connecting to the cluster
+ boolean pushNodeName = true;
+ if (this.nodeName == null || "".equals(this.nodeName)) {
+ IpAddress ourAddr = (IpAddress) channel.getLocalAddress();
+ if (ourAddr != null)
+ {
+ byte[] additional_data = ourAddr.getAdditionalData();
+ if (additional_data != null)
+ {
+ nodeName = new String(additional_data);
+ pushNodeName = false;
+ }
+ }
+ }
if (this.nodeName == null || "".equals(this.nodeName)) {
this.nodeName = generateUniqueNodeName();
}
+
+ if (pushNodeName)
+ {
java.util.HashMap staticNodeName = new java.util.HashMap();
staticNodeName.put("additional_data", this.nodeName.getBytes());
this.channel.down(new Event(Event.CONFIG, staticNodeName));
+ }
// this.channel.getProtocolStack().flushEvents(); // temporary fix for JG bug (808170) TODO: REMOVE ONCE JGROUPS IS FIXED
channel.connect(partitionName);
1.1 date: 2006/07/25 15:33:12; author: bstansberry; state: Exp;jbossmx/src/main/org/jboss/ha/framework/server/JChannelFactory.java
Index: JChannelFactory.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.ha.framework.server;
import java.net.InetAddress;
import java.rmi.dgc.VMID;
import java.rmi.server.UID;
import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanServer;
import javax.management.ReflectionException;
import org.jboss.logging.Logger;
import org.jboss.mx.util.MBeanServerLocator;
import org.jboss.naming.NamingServiceMBean;
import org.jboss.system.ServiceMBean;
import org.jboss.system.server.ServerConfigUtil;
import org.jgroups.Channel;
import org.jgroups.Event;
import org.jgroups.stack.IpAddress;
/**
* Extension to the JGroups JChannelFactory that supports the addition
* of "additional_data" to the channel config. Needed until logical
* addresses are supported in JGroups.
*
* @author <a href="mailto://brian.stansberry@jboss.com">Brian Stansberry</a>
* @version $Revision$
*/
public class JChannelFactory extends org.jgroups.JChannelFactory
{
protected static Logger log = Logger.getLogger(JChannelFactory.class);
private InetAddress nodeAddress;
private String nodeName;
public Channel createMultiplexerChannel(String stack_name, String id, boolean register_for_state_transfer, String substate_id) throws Exception
{
Channel channel = super.createMultiplexerChannel(stack_name, id, register_for_state_transfer, substate_id);
IpAddress address = (IpAddress) channel.getLocalAddress();
if (address == null)
{
// We push the independent name in the protocol stack before connecting to the cluster
if (this.nodeName == null || "".equals(this.nodeName)) {
this.nodeName = generateUniqueNodeName();
}
java.util.HashMap staticNodeName = new java.util.HashMap();
staticNodeName.put("additional_data", this.nodeName.getBytes());
channel.down(new Event(Event.CONFIG, staticNodeName));
}
return channel;
}
public InetAddress getNodeAddress()
{
return nodeAddress;
}
public void setNodeAddress(InetAddress nodeAddress)
{
this.nodeAddress = nodeAddress;
}
public String getNodeName()
{
return nodeName;
}
public void setNodeName(String nodeName)
{
this.nodeName = nodeName;
}
private String generateUniqueNodeName () throws Exception
{
// we first try to find a simple meaningful name:
// 1st) "local-IP:JNDI_PORT" if JNDI is running on this machine
// 2nd) "local-IP:JMV_GUID" otherwise
// 3rd) return a fully GUID-based representation
//
// Before anything we determine the local host IP (and NOT name as this could be
// resolved differently by other nodes...)
// But use the specified node address for multi-homing
String hostIP = null;
InetAddress address = ServerConfigUtil.fixRemoteAddress(nodeAddress);
if (address == null)
{
log.debug ("unable to create a GUID for this cluster, check network configuration is correctly setup (getLocalHost has returned an exception)");
log.debug ("using a full GUID strategy");
return new VMID().toString();
}
else
{
hostIP = address.getHostAddress();
}
// 1st: is JNDI up and running?
//
try
{
MBeanServer server = MBeanServerLocator.locateJBoss();
AttributeList al = server.getAttributes(NamingServiceMBean.OBJECT_NAME,
new String[] {"State", "Port"});
int status = ((Integer)((Attribute)al.get(0)).getValue()).intValue();
if (status == ServiceMBean.STARTED)
{
// we can proceed with the JNDI trick!
int port = ((Integer)((Attribute)al.get(1)).getValue()).intValue();
return hostIP + ":" + port;
}
else
{
log.debug("JNDI has been found but the service wasn't started so we cannot " +
"be entirely sure we are the only one that wants to use this PORT " +
"as a GUID on this host.");
}
}
catch (InstanceNotFoundException e)
{
log.debug ("JNDI not running here, cannot use this strategy to find a node GUID for the cluster");
}
catch (ReflectionException e)
{
log.debug ("JNDI querying has returned an exception, cannot use this strategy to find a node GUID for the cluster");
}
// 2nd: host-GUID strategy
//
String uid = new UID().toString();
return hostIP + ":" + uid;
}
}
More information about the jboss-cvs-commits
mailing list