Interface JmxService
-
- All Superinterfaces:
Service
@DefaultServiceFactory(JmxServiceFactory.class) public interface JmxService extends Service
« start hereJava Management Extensions service.Overview
The
JmxService
is the utility service that provides an abstraction layer on top of JMX facilities that are provided by the JMV. This service is primarily intended to be used by theHekate
's internal components and services.Service Configuration
JmxService
can be registered and configured inHekateBootstrap
with the help ofJmxServiceFactory
as shown in the example below:// Prepare service factory and configure some options. JmxServiceFactory factory = new JmxServiceFactory(); // (optional) explicitly specify MBean server. factory.setServer(ManagementFactory.getPlatformMBeanServer()); // ...other options... // Start node. Hekate hekate = new HekateBootstrap() .withService(factory) .join();
Note: This example requires Spring Framework integration (see HekateSpringBootstrap).<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:h="http://www.hekate.io/spring/hekate-core" xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.hekate.io/spring/hekate-core http://www.hekate.io/spring/hekate-core.xsd"> <h:node id="hekate"> <!-- JMX service. --> <h:jmx> <!-- ...JMX configuration options... --> </h:jmx> <!-- ...other services... --> </h:node> </beans>
Note: This example requires Spring Framework integration (see HekateSpringBootstrap).<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="hekate" class="io.hekate.spring.bean.HekateSpringBootstrap"> <property name="services"> <list> <!-- JMX service. --> <bean class="io.hekate.core.jmx.JmxServiceFactory"> <!-- ...JMX configuration options... --> </bean> <!-- ...other services... --> </list> </property> </bean> </beans>
Accessing the Service
JmxService
is an optional service that is available only if application registers an instance ofJmxServiceFactory
within theHekateBootstrap
. Availability of this service can be checked at runtime via theHekate.has(Class)
method. If service is available then it can be accessed via theHekate.get(Class)
method as shown in the example below:JmxService jmx = hekate.get(JmxService.class);
Registering MXBeans
JMX objects can be registered to the
JmxService
viaregister(Object)
method. Such objects must implement exactly oneMXBean
-annotated interface (i.e. 'MXBean' suffix in interface name is not supported). Alternatively, instead of implementing such interface directly, objects can implementJmxSupport
interface. In such case the object that is returned by theJmxSupport.jmx()
method will be registered as an MX bean.JMX Object Names
ObjectName
s of all registered beans are constructed as follows:[domain]:type=[simple_class_name],name=[name_attribute]
-
[domain]
- value ofJmxServiceFactory.setDomain(String)
-
[simple_class_name]
-Class.getSimpleName()
of the JMX bean object -
[name_attribute]
- (optional) value ofnameAttribute
if bean is registered viaregister(Object, String)
.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description String
domain()
Returns the JMX domain of this service.ObjectName
nameFor(Class<?> jmxInterface)
Constructs a new object name for the specified JMX interface.ObjectName
nameFor(Class<?> jmxInterface, String nameAttribute)
Constructs a new object name for the specified JMX interface and an additional'name'
attribute.List<ObjectName>
names()
Returns the list of names of all MBeans that are registered to this service.Optional<ObjectName>
register(Object mxBean)
Registers the specified object asMXBean
.Optional<ObjectName>
register(Object mxBean, String nameAttribute)
Registers the specified object asMXBean
.MBeanServer
server()
Returns the MBean server.
-
-
-
Method Detail
-
domain
String domain()
Returns the JMX domain of this service.- Returns:
- JMX domain.
- See Also:
JmxServiceFactory.setDomain(String)
-
names
List<ObjectName> names()
Returns the list of names of all MBeans that are registered to this service.- Returns:
- List of all registered MBean names or an empty list if none are registered.
-
nameFor
ObjectName nameFor(Class<?> jmxInterface)
Constructs a new object name for the specified JMX interface.- Parameters:
jmxInterface
- JMX interface.- Returns:
- Object name.
-
nameFor
ObjectName nameFor(Class<?> jmxInterface, String nameAttribute)
Constructs a new object name for the specified JMX interface and an additional'name'
attribute.- Parameters:
jmxInterface
- JMX interface.nameAttribute
- Optional value for the'name'
attribute of the resulting object name. If omitted then'name'
attribute will not be added to the object name.- Returns:
- Object name.
-
register
Optional<ObjectName> register(Object mxBean) throws JmxServiceException
Registers the specified object asMXBean
.The specified object is expected to implement exactly one interface that is marked with @
MXBean
annotation or implement theJmxSupport
interface. If object doesn't implement any of those interfaces then nothing will happen and registration operation will be ignored.- Parameters:
mxBean
- JMX bean.- Returns:
- Object name if registration took place.
- Throws:
JmxServiceException
- Signals that JMX registration failed.
-
register
Optional<ObjectName> register(Object mxBean, String nameAttribute) throws JmxServiceException
Registers the specified object asMXBean
.The specified object is expected to implement exactly one interface that is marked with @
MXBean
annotation or implement theJmxSupport
interface. If object doesn't implement any of those interfaces then nothing will happen and registration operation will be ignored.- Parameters:
mxBean
- JMX bean.nameAttribute
- Optional value for the'name'
attribute of the resulting object name. If omitted then'name'
attribute will not be added to the object name.- Returns:
- Object name if registration took place.
- Throws:
JmxServiceException
- Signals that JMX registration failed.
-
server
MBeanServer server()
Returns the MBean server.- Returns:
- MBean server.
- See Also:
JmxServiceFactory.setServer(MBeanServer)
-
-