Package wt.jmx.core

Class AttributeListWrapper

java.lang.Object
wt.jmx.core.AttributeListWrapper
All Implemented Interfaces:
AttributeListProvider

public abstract class AttributeListWrapper extends Object implements AttributeListProvider
Wraps a JMX AttributeList so as to provide better toString() behaviors for use in logging, etc, and to provide an easily identifiable type for use with custom log4j renderers.

This class' toString() will either output in a default format unless provided with a non-null, non-empty Formatter formatString, in which case it will use it.

Supported API: true

Extendable: true

  • Method Details

    • getDefaultSeparator

      public static String getDefaultSeparator()
      Default value of separator property.

      Supported API: true
    • newInstance

      public static AttributeListWrapper newInstance(AttributeList attributeList)
      Get instance wrapping given attribute list.

      Supported API: true
    • newInstance

      public static AttributeListWrapper newInstance(Map<String,?> attrMap, String[] attributeNames)
      Get instance wrapping which will produce an attribute list containing the attributes from attrMap specified by attributeNames -- or all attributes from attrMap if attributeNames is null.

      Supported API: true
    • newInstance

      public static AttributeListWrapper newInstance(DynamicMBean mbean, String[] attributeNames)
      Shorthand for newInstance( mbean.getAttributes( attributeNames ) ).

      Supported API: true
    • newInstance

      public static AttributeListWrapper newInstance(MBeanServerConnection mbeanServer, ObjectName objectName)
      Get instance wrapping which will produce an attribute list from the given MBean as needed. This list will contain all readable attributes.

      Supported API: true
    • getAttributeList

      public final AttributeList getAttributeList()
      Method used by toString() [or a custom log4j renderer] to get attribute list when needed.

      Supported API: true
      Specified by:
      getAttributeList in interface AttributeListProvider
    • computeAttributeList

      protected abstract AttributeList computeAttributeList()
      Method used by getAttributeList() to compute attribute list when needed, as governed by isCaching().

      Subclasses must override this method.

      Supported API: true

    • getFormatString

      public final String getFormatString()
      Returns format string specified for use with Formatter.

      Supported API: true
    • setFormatString

      public final void setFormatString(String formatString)
      Sets format string specified for use with Formatter; when this is null Formatter is not used.

      Supported API: true
    • isShortFormat

      public final boolean isShortFormat()
      Returns true if attribute names are included by default format (i.e. that used format string is not set)

      Supported API: true
    • setShortFormat

      public final void setShortFormat(boolean shortFormat)
      Sets whether attribute names are included by default format (i.e. that used format string is not set)

      Supported API: true
    • isMultiLineFormat

      public final boolean isMultiLineFormat()
      Returns whether multi-line format is used

      Supported API: true
    • setMultiLineFormat

      public final void setMultiLineFormat(boolean multiLineFormat)
      Sets whether multi-line format is used

      Supported API: true
    • getSeparator

      public final String getSeparator()
      Returns separator string used by default format (i.e. that used format string is not set)

      Supported API: true
    • setSeparator

      public final void setSeparator(String separator)
      Sets separator string used by default format (i.e. that used format string is not set)

      Supported API: true
    • isCaching

      public final boolean isCaching()
      Returns whether first result of computeAttributeList() and computeStringRep() will be cached or be called again on each call of getAttributeList() and toString(), respectively. This property is true by default as normal usage of this class is to capture one set of values into an instance which may be used multiple times.

      Note that the caching mechanism does not use synchronization, locking, or volatiles to absolutely ensure only one invocation of each method. Rather the caching strategy makes a best effort to avoid multiple calls while avoiding additional bottlenecks.

      Supported API: true

    • setCaching

      public final void setCaching(boolean caching)
      Sets whether first result of computeAttributeList() and computeStringRep() will be cached or be called again on each call of getAttributeList() and toString(), respectively. This property is true by default as normal usage of this class is to capture one set of values into an instance which may be used multiple times.

      Note that the caching mechanism does not use synchronization, locking, or volatiles to absolutely ensure only one invocation of each method. Rather the caching strategy makes a best effort to avoid multiple calls while avoiding additional bottlenecks.

      Supported API: true

    • clearCaches

      public final void clearCaches()
      Clear attribute list and string rep caches.

      Supported API: true
    • clearStringRepCache

      public final void clearStringRepCache()
      Clear string rep cache.

      Supported API: true
    • getActualSeparator

      public static String getActualSeparator(String separator)
      setSeparator() will not accept certain separators, e.g. null or "", and will use the result of getDefaultSeparator() instead. This routine returns what setSeparator() will actually use.

      Supported API: true
    • toString

      public String toString()
      Renders the attribute list returned by getAttributeList() as a String.

      Subclasses can override this method, but should override computeStringRep() instead unless they wish to alter the caching behavior.

      Supported API: true

      Overrides:
      toString in class Object
    • computeStringRep

      protected String computeStringRep()
      Method used by toString() to compute string representation when needed, as governed by isCaching().

      Subclasses can override this method.

      Supported API: true

    • defaultRenderObjectAsString

      public static String defaultRenderObjectAsString(Object obj)
      Render the given object to a String using non-multi-line formatting.

      Supported API: true
    • defaultRenderObjectAsString

      public static String defaultRenderObjectAsString(Object obj, boolean multiLineFormat)
      Render the given object to a String.

      Supported API: true
    • getNamesOfReadableAttributes

      public static String[] getNamesOfReadableAttributes(MBeanInfo mbeanInfo)
      Get list of all of the readable attributes from an MBeanInfo.

      Supported API: true
    • getReadableProperties

      public static Map<String,Object> getReadableProperties(Object bean)
      Get names of readable properties and their values from regular Java bean
      Parameters:
      bean - Object to introspect for Java Beans properties

      Supported API: true
    • getReadableProperties

      public static Map<String,Object> getReadableProperties(Object bean, Class stopClass)
      Get names of readable properties and their values from regular Java bean.

      Supported API: true
      Parameters:
      bean - Object to introspect for Java Beans properties
      stopClass - The base class at which to stop the analysis. Any methods/properties/events in the stopClass or in its base classes will be ignored in the analysis.