Example usage for javax.management.remote JMXConnector close

List of usage examples for javax.management.remote JMXConnector close

Introduction

In this page you can find the example usage for javax.management.remote JMXConnector close.

Prototype

public void close() throws IOException;

Source Link

Document

Closes the client connection to its server.

Usage

From source file:dk.netarkivet.common.utils.JMXUtils.java

/** Get the value of an attribute, closing the connector afterwards.  If you
 * wish to hold on to the connector, call
 * JMXUtils#executeCommand(MBeanServerConnection, String, String, String[])
 *
 * @param connector A one-shot connector object.
 * @param beanName The name of the bean to get an attribute from.
 * @param attribute The attribute to get.
 * @return Whatever the command returned.
 *///from w ww  .  ja va 2s .  co  m
public static Object getAttribute(JMXConnector connector, String beanName, String attribute) {
    ArgumentNotValid.checkNotNull(connector, "JMXConnector connector");
    ArgumentNotValid.checkNotNullOrEmpty(beanName, "String beanName");
    ArgumentNotValid.checkNotNullOrEmpty(attribute, "String attribute");

    MBeanServerConnection connection;
    try {
        connection = connector.getMBeanServerConnection();
    } catch (IOException e) {
        throw new IOFailure("Failure getting JMX connection", e);
    }
    try {
        return getAttribute(beanName, attribute, connection);
    } finally {
        try {
            connector.close();
        } catch (IOException e) {
            log.warn("Couldn't close connection to " + beanName, e);
        }
    }
}

From source file:dk.netarkivet.common.utils.JMXUtils.java

/** Execute a single command, closing the connector afterwards.  If you
 * wish to hold on to the connector, call
 * JMXUtils#executeCommand(MBeanServerConnection, String, String, String[])
 *
 * @param connector A one-shot connector object.
 * @param beanName The name of the bean to execute a command on.
 * @param command The command to execute.
 * @param arguments The arguments to the command (all strings)
 * @return Whatever the command returned.
 *//*from  w w  w  .  j a  v a  2  s . c o  m*/
public static Object executeCommand(JMXConnector connector, String beanName, String command,
        String... arguments) {
    ArgumentNotValid.checkNotNull(connector, "JMXConnector connector");
    ArgumentNotValid.checkNotNullOrEmpty(beanName, "String beanName");
    ArgumentNotValid.checkNotNullOrEmpty(command, "String command");
    ArgumentNotValid.checkNotNull(arguments, "String... arguments");

    MBeanServerConnection connection;
    try {
        connection = connector.getMBeanServerConnection();
    } catch (IOException e) {
        throw new IOFailure("Failure getting JMX connection", e);
    }
    try {
        return executeCommand(connection, beanName, command, arguments);
    } finally {
        try {
            connector.close();
        } catch (IOException e) {
            log.warn("Couldn't close connection to " + beanName, e);
        }
    }
}

From source file:com.lmig.cf.metrics.opsmetrics.OpsMetrics.java

private void close(JMXConnector connector) {
    if (connector != null) {
        try {//from w  w w  .  ja  v  a 2  s. com
            connector.close();
        } catch (IOException e) {
        }
    }
}

From source file:com.xoriant.jmx.pool.JmxPoolFactory.java

/**
 * This method will destroy the JMX connection. 
 */// w  w w. j  av a  2 s  . c  om
@Override
public void destroyObject(PooledObject<Q> jmxPooledObject) throws Exception {
    JMXConnector jMXConnector = ((JMXConnector) (jmxPooledObject.getObject()));
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("In destroyObject : jMXConnector " + jMXConnector.getConnectionId());
    }
    jMXConnector.close();
}

From source file:com.adaptris.core.services.jmx.JmxOperationInvoker.java

public Object invoke(String serviceUrl, String objectName, String username, String password, String methodName,
        Object[] params, String[] signatures) throws Exception {
    Map<String, String[]> env = new HashMap<>();
    if ((!StringUtils.isEmpty(username)) && (!StringUtils.isEmpty(password))) {
        String[] credentials = { username, Password.decode(password) };
        env.put(JMXConnector.CREDENTIALS, credentials);
    }//from w w  w .  jav a  2s . co m
    JMXServiceURL jmxServiceUrl = new JMXServiceURL(serviceUrl);
    JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxServiceUrl, env);
    ObjectName objectNameInst = ObjectName.getInstance(objectName);
    MBeanServerConnection mbeanConn = jmxConnector.getMBeanServerConnection();
    try {
        return mbeanConn.invoke(objectNameInst, methodName, params, signatures);
    } finally {
        jmxConnector.close();

    }
}

From source file:org.apache.hadoop.hbase.TestJMXListener.java

@Test
public void testStart() throws Exception {
    JMXConnector connector = JMXConnectorFactory
            .connect(JMXListener.buildJMXServiceURL(connectorPort, connectorPort));

    MBeanServerConnection mb = connector.getMBeanServerConnection();
    String domain = mb.getDefaultDomain();
    Assert.assertTrue("default domain is not correct", !domain.isEmpty());
    connector.close();

}

From source file:org.eclipse.virgo.ide.runtime.internal.core.command.AbstractJmxServerCommand.java

protected final Object execute(final JmxServerCommandTemplate template) throws TimeoutException {

    Callable<Object> deployOperation = new Callable<Object>() {

        public Object call() throws Exception {
            JMXConnector connector = null;
            try {
                connector = getJmxConnector();
                return template.invokeOperation(connector.getMBeanServerConnection());
            } finally {
                if (connector != null) {
                    try {
                        connector.close();
                    } catch (IOException e) {
                        SpringCore.log(e);
                    }//  w w  w .  j  a  v a  2s .c om
                }
            }
        }
    };

    FutureTask<Object> task = new FutureTask<Object>(deployOperation);
    ServerCorePlugin.EXECUTOR.submit(task);

    try {
        return task.get(30, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        // swallow exception here
    } catch (ExecutionException e) {
        // swallow exception here
    }

    return null;
}

From source file:com.springsource.hq.plugin.tcserver.plugin.wrapper.MxUtilJmxUtils.java

public boolean checkConnection(ConfigResponse config) {
    JMXConnector jmxConnector = null;

    try {/* ww  w .  j a va 2s  .c o  m*/
        jmxConnector = MxUtil.getMBeanConnector(config.toProperties());
        return true;
    } catch (IOException ioe) {
        log.warn("Connection check failed", ioe);
        return false;
    } finally {
        if (jmxConnector != null) {
            try {
                jmxConnector.close();
            } catch (IOException ioe) {
                log.warn("Failed to close connection following check", ioe);
            }
        }
    }
}

From source file:org.jumpmind.symmetric.JmxCommand.java

protected <T> T execute(IJmxTemplate<T> template) throws Exception {
    String host = "localhost";
    String url = "service:jmx:rmi:///jndi/rmi://" + host + ":" + System.getProperty("jmx.agent.port", "31418")
            + "/jmxrmi";
    JMXServiceURL serviceUrl = new JMXServiceURL(url);
    JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceUrl, null);
    TypedProperties properties = getTypedProperties();
    String engineName = properties.get(ParameterConstants.ENGINE_NAME, "unknown");
    try {//  w  w  w  .  j ava  2 s .c o  m
        MBeanServerConnection mbeanConn = jmxConnector.getMBeanServerConnection();
        return template.execute(engineName, mbeanConn);
    } finally {
        jmxConnector.close();
    }
}

From source file:net.nicoll.boot.daemon.SpringBootService.java

public void stop(String[] args) throws IOException {
    System.out.println("Stopping Spring Boot application...");
    int jmxPort = Integer.parseInt(args[0]);
    String jmxName = SpringApplicationAdminClient.DEFAULT_OBJECT_NAME;
    JMXConnector connector = SpringApplicationAdminClient.connect(jmxPort);
    try {/*from  w ww  . ja v a2  s  . c  o  m*/
        MBeanServerConnection connection = connector.getMBeanServerConnection();
        try {
            new SpringApplicationAdminClient(connection, jmxName).stop();
        } catch (InstanceNotFoundException ex) {
            throw new IllegalStateException("Spring application lifecycle JMX bean not "
                    + "found, could not stop application gracefully", ex);
        }
    } finally {
        connector.close();
    }
}