-
1. Re: Connecting to remote MBean server
davidjencks Jul 1, 2002 7:01 PM (in response to angelawhelan)Look at the jboss ant jmx task in varia or in the JBossTestServices in the testsuite.
-
2. Re: Connecting to remote MBean server
minamoto Jul 3, 2002 12:00 AM (in response to angelawhelan)Hi,
I wrote a small code to access the RemoteMBeanServer for my ant scripts.
I hope this helps.
Miki
------
import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
import org.jboss.jmx.connector.RemoteMBeanServer;
import org.jboss.jmx.connector.rmi.RMIConnectorImpl;
import javax.naming.InitialContext;
import javax.management.ObjectName;
import java.io.File;
import java.net.InetAddress;
/**
* DeployerInvoker is a class to invoke the MainDeployer from ant build scripts.
*
* example:
*
*
*
*
*
*/
public class DeployerInvoker {
public static final String DEPLOYER_NAME = "jboss.system:service=MainDeployer";
public static void main(String args[] ) {
InitialContext ctx = null;
try {
String operation = args[0];
String fileName = args[1];
String deployName = new File(fileName).toURL().toString();
// get a remote mbean server from the jndi
ctx = new InitialContext();
String serverName = InetAddress.getLocalHost().getHostName();
String adaptorName = "jmx:" + serverName + ":rmi";
RMIAdaptor adaptor = (RMIAdaptor) ctx.lookup(adaptorName);
RemoteMBeanServer server = new RMIConnectorImpl(adaptor);
// invoke an operation to the server
server.invoke(new ObjectName(DEPLOYER_NAME),
operation,
new Object[] {deployName},
new String[] {"java.lang.String"});
}
catch (Exception e) {
e.printStackTrace();
}
finally {
try {
if (ctx != null) ctx.close();
}
catch (Exception ignore) {}
}
}
}