[jboss-user] [Clustering/JBoss] - HA-JNDI server side problem

wecucho do-not-reply at jboss.com
Tue May 20 17:02:00 EDT 2008

Hi all, first at all i am running JBoss 4.2.2 GA.

I develop a few methods to obtain the master node for a cluster easily given at least a node and all works great outside the server (the reason i need the master node is to create and delete JMS queues).

In my test enviroment i have a cluster with 2 nodes, A and B, and i have a web application deployed on both nodes who has the fancy buttons to see, create and remove my queues... so, i ported my tests code into the web component and fails obtaining the master node, i already read the documentation and i am doing exactly what they say without a positive result, my InitialContext always return the local instance for the node who runs the web component, so, if i start the web page in the master node all runs ok, by the other hand if i use the web pages in the Non Master node it will fail.

My Nodes are:
B = (Non Master)

The magic button who try to obtain the correct Master Node has the following code (just as the documentation says):

anonymous wrote : 
  | public static MBeanServerConnection getMasterNodeFromCluster(int tries, String node) {
  | 		try {
  | 			for (int i = 0; i < tries; i++) {
  | 				Properties env = new Properties();
  | 				env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
  | 				env.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
  | 				env.put(Context.PROVIDER_URL, node);
  | 				System.out.print("trying with " + node);
  | 				Context ctx = new InitialContext(env);
  | 				MBeanServerConnection mbs = (MBeanServerConnection) ctx.lookup("jmx/invoker/RMIAdaptor");
  | 				System.out.print(" obtained "
  | 						+ mbs.getAttribute(new ObjectName("jboss:service=HAJNDI"), "BindAddress").toString());
  | 				if (mbs.getAttribute(new ObjectName("jboss.ha:service=HASingletonDeployer"), "MasterNode").toString()
  | 						.equalsIgnoreCase("true")) {
  | 					System.out.println();
  | 					return mbs;
  | 				}
  | 			}
  | 		} catch (Exception e) {
  | 			e.printStackTrace();
  | 		}
  | 		System.out.println("not found");
  | 		return null;
  | 	}

and i am calling this method from the action of the button this way:

anonymous wrote : 
  | JMQueuesUtils.getMasterNodeFromCluster(10, "");

Don't pay any attention to the 'tries' variable, that was just a test...

The Cluster Guide for JBoss 4.2 says literally this:

anonymous wrote : 
  | So, an EJB home lookup through HA-JNDI, will always be delegated to the local
  | JNDI instance. If different beans (even of the same type, but participating in different
  | clusters) use the same JNDI name, it means that each JNDI server will have a
  | different "target" bound (JNDI on node 1 will have a binding for bean A and JNDI
  | on node 2 will have a binding, under the same name, for bean B). Consequently, if
  | a client performs a HA-JNDI query for this name, the query will be invoked on any
  | JNDI server of the cluster and will return the locally bound stub. Nevertheless, it may
  | not be the correct stub that the client is expecting to receive!
  | and ....
  |    If you want to access HA-JNDI from inside the application server, you must explicitly
  |    get an InitialContext by passing in JNDI properties. The following code shows how to
  |    create a naming Context bound to HA-JNDI:
  |         Properties p = new Properties();
  |         p.put(Context.INITIAL_CONTEXT_FACTORY,
  |         "org.jnp.interfaces.NamingContextFactory");
  | p.put(Context.URL_PKG_PREFIXES,
  | "jboss.naming:org.jnp.interfaces");
  | p.put(Context.PROVIDER_URL, "localhost:1100"); // HA-JNDI port.
  | return new InitialContext(p);

im doing exactly this but simply does not work... :(

Thanks in advance! and forgive my english.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4152143#4152143

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4152143

More information about the jboss-user mailing list