use of javax.management.MBeanServerNotification in project jdk8u_jdk by JetBrains.
the class RelationService method purgeRelations.
/**
* Purges the relations.
*
* <P>Depending on the purgeFlag value, this method is either called
* automatically when a notification is received for the unregistration of
* an MBean referenced in a relation (if the flag is set to true), or not
* (if the flag is set to false).
* <P>In that case it is up to the user to call it to maintain the
* consistency of the relations. To be kept in mind that if an MBean is
* unregistered and the purge not done immediately, if the ObjectName is
* reused and assigned to another MBean referenced in a relation, calling
* manually this purgeRelations() method will cause trouble, as will
* consider the ObjectName as corresponding to the unregistered MBean, not
* seeing the new one.
*
* <P>The behavior depends on the cardinality of the role where the
* unregistered MBean is referenced:
* <P>- if removing one MBean reference in the role makes its number of
* references less than the minimum degree, the relation has to be removed.
* <P>- if the remaining number of references after removing the MBean
* reference is still in the cardinality range, keep the relation and
* update it calling its handleMBeanUnregistration() callback.
*
* @exception RelationServiceNotRegisteredException if the Relation
* Service is not registered in the MBean Server.
*/
public void purgeRelations() throws RelationServiceNotRegisteredException {
RELATION_LOGGER.entering(RelationService.class.getName(), "purgeRelations");
// Can throw RelationServiceNotRegisteredException
isActive();
// Revisit [cebro] Handle the CIM "Delete" and "IfDeleted" qualifier:
// if the unregistered MBean has the "IfDeleted" qualifier,
// possible that the relation itself or other referenced MBeans
// have to be removed (then a notification would have to be sent
// to inform that they should be unregistered.
// Clones the list of notifications to be able to still receive new
// notifications while proceeding those ones
List<MBeanServerNotification> localUnregNtfList;
synchronized (myRefedMBeanObjName2RelIdsMap) {
localUnregNtfList = new ArrayList<MBeanServerNotification>(myUnregNtfList);
// Resets list
myUnregNtfList = new ArrayList<MBeanServerNotification>();
}
// Updates the listener filter to avoid receiving notifications for
// those MBeans again
// Makes also a local "myRefedMBeanObjName2RelIdsMap" map, mapping
// ObjectName -> relId -> roles, to remove the MBean from the global
// map
// List of references to be removed from the listener filter
List<ObjectName> obsRefList = new ArrayList<ObjectName>();
// Map including ObjectNames for unregistered MBeans, with
// referencing relation ids and roles
Map<ObjectName, Map<String, List<String>>> localMBean2RelIdMap = new HashMap<ObjectName, Map<String, List<String>>>();
synchronized (myRefedMBeanObjName2RelIdsMap) {
for (MBeanServerNotification currNtf : localUnregNtfList) {
ObjectName unregMBeanName = currNtf.getMBeanName();
// Adds the unregsitered MBean in the list of references to
// remove from the listener filter
obsRefList.add(unregMBeanName);
// Retrieves the associated map of relation ids and roles
Map<String, List<String>> relIdMap = myRefedMBeanObjName2RelIdsMap.get(unregMBeanName);
localMBean2RelIdMap.put(unregMBeanName, relIdMap);
myRefedMBeanObjName2RelIdsMap.remove(unregMBeanName);
}
}
// Updates the listener
// Can throw RelationServiceNotRegisteredException
updateUnregistrationListener(null, obsRefList);
for (MBeanServerNotification currNtf : localUnregNtfList) {
ObjectName unregMBeanName = currNtf.getMBeanName();
// Retrieves the relations where the MBean is referenced
Map<String, List<String>> localRelIdMap = localMBean2RelIdMap.get(unregMBeanName);
// referenced
for (Map.Entry<String, List<String>> currRel : localRelIdMap.entrySet()) {
final String currRelId = currRel.getKey();
// List of roles of the relation where the MBean is
// referenced
List<String> localRoleNameList = currRel.getValue();
// RoleNotFoundException, MBeanException
try {
handleReferenceUnregistration(currRelId, unregMBeanName, localRoleNameList);
} catch (RelationNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (RoleNotFoundException exc2) {
throw new RuntimeException(exc2.getMessage());
}
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(), "purgeRelations");
return;
}
use of javax.management.MBeanServerNotification in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method sendNotification.
/**
* Sends an MBeanServerNotifications with the specified type for the
* MBean with the specified ObjectName
*/
private void sendNotification(String NotifType, ObjectName name) {
// ------------------------------
// ------------------------------
// ---------------------
// Create notification
// ---------------------
MBeanServerNotification notif = new MBeanServerNotification(NotifType, MBeanServerDelegate.DELEGATE_NAME, 0, name);
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "sendNotification", NotifType + " " + name);
}
delegate.sendNotification(notif);
}
use of javax.management.MBeanServerNotification in project jdk8u_jdk by JetBrains.
the class MBeanServerNotificationFilter method isNotificationEnabled.
//
// NotificationFilter interface
//
/**
* Invoked before sending the specified notification to the listener.
* <P>If:
* <P>- the ObjectName of the concerned MBean is selected (explicitly OR
* (implicitly and not explicitly deselected))
* <P>AND
* <P>- the type of the operation (registration or unregistration) is
* selected
* <P>then the notification is sent to the listener.
*
* @param notif The notification to be sent.
*
* @return true if the notification has to be sent to the listener, false
* otherwise.
*
* @exception IllegalArgumentException if null parameter
*/
public synchronized boolean isNotificationEnabled(Notification notif) throws IllegalArgumentException {
if (notif == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(MBeanServerNotificationFilter.class.getName(), "isNotificationEnabled", notif);
// Checks the type first
String ntfType = notif.getType();
Vector<String> enabledTypes = getEnabledTypes();
if (!(enabledTypes.contains(ntfType))) {
RELATION_LOGGER.logp(Level.FINER, MBeanServerNotificationFilter.class.getName(), "isNotificationEnabled", "Type not selected, exiting");
return false;
}
// We have a MBeanServerNotification: downcasts it
MBeanServerNotification mbsNtf = (MBeanServerNotification) notif;
// Checks the ObjectName
ObjectName objName = mbsNtf.getMBeanName();
// Is it selected?
boolean isSelectedFlg = false;
if (selectedNames != null) {
// checks for explicit selection
if (selectedNames.size() == 0) {
// All are explicitly not selected
RELATION_LOGGER.logp(Level.FINER, MBeanServerNotificationFilter.class.getName(), "isNotificationEnabled", "No ObjectNames selected, exiting");
return false;
}
isSelectedFlg = selectedNames.contains(objName);
if (!isSelectedFlg) {
// Not in the explicit selected list
RELATION_LOGGER.logp(Level.FINER, MBeanServerNotificationFilter.class.getName(), "isNotificationEnabled", "ObjectName not in selected list, exiting");
return false;
}
}
if (!isSelectedFlg) {
if (deselectedNames == null) {
// All are implicitly deselected and it is not explicitly
// selected
RELATION_LOGGER.logp(Level.FINER, MBeanServerNotificationFilter.class.getName(), "isNotificationEnabled", "ObjectName not selected, and all " + "names deselected, exiting");
return false;
} else if (deselectedNames.contains(objName)) {
// Explicitly deselected
RELATION_LOGGER.logp(Level.FINER, MBeanServerNotificationFilter.class.getName(), "isNotificationEnabled", "ObjectName explicitly not selected, exiting");
return false;
}
}
RELATION_LOGGER.logp(Level.FINER, MBeanServerNotificationFilter.class.getName(), "isNotificationEnabled", "ObjectName selected, exiting");
return true;
}
use of javax.management.MBeanServerNotification in project geode by apache.
the class MBeanUtil method registerServerNotificationListener.
static void registerServerNotificationListener() {
if (mbeanServer == null) {
return;
}
try {
// the MBeanServerDelegate name is spec'ed as the following...
ObjectName delegate = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");
mbeanServer.addNotificationListener(delegate, new NotificationListener() {
public void handleNotification(Notification notification, Object handback) {
MBeanServerNotification serverNotification = (MBeanServerNotification) notification;
if (MBeanServerNotification.UNREGISTRATION_NOTIFICATION.equals(serverNotification.getType())) {
ObjectName objectName = serverNotification.getMBeanName();
synchronized (MBeanUtil.managedResources) {
Object entry = MBeanUtil.managedResources.get(objectName);
if (entry == null)
return;
if (!(entry instanceof ManagedResource)) {
throw new ClassCastException(LocalizedStrings.MBeanUtil_0_IS_NOT_A_MANAGEDRESOURCE.toLocalizedString(new Object[] { entry.getClass().getName() }));
}
ManagedResource resource = (ManagedResource) entry;
{
// call cleanup on managedResource
cleanupResource(resource);
}
}
}
}
}, null, null);
} catch (JMException e) {
logStackTrace(Level.WARN, e, LocalizedStrings.MBeanUtil_FAILED_TO_REGISTER_SERVERNOTIFICATIONLISTENER.toLocalizedString());
} catch (JMRuntimeException e) {
logStackTrace(Level.WARN, e, LocalizedStrings.MBeanUtil_FAILED_TO_REGISTER_SERVERNOTIFICATIONLISTENER.toLocalizedString());
}
}
use of javax.management.MBeanServerNotification in project logging-log4j2 by apache.
the class ClientGui method handleNotificationInAwtEventThread.
private void handleNotificationInAwtEventThread(final Notification notif, final Object paramObject) {
if (StatusLoggerAdminMBean.NOTIF_TYPE_MESSAGE.equals(notif.getType())) {
if (!(paramObject instanceof ObjectName)) {
handle("Invalid notification object type", new ClassCastException(paramObject.getClass().getName()));
return;
}
final ObjectName param = (ObjectName) paramObject;
final JTextArea text = statusLogTextAreaMap.get(param);
if (text != null) {
text.append(notif.getMessage() + '\n');
}
return;
}
if (notif instanceof MBeanServerNotification) {
final MBeanServerNotification mbsn = (MBeanServerNotification) notif;
final ObjectName mbeanName = mbsn.getMBeanName();
if (MBeanServerNotification.REGISTRATION_NOTIFICATION.equals(notif.getType())) {
onMBeanRegistered(mbeanName);
} else if (MBeanServerNotification.UNREGISTRATION_NOTIFICATION.equals(notif.getType())) {
onMBeanUnregistered(mbeanName);
}
}
}
Aggregations