Commit 5585016f authored by Thibaut Guinoiseau's avatar Thibaut Guinoiseau

Corrected mom:list. Corrected Record.toString (parenthesis). Added new JMX cmd...

Corrected mom:list. Corrected Record.toString (parenthesis). Added new JMX cmd for NamingContext. Replaced all JNDI cmds by a new one: jndi:list.
parent 6610cf68
......@@ -25,6 +25,7 @@ package fr.dyade.aaa.jndi2.impl;
import java.io.Serializable;
import java.util.Enumeration;
import java.util.Properties;
import java.util.Vector;
import javax.naming.Binding;
......@@ -36,6 +37,7 @@ import javax.naming.NamingException;
import javax.naming.Reference;
import org.objectweb.util.monolog.api.BasicLevel;
import org.osgi.service.io.ConnectionFactory;
import fr.dyade.aaa.agent.AgentId;
import fr.dyade.aaa.agent.Channel;
......@@ -250,6 +252,27 @@ public class NamingContext implements NamingContextMBean, Serializable, Cloneabl
cn = getCompositeName(name);
sendTo(new UnbindRequest(cn));
}
public Properties getProperties(String name) throws NamingException {
Properties prop = new Properties();
Record rec = getRecord(name);
if(rec instanceof ObjectRecord) {
Reference ref = (Reference) ((ObjectRecord) rec).getObject();
String className = ref.getClassName();
prop.setProperty("className", className);
if(className.equals("org.objectweb.joram.client.jms.Topic")
|| className.equals("org.objectweb.joram.client.jms.Queue")) {
prop.setProperty("agentId", (String) ref.get("dest.agentId").getContent());
prop.setProperty("name", (String) ref.get("dest.adminName").getContent());
} else if(className.equals("org.objectweb.joram.client.jms.tcp.QueueTcpConnectionFactory")
||className.equals("org.objectweb.joram.client.jms.tcp.TopicTcpConnectionFactory")
|| className.equals("org.objectweb.joram.client.jms.tcp.TcpConnectionFactory")) {
prop.setProperty("host", (String) ref.get("cf.host").getContent());
prop.setProperty("port", (String) ref.get("cf.port").getContent());
}
}
return prop;
}
private CompositeName getCompositeName(String path) throws InvalidNameException {
if (path.startsWith("/"))
......
......@@ -22,6 +22,8 @@
*/
package fr.dyade.aaa.jndi2.impl;
import java.util.Properties;
import javax.naming.NamingException;
public interface NamingContextMBean {
......@@ -39,4 +41,6 @@ public interface NamingContextMBean {
public String lookup(String name) throws NamingException;
public void unbind(String name) throws NamingException;
public Properties getProperties(String name) throws NamingException;
}
......@@ -42,7 +42,7 @@ public abstract class Record implements Serializable {
public String toString() {
StringBuffer buf = new StringBuffer();
buf.append('(' + super.toString());
buf.append(",name = " + name);
buf.append(",name = " + name+')');
return buf.toString();
}
}
......@@ -22,11 +22,15 @@
*/
package org.ow2.joram.shell.jndi.commands;
import java.util.Properties;
import java.util.StringTokenizer;
import javax.naming.NamingException;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
import fr.dyade.aaa.jndi2.impl.NamingContext;
import fr.dyade.aaa.jndi2.impl.NamingContextMBean;
public class JNDICommandsImpl implements JNDICommands {
......@@ -34,11 +38,13 @@ public class JNDICommandsImpl implements JNDICommands {
private static final int TIMEOUT = 1000;
public static final String NAMESPACE = "joram:jndi";
// public static final String[] COMMANDS = new String[] {
// "getNamingContext", "getStrOwnerId",
// "setStrOwnerId", "createSubcontext",
// "destroySubcontext", "lookup",
// "unbind"};
public static final String[] COMMANDS = new String[] {
"getNamingContext", "getStrOwnerId",
"setStrOwnerId", "createSubcontext",
"destroySubcontext", "lookup",
"unbind"};
"list"};
private BundleContext bundleContext;
private ServiceTracker tracker;
......@@ -59,16 +65,7 @@ public class JNDICommandsImpl implements JNDICommands {
if(names != null && names.length > 0) {
System.out.println("Naming context:");
for(String n : names) {
// String detail;
// try {
// String s = nc.lookup(n);
// Pattern p = Pattern.compile("Reference Class Name: (\p{Alnum}{2}");
// detail = (String) o;
// } catch (Exception e) {
// detail="<error>";
// }
// System.out.println("\t"+n+" : "+detail);
System.out.println("\t"+n);
System.out.println("\t"+n);
}
} else {
System.out.println("No name in the naming context.");
......@@ -166,4 +163,23 @@ public class JNDICommandsImpl implements JNDICommands {
System.err.println("Error: Invalid record name.");
}
}
public void list() {
try {
NamingContextMBean nc = (NamingContextMBean) tracker.waitForService(TIMEOUT);
for(String name : nc.getNamingContext()) {
try {
System.out.println(name + ":");
Properties prop = nc.getProperties(name);
for(String key : prop.stringPropertyNames()) {
System.out.println("\t"+key+" : "+prop.getProperty(key));
}
} catch (NamingException e) {
System.err.println("Error: Naming exception.");
}
}
} catch(InterruptedException e) {
System.err.println("Error: Interrupted.");
}
}
}
......@@ -201,7 +201,7 @@ public class MOMCommandsImpl implements MOMCommands {
help("list");
return;
}
String category = args[0];
String category = args[0].toLowerCase();
if(category.equals("destination")
|| category.equals("queue")
|| category.equals("topic")) {
......@@ -227,7 +227,7 @@ public class MOMCommandsImpl implements MOMCommands {
}
if(obj == null || obj.length ==0) {
System.err.println("Error: There is no "+category);
System.out.println("There is no "+category);
return;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment