Example usage for javax.management ObjectName apply

List of usage examples for javax.management ObjectName apply

Introduction

In this page you can find the example usage for javax.management ObjectName apply.

Prototype

public boolean apply(ObjectName name) 

Source Link

Document

Test whether this ObjectName, which may be a pattern, matches another ObjectName.

Usage

From source file:org.apache.geode.management.internal.beans.DistributedSystemBridge.java

public ObjectName[] listGatewaySenderObjectNames(String member) throws Exception {
    validateMember(member);//from   ww  w  .jav  a2s  .c  o  m
    DistributedMember distributedMember = BeanUtilFuncs.getDistributedMemberByNameOrId(member);

    List<ObjectName> listName = null;

    ObjectName pattern = new ObjectName(ManagementConstants.GATEWAY_SENDER_PATTERN);

    Set<ObjectName> mbeanSet = service.queryMBeanNames(distributedMember);

    if (mbeanSet != null && mbeanSet.size() > 0) {
        listName = new ArrayList<>();
        for (ObjectName name : mbeanSet) {
            if (pattern.apply(name)) {
                listName.add(name);
            }
        }
    }

    if (listName != null && listName.size() > 0) {
        ObjectName[] array = new ObjectName[listName.size()];
        return listName.toArray(array);
    }
    return ManagementConstants.NO_DATA_OBJECTNAME;
}

From source file:org.apache.geode.management.internal.beans.ManagementAdapter.java

/**
 * Handles all the clean up activities when a Manager is stopped It clears the distributed mbeans
 * and underlying data structures//from  ww  w  . j  a v a  2  s . c  o m
 */
public void handleManagerStop() throws ManagementException {
    if (!isServiceInitialised("handleManagerStop")) {
        return;
    }
    MBeanJMXAdapter jmxAdapter = service.getJMXAdapter();
    Map<ObjectName, Object> registeredMBeans = jmxAdapter.getLocalGemFireMBean();

    ObjectName aggregatemMBeanPattern;
    try {
        aggregatemMBeanPattern = new ObjectName(ManagementConstants.AGGREGATE_MBEAN_PATTERN);
    } catch (MalformedObjectNameException | NullPointerException e1) {
        throw new ManagementException(e1);
    }

    MemberMXBean localMember = service.getMemberMXBean();

    ObjectName memberObjectName = MBeanJMXAdapter
            .getMemberMBeanName(InternalDistributedSystem.getConnectedInstance().getDistributedMember());

    FederationComponent removedComp = service.getLocalManager().getFedComponents().get(memberObjectName);

    service.afterRemoveProxy(memberObjectName, MemberMXBean.class, localMember, removedComp);

    for (ObjectName objectName : registeredMBeans.keySet()) {
        if (objectName.equals(memberObjectName)) {
            continue;
        }
        if (aggregatemMBeanPattern.apply(objectName)) {
            continue;
        }
        Object object = registeredMBeans.get(objectName);
        ObjectInstance instance;
        try {
            instance = mbeanServer.getObjectInstance(objectName);
            String className = instance.getClassName();
            Class cls = ClassLoadUtil.classFromName(className);
            Type[] intfTyps = cls.getGenericInterfaces();

            FederationComponent oldObj = service.getLocalManager().getFedComponents().get(objectName);

            for (Type intfTyp1 : intfTyps) {
                Class intfTyp = (Class) intfTyp1;
                service.afterRemoveProxy(objectName, intfTyp, object, oldObj);
            }
        } catch (InstanceNotFoundException | ClassNotFoundException e) {
            logger.warn("Failed to invoke aggregator for {} with exception {}", objectName, e.getMessage(), e);
        }
    }
    service.removeProxyListener(this.aggregator);
    this.aggregator = null;
}