Index: jbossas-jmx-remoting/build.bat =================================================================== --- jbossas-jmx-remoting/build.bat (revision 102529) +++ jbossas-jmx-remoting/build.bat (working copy) @@ -1,90 +0,0 @@ -@echo off -REM ====================================================================== -REM -REM This is the main entry point for the build system. -REM -REM Users should be sure to execute this file rather than 'mvn' to ensure -REM the correct version is being used with the correct configuration. -REM -REM ====================================================================== -REM -REM $Id$ -REM -REM Authors: -REM Jason Dillon -REM Sacha Labourey -REM - -REM ****************************************************** -REM Ignore the MAVEN_HOME variable: we want to use *our* -REM Maven version and associated JARs. -REM ****************************************************** -REM Ignore the users classpath, cause it might mess -REM things up -REM ****************************************************** - -SETLOCAL - -set CLASSPATH= -set MAVEN_HOME= - -REM ****************************************************** -REM - "for" loops have been unrolled for compatibility -REM with some WIN32 systems. -REM ****************************************************** - -set NAMES=tools;tools\maven;tools\apache\maven -set SUBFOLDERS=..;..\..;..\..\..;..\..\..\.. - -REM ****************************************************** -REM ****************************************************** - -SET EXECUTED=FALSE -for %%i in (%NAMES%) do call :subLoop %%i %1 %2 %3 %4 %5 %6 - -goto :EOF - - -REM ****************************************************** -REM ********* Search for names in the subfolders ********* -REM ****************************************************** - -:subLoop -for %%j in (%SUBFOLDERS%) do call :testIfExists %%j\%1\bin\mvn.bat %2 %3 %4 %5 %6 %7 - -goto :EOF - - -REM ****************************************************** -REM ************ Test if Maven Batch file exists *********** -REM ****************************************************** - -:testIfExists -if exist %1 call :BatchFound %1 %2 %3 %4 %5 %6 %7 %8 - -goto :EOF - - -REM ****************************************************** -REM ************** Batch file has been found ************* -REM ****************************************************** - -:BatchFound -if (%EXECUTED%)==(FALSE) call :ExecuteBatch %1 %2 %3 %4 %5 %6 %7 %8 -set EXECUTED=TRUE - -goto :EOF - -REM ****************************************************** -REM ************* Execute Batch file only once *********** -REM ****************************************************** - -:ExecuteBatch -echo Calling %1 %2 %3 %4 %5 %6 %7 %8 -set GOAL=%2 -if "%GOAL%"=="" set GOAL=install -call %1 %GOAL% %3 %4 %5 %6 %7 %8 - -:end - -if "%NOPAUSE%" == "" pause Index: jbossas-jmx-remoting/src/main/java/org/jboss/mx/remoting/service/JMXConnectorServerService.java =================================================================== --- jbossas-jmx-remoting/src/main/java/org/jboss/mx/remoting/service/JMXConnectorServerService.java (revision 102529) +++ jbossas-jmx-remoting/src/main/java/org/jboss/mx/remoting/service/JMXConnectorServerService.java (working copy) @@ -1,181 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * Copyright 2008, Red Hat Middleware LLC, and individual contributors - * as indicated by the @author tags. See the copyright.txt file 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.mx.remoting.service; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.rmi.registry.LocateRegistry; -import java.rmi.registry.Registry; -import java.rmi.RemoteException; -import javax.management.MBeanServer; -import javax.management.ObjectName; -import javax.management.remote.JMXConnectorServer; -import javax.management.remote.JMXConnectorServerFactory; -import javax.management.remote.JMXServiceURL; -import org.jboss.logging.Logger; -import org.jboss.net.sockets.DefaultSocketFactory; -/** - * Service mbean for starting the JMX Remoting (JSR-160) connector server. - * - * @author Tom Elrod - * @author Dimitris Andreadis - */ -public class JMXConnectorServerService implements JMXConnectorServerServiceMBean -{ - /** - * Default jndi path used to specify location of connector server. - * Value is '/jmxconnector'. - */ - public static final String JNDI_PATH_DEFAULT = "/jmxconnector"; - - private MBeanServer mbeanServer; - - /** The interface to bind, useful for multi-homed hosts */ - private InetAddress bindAddress; - private int registryPort = Registry.REGISTRY_PORT; - private String jndiPath = JNDI_PATH_DEFAULT; - private JMXConnectorServer connectorServer = null; - private Registry rmiRegistry = null; - - private static final Logger log = Logger.getLogger(JMXConnectorServerService.class); - - public void setRegistryPort(int registryPort) - { - this.registryPort = registryPort; - } - - public int getRegistryPort() - { - return registryPort; - } - - public void setBindAddress(String bindAddress) throws UnknownHostException - { - this.bindAddress = toInetAddress(bindAddress); - } - - public String getBindAddress() - { - if (bindAddress != null) - return bindAddress.getHostAddress(); - else - return null; - } - - public String getJndiPath() - { - return jndiPath; - } - - public void setJndiPath(String jndiPath) - { - this.jndiPath = jndiPath; - } - - public void create() throws Exception - { - // do nothing, putting code in start - } - - public void start() throws Exception - { - // the address to expose in the urls - String host = System.getProperty("java.rmi.server.hostname"); - - // check to see if registry already created - rmiRegistry = LocateRegistry.getRegistry(host, registryPort); - if (rmiRegistry != null) - { - try - { - rmiRegistry.list(); - } - catch(RemoteException e) - { - log.debug("No registry running at host '" + host + - "', port '" + registryPort + "'. Will create one."); - rmiRegistry = LocateRegistry.createRegistry(registryPort, null, new DefaultSocketFactory(bindAddress)); - } - } - else - { - rmiRegistry = LocateRegistry.createRegistry(registryPort, null, new DefaultSocketFactory(bindAddress)); - } - - String serviceURL = "service:jmx:rmi://" + host + "/jndi/rmi://" + host + ":" + registryPort + jndiPath; - - JMXServiceURL url = new JMXServiceURL(serviceURL); - - // create new connector server and start it - connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbeanServer); - connectorServer.start(); - - log.info("JMX Connector server: " + serviceURL); - } - - public void stop() throws IOException - { - if(connectorServer != null) - { - connectorServer.stop(); - } - } - - public void destroy() - { - // do nothing, putting code in stop - } - - public ObjectName preRegister(MBeanServer mBeanServer, ObjectName objectName) throws Exception - { - this.mbeanServer = mBeanServer; - return objectName; - } - - public void postRegister(Boolean aBoolean) - { - // no op, needed for MBeanRegistration interface - } - - public void preDeregister() throws Exception - { - // no op, needed for MBeanRegistration interface - } - - public void postDeregister() - { - // no op, needed for MBeanRegistration interface - } - - /** - * Safely convert a host string to InetAddress or null - */ - private InetAddress toInetAddress(String host) throws UnknownHostException - { - if (host == null || host.length() == 0) - return null; - else - return InetAddress.getByName(host); - } - -} \ No newline at end of file Index: jbossas-jmx-remoting/src/main/java/org/jboss/mx/remoting/service/JMXConnectorServerServiceMBean.java =================================================================== --- jbossas-jmx-remoting/src/main/java/org/jboss/mx/remoting/service/JMXConnectorServerServiceMBean.java (revision 102529) +++ jbossas-jmx-remoting/src/main/java/org/jboss/mx/remoting/service/JMXConnectorServerServiceMBean.java (working copy) @@ -1,53 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * Copyright 2008, Red Hat Middleware LLC, and individual contributors - * as indicated by the @author tags. See the copyright.txt file 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.mx.remoting.service; - -import java.io.IOException; -import java.net.UnknownHostException; -import javax.management.MBeanRegistration; - -/** - * @author Tom Elrod - * @author Dimitris Andreadis - */ -public interface JMXConnectorServerServiceMBean extends MBeanRegistration -{ - void create() throws Exception; - - void start() throws Exception; - - void stop() throws IOException; - - void destroy(); - - void setRegistryPort(int registryPort); - - int getRegistryPort(); - - void setBindAddress(String bindAddress) throws UnknownHostException; - - String getBindAddress(); - - String getJndiPath(); - - void setJndiPath(String jndiPath); -} Index: jbossas-jmx-remoting/src/etc/default.mf =================================================================== --- jbossas-jmx-remoting/src/etc/default.mf (revision 102529) +++ jbossas-jmx-remoting/src/etc/default.mf (working copy) @@ -1,10 +0,0 @@ -Manifest-Version: 1.0 -Created-By: @java.vm.version@ (@java.vm.vendor@) -Specification-Title: @specification.title@ -Specification-Version: @specification.version@ -Specification-Vendor: @specification.vendor@ -Implementation-Title: @implementation.title@ -Implementation-URL: @implementation.url@ -Implementation-Version: @implementation.version@ -Implementation-Vendor: @implementation.vendor@ -Implementation-Vendor-Id: @implementation.vendor.id@ \ No newline at end of file Index: jbossas-jmx-remoting/src/etc/jboss-scanning.xml =================================================================== --- jbossas-jmx-remoting/src/etc/jboss-scanning.xml (revision 102529) +++ jbossas-jmx-remoting/src/etc/jboss-scanning.xml (working copy) @@ -1,3 +0,0 @@ - - - Index: jbossas-jmx-remoting/src/etc/jboss-service.xml =================================================================== --- jbossas-jmx-remoting/src/etc/jboss-service.xml (revision 102529) +++ jbossas-jmx-remoting/src/etc/jboss-service.xml (working copy) @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - Index: jbossas-jmx-remoting/build.sh =================================================================== --- jbossas-jmx-remoting/build.sh (revision 102529) +++ jbossas-jmx-remoting/build.sh (working copy) @@ -1,175 +0,0 @@ -#!/bin/sh -### ====================================================================== ### -## ## -## This is the main entry point for the build system. ## -## ## -## Users should execute this file rather than 'mvn' to ensure ## -## the correct version is being used with the correct configuration. ## -## ## -### ====================================================================== ### - -# $Id$ - -PROGNAME=`basename $0` -DIRNAME=`dirname $0` -GREP="grep" -ROOT="/" - -# Ignore user's MAVEN_HOME if it is set -MAVEN_HOME="" - -# the default search path for maven -MAVEN_SEARCH_PATH="\ - tools - tools/maven \ - tools/apache/maven \ - maven" - -# the default arguments -MVN_OPTIONS="" - -# Use the maximum available, or set MAX_FD != -1 to use that -MAX_FD="maximum" - -# OS specific support (must be 'true' or 'false'). -cygwin=false; -darwin=false; -case "`uname`" in - CYGWIN*) - cygwin=true - ;; - - Darwin*) - darwin=true - ;; -esac - -# -# Helper to complain. -# -die() { - echo "${PROGNAME}: $*" - exit 1 -} - -# -# Helper to complain. -# -warn() { - echo "${PROGNAME}: $*" -} - -# -# Helper to source a file if it exists. -# -maybe_source() { - for file in $*; do - if [ -f "$file" ]; then - . $file - fi - done -} - -search() { - search="$*" - for d in $search; do - MAVEN_HOME="`pwd`/$d" - MVN="$MAVEN_HOME/bin/mvn" - if [ -x "$MVN" ]; then - # found one - echo $MAVEN_HOME - break - fi - done -} - -# -# Main function. -# -main() { - # if there is a build config file. then source it - maybe_source "$DIRNAME/build.conf" "$HOME/.build.conf" - - # Increase the maximum file descriptors if we can - if [ $cygwin = "false" ]; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ]; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ]; then - # use the system max - MAX_FD="$MAX_FD_LIMIT" - fi - - ulimit -n $MAX_FD - if [ $? -ne 0 ]; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query system maximum file descriptor limit: $MAX_FD_LIMIT" - fi - fi - - # try the search path - MAVEN_HOME=`search $MAVEN_SEARCH_PATH` - - # try looking up to root - if [ "x$MAVEN_HOME" = "x" ]; then - target="build" - _cwd=`pwd` - - while [ "x$MAVEN_HOME" = "x" ] && [ "$cwd" != "$ROOT" ]; do - cd .. - cwd=`pwd` - MAVEN_HOME=`search $MAVEN_SEARCH_PATH` - done - - # make sure we get back - cd $_cwd - - if [ "$cwd" != "$ROOT" ]; then - found="true" - fi - - # complain if we did not find anything - if [ "$found" != "true" ]; then - die "Could not locate Maven; check \$MVN or \$MAVEN_HOME." - fi - fi - - # make sure we have one - MVN=$MAVEN_HOME/bin/mvn - if [ ! -x "$MVN" ]; then - die "Maven file is not executable: $MVN" - fi - - # need to specify planet57/buildmagic protocol handler package - MVN_OPTS="-Djava.protocol.handler.pkgs=org.jboss.net.protocol" - - # setup some build properties - MVN_OPTS="$MVN_OPTS -Dbuild.script=$0" - - # change to the directory where the script lives so users are not forced - # to be in the same directory as build.xml - cd $DIRNAME - - MVN_GOAL=$@ - if [ -z "$MVN_GOAL" ]; then - MVN_GOAL="install" - fi - - # export some stuff for maven - export MVN MAVEN_HOME MVN_OPTS MVN_GOAL - - - # execute in debug mode, or simply execute - if [ "x$MVN_DEBUG" != "x" ]; then - /bin/sh -x $MVN $MVN_OPTIONS $MVN_GOAL - else - exec $MVN $MVN_OPTIONS $MVN_GOAL - fi -} - -## -## Bootstrap -## - -main "$@" Index: jbossas-jmx-remoting/pom.xml =================================================================== --- jbossas-jmx-remoting/pom.xml (revision 102529) +++ jbossas-jmx-remoting/pom.xml (working copy) @@ -1,81 +0,0 @@ - - - org.jboss.jbossas - jboss-as-parent - 6.0.0-SNAPSHOT - - 4.0.0 - org.jboss.jbossas - jboss-as-jbossas-jmx-remoting - jar - JBoss Application Server JBossAS JMX Remoting - http://www.jboss.com/products/jbossas - JBoss Application Server (jbossas-jmx-remoting module) - - - ${project.artifactId} - - - src/resources - - - - - org.apache.maven.plugins - maven-antrun-plugin - - - create-output - - run - - package - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - org.jboss.mx - jboss-j2se - - - org.jboss.logging - jboss-logging-spi - - - junit - junit - test - - - - Index: jbossas-jmx-remoting/.cvsignore =================================================================== --- jbossas-jmx-remoting/.cvsignore (revision 102529) +++ jbossas-jmx-remoting/.cvsignore (working copy) @@ -1 +0,0 @@ -output Index: system/src/main/java/org/jboss/system/server/jmx/JMXConnector.java =================================================================== --- system/src/main/java/org/jboss/system/server/jmx/JMXConnector.java (revision 0) +++ system/src/main/java/org/jboss/system/server/jmx/JMXConnector.java (revision 0) @@ -0,0 +1,121 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2010, Red Hat Middleware LLC, and individual contributors + * as indicated by the @author tags. See the copyright.txt file 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.system.server.jmx; + +import org.jboss.logging.Logger; + +import javax.management.MBeanServer; +import javax.management.remote.JMXServiceURL; +import javax.management.remote.rmi.RMIConnectorServer; +import javax.management.remote.rmi.RMIJRMPServerImpl; +import java.lang.management.ManagementFactory; +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; +import java.util.HashMap; + +/** + * setup JSR-160 JMXConnector + * @author Scott Marlow smarlow@redhat.com + * + */ +public class JMXConnector { + + /* start of configurable settings */ + private int rmiRegistryPort=8099; // create a RMI registry at this port + private int rmiServerPort=8100; // create the RMI rmiServer object at this port + private String hostname= "localhost"; + private MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); + /* end of configurable settings */ + private RMIConnectorServer adapter; + private RMIJRMPServerImpl rmiServer; + private Registry registry; + private String securityDomain; + private static final Logger log = Logger.getLogger(JMXConnector.class); + + public JMXConnector() { + + } + + public String getSecurityDomain() { + return securityDomain; + } + + public void setSecurityDomain(String securityDomain) { + this.securityDomain = securityDomain; + } + + public MBeanServer getMbeanServer() { + return mbeanServer; + } + + public void setMbeanServer(MBeanServer mbeanServer) { + this.mbeanServer = mbeanServer; + } + + public int getRmiRegistryPort() { + return rmiRegistryPort; + } + + public void setRmiRegistryPort(int rmiRegistryPort) { + this.rmiRegistryPort = rmiRegistryPort; + } + + public int getRmiServerPort() { + return rmiServerPort; + } + + public void setRmiServerPort(int rmiServerPort) { + this.rmiServerPort = rmiServerPort; + } + + public String getHostname() { + return hostname; + } + + public void setHostname(String hostname) { + this.hostname = hostname; + } + + public void start() throws Exception { + rmiServer = new RMIJRMPServerImpl(rmiServerPort, null, null, new HashMap()); + registry = LocateRegistry.createRegistry(rmiRegistryPort); + + JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://" + hostname); + HashMap env = new HashMap(); + + adapter = new RMIConnectorServer(url, env, rmiServer, mbeanServer); + adapter.start(); + + url = adapter.getAddress(); + registry.bind("jmxrmi", rmiServer.toStub()); + + if(log.isInfoEnabled()) { + log.info("started JMXConnector (" + url.toString() + ")"); + } + } + + public void stop() throws Exception { + registry.unbind("jmxrmi"); + adapter.stop(); + } + +} Index: pom.xml =================================================================== --- pom.xml (revision 102529) +++ pom.xml (working copy) @@ -339,11 +339,6 @@ org.jboss.jbossas - jboss-as-jbossas-jmx-remoting - ${project.version} - - - org.jboss.jbossas jboss-as-jbossas-remoting ${project.version} @@ -561,7 +556,6 @@ server deployment jbossas-remoting - jbossas-jmx-remoting hornetq-int cluster varia Index: server/src/etc/deploy/jmx-jboss-beans.xml =================================================================== --- server/src/etc/deploy/jmx-jboss-beans.xml (revision 0) +++ server/src/etc/deploy/jmx-jboss-beans.xml (revision 0) @@ -0,0 +1,33 @@ + + + + + + + + + + localhost + + + 8099 + + + 8100 + + + + + + + Index: build/pom.xml =================================================================== --- build/pom.xml (revision 102529) +++ build/pom.xml (working copy) @@ -136,11 +136,6 @@ org.jboss.jbossas - jboss-as-jbossas-jmx-remoting - true - - - org.jboss.jbossas jboss-as-jbossas-remoting true Index: build/build.xml =================================================================== --- build/build.xml (revision 102529) +++ build/build.xml (working copy) @@ -184,7 +184,6 @@ module-server, module-deployment, module-jbossas-remoting, - module-jbossas-jmx-remoting, module-cluster, module-varia, module-iiop, @@ -608,31 +607,7 @@ - - - - - - - - - - - - - - - - - - - - - - - Index: console/src/main/java/org/jboss/console/twiddle/Twiddle.java =================================================================== --- console/src/main/java/org/jboss/console/twiddle/Twiddle.java (revision 102529) +++ console/src/main/java/org/jboss/console/twiddle/Twiddle.java (working copy) @@ -25,28 +25,22 @@ import gnu.getopt.LongOpt; import java.io.File; +import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.net.MalformedURLException; import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Properties; - +import java.util.*; import javax.management.MBeanServerConnection; -import javax.naming.Context; -import javax.naming.InitialContext; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXServiceURL; import javax.naming.NamingException; import org.jboss.console.twiddle.command.Command; import org.jboss.console.twiddle.command.CommandContext; import org.jboss.console.twiddle.command.CommandException; import org.jboss.console.twiddle.command.NoSuchCommandException; -import org.jboss.jmx.adaptor.rmi.RMIAdaptor; import org.jboss.logging.Logger; import org.jboss.security.SecurityAssociation; import org.jboss.security.SimplePrincipal; @@ -64,7 +58,12 @@ { public static final String PROGRAM_NAME = System.getProperty("program.name", "twiddle"); public static final String CMD_PROPERTIES = "/org/jboss/console/twiddle/commands.properties"; - public static final String DEFAULT_JNDI_NAME = "jmx/invoker/RMIAdaptor"; + public static final String DEFAULT_BASEURL = "service:jmx:rmi:///jndi/rmi://"; + public static final String DEFAULT_RMIOBJECTNAME = "/jmxrmi"; + public static final String DEFAULT_JMXSERVICEURL = "service:jmx:rmi:///jndi/rmi://localhost:8099/jmxrmi"; + public static final String DEFAULT_HOSTNAME = "localhost"; + public static final String DEFAULT_PORT ="8099"; + private static final Logger log = Logger.getLogger(Twiddle.class); // Command Line Support private static Twiddle twiddle = new Twiddle(new PrintWriter(System.out, true), @@ -78,10 +77,14 @@ private Map commandProtoMap = new HashMap(); private PrintWriter out; private PrintWriter err; - private String serverURL; - private String adapterName; + private String serverURL = buildJMXServiceUrl(); + private String hostname; + private String port; private boolean quiet; private MBeanServerConnection server; + private String username; + private String password; + private boolean verbose; public Twiddle(final PrintWriter out, final PrintWriter err) { @@ -89,16 +92,43 @@ this.err = err; } - public void setServerURL(final String url) + // build JMXServiceURL, should look like "service:jmx:rmi:///jndi/rmi://localhost:8099/jmxrmi"; + private String buildJMXServiceUrl() { - this.serverURL = url; + return + DEFAULT_BASEURL + + (hostname != null ? hostname : DEFAULT_HOSTNAME) + + ":" + + (port != null ? port : DEFAULT_PORT) + + DEFAULT_RMIOBJECTNAME; } - public void setAdapterName(final String name) + public void setHostname(String hostname) { - this.adapterName = name; + this.hostname = hostname; + setServerURL(buildJMXServiceUrl()); // use new hostname } + public void setPort(String port) + { + this.port = port; + setServerURL(buildJMXServiceUrl()); // use new port setting + } + + public void setVerbose( boolean verbose ) + { + this.verbose = verbose; + } + + public void setServerURL(final String url) + { + if (verbose) + { + log.info("replacing JMX service url (" + this.serverURL + ") with " + url); + } + this.serverURL = url; + } + public void setQuiet(final boolean flag) { this.quiet = flag; @@ -227,42 +257,21 @@ } private MBeanServerConnection createMBeanServerConnection() - throws NamingException + throws NamingException, IOException { - InitialContext ctx; - - if (serverURL == null) - { - ctx = new InitialContext(); - } - else - { - Hashtable props = new Hashtable(System.getProperties()); - props.put(Context.PROVIDER_URL, serverURL); - ctx = new InitialContext(props); - } - - // if adapter is null, the use the default - if (adapterName == null) - { - adapterName = DEFAULT_JNDI_NAME; - } - - Object obj = ctx.lookup(adapterName); - ctx.close(); - - if (!(obj instanceof RMIAdaptor)) - { - throw new ClassCastException - ("Object not of type: RMIAdaptorImpl, but: " + - (obj == null ? "not found" : obj.getClass().getName())); - } - - return (MBeanServerConnection) obj; + HashMap env = new HashMap(); + JMXServiceURL url = new JMXServiceURL(this.serverURL); + JMXConnector jmxc = JMXConnectorFactory.connect(url, env); + //Subject delegationSubject = + // new Subject(true, + // Collections.singleton(new JMXPrincipal("delegate")), + // Collections.EMPTY_SET, + // Collections.EMPTY_SET); + return jmxc.getMBeanServerConnection(SecurityAssociation.getSubject()); } private void connect() - throws NamingException + throws NamingException, IOException { if (server == null) { @@ -392,11 +401,15 @@ out.println(" -c=command.properties Specify the command.properties file to use"); out.println(" -D[=] Set a system property"); out.println(" -- Stop processing options"); - out.println(" -s, --server= The JNDI URL of the remote server"); - out.println(" -a, --adapter= The JNDI name of the RMI adapter to use"); + out.println(" -s, --server= The JMX service URL of the remote server (e.g. "+ DEFAULT_JMXSERVICEURL +") "); + out.println(" -o, --host= The name of the remote server (e.g. "+ DEFAULT_HOSTNAME +") "); + out.println(" -r, --port= The rmiRegistryPort of the remote server (e.g. "+ DEFAULT_PORT +") "); out.println(" -u, --user= Specify the username for authentication"); out.println(" -p, --password= Specify the password for authentication"); out.println(" -q, --quiet Be somewhat more quiet"); + out.println(" -v, --verbose Be noisy"); + out.println(); + out.println("for convenience, you can specify --host and --port but not with the --server= which overrides host + port. "); out.flush(); } @@ -407,7 +420,7 @@ if (!logPassword(args, a)) log.debug("args["+a+"]="+args[a]); } - String sopts = "-:hH:u:p:c:D:s:a:q"; + String sopts = "-:hH:u:p:c:D:s:a:q::v::o:r:"; LongOpt[] lopts = { new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h'), @@ -415,7 +428,10 @@ new LongOpt("server", LongOpt.REQUIRED_ARGUMENT, null, 's'), new LongOpt("adapter", LongOpt.REQUIRED_ARGUMENT, null, 'a'), new LongOpt("quiet", LongOpt.NO_ARGUMENT, null, 'q'), + new LongOpt("verbose", LongOpt.NO_ARGUMENT, null, 'v'), new LongOpt("user", LongOpt.REQUIRED_ARGUMENT, null, 'u'), + new LongOpt("host", LongOpt.REQUIRED_ARGUMENT, null, 'o'), + new LongOpt("port", LongOpt.REQUIRED_ARGUMENT, null, 'r'), new LongOpt("password", LongOpt.REQUIRED_ARGUMENT, null, 'p'), }; @@ -518,14 +534,25 @@ break; } + // host name + case 'o': + twiddle.setHostname(getopt.getOptarg()); + break; + + // host port + case 'r': + twiddle.setPort(getopt.getOptarg()); + break; + // Set the JNDI server URL case 's': twiddle.setServerURL(getopt.getOptarg()); break; - // Set the adapter JNDI name + // adapter JNDI name is not supported anymore case 'a': - twiddle.setAdapterName(getopt.getOptarg()); + String arg = getopt.getOptarg(); + log.info("adapter name is ignored " + arg); break; case 'u': String username = getopt.getOptarg(); @@ -536,6 +563,11 @@ SecurityAssociation.setCredential(password); break; + // be noisy + case 'v': + twiddle.setVerbose(true); + break; + // Enable quiet operations case 'q': twiddle.setQuiet(true); @@ -574,4 +606,5 @@ } return false; } + }