de.is24.util.monitoring.jmx
Class InApplicationMonitorJMXConnector

java.lang.Object
  extended by de.is24.util.monitoring.jmx.InApplicationMonitorJMXConnector
All Implemented Interfaces:
ReportableObserver, DynamicMBean

public final class InApplicationMonitorJMXConnector
extends Object
implements DynamicMBean, ReportableObserver

This class publishes values registered at the InApplicationMonitor as JMX MBeans. Simple values (Counter, Version, StateValue) are published directly via this class as dynamic MBean, complex types are published using an own MBean for each Reportable.

Author:
ptraeder

Field Summary
private static String ACTIVATE
           
private static String ADD_STATSD_PLUGIN
           
private  MBeanServer beanServer
           
private static String DEACTIVATE
           
private static String DUMP_HISTOGRAM_LIKE_VALUE_ANALYSIS
           
private static String DUMP_STRING_WRITER
           
private static String GET_REGISTERED_PLUGIN_KEYS
           
private static InApplicationMonitorJMXConnector instance
           
private static String IS_MONITOR_ACTIVE
           
private  String jmxPrefix
           
private static org.apache.log4j.Logger LOG
           
private  boolean registerAllReportables
           
private static String REMOVE_ALL_PLUGINS
           
private  Map<String,Reportable> reportables
           
private  Map<String,String> reportablesThatShouldBeRegistered
           
 
Constructor Summary
private InApplicationMonitorJMXConnector(boolean interestedInAllReportables, String jmxPrefix)
           
 
Method Summary
 void activate()
           
 void addNewReportable(Reportable reportable)
          This method is called for each reportable that is registered on the InApplicationMonitor.
private  void addStatsdPlugin(String host, Integer port, String appName, Double sampleRate)
           
private  ObjectName createBeanName(String name, String type)
           
 void deactivate()
           
 String dumpHistogramLikeValueAnalysis(String base)
           
 String dumpStringWriter()
           
 Object getAttribute(String attribute)
           
 AttributeList getAttributes(String[] attributes)
           
static InApplicationMonitorJMXConnector getInstance()
           
static InApplicationMonitorJMXConnector getInstance(boolean interestedInAllReportables)
          singleton access method WARNING : when called, this method registers the InApplicationMonitor as dynamic MBean on the JMX MBean server thing - use after thinking only.
static InApplicationMonitorJMXConnector getInstance(boolean interestedInAllReportables, JmxAppMon4JNamingStrategy namingStrategy)
          singleton access method WARNING : when called, this method registers the InApplicationMonitor as dynamic MBean on the JMX MBean server thing - use after thinking only.
 MBeanInfo getMBeanInfo()
           
 List<String> getRegisteredPluginKeys()
           
private  Object getValueForReportable(String attribute)
           
 Object invoke(String actionName, Object[] params, String[] signature)
           
 Boolean isMonitorActive()
           
 void markCounterForJMX(String string)
          Indicates that a reportable should be registered as JMX attribute This method must be called before the reportable is registered at the InApplicationMonitor, otherwise the reportable will not be registered here.
private  void registerJMXStuff()
          registers the InApplicationMonitor as JMX MBean on the running JMX server - if no JMX server is running, one is started automagically.
 void registerMBeanOnJMX(Object object, String name)
           
 void registerMBeanOnJMX(Object object, String name, String type)
           
private  void registerReportable(String reportableKey, Reportable reportable)
           
 void setAttribute(Attribute attribute)
           
 AttributeList setAttributes(AttributeList attributes)
           
 boolean shouldRegisterAllReportables()
           
 void unregisterMBeanOnJMX(Object object, String name, String type)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DUMP_STRING_WRITER

private static final String DUMP_STRING_WRITER
See Also:
Constant Field Values

DUMP_HISTOGRAM_LIKE_VALUE_ANALYSIS

private static final String DUMP_HISTOGRAM_LIKE_VALUE_ANALYSIS
See Also:
Constant Field Values

ACTIVATE

private static final String ACTIVATE
See Also:
Constant Field Values

DEACTIVATE

private static final String DEACTIVATE
See Also:
Constant Field Values

IS_MONITOR_ACTIVE

private static final String IS_MONITOR_ACTIVE
See Also:
Constant Field Values

GET_REGISTERED_PLUGIN_KEYS

private static final String GET_REGISTERED_PLUGIN_KEYS
See Also:
Constant Field Values

REMOVE_ALL_PLUGINS

private static final String REMOVE_ALL_PLUGINS
See Also:
Constant Field Values

ADD_STATSD_PLUGIN

private static final String ADD_STATSD_PLUGIN
See Also:
Constant Field Values

LOG

private static final org.apache.log4j.Logger LOG

instance

private static InApplicationMonitorJMXConnector instance

reportables

private final Map<String,Reportable> reportables

reportablesThatShouldBeRegistered

private final Map<String,String> reportablesThatShouldBeRegistered

registerAllReportables

private boolean registerAllReportables

beanServer

private MBeanServer beanServer

jmxPrefix

private String jmxPrefix
Constructor Detail

InApplicationMonitorJMXConnector

private InApplicationMonitorJMXConnector(boolean interestedInAllReportables,
                                         String jmxPrefix)
Method Detail

getInstance

public static InApplicationMonitorJMXConnector getInstance(boolean interestedInAllReportables,
                                                           JmxAppMon4JNamingStrategy namingStrategy)
singleton access method WARNING : when called, this method registers the InApplicationMonitor as dynamic MBean on the JMX MBean server thing - use after thinking only.

Parameters:
interestedInAllReportables - set this to true if you want all reportables registered at the InApplicationMonitor to be available as JMX attributes
namingStrategy - the JmxAppMon4JNamingStrategy alters the standard prefix from "is24" to what is provided by the strategy.
Returns:
the singleton instance

getInstance

public static InApplicationMonitorJMXConnector getInstance(boolean interestedInAllReportables)
singleton access method WARNING : when called, this method registers the InApplicationMonitor as dynamic MBean on the JMX MBean server thing - use after thinking only.

Parameters:
interestedInAllReportables - set this to true if you want all reportables registered at the InApplicationMonitor to be available as JMX attributes
Returns:
the singleton instance

getInstance

public static InApplicationMonitorJMXConnector getInstance()

markCounterForJMX

public void markCounterForJMX(String string)
Indicates that a reportable should be registered as JMX attribute This method must be called before the reportable is registered at the InApplicationMonitor, otherwise the reportable will not be registered here. TODO [ptraeder] it should be possible to mark reportables that have already been registered at the InApplicationMonitor

Parameters:
string - name of the reportable

addNewReportable

public void addNewReportable(Reportable reportable)
This method is called for each reportable that is registered on the InApplicationMonitor. Basically, it checks if the JMX implementation is interested in the reportable and adds it to the "reportables" map which is the base for both getAttribute(s) and getMBeanInfo().

Specified by:
addNewReportable in interface ReportableObserver

registerReportable

private void registerReportable(String reportableKey,
                                Reportable reportable)

shouldRegisterAllReportables

public boolean shouldRegisterAllReportables()

registerJMXStuff

private void registerJMXStuff()
registers the InApplicationMonitor as JMX MBean on the running JMX server - if no JMX server is running, one is started automagically.


registerMBeanOnJMX

public void registerMBeanOnJMX(Object object,
                               String name)
                        throws InstanceAlreadyExistsException,
                               MBeanRegistrationException,
                               NotCompliantMBeanException,
                               MalformedObjectNameException
Throws:
InstanceAlreadyExistsException
MBeanRegistrationException
NotCompliantMBeanException
MalformedObjectNameException

registerMBeanOnJMX

public void registerMBeanOnJMX(Object object,
                               String name,
                               String type)
                        throws InstanceAlreadyExistsException,
                               MBeanRegistrationException,
                               NotCompliantMBeanException,
                               MalformedObjectNameException
Throws:
InstanceAlreadyExistsException
MBeanRegistrationException
NotCompliantMBeanException
MalformedObjectNameException

unregisterMBeanOnJMX

public void unregisterMBeanOnJMX(Object object,
                                 String name,
                                 String type)
                          throws InstanceNotFoundException,
                                 MBeanRegistrationException,
                                 MalformedObjectNameException
Throws:
InstanceNotFoundException
MBeanRegistrationException
MalformedObjectNameException

createBeanName

private ObjectName createBeanName(String name,
                                  String type)
                           throws MalformedObjectNameException
Throws:
MalformedObjectNameException

getMBeanInfo

public MBeanInfo getMBeanInfo()
Specified by:
getMBeanInfo in interface DynamicMBean

getValueForReportable

private Object getValueForReportable(String attribute)

getAttribute

public Object getAttribute(String attribute)
                    throws AttributeNotFoundException,
                           MBeanException,
                           ReflectionException
Specified by:
getAttribute in interface DynamicMBean
Throws:
AttributeNotFoundException
MBeanException
ReflectionException

getAttributes

public AttributeList getAttributes(String[] attributes)
Specified by:
getAttributes in interface DynamicMBean

setAttribute

public void setAttribute(Attribute attribute)
                  throws AttributeNotFoundException,
                         InvalidAttributeValueException,
                         MBeanException,
                         ReflectionException
Specified by:
setAttribute in interface DynamicMBean
Throws:
AttributeNotFoundException
InvalidAttributeValueException
MBeanException
ReflectionException

setAttributes

public AttributeList setAttributes(AttributeList attributes)
Specified by:
setAttributes in interface DynamicMBean

invoke

public Object invoke(String actionName,
                     Object[] params,
                     String[] signature)
              throws MBeanException,
                     ReflectionException
Specified by:
invoke in interface DynamicMBean
Throws:
MBeanException
ReflectionException

addStatsdPlugin

private void addStatsdPlugin(String host,
                             Integer port,
                             String appName,
                             Double sampleRate)

dumpStringWriter

public String dumpStringWriter()

dumpHistogramLikeValueAnalysis

public String dumpHistogramLikeValueAnalysis(String base)

activate

public void activate()

deactivate

public void deactivate()

isMonitorActive

public Boolean isMonitorActive()

getRegisteredPluginKeys

public List<String> getRegisteredPluginKeys()


Copyright © 2013 Immobilien Scout GmbH. All Rights Reserved.