Search in sources :

Example 1 with ManagedWithObjectNameTemplate

use of org.exoplatform.container.jmx.support.ManagedWithObjectNameTemplate in project kernel by exoplatform.

the class TestRootContainerManagedIntegration method testManagementAwareManagingOtherBeans.

public void testManagementAwareManagingOtherBeans() throws Exception {
    RootContainer container = createRootContainer("configuration4.xml");
    ManagedManagementAware aware = (ManagedManagementAware) container.getComponentInstance("ManagedManagementAware");
    aware.context.register(new ManagedWithObjectNameTemplate("juu"));
    container.getMBeanServer().getObjectInstance(new ObjectName("exo:object=juu"));
}
Also used : ManagedWithObjectNameTemplate(org.exoplatform.container.jmx.support.ManagedWithObjectNameTemplate) ManagedManagementAware(org.exoplatform.container.jmx.support.ManagedManagementAware) RootContainer(org.exoplatform.container.RootContainer) ObjectName(javax.management.ObjectName)

Example 2 with ManagedWithObjectNameTemplate

use of org.exoplatform.container.jmx.support.ManagedWithObjectNameTemplate in project kernel by exoplatform.

the class TestRegistration method testFoo.

public void testFoo() throws Exception {
    RootContainer root = createRootContainer("registration-configuration.xml");
    assertNotNull(root.getMBeanServer());
    Object instance = root.getComponentInstance("Foo");
    assertNotNull(instance);
    MBeanServer server = root.getMBeanServer();
    Set<ObjectInstance> set = server.queryMBeans(ObjectName.getInstance("exo:object=Foo"), null);
    assertEquals(1, set.size());
    ObjectInstance oi = set.iterator().next();
    ExoContainer oldContainer = ExoContainerContext.getCurrentContainerIfPresent();
    ExoContainer currentContainer = new ExoContainer();
    ExoContainerContext.setCurrentContainer(currentContainer);
    try {
        ExoContainerFinder proxyObject = MBeanServerInvocationHandler.newProxyInstance(server, oi.getObjectName(), ExoContainerFinder.class, false);
        assertTrue("We expect to get the current exo container", oldContainer == proxyObject.getCurrentExoContainer());
        assertTrue("We expect to get the previous exo container", ExoContainerContext.getCurrentContainerIfPresent() == currentContainer);
        ExoContainerContext.setCurrentContainer(oldContainer);
        assertTrue("We expect to get the current exo container", oldContainer == proxyObject.getCurrentExoContainer());
        assertTrue("We expect to get the previous exo container", ExoContainerContext.getCurrentContainerIfPresent() == oldContainer);
        ExoContainerContext.setCurrentContainer(null);
        assertTrue("We expect to get the current exo container", oldContainer == proxyObject.getCurrentExoContainer());
        assertTrue("We expect to get the previous exo container", ExoContainerContext.getCurrentContainerIfPresent() == oldContainer);
    } finally {
        ExoContainerContext.setCurrentContainer(oldContainer);
    }
    // Manual
    root.registerComponentInstance("Bar", new ManagedWithObjectNameTemplate("Bar"));
    Object instance2 = root.getComponentInstance("Bar");
    assertNotNull(instance2);
    Set set2 = server.queryMBeans(ObjectName.getInstance("exo:object=Bar"), null);
    assertEquals(1, set2.size());
}
Also used : ManagedWithObjectNameTemplate(org.exoplatform.container.jmx.support.ManagedWithObjectNameTemplate) Set(java.util.Set) ExoContainer(org.exoplatform.container.ExoContainer) ExoContainerFinder(org.exoplatform.container.jmx.support.ExoContainerFinder) ObjectInstance(javax.management.ObjectInstance) RootContainer(org.exoplatform.container.RootContainer) MBeanServer(javax.management.MBeanServer)

Aggregations

RootContainer (org.exoplatform.container.RootContainer)2 ManagedWithObjectNameTemplate (org.exoplatform.container.jmx.support.ManagedWithObjectNameTemplate)2 Set (java.util.Set)1 MBeanServer (javax.management.MBeanServer)1 ObjectInstance (javax.management.ObjectInstance)1 ObjectName (javax.management.ObjectName)1 ExoContainer (org.exoplatform.container.ExoContainer)1 ExoContainerFinder (org.exoplatform.container.jmx.support.ExoContainerFinder)1 ManagedManagementAware (org.exoplatform.container.jmx.support.ManagedManagementAware)1