Class Util


  • @Taxonomy(stability=UNCOMMITTED)
    public final class Util
    extends Object
    Utility routines pertinent to the MBean API.
    • Field Detail

      • TYPE_FIELD

        public static final String TYPE_FIELD
        Proxy interfaces may contain a type field denoting the type to be used in the ObjectName; this is an alternative to an annotation that may be desirable to avoid a dependency on the amx-core module. Some proxy interfaces also represent MBeans whose type and other metadata is derived not from the proxy interface, but from another authoritative source; this allows an explicit linkage that allows the AMXProxyHandler to deduce the correct type, given the interface (and avoids any further complexity, the KISS principle). eg public static final String AMX_TYPE = "MyType";

        A good example of this is the config MBeans which use lower case types with dashes. Other types may use classnames, or other variants; the proxy code can't assume any particular mapping from a proxy interface to the actual MBean type.

        See Also:
        Constant Field Values
    • Method Detail

      • quoteIfNeeded

        public static String quoteIfNeeded​(String name)
      • unquoteIfNeeded

        public static String unquoteIfNeeded​(String name)
      • newObjectName

        public static ObjectName newObjectName​(String name)
        Create a new ObjectName, caller is guaranteeing that the name is well-formed (a RuntimeException will be thrown if not). This avoids having to catch all sorts of JMX exceptions.
        NOTE: Do not call this method if there is not certainty of a well-formed name.
        Parameters:
        name -
      • newObjectName

        public static ObjectName newObjectName​(String domain,
                                               String props)
        Build an ObjectName. Calls newObjectName( domain + ":" + props )
        Parameters:
        domain - the JMX domain
        props - properties of the ObjectName
      • newObjectNamePattern

        public static ObjectName newObjectNamePattern​(String domain,
                                                      String props)
        Build an ObjectName pattern.
        Parameters:
        domain - the JMX domain
        props - properties of the ObjectName
      • newObjectNamePattern

        public static ObjectName newObjectNamePattern​(ObjectName objectName)
        Build an ObjectName pattern.
        Parameters:
        objectName -
      • makeProp

        public static String makeProp​(String name,
                                      String value)
        Make an ObjectName property of the form name=value.
        Parameters:
        name -
        value -
      • makeTypeProp

        public static String makeTypeProp​(String value)
        Make an ObjectName property of the form type=value.
        Parameters:
        value -
      • makeNameProp

        public static String makeNameProp​(String name)
        Make an ObjectName property of the form name=value.
      • makeRequiredProps

        public static String makeRequiredProps​(String type,
                                               String name)
        Parameters:
        type -
        name -
      • getSelfProp

        public static String getSelfProp​(ObjectName objectName)
        Extract the type and name properties and return it as a single property type=name
        Parameters:
        objectName -
      • getAdditionalProps

        public static String getAdditionalProps​(ObjectName objectName)
        Extract all properties other than type=,name=.
        Parameters:
        objectName -
      • concatenateProps

        public static String concatenateProps​(String props1,
                                              String props2)
      • toObjectNameMap

        public static Map<String,​ObjectName> toObjectNameMap​(Map<String,​? extends AMXProxy> amxMap)
        Returns:
        a Map of ObjectNames from a Map whose values are AMX.
      • toObjectNamesArray

        public static ObjectName[] toObjectNamesArray​(AMXProxy[] amx)
        Returns:
        an ObjectName[] from an AMX[]
      • createNameMap

        public static <T extends AMXProxyMap<String,​T> createNameMap​(Set<T> amxs)
        Create a Map keyed by the value of the NAME_KEY with value the AMX item.
        Parameters:
        amxs - Set of AMX
      • createObjectNameMap

        public static final Map<String,​ObjectName> createObjectNameMap​(Set<ObjectName> objectNames)
        Create a Map keyed by the value of the NAME_KEY with value the ObjectName. Note that if two or more ObjectNames share the same name, the resulting Map will contain only one of the original ObjectNames.
        Parameters:
        objectNames - Set of ObjectName
      • getAMXNotificationData

        public static Map<String,​Serializable> getAMXNotificationData​(Notification notif)
        All Notifications emitted by AMX MBeans which are not standard types defined by JMX place a Map into the userData field of the Notification. This call retrieves that Map, which may be null if no additional data is included.
      • getAMXNotificationValue

        public static Serializable getAMXNotificationValue​(Notification notif,
                                                           String key)
        Use of generic type form taking Class is preferred.
      • asAMX

        public static AMXProxy asAMX​(Object o)
        A safe way to cast to AMX.
      • filterAMX

        public static <T extends AMXProxySet<T> filterAMX​(Set<T> candidates,
                                                            Class<?> desired)
        Filter the AMX dynamic proxies to those that implement the specified interface, and return a new Set with the matching items. The 'desired' interface can be any AMX-defined class, including the mixin ones.
        Parameters:
        candidates - the Set to be filtered
        desired - the interface to filter by
      • filterAMX

        public static <T extends AMXProxyMap<String,​T> filterAMX​(Map<String,​T> candidates,
                                                                         Class<?> desired)
        Filter the AMX dynamic proxies to those that implement the specified interface, and return a new Map with the matching items. The 'desired' interface can be any AMX-defined class, including the mixin ones.
        Parameters:
        candidates - the Map to be filtered
        desired - the interface to filter by
      • getNameProp

        public static String getNameProp​(ObjectName objectName)
        Get the value of the NAME_KEY property within the ObjectName, or null if not present.
        Returns:
        the name
      • getParentPathProp

        public static String getParentPathProp​(ObjectName objectName)
      • getParentPathProp

        public static String getParentPathProp​(AMXProxy amx)
      • typeFromName

        public static String typeFromName​(String s)
        Generate the default MBean type from a String, eg from a classname.
      • deduceType

        public static String deduceType​(Class<?> intf)
        Deduce the type to be used in the path. Presence of a TYPE_FIELD field always take precedence, then the AMXMBeanMetadata.