public static JmxMonitor getInstance() { if ( monitorInstance == null ) { monitorInstance = new JmxMonitor(); } return monitorInstance; }
public void registerMonitor(String name, String monitorType, Object monitoringInterface) throws MalformedObjectNameException, InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException { String monitorName = generateMonitorName(name, monitorType); log.info("Registering JMX {}", monitorName); ObjectName oName = new ObjectName(monitorName); // Check if the monitor is already registered if (mbs.isRegistered(oName)) { log.info("Monitor already registered: {}", oName); return; } mbs.registerMBean(monitoringInterface, oName); }
public AbstractCluster(String clusterName, CassandraHostConfigurator cassandraHostConfigurator, Map<String, String> credentials) { connectionManager = new HConnectionManager(clusterName, cassandraHostConfigurator); name = clusterName; configurator = cassandraHostConfigurator; failoverPolicy = FailoverPolicy.ON_FAIL_TRY_ALL_AVAILABLE; cassandraClientMonitor = JmxMonitor.getInstance().getCassandraMonitor(connectionManager); xtrans = new ExceptionsTranslatorImpl(); clockResolution = cassandraHostConfigurator.getClockResolution(); this.credentials = Collections.unmodifiableMap(credentials == null? EMPTY_CREDENTIALS : credentials); }
public void shutdown() { log.info("Shutdown called on HConnectionManager"); if ( cassandraHostRetryService != null ) cassandraHostRetryService.shutdown(); if ( nodeAutoDiscoverService != null ) nodeAutoDiscoverService.shutdown(); if ( hostTimeoutTracker != null ) hostTimeoutTracker.shutdown(); JmxMonitor.getInstance().removeCassandraMonitor(this); for (HClientPool pool : hostPools.values()) { try { pool.shutdown(); } catch (IllegalArgumentException iae) { log.error("Out of order in HConnectionManager shutdown()?: {}", iae.getMessage()); } } }
/** * Generates a unique, but still nice and predictable name representing this classloader so that * even apps operating under a web server such as tomcat with multiple classloaders would bee able * to register each with its own unique mbean. */ private String getUniqueClassloaderIdentifier() { String contextPath = getContextPath(); if (contextPath != null) { return contextPath; } return "hector"; }
private String generateMonitorName(String className, String monitorType) { StringBuilder sb = new StringBuilder(); sb.append(className); sb.append(":ServiceType="); // append the classloader name so we have unique names in web apps. sb.append(getUniqueClassloaderIdentifier()); if (null != monitorType && monitorType.length() > 0) { sb.append(",MonitorType=" + monitorType); } return sb.toString(); }
public CassandraClientMonitor getCassandraMonitor(HConnectionManager connectionManager) { CassandraClientMonitor cassandraClientMonitor = monitors.get(connectionManager.getClusterName()); if ( cassandraClientMonitor == null ) { try { cassandraClientMonitor = new CassandraClientMonitor(connectionManager); registerMonitor("me.prettyprint.cassandra.service_"+connectionManager.getClusterName(), "hector", cassandraClientMonitor); monitors.put(connectionManager.getClusterName(), cassandraClientMonitor); } catch (MalformedObjectNameException e) { log.error("Unable to register JMX monitor", e); } catch (InstanceAlreadyExistsException e) { log.error("Unable to register JMX monitor", e); } catch (MBeanRegistrationException e) { log.error("Unable to register JMX monitor", e); } catch (NotCompliantMBeanException e) { log.error("Unable to register JMX monitor", e); } } return cassandraClientMonitor; }
public void removeCassandraMonitor(HConnectionManager connectionManager) { CassandraClientMonitor cassandraClientMonitor = monitors.remove(connectionManager.getClusterName()); if(cassandraClientMonitor != null) { try { unregisterMonitor("me.prettyprint.cassandra.service_"+connectionManager.getClusterName(), "hector"); } catch(MalformedObjectNameException e) { log.error("Unable to unregister JMX monitor", e); } catch(InstanceAlreadyExistsException e) { log.error("Unable to unregister JMX monitor", e); } catch(MBeanRegistrationException e) { log.error("Unable to unregister JMX monitor", e); } catch(NotCompliantMBeanException e) { log.error("Unable to unregister JMX monitor", e); } } } }
public void shutdown() { log.info("Shutdown called on HConnectionManager"); if ( cassandraHostRetryService != null ) cassandraHostRetryService.shutdown(); if ( nodeAutoDiscoverService != null ) nodeAutoDiscoverService.shutdown(); if ( hostTimeoutTracker != null ) hostTimeoutTracker.shutdown(); JmxMonitor.getInstance().removeCassandraMonitor(this); for (HClientPool pool : hostPools.values()) { try { pool.shutdown(); } catch (IllegalArgumentException iae) { log.error("Out of order in HConnectionManager shutdown()?: {}", iae.getMessage()); } } }
/** * Generates a unique, but still nice and predictable name representing this classloader so that * even apps operating under a web server such as tomcat with multiple classloaders would bee able * to register each with its own unique mbean. */ private String getUniqueClassloaderIdentifier() { String contextPath = getContextPath(); if (contextPath != null) { return contextPath; } return "hector"; }
private String generateMonitorName(String className, String monitorType) { StringBuilder sb = new StringBuilder(); sb.append(className); sb.append(":ServiceType="); // append the classloader name so we have unique names in web apps. sb.append(getUniqueClassloaderIdentifier()); if (null != monitorType && monitorType.length() > 0) { sb.append(",MonitorType=" + monitorType); } return sb.toString(); }
public CassandraClientMonitor getCassandraMonitor(HConnectionManager connectionManager) { CassandraClientMonitor cassandraClientMonitor = monitors.get(connectionManager.getClusterName()); if ( cassandraClientMonitor == null ) { try { cassandraClientMonitor = new CassandraClientMonitor(connectionManager); registerMonitor("me.prettyprint.cassandra.service_"+connectionManager.getClusterName(), "hector", cassandraClientMonitor); monitors.put(connectionManager.getClusterName(), cassandraClientMonitor); } catch (MalformedObjectNameException e) { log.error("Unable to register JMX monitor", e); } catch (InstanceAlreadyExistsException e) { log.error("Unable to register JMX monitor", e); } catch (MBeanRegistrationException e) { log.error("Unable to register JMX monitor", e); } catch (NotCompliantMBeanException e) { log.error("Unable to register JMX monitor", e); } } return cassandraClientMonitor; }
public void removeCassandraMonitor(HConnectionManager connectionManager) { CassandraClientMonitor cassandraClientMonitor = monitors.remove(connectionManager.getClusterName()); if(cassandraClientMonitor != null) { try { unregisterMonitor("me.prettyprint.cassandra.service_"+connectionManager.getClusterName(), "hector"); } catch(MalformedObjectNameException e) { log.error("Unable to unregister JMX monitor", e); } catch(InstanceAlreadyExistsException e) { log.error("Unable to unregister JMX monitor", e); } catch(MBeanRegistrationException e) { log.error("Unable to unregister JMX monitor", e); } catch(NotCompliantMBeanException e) { log.error("Unable to unregister JMX monitor", e); } } } }
cassandraHostRetryService = new CassandraHostRetryService(this, clientFactory, cassandraHostConfigurator, listenerHandler); monitor = JmxMonitor.getInstance().getCassandraMonitor(this); for ( CassandraHost host : cassandraHostConfigurator.buildCassandraHosts()) { try {
public void unregisterMonitor(String name, String monitorType) throws MalformedObjectNameException, InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException { String monitorName = generateMonitorName(name, monitorType); log.info("Unregistering JMX {}", monitorName); ObjectName oName = new ObjectName(monitorName); // Check if the monitor is already registered if (!mbs.isRegistered(oName)) { log.info("Monitor is not registered: {}", oName); return; } try { mbs.unregisterMBean(oName); } catch(InstanceNotFoundException e) { log.warn("Failed to unregister monitor: {}" + oName.toString(), e); } }
public static JmxMonitor getInstance() { if ( monitorInstance == null ) { monitorInstance = new JmxMonitor(); } return monitorInstance; }
/** * Generates a unique, but still nice and predictable name representing this classloader so that * even apps operating under a web server such as tomcat with multiple classloaders would bee able * to register each with its own unique mbean. */ private String getUniqueClassloaderIdentifier() { String contextPath = getContextPath(); if (contextPath != null) { return contextPath; } return "hector"; }
private String generateMonitorName(String className, String monitorType) { StringBuilder sb = new StringBuilder(); sb.append(className); sb.append(":ServiceType="); // append the classloader name so we have unique names in web apps. sb.append(getUniqueClassloaderIdentifier()); if (null != monitorType && monitorType.length() > 0) { sb.append(",MonitorType=" + monitorType); } return sb.toString(); }
public CassandraClientMonitor getCassandraMonitor(HConnectionManager connectionManager) { CassandraClientMonitor cassandraClientMonitor = monitors.get(connectionManager.getClusterName()); if ( cassandraClientMonitor == null ) { try { cassandraClientMonitor = new CassandraClientMonitor(connectionManager); registerMonitor("me.prettyprint.cassandra.service_"+connectionManager.getClusterName(), "hector", cassandraClientMonitor); monitors.put(connectionManager.getClusterName(), cassandraClientMonitor); } catch (MalformedObjectNameException e) { log.error("Unable to register JMX monitor", e); } catch (InstanceAlreadyExistsException e) { log.error("Unable to register JMX monitor", e); } catch (MBeanRegistrationException e) { log.error("Unable to register JMX monitor", e); } catch (NotCompliantMBeanException e) { log.error("Unable to register JMX monitor", e); } } return cassandraClientMonitor; }
public AbstractCluster(String clusterName, CassandraHostConfigurator cassandraHostConfigurator, Map<String, String> credentials) { connectionManager = new HConnectionManager(clusterName, cassandraHostConfigurator); name = clusterName; configurator = cassandraHostConfigurator; failoverPolicy = FailoverPolicy.ON_FAIL_TRY_ALL_AVAILABLE; cassandraClientMonitor = JmxMonitor.getInstance().getCassandraMonitor(connectionManager); xtrans = new ExceptionsTranslatorImpl(); clockResolution = cassandraHostConfigurator.getClockResolution(); this.credentials = Collections.unmodifiableMap(credentials == null? EMPTY_CREDENTIALS : credentials); }