/** * Return the Java 6 MXBean interface exists for the given class, if any * (that is, an interface whose name ends with "MXBean" and/or * carries an appropriate MXBean annotation). * @param clazz the class to check * @return whether there is an MXBean interface for the given class */ @Nullable public static Class<?> getMXBeanInterface(@Nullable Class<?> clazz) { if (clazz == null || clazz.getSuperclass() == null) { return null; } Class<?>[] implementedInterfaces = clazz.getInterfaces(); for (Class<?> iface : implementedInterfaces) { if (JMX.isMXBeanInterface(iface)) { return iface; } } return getMXBeanInterface(clazz.getSuperclass()); }
/** * Return the Java 6 MXBean interface exists for the given class, if any * (that is, an interface whose name ends with "MXBean" and/or * carries an appropriate MXBean annotation). * @param clazz the class to check * @return whether there is an MXBean interface for the given class */ @Nullable public static Class<?> getMXBeanInterface(@Nullable Class<?> clazz) { if (clazz == null || clazz.getSuperclass() == null) { return null; } Class<?>[] implementedInterfaces = clazz.getInterfaces(); for (Class<?> iface : implementedInterfaces) { if (JMX.isMXBeanInterface(iface)) { return iface; } } return getMXBeanInterface(clazz.getSuperclass()); }
/** * Ensures that an {@code MBeanServerConnection} is configured and attempts * to detect a local connection if one is not supplied. */ public void prepare() { synchronized (this.preparationMonitor) { if (this.server != null) { this.serverToUse = this.server; } else { this.serverToUse = null; this.serverToUse = this.connector.connect(this.serviceUrl, this.environment, this.agentId); } this.invocationHandler = null; if (this.useStrictCasing) { Assert.state(this.objectName != null, "No ObjectName set"); // Use the JDK's own MBeanServerInvocationHandler, in particular for native MXBean support. this.invocationHandler = new MBeanServerInvocationHandler(this.serverToUse, this.objectName, (this.managementInterface != null && JMX.isMXBeanInterface(this.managementInterface))); } else { // Non-strict casing can only be achieved through custom invocation handling. // Only partial MXBean support available! retrieveMBeanInfo(this.serverToUse); } } } /**
/** * * @param member member to which this MBean belongs * @param monitoringRegion corresponding MonitoringRegion * @param objectName ObjectName of the MBean * @param interfaceClass on which interface the proxy to be exposed */ public static Object newProxyInstance(DistributedMember member, Region<String, Object> monitoringRegion, ObjectName objectName, FederationComponent federationComponent, Class interfaceClass) throws ClassNotFoundException, IntrospectionException { boolean isMXBean = JMX.isMXBeanInterface(interfaceClass); boolean notificationBroadcaster = federationComponent.isNotificationEmitter(); InvocationHandler handler = new MBeanProxyInvocationHandler(member, objectName, monitoringRegion, isMXBean); Class[] interfaces; if (notificationBroadcaster) { interfaces = new Class[] {interfaceClass, ProxyInterface.class, NotificationBroadCasterProxy.class}; } else { interfaces = new Class[] {interfaceClass, ProxyInterface.class}; } Object proxy = Proxy.newProxyInstance(MBeanProxyInvocationHandler.class.getClassLoader(), interfaces, handler); return interfaceClass.cast(proxy); }
@Override public <T> T getMBeanProxy(final ObjectName objectName, final Class<T> mbeanInterface) { if (DistributedSystemMXBean.class.equals(mbeanInterface) && ManagementConstants.OBJECTNAME__DISTRIBUTEDSYSTEM_MXBEAN.equals(objectName.toString())) { return mbeanInterface.cast(getDistributedSystemMXBean()); } else if (JMX.isMXBeanInterface(mbeanInterface)) { return JMX.newMXBeanProxy(getMBeanServerConnection(), objectName, mbeanInterface); } else { return JMX.newMBeanProxy(getMBeanServerConnection(), objectName, mbeanInterface); } }
/** * Ensures that an {@code MBeanServerConnection} is configured and attempts * to detect a local connection if one is not supplied. */ public void prepare() { synchronized (this.preparationMonitor) { if (this.server != null) { this.serverToUse = this.server; } else { this.serverToUse = null; this.serverToUse = this.connector.connect(this.serviceUrl, this.environment, this.agentId); } this.invocationHandler = null; if (this.useStrictCasing) { Assert.state(this.objectName != null, "No ObjectName set"); // Use the JDK's own MBeanServerInvocationHandler, in particular for native MXBean support. this.invocationHandler = new MBeanServerInvocationHandler(this.serverToUse, this.objectName, (this.managementInterface != null && JMX.isMXBeanInterface(this.managementInterface))); } else { // Non-strict casing can only be achieved through custom invocation handling. // Only partial MXBean support available! retrieveMBeanInfo(this.serverToUse); } } } /**
/** * @return the open type converter for a given type */ private static OpenTypeConverter makeConverter(Type objType) throws OpenDataException { if (objType instanceof GenericArrayType) { Type componentType = ((GenericArrayType) objType).getGenericComponentType(); return makeArrayOrCollectionConverter(objType, componentType); } else if (objType instanceof Class) { Class objClass = (Class<?>) objType; if (objClass.isEnum()) { return makeEnumConverter(objClass); } else if (objClass.isArray()) { Type componentType = objClass.getComponentType(); return makeArrayOrCollectionConverter(objClass, componentType); } else if (JMX.isMXBeanInterface(objClass)) { throw openDataException("Cannot obtain array class", new ManagementException(" MXBean as an Return Type is not supported")); } else { return makeCompositeConverter(objClass); } } else if (objType instanceof ParameterizedType) { return makeParameterizedConverter((ParameterizedType) objType); } else throw new OpenDataException("Cannot map type: " + objType); }
} else { this.managerMemberObjectName = this.distributedSystemMXBeanProxy.getMemberObjectName(); if (this.managerMemberObjectName == null || !JMX.isMXBeanInterface(MemberMXBean.class)) { logger.info("MemberMXBean with ObjectName " + this.managerMemberObjectName + " is not present on member with endpoints : " + endpoints);
/** * Returns true if the supplied object implements an * interface that is an MXBean interface or a DynamicMBean interface. * * @param inObject the object instance that needs to be tested * * @return if the object is an MXBean. */ private static boolean isMXBean(Object inObject) { for (Class<?> c = inObject.getClass(); !Object.class.equals(c); c = c.getSuperclass()) { for(Class<?> intf: c.getInterfaces()) { if(JMX.isMXBeanInterface(intf) || DynamicMBean.class.equals(intf)) { return true; } } } return false; }
/** * Instance where the MBean interface is implemented by another object. * * @param <T> * Compiler check that <code>mbeanImplementation</code> * implements <code>mbeanInterface</code> * @param mbeanImplementation * The implementation of the MBean implementing the * <code>mbeanInterface</code> * @param mbeanInterface * The interface of the MBean * @throws NotCompliantMBeanException * If <code>mbeanImplementation</code> is not a JMX compliant * MBean */ public <T> AnnotatedStandardMBean(T mbeanImplementation, Class<T> mbeanInterface) throws NotCompliantMBeanException { super(mbeanImplementation, mbeanInterface, JMX.isMXBeanInterface(mbeanInterface)); this.mbeanImplementation = mbeanImplementation; this.mBeanRegistration = mbeanImplementation instanceof MBeanRegistration ? (MBeanRegistration) mbeanImplementation : NullMBeanRegistration.INSTANCE; this.beanInfoCache = new MBeanInfoCache(mbeanInterface); }
/** * Return the Java 6 MXBean interface exists for the given class, if any * (that is, an interface whose name ends with "MXBean" and/or * carries an appropriate MXBean annotation). * @param clazz the class to check * @return whether there is an MXBean interface for the given class */ @Nullable public static Class<?> getMXBeanInterface(@Nullable Class<?> clazz) { if (clazz == null || clazz.getSuperclass() == null) { return null; } Class<?>[] implementedInterfaces = clazz.getInterfaces(); for (Class<?> iface : implementedInterfaces) { if (JMX.isMXBeanInterface(iface)) { return iface; } } return getMXBeanInterface(clazz.getSuperclass()); }
public <T> T getMBeanProxy(final ObjectName objectName, final Class<T> mbeanInterface) { if (DistributedSystemMXBean.class.equals(mbeanInterface) && ManagementConstants.OBJECTNAME__DISTRIBUTEDSYSTEM_MXBEAN.equals(objectName.toString())) { return mbeanInterface.cast(getDistributedSystemMXBean()); } else if (JMX.isMXBeanInterface(mbeanInterface)) { return JMX.newMXBeanProxy(getMBeanServerConnection(), objectName, mbeanInterface); } else { return JMX.newMBeanProxy(getMBeanServerConnection(), objectName, mbeanInterface); } }
public <T> T getMBeanProxy(final ObjectName objectName, final Class<T> mbeanInterface) { if (DistributedSystemMXBean.class.equals(mbeanInterface) && ManagementConstants.OBJECTNAME__DISTRIBUTEDSYSTEM_MXBEAN.equals(objectName.toString())) { return mbeanInterface.cast(getDistributedSystemMXBean()); } else if (JMX.isMXBeanInterface(mbeanInterface)) { return JMX.newMXBeanProxy(getMBeanServerConnection(), objectName, mbeanInterface); } else { return JMX.newMBeanProxy(getMBeanServerConnection(), objectName, mbeanInterface); } }
Class interfaceClass) throws ClassNotFoundException, IntrospectionException { boolean isMXBean = JMX.isMXBeanInterface(interfaceClass); boolean notificationBroadcaster = ((FederationComponent) monitoringRegion .get(objectName.toString())).isNotificationEmitter();
Class interfaceClass) throws ClassNotFoundException, IntrospectionException { boolean isMXBean = JMX.isMXBeanInterface(interfaceClass); boolean notificationBroadcaster = ((FederationComponent) monitoringRegion .get(objectName.toString())).isNotificationEmitter();
/** * Ensures that an {@code MBeanServerConnection} is configured and attempts * to detect a local connection if one is not supplied. */ public void prepare() { synchronized (this.preparationMonitor) { if (this.server != null) { this.serverToUse = this.server; } else { this.serverToUse = null; this.serverToUse = this.connector.connect(this.serviceUrl, this.environment, this.agentId); } this.invocationHandler = null; if (this.useStrictCasing) { Assert.state(this.objectName != null, "No ObjectName set"); // Use the JDK's own MBeanServerInvocationHandler, in particular for native MXBean support. this.invocationHandler = new MBeanServerInvocationHandler(this.serverToUse, this.objectName, (this.managementInterface != null && JMX.isMXBeanInterface(this.managementInterface))); } else { // Non-strict casing can only be achieved through custom invocation handling. // Only partial MXBean support available! retrieveMBeanInfo(this.serverToUse); } } } /**
this.distributedSystemMXBeanProxy = JMX.newMXBeanProxy(mbsc, MBeanJMXAdapter.getDistributedSystemName(), DistributedSystemMXBean.class); if (this.distributedSystemMXBeanProxy == null || !JMX.isMXBeanInterface(DistributedSystemMXBean.class)) { LogWrapper.getInstance().info("DistributedSystemMXBean is not present on member with endpoints : "+this.endpoints); connector.close(); if (this.managerMemberObjectName == null || !JMX.isMXBeanInterface(MemberMXBean.class)) { LogWrapper.getInstance().info("MemberMXBean with ObjectName "+this.managerMemberObjectName+" is not present on member with endpoints : "+endpoints); this.connector.close();
this.distributedSystemMXBeanProxy = JMX.newMXBeanProxy(mbsc, MBeanJMXAdapter.getDistributedSystemName(), DistributedSystemMXBean.class); if (this.distributedSystemMXBeanProxy == null || !JMX.isMXBeanInterface(DistributedSystemMXBean.class)) { LogWrapper.getInstance().info("DistributedSystemMXBean is not present on member with endpoints : "+this.endpoints); connector.close(); if (this.managerMemberObjectName == null || !JMX.isMXBeanInterface(MemberMXBean.class)) { LogWrapper.getInstance().info("MemberMXBean with ObjectName "+this.managerMemberObjectName+" is not present on member with endpoints : "+endpoints); this.connector.close();
Type componentType = objClass.getComponentType(); return makeArrayOrCollectionConverter(objClass, componentType); } else if (JMX.isMXBeanInterface(objClass)) { throw openDataException("Cannot obtain array class", new ManagementException(