this.connector = JMXConnectorFactory.connect(url, env); this.mbsc = connector.getMBeanServerConnection(); this.connector.addConnectionNotificationListener(new JMXConnectionListener(this), null, null); this.distributedSystemMXBeanProxy = JMX.newMXBeanProxy(mbsc, MBeanJMXAdapter.getDistributedSystemName(), DistributedSystemMXBean.class);
@Override public void addConnectionNotificationListener(NotificationListener listener, NotificationFilter filter, Object data) { m_connectorProxy.addConnectionNotificationListener(listener, filter, data); }
@Override public void addConnectionNotificationListener(NotificationListener listener, NotificationFilter filter, Object data) { m_connectorProxy.addConnectionNotificationListener(listener, filter, data); }
@Override public void addConnectionNotificationListener(NotificationListener listener, NotificationFilter filter, Object data) { m_connectorProxy.addConnectionNotificationListener(listener, filter, data); }
public void connect() throws Exception { this.jmxUrl = new JMXServiceURL("rmi", "", 0, this.urlPath); String[] userCred = new String[] { userName, password }; HashMap<String, Object> env = new HashMap<String, Object>(); env.put(JMXConnector.CREDENTIALS, userCred); jmxc = JMXConnectorFactory.newJMXConnector(jmxUrl, env); jmxc.addConnectionNotificationListener(this, null, null); jmxc.connect(); }
private JMXConnector createConnector(String serverUrl) throws IOException { JMXServiceURL jmxServerUrl = null; JMXConnector jmxConnector = null; jmxServerUrl = new JMXServiceURL(serverUrl); jmxConnector = JMXConnectorFactory.connect(jmxServerUrl); NotificationListener listener = new MyNotificationListener(); jmxConnector.addConnectionNotificationListener(listener, null, new JmxConnectorDisabler(serverUrl)); return jmxConnector; }
public void connect() throws Exception { this.jmxUrl = new JMXServiceURL("rmi", "", 0, this.urlPath); String[] userCred = new String[] { userName, password }; HashMap<String, Object> env = new HashMap<String, Object>(); env.put(JMXConnector.CREDENTIALS, userCred); jmxc = JMXConnectorFactory.newJMXConnector(jmxUrl, env); jmxc.addConnectionNotificationListener(this, null, null); jmxc.connect(); }
private void registerNotificationListeners(final ObjectName objectName, final MBeanServerConnection mBeanServerConnection, final JMXConnector jmxConnector) throws InstanceNotFoundException, IOException { for (JobMonitoringListener notificationListener : notificationListeners) { mBeanServerConnection.addNotificationListener(objectName, notificationListener, null, null); jmxConnector.addConnectionNotificationListener(notificationListener, new ConnectionClosedNotificationFilter(), null); jmxConnector.addConnectionNotificationListener(notificationListener, new ConnectionOpenedNotificationFilter(), null); } }
/** * Initialize the JMX client to listen to notification sent by CB4J monitor. * @param notificationListener the listener for report updates * @param connectionClosedNotificationListener the listener for JMX connection-closed event * @throws Exception thrown if an exception occurs during client initialization */ public void init(NotificationListener notificationListener, NotificationListener connectionClosedNotificationListener) throws Exception { JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi"); JMXConnector jmxc = JMXConnectorFactory.connect(url, null); MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); ObjectName mbeanName = new ObjectName("io.github.benas.cb4j.jmx:type=BatchMonitorMBean"); mbsc.addNotificationListener(mbeanName, notificationListener, null, null); if (connectionClosedNotificationListener != null) { jmxc.addConnectionNotificationListener(connectionClosedNotificationListener, new ConnectionClosedNotificationFilter(), null); } }
/** * Initializes a network connection to the configured JMX server and registers a connection * notification listener to to receive notifications of connection loss */ private void initNetworkConnection() throws IOException { if (mConnector != null) { try { mConnector.close(); } catch (Exception e) { // ignore, as this is best effort } } JMXServiceURL url = new JMXServiceURL(mJmxEndpoint.getServerURL()); String[] creds = {mJmxEndpoint.getUser(), mJmxEndpoint.getPassword()}; Map<String, String[]> map = Collections.singletonMap(JMXConnector.CREDENTIALS, creds); mConnector = JMXConnectorFactory.connect(url, map); mConnector.addConnectionNotificationListener(getConnectionNotificationListener(), null, null); mConnectionId = mConnector.getConnectionId(); setServerConnection(mConnector.getMBeanServerConnection()); }
private JMXConnector connect(final InetSocketAddress endpoint) throws Exception { JMXConnector cachedConnector = connectors.get(endpoint); if (cachedConnector != null) { return cachedConnector; } JMXServiceURL serviceURL = new JMXServiceURL(String.format(this.serviceUrlTemplate, endpoint.getHostName(), endpoint.getPort())); JMXConnector newConnector = JMXConnectorFactory.newJMXConnector(serviceURL, null); try { newConnector.connect(); } catch (Exception e) { newConnector.close(); throw e; } if (log.isTraceEnabled()) { log.trace("created new connector " + newConnector + " to " + endpoint); } JMXConnector oldConnector = connectors.putIfAbsent(endpoint, newConnector); if (oldConnector != null) { newConnector.close(); cachedConnector = oldConnector; } else { NotificationFilterSupport closedFilter = new NotificationFilterSupport(); closedFilter.enableType(JMXConnectionNotification.CLOSED); newConnector.addConnectionNotificationListener(this, closedFilter, endpoint); cachedConnector = newConnector; } return cachedConnector; }
try jmxc.addConnectionNotificationListener(monitor, null, null); ssProxy.addNotificationListener(monitor, null, null); if (ssProxy.resumeBootstrap())
public void repairAsync(final PrintStream out, final String keyspace, Map<String, String> options) throws IOException { RepairRunner runner = new RepairRunner(out, ssProxy, keyspace, options); try { jmxc.addConnectionNotificationListener(runner, null, null); ssProxy.addNotificationListener(runner, null, null); runner.run(); } catch (Exception e) { throw new IOException(e) ; } finally { try { ssProxy.removeNotificationListener(runner); jmxc.removeConnectionNotificationListener(runner); } catch (Throwable e) { out.println("Exception occurred during clean-up. " + e); } } }
try jmxc.addConnectionNotificationListener(monitor, null, null); ssProxy.addNotificationListener(monitor, null, null); if (ssProxy.resumeBootstrap())
private static JMXConnector getConnection(JMConnBean conn) { try { Map<String, String[]> map = new HashMap<String, String[]>(); if (conn.getUser() != null && conn.getPwd() != null) { map.put(JMXConnector.CREDENTIALS, new String[] { conn.getUser(), conn.getPwd() }); } String jmxURL = "service:jmx:rmi:///jndi/rmi://" + conn.getHost() + ":" + conn.getPort() + "/jmxrmi"; JMXConnector connector = JMXConnectorFactory.newJMXConnector(new JMXServiceURL(jmxURL), map); connector.addConnectionNotificationListener(INSTANCE, null, conn.getName()); connector.connect(); return connector; } catch (Exception e) { throw new RuntimeException(e); } }
public void repairAsync(final PrintStream out, final String keyspace, Map<String, String> options) throws IOException { RepairRunner runner = new RepairRunner(out, ssProxy, keyspace, options); try { jmxc.addConnectionNotificationListener(runner, null, null); ssProxy.addNotificationListener(runner, null, null); runner.run(); } catch (Exception e) { throw new IOException(e) ; } finally { try { ssProxy.removeNotificationListener(runner); jmxc.removeConnectionNotificationListener(runner); } catch (Throwable e) { out.println("Exception occurred during clean-up. " + e); } } }
public void forceRepairRangeAsync(final PrintStream out, final String keyspaceName, RepairParallelism parallelismDegree, Collection<String> dataCenters, final Collection<String> hosts, final String startToken, final String endToken, boolean fullRepair, String... columnFamilies) throws IOException { RepairRunner runner = new RepairRunner(out, keyspaceName, columnFamilies); try { jmxc.addConnectionNotificationListener(runner, null, null); ssProxy.addNotificationListener(runner, null, null); if (!runner.repairRangeAndWait(ssProxy, parallelismDegree, dataCenters, hosts, startToken, endToken, fullRepair)) failed = true; } catch (Exception e) { throw new IOException(e) ; } finally { try { ssProxy.removeNotificationListener(runner); jmxc.removeConnectionNotificationListener(runner); } catch (Throwable e) { out.println("Exception occurred during clean-up. " + e); } } }
public void repairAsync(final PrintStream out, final String keyspace, Map<String, String> options) throws IOException { RepairRunner runner = new RepairRunner(out, ssProxy, keyspace, options); try { jmxc.addConnectionNotificationListener(runner, null, null); ssProxy.addNotificationListener(runner, null, null); runner.run(); } catch (Exception e) { throw new IOException(e) ; } finally { try { ssProxy.removeNotificationListener(runner); jmxc.removeConnectionNotificationListener(runner); } catch (Throwable e) { out.println("Exception occurred during clean-up. " + e); } } }
try jmxc.addConnectionNotificationListener(monitor, null, null); ssProxy.addNotificationListener(monitor, null, null); if (ssProxy.resumeBootstrap())
public void forceRepairAsync(final PrintStream out, final String keyspaceName, RepairParallelism parallelismDegree, Collection<String> dataCenters, final Collection<String> hosts, boolean primaryRange, boolean fullRepair, String... columnFamilies) throws IOException { RepairRunner runner = new RepairRunner(out, keyspaceName, columnFamilies); try { jmxc.addConnectionNotificationListener(runner, null, null); ssProxy.addNotificationListener(runner, null, null); if (!runner.repairAndWait(ssProxy, parallelismDegree, dataCenters, hosts, primaryRange, fullRepair)) failed = true; } catch (Exception e) { throw new IOException(e) ; } finally { try { ssProxy.removeNotificationListener(runner); jmxc.removeConnectionNotificationListener(runner); } catch (Throwable t) { JVMStabilityInspector.inspectThrowable(t); out.println("Exception occurred during clean-up. " + t); } } }