Example usage for javax.management ObjectName equals

List of usage examples for javax.management ObjectName equals

Introduction

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

Prototype

@Override
public boolean equals(Object object) 

Source Link

Document

Compares the current object name with another object name.

Usage

From source file:org.cipango.console.ApplicationManager.java

private static boolean isContext(ObjectName objectName, MBeanServerConnection mbsc) throws Exception {
    ObjectName[] contexts = getWebAppContexts(mbsc);
    for (ObjectName name : contexts)
        if (name.equals(objectName))
            return true;
    return false;
}

From source file:org.rhq.plugins.jbosscache3.test.CacheComponentTest.java

@Test
public void testDiscovery() throws Exception {
    PluginContainer.getInstance().getInventoryManager().executeServiceScanImmediately();

    Set<Resource> resources = TestHelper
            .getResources(TestHelper.getResourceType(CACHE_RESOURCE_TYPE_NAME, CACHE_PLUGIN_NAME));

    ObjectName testResource = new ObjectName(ADDED_RESOURCE);

    for (int i = 0; i < RESOURCE_TYPES.length - 1; i++) {
        System.out.println(RESOURCE_TYPES[i]);
        ResourceType type = TestHelper.getResourceType(RESOURCE_TYPES[i], CACHE_PLUGIN_NAME);
        if (type != null) {
            Set<Resource> res = TestHelper.getResources(type);
            List<EmsBean> beans = connection.queryBeans(searchString + JMX_COMPONENT_NAMES[i]);

            assert (res.size() == beans.size());
            resources.addAll(res);/*w ww  . j a v  a2s.co m*/
        } else {
            assert (connection.queryBeans(searchString + JMX_COMPONENT_NAMES[i]).size() == 0);
        }
    }

    boolean isTestExamplePresent = false;
    Set cacheNames = new HashSet();
    Pattern p = Pattern.compile(REGEX);

    for (Resource resource : resources) {
        ObjectName resourceName = new ObjectName(resource.getResourceKey());

        if (resourceName.equals(testResource)) {
            isTestExamplePresent = true;
        }

        String beanName = resource.getResourceKey();

        Matcher m = p.matcher(beanName);
        if (m.find()) {
            beanName = m.replaceFirst(m.group(2).equals(",") ? m.group(1) : "");

            if (!cacheNames.contains(beanName)) {
                EmsBean bean = connection.getBean(beanName);
                if (bean != null)
                    cacheNames.add(beanName);
            }
        }
    }

    ResourceType type = TestHelper.getResourceType(CACHE_RESOURCE_TYPE_NAME, CACHE_PLUGIN_NAME);
    Set<Resource> res = TestHelper.getResources(type);

    for (Resource resource : res) {
        assert (cacheNames.contains(resource.getResourceKey()));
    }

    assert (res.size() == cacheNames.size());
    assert !resources.isEmpty();
    assert isTestExamplePresent;
}

From source file:org.jolokia.client.request.J4pReadResponse.java

/**
 * Get the name of all attributes fetched for a certain MBean name. If the request was
 * performed for a single MBean, then the given name must match that of the MBean name
 * provided in the request. If <code>null</code> is given as argument, then this method
 * will return all attributes for the single MBean given in the request
 *
 * @param pObjectName MBean for which to get the attribute names,
 * @return a collection of attribute names
 *///from  w  ww  .j  a  v  a 2s.  c o  m
public Collection<String> getAttributes(ObjectName pObjectName) {
    ObjectName requestMBean = getRequest().getObjectName();
    if (requestMBean.isPattern()) {
        // We need to got down one level in the returned values
        JSONObject attributes = getAttributesForObjectNameWithPatternRequest(pObjectName);
        return attributes.keySet();
    } else {
        if (pObjectName != null && !pObjectName.equals(requestMBean)) {
            throw new IllegalArgumentException("Given ObjectName " + pObjectName + " doesn't match with"
                    + " the single ObjectName " + requestMBean + " given in the request");
        }
        return getAttributes();
    }
}

From source file:org.jboss.web.tomcat.tc5.Tomcat5.java

public void startService() throws Exception {

    System.setProperty("catalina.ext.dirs",
            (System.getProperty("jboss.server.home.dir") + File.separator + "lib"));

    String objectNameS = catalinaDomain + ":type=server";
    ObjectName objectName = new ObjectName(objectNameS);

    // Set the modeler Registry MBeanServer to the that of the tomcat service
    Registry.getRegistry().setMBeanServer(server);

    server.createMBean("org.apache.commons.modeler.BaseModelMBean", objectName,
            new Object[] { "org.apache.catalina.startup.Catalina" }, new String[] { "java.lang.String" });

    server.setAttribute(objectName, new Attribute("catalinaHome", System.getProperty("jboss.server.home.dir")));
    server.setAttribute(objectName, new Attribute("configFile", serverConfigFile));
    server.setAttribute(objectName, new Attribute("useNaming", new Boolean(false)));
    server.setAttribute(objectName, new Attribute("useShutdownHook", new Boolean(false)));
    server.setAttribute(objectName, new Attribute("await", new Boolean(false)));
    server.setAttribute(objectName, new Attribute("redirectStreams", new Boolean(false)));

    server.invoke(objectName, "create", new Object[] {}, new String[] {});

    server.invoke(objectName, "start", new Object[] {}, new String[] {});

    // Configure any SingleSignOn valves      

    ObjectName ssoQuery = new ObjectName("*:type=Valve,*");
    Iterator iterator = server.queryMBeans(ssoQuery, null).iterator();
    while (iterator.hasNext()) {
        ObjectName ssoObjectName = ((ObjectInstance) iterator.next()).getObjectName();
        String name = ssoObjectName.getKeyProperty("name");

        /* Ensure that the SingleSignOn valve requires that each
           request be reauthenticated to the security mgr. Should not
           be neccessary now that we cache the principal in the session.
        if ((name != null) && (name.indexOf("SingleSignOn") >= 0))
        {/*from  w ww  .  j a v a2 s .  c o m*/
           log.info("Turning on reauthentication of each request on " +
             ssoObjectName);
           server.setAttribute(ssoObjectName, new Attribute
              ("requireReauthentication", Boolean.TRUE));
        }
        */

        // If the valve is a ClusteredSingleSignOn and we have a shared
        // TreeCache configured, configure the valve to use the shared one
        if (cacheName != null && "ClusteredSingleSignOn".equals(name)) {
            String tcName = (String) server.getAttribute(ssoObjectName, "treeCacheName");
            tcName = (tcName != null ? tcName : DEFAULT_CACHE_NAME);
            ObjectName ssoCacheName = new ObjectName(tcName);
            // Only override if the valve's cacheName property was not
            // explicitly set in server.xml to a non-default value
            if (ssoCacheName.equals(new ObjectName(DEFAULT_CACHE_NAME))) {
                log.info("Setting the cache name to " + cacheName + " on " + ssoObjectName);
                server.setAttribute(ssoObjectName, new Attribute("treeCacheName", cacheName));
            }
        }
    }

    // Register the web container JACC PolicyContextHandlers
    HttpServletRequestPolicyContextHandler handler = new HttpServletRequestPolicyContextHandler();
    PolicyContext.registerHandler(HttpServletRequestPolicyContextHandler.WEB_REQUEST_KEY, handler, true);

    // The ServiceController used to control web app startup dependencies
    serviceController = (ServiceControllerMBean) MBeanProxyExt.create(ServiceControllerMBean.class,
            ServiceControllerMBean.OBJECT_NAME, server);

    // make a proxy to myself, so that calls from the MainDeployer
    // can go through the MBeanServer, so interceptors can be added
    thisProxy = (SubDeployerExt) MBeanProxyExt.create(SubDeployerExt.class, super.getServiceName(),
            super.getServer());

    // Register with the main deployer
    mainDeployer.addDeployer(thisProxy);

    // If we are hot-deployed *after* the overall server is started
    // we'll never receive Server.START_NOTIFICATION_TYPE, so check
    // with the Server and start the connectors immediately, if this is the case.
    // Otherwise register to receive the server start-up notification.
    Boolean started = (Boolean) server.getAttribute(ServerImplMBean.OBJECT_NAME, "Started");
    if (started.booleanValue() == true) {
        log.debug("Server '" + ServerImplMBean.OBJECT_NAME + "' already started, starting connectors now");

        startConnectors();
    } else {
        // Register for notification of the overall server startup
        log.debug("Server '" + ServerImplMBean.OBJECT_NAME
                + "' not started, registering for start-up notification");

        server.addNotificationListener(ServerImplMBean.OBJECT_NAME, this, null, null);
    }
}

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//w  w w .j a va 2 s . com
 */
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;
}

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

/**
 * Handles all the distributed mbean creation part when a Manager is started
 *//*from w w w .  ja v a2 s.c  o  m*/
public void handleManagerStart() throws ManagementException {
    if (!isServiceInitialised("handleManagerStart")) {
        return;
    }
    MBeanJMXAdapter jmxAdapter = service.getJMXAdapter();
    Map<ObjectName, Object> registeredMBeans = jmxAdapter.getLocalGemFireMBean();

    DistributedSystemBridge dsBridge = new DistributedSystemBridge(service);
    this.aggregator = new MBeanAggregator(dsBridge);
    // register the aggregator for Federation framework to use
    service.addProxyListener(aggregator);

    /*
     * get the local member mbean as it need to be provided to aggregator first
     */

    MemberMXBean localMember = service.getMemberMXBean();
    ObjectName memberObjectName = MBeanJMXAdapter
            .getMemberMBeanName(InternalDistributedSystem.getConnectedInstance().getDistributedMember());

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

    service.afterCreateProxy(memberObjectName, MemberMXBean.class, localMember, addedComp);

    for (ObjectName objectName : registeredMBeans.keySet()) {
        if (objectName.equals(memberObjectName)) {
            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 newObj = service.getLocalManager().getFedComponents().get(objectName);

            for (Type intfTyp1 : intfTyps) {
                Class intfTyp = (Class) intfTyp1;
                service.afterCreateProxy(objectName, intfTyp, object, newObj);

            }
        } catch (InstanceNotFoundException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Failed in Registering distributed mbean ");
            }
            throw new ManagementException(e);
        } catch (ClassNotFoundException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Failed in Registering distributed mbean");
            }
            throw new ManagementException(e);
        }
    }
}

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

/**
 * Add a proxy to the map to be used by bridge.
 *
 * @param objectName object name of the proxy
 * @param proxy actual proxy instance/*  ww  w  .j a  v  a2 s.  co  m*/
 */
public void addMemberToSystem(ObjectName objectName, MemberMXBean proxy, FederationComponent newState) {

    if (objectName.equals(thisMemberName)) {
        ObjectName distrObjectName = MBeanJMXAdapter.getDistributedSystemName();
        DistributedSystemMXBean systemMBean = new DistributedSystemMBean(this);
        service.registerInternalMBean(systemMBean, distrObjectName);
        this.systemLevelNotifEmitter = (DistributedSystemMBean) service.getDistributedSystemMXBean();
        this.distListener = new DistributedSystemNotifListener();
    }

    if (mapOfMembers != null) {
        mapOfMembers.put(objectName, proxy);
        memberSetSize = mapOfMembers.values().size();

    }
    updateMember(objectName, newState, null);

    try {
        mbeanServer.addNotificationListener(objectName, distListener, null, null);
    } catch (InstanceNotFoundException e) {

        if (logger.isDebugEnabled()) {
            logger.debug(e.getMessage());
        }

        logger.info(LocalizedMessage.create(ManagementStrings.INSTANCE_NOT_FOUND, objectName));
    }
}