Package org.jolokia.server.core.util.jmx
Class DefaultMBeanServerAccess
java.lang.Object
org.jolokia.server.core.util.jmx.DefaultMBeanServerAccess
- All Implemented Interfaces:
EventListener,NotificationListener,MBeanServerAccess
public class DefaultMBeanServerAccess
extends Object
implements MBeanServerAccess, NotificationListener
Base class for providing access to the list of MBeanServer handled by this agent.
- Since:
- 22.01.13
- Author:
- roland
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jolokia.server.core.util.jmx.MBeanServerAccess
MBeanServerAccess.MBeanAction<R>, MBeanServerAccess.MBeanEachCallback -
Constructor Summary
ConstructorsConstructorDescriptionConstructor using default MBeanServersDefaultMBeanServerAccess(Set<MBeanServerConnection> pServers) Create an MBeanServer executor for calling MBeanServers -
Method Summary
Modifier and TypeMethodDescription<T> Tcall(ObjectName pObjectName, MBeanServerAccess.MBeanAction<T> pMBeanAction, Object... pExtraArgs) Call an action an the first MBeanServer on which the action does not throw an InstanceNotFoundException will considered to be successful and this method returns with the return value of the succesful action.voideach(ObjectName pObjectName, MBeanServerAccess.MBeanEachCallback pCallback) Iterate over all MBeanServers managed and call the handler via a callback.protected MBeanServerConnectionOverride this method if you want to provide a Jolokia private MBeanServer.Get all MBeanServersvoidhandleNotification(Notification pNotification, Object pHandback) booleanhasMBeansListChangedSince(long pTimestamp) Check whether the set of MBeans in all managed MBeanServer has been changed since the given time.queryNames(ObjectName pObjectName) Query all MBeanServer and return the union of all resultsvoidUnregister us as listener from every registered server
-
Constructor Details
-
DefaultMBeanServerAccess
public DefaultMBeanServerAccess()Constructor using default MBeanServers -
DefaultMBeanServerAccess
Create an MBeanServer executor for calling MBeanServers- Parameters:
pServers- mbean servers to wrap and call
-
-
Method Details
-
getMBeanServers
Get all MBeanServers- Specified by:
getMBeanServersin interfaceMBeanServerAccess- Returns:
- all MBeanServers in the merge order
-
getJolokiaMBeanServer
Override this method if you want to provide a Jolokia private MBeanServer. Note, that this method should only return a non-null value, if the Jolokia private MBean Server has some MBeans registered- Returns:
- the Jolokia MBeanServer
-
each
public void each(ObjectName pObjectName, MBeanServerAccess.MBeanEachCallback pCallback) throws IOException, ReflectionException, MBeanException Iterate over all MBeanServers managed and call the handler via a callback. If is null or a pattern, the MBean names are queried on each MBeanServer and feed into the callback. If it is a full object name, then all MBeanServers are called with this object name in turn.- Specified by:
eachin interfaceMBeanServerAccess- Parameters:
pObjectName- object name to lookup, which can be a pattern in which case a query is performed.pCallback- the action to be called for each MBean found on every server- Throws:
IOExceptionReflectionExceptionMBeanException
-
call
public <T> T call(ObjectName pObjectName, MBeanServerAccess.MBeanAction<T> pMBeanAction, Object... pExtraArgs) throws IOException, ReflectionException, MBeanException, AttributeNotFoundException, InstanceNotFoundException Call an action an the first MBeanServer on which the action does not throw an InstanceNotFoundException will considered to be successful and this method returns with the return value of the succesful action. If no action was succesful, anIllegalArgumentExceptionis raised (containing the lastInstanceNotFoundExceptionfrom the last tried server)- Specified by:
callin interfaceMBeanServerAccess- Type Parameters:
T- type of the return value- Parameters:
pObjectName- objectname given through to the actionpMBeanAction- the action to callpExtraArgs- any extra args given also to the action- Returns:
- the return value of the succesful action
- Throws:
IOExceptionReflectionExceptionMBeanException- if the JMX call causes an issueAttributeNotFoundExceptionInstanceNotFoundException
-
queryNames
Query all MBeanServer and return the union of all results- Specified by:
queryNamesin interfaceMBeanServerAccess- Parameters:
pObjectName- pattern to query for. If null, then all MBean of all MBeanServers are returned- Returns:
- the found MBeans
- Throws:
IOException- if called remotely and an IOError occured.
-
unregisterFromMBeanNotifications
public void unregisterFromMBeanNotifications()Unregister us as listener from every registered server -
handleNotification
- Specified by:
handleNotificationin interfaceNotificationListener
-
hasMBeansListChangedSince
public boolean hasMBeansListChangedSince(long pTimestamp) Check whether the set of MBeans in all managed MBeanServer has been changed since the given time. The input is the epoch time in seconds, however, milliseconds would be much more appropriate. However, the Jolokia responses contain currently time measured in seconds. This should be changed in a future version, but this implies a quite heavy API changed (and if this is changed, the key "timestamp" should be changed to "time", too, in order to fail early in case of problems). In order to avoid inconsistencies for sub-second updates, we are comparing conservatively (so hasBeenUpdated might return "true" more often than required).- Specified by:
hasMBeansListChangedSincein interfaceMBeanServerAccess- Parameters:
pTimestamp- seconds since 1.1.1970- Returns:
- true if the MBeans has been updated since this time, false otherwise
-
dumpMBeanServers
-