Search in sources :

Example 1 with ProxyFactory

use of com.sun.appserv.management.client.ProxyFactory in project Payara by payara.

the class ProxyFactoryTest method testProxyFactoryDetectsMBeanRemoved.

/**
 *     Verify that when an MBean is removed, the ProxyFactory
 *     detects this, and removes any proxy from its cache.
 */
public void testProxyFactoryDetectsMBeanRemoved() throws InstanceNotFoundException {
    // use the NotificationServiceMgr as a convenient way of making
    // an MBean (a NotificationService) come and go.
    final NotificationServiceMgr mgr = getDomainRoot().getNotificationServiceMgr();
    final NotificationService ns = mgr.createNotificationService("UserData", 10);
    final ObjectName nsObjectName = Util.getObjectName(ns);
    assert (ns.getUserData().equals("UserData"));
    final ProxyFactory factory = getProxyFactory();
    final NotificationService proxy = factory.getProxy(nsObjectName, NotificationService.class, false);
    assert (proxy == ns) : "proxies differ: " + ns + "\n" + proxy;
    mgr.removeNotificationService(ns.getName());
    int iterations = 0;
    long sleepMillis = 10;
    while (factory.getProxy(nsObjectName, NotificationService.class, false) != null) {
        mySleep(sleepMillis);
        if (sleepMillis >= 400) {
            trace("testProxyFactoryDetectsMBeanRemoved: waiting for proxy to be removed");
        }
        sleepMillis *= 2;
    }
}
Also used : NotificationServiceMgr(com.sun.appserv.management.base.NotificationServiceMgr) ProxyFactory(com.sun.appserv.management.client.ProxyFactory) NotificationService(com.sun.appserv.management.base.NotificationService) ObjectName(javax.management.ObjectName)

Example 2 with ProxyFactory

use of com.sun.appserv.management.client.ProxyFactory in project Payara by payara.

the class AMXTestBase method getProxy.

protected final AMX getProxy(final ObjectName objectName) {
    final ProxyFactory factory = ProxyFactory.getInstance(getConnectionSource(), true);
    final AMX proxy = factory.getProxy(objectName, AMX.class);
    return (proxy);
}
Also used : ProxyFactory(com.sun.appserv.management.client.ProxyFactory) AMX(com.sun.appserv.management.base.AMX)

Example 3 with ProxyFactory

use of com.sun.appserv.management.client.ProxyFactory in project Payara by payara.

the class TestUtil method asAMXDebugStuff.

public AMXDebugStuff asAMXDebugStuff(final AMX amx) {
    final String[] attrNames = Util.getExtra(amx).getAttributeNames();
    AMXDebugStuff result = null;
    if (GSetUtil.newUnmodifiableStringSet(attrNames).contains("AMXDebug")) {
        final ProxyFactory factory = Util.getExtra(amx).getProxyFactory();
        try {
            final Class amxClass = ClassUtil.getClassFromName(Util.getExtra(amx).getInterfaceName());
            final Class[] interfaces = new Class[] { amxClass, AMXDebugStuff.class };
            final ObjectName objectName = Util.getObjectName(amx);
            return (AMXDebugStuff) factory.newProxyInstance(objectName, interfaces);
        } catch (Exception e) {
            trace(ExceptionUtil.toString(e));
            throw new RuntimeException(e);
        }
    }
    return result;
}
Also used : ProxyFactory(com.sun.appserv.management.client.ProxyFactory) AMXDebugStuff(org.glassfish.admin.amx.util.AMXDebugStuff) ObjectName(javax.management.ObjectName)

Example 4 with ProxyFactory

use of com.sun.appserv.management.client.ProxyFactory in project Payara by payara.

the class TestUtil method getAllAMX.

/**
 *     @return all AMX, sorted by ObjectName
 */
public SortedSet<AMX> getAllAMX() {
    final SortedSet<ObjectName> all = getAllObjectNames();
    final SortedSet<AMX> allAMX = new TreeSet<AMX>(new AMXComparator<AMX>());
    final ProxyFactory proxyFactory = Util.getExtra(mDomainRoot).getProxyFactory();
    for (final ObjectName objectName : all) {
        try {
            final AMX amx = proxyFactory.getProxy(objectName, AMX.class);
            allAMX.add(amx);
        } catch (Exception e) {
            trace(ExceptionUtil.toString(e));
        }
    }
    return allAMX;
}
Also used : ProxyFactory(com.sun.appserv.management.client.ProxyFactory) TreeSet(java.util.TreeSet) AMX(com.sun.appserv.management.base.AMX) ObjectName(javax.management.ObjectName)

Example 5 with ProxyFactory

use of com.sun.appserv.management.client.ProxyFactory in project Payara by payara.

the class ConfigMgrTestBase method testCreateRemove.

public final synchronized void testCreateRemove() throws Exception {
    if (!checkNotOffline("testCreateRemove")) {
        return;
    }
    final long start = now();
    String name = getProgenyTestName();
    final String progenyJ2EEType = getProgenyJ2EEType();
    AMXConfig proxy = getProgeny(name);
    if (proxy != null) {
        final ObjectName objectName = Util.getExtra(proxy).getObjectName();
        remove(name);
        waitUnregistered(objectName);
        assert (!getConnection().isRegistered(objectName));
        assert (getProgeny(name) == null);
        proxy = null;
    }
    final Container container = getProgenyContainer();
    final CreateRemoveListener listener = new CreateRemoveListener(container, progenyJ2EEType, name);
    // create it
    try {
        proxy = createProgeny(name, null);
    } catch (Exception e) {
        trace(getStackTrace(ExceptionUtil.getRootCause(e)));
        failure("Can't create item of j2eeType=" + progenyJ2EEType + ",name=" + name);
    }
    assert (proxy.getName().equals(name));
    final ObjectName objectName = Util.getObjectName(proxy);
    assert (getConnection().isRegistered(objectName));
    assert (container.getContainee(progenyJ2EEType, name) != null);
    assert (container.getContainee(progenyJ2EEType, name) == proxy);
    final AMXConfig progeny = getProgeny(name);
    assert (progeny == proxy);
    // remove it
    final ProxyFactory factory = Util.getExtra(proxy).getProxyFactory();
    assert (name.equals(progeny.getName()));
    remove(name);
    waitUnregistered(objectName);
    assert (!getConnection().isRegistered(objectName));
    waitProxyGone(factory, objectName);
    assert (getProgeny(name) == null);
    listener.waitNotifs();
    printElapsed("testCreateRemove: created/remove/listen for: " + progenyJ2EEType, start);
}
Also used : Container(com.sun.appserv.management.base.Container) ProxyFactory(com.sun.appserv.management.client.ProxyFactory) AMXConfig(com.sun.appserv.management.config.AMXConfig) CreateRemoveListener(org.glassfish.admin.amxtest.support.CreateRemoveListener) ObjectName(javax.management.ObjectName)

Aggregations

ProxyFactory (com.sun.appserv.management.client.ProxyFactory)5 ObjectName (javax.management.ObjectName)4 AMX (com.sun.appserv.management.base.AMX)2 Container (com.sun.appserv.management.base.Container)1 NotificationService (com.sun.appserv.management.base.NotificationService)1 NotificationServiceMgr (com.sun.appserv.management.base.NotificationServiceMgr)1 AMXConfig (com.sun.appserv.management.config.AMXConfig)1 TreeSet (java.util.TreeSet)1 AMXDebugStuff (org.glassfish.admin.amx.util.AMXDebugStuff)1 CreateRemoveListener (org.glassfish.admin.amxtest.support.CreateRemoveListener)1