private static <T extends NotificationBroadcaster> T getNotificationBroadcaster(ObjectName name, Object instance, Class<T> reqClass) { if (reqClass.isInstance(instance)) return reqClass.cast(instance); if (instance instanceof DynamicMBean2) instance = ((DynamicMBean2) instance).getResource(); if (reqClass.isInstance(instance)) return reqClass.cast(instance); final RuntimeException exc = new IllegalArgumentException(name.getCanonicalName()); final String msg = "MBean " + name.getCanonicalName() + " does not " + "implement " + reqClass.getName(); throw new RuntimeOperationsException(exc, msg); }
static boolean isDefinitelyImmutableInfo(Class<?> implClass) { if (!NotificationBroadcaster.class.isAssignableFrom(implClass)) return true; synchronized (definitelyImmutable) { Boolean immutable = definitelyImmutable.get(implClass); if (immutable == null) { final Class<NotificationBroadcasterSupport> nbs = NotificationBroadcasterSupport.class; if (nbs.isAssignableFrom(implClass)) { try { Method m = implClass.getMethod("getNotificationInfo"); immutable = (m.getDeclaringClass() == nbs); } catch (Exception e) { // Too bad, we'll say no for now. return false; } } else immutable = false; definitelyImmutable.put(implClass, immutable); } return immutable; } }
static MBeanNotificationInfo[] findNotifications(Object moi) { if (!(moi instanceof NotificationBroadcaster)) return null; MBeanNotificationInfo[] mbn = ((NotificationBroadcaster) moi).getNotificationInfo(); if (mbn == null) return null; MBeanNotificationInfo[] result = new MBeanNotificationInfo[mbn.length]; for (int i = 0; i < mbn.length; i++) { MBeanNotificationInfo ni = mbn[i]; if (ni.getClass() != MBeanNotificationInfo.class) ni = (MBeanNotificationInfo) ni.clone(); result[i] = ni; } return result; }
public MemoryTileCache() { log = Logger.getLogger(this.getClass()); hashtable = new Hashtable<String, CacheEntry>(cacheSize); lruTiles = new CacheLinkedListElement(); cacheSize = 500; MemoryMXBean mbean = ManagementFactory.getMemoryMXBean(); NotificationBroadcaster emitter = (NotificationBroadcaster) mbean; emitter.addNotificationListener(this, null, null); // Set-up each memory pool to notify if the free memory falls below 10% for (MemoryPoolMXBean memPool : ManagementFactory.getMemoryPoolMXBeans()) { if (memPool.isUsageThresholdSupported()) { MemoryUsage memUsage = memPool.getUsage(); memPool.setUsageThreshold((long) (memUsage.getMax() * 0.95)); } } }
public void addNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException { // ------------------------------ // ------------------------------ if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "addNotificationListener", "ObjectName = " + name); } DynamicMBean instance = getMBean(name); checkMBeanPermission(instance, null, name, "addNotificationListener"); NotificationBroadcaster broadcaster = getNotificationBroadcaster(name, instance, NotificationBroadcaster.class); // ------------------ // Check listener // ------------------ if (listener == null) { throw new RuntimeOperationsException(new IllegalArgumentException("Null listener"),"Null listener"); } NotificationListener listenerWrapper = getListenerWrapper(listener, name, instance, true); broadcaster.addNotificationListener(listenerWrapper, filter, handback); }
public void addNotificationListener( ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException { NotificationBroadcaster userMBean = (NotificationBroadcaster) getUserMBean(name); NotificationListener wrappedListener = wrappedListener(name, userMBean, listener); userMBean.addNotificationListener(wrappedListener, filter, handback); }