Java Code Examples for javax.management.ObjectName#equals()

The following examples show how to use javax.management.ObjectName#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NotificationAccessControllerTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check received notifications
 */
public int checkNotifs(int size,
                       List<Notification> received,
                       List<ObjectName> expected) {
    if (received.size() != size) {
        echo("Error: expecting " + size + " notifications, got " +
                received.size());
        return 1;
    } else {
        for (Notification n : received) {
            echo("Received notification: " + n);
            if (!n.getType().equals("nb")) {
                echo("Notification type must be \"nb\"");
                return 1;
            }
            ObjectName o = (ObjectName) n.getSource();
            int index = (int) n.getSequenceNumber();
            ObjectName nb = expected.get(index);
            if (!o.equals(nb)) {
                echo("Notification source must be " + nb);
                return 1;
            }
        }
    }
    return 0;
}
 
Example 2
Source File: NotificationEmissionTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public int checkNotifs(int size,
                       List<Notification> received,
                       List<ObjectName> expected) {
    if (received.size() != size) {
        echo("Error: expecting " + size + " notifications, got " +
                received.size());
        return 1;
    } else {
        for (Notification n : received) {
            echo("Received notification: " + n);
            if (!n.getType().equals("nb")) {
                echo("Notification type must be \"nb\"");
                return 1;
            }
            ObjectName o = (ObjectName) n.getSource();
            int index = (int) n.getSequenceNumber();
            ObjectName nb = expected.get(index);
            if (!o.equals(nb)) {
                echo("Notification source must be " + nb);
                return 1;
            }
        }
    }
    return 0;
}
 
Example 3
Source File: ClassLoaderRepositorySupport.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Same behavior as remove(Object o) in {@link java.util.List}.
 * Replace the loader list with a new one in which the old loader
 * has been removed.
 *
 * The ObjectName may be null, in which case the entry to
 * be removed must also have a null ObjectName and the ClassLoader
 * values must match.  If the ObjectName is not null, then
 * the first entry with a matching ObjectName is removed,
 * regardless of whether ClassLoader values match.  (In fact,
 * the ClassLoader parameter will usually be null in this case.)
 **/
private synchronized boolean remove(ObjectName name, ClassLoader cl) {
    final int size = loaders.length;
    for (int i = 0; i < size; i++) {
        LoaderEntry entry = loaders[i];
        boolean match =
            (name == null) ?
            cl == entry.loader :
            name.equals(entry.name);
        if (match) {
            LoaderEntry[] newloaders = new LoaderEntry[size - 1];
            System.arraycopy(loaders, 0, newloaders, 0, i);
            System.arraycopy(loaders, i + 1, newloaders, i,
                             size - 1 - i);
            loaders = newloaders;
            return true;
        }
    }
    return false;
}
 
Example 4
Source File: ClassLoaderRepositorySupport.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Same behavior as remove(Object o) in {@link java.util.List}.
 * Replace the loader list with a new one in which the old loader
 * has been removed.
 *
 * The ObjectName may be null, in which case the entry to
 * be removed must also have a null ObjectName and the ClassLoader
 * values must match.  If the ObjectName is not null, then
 * the first entry with a matching ObjectName is removed,
 * regardless of whether ClassLoader values match.  (In fact,
 * the ClassLoader parameter will usually be null in this case.)
 **/
private synchronized boolean remove(ObjectName name, ClassLoader cl) {
    final int size = loaders.length;
    for (int i = 0; i < size; i++) {
        LoaderEntry entry = loaders[i];
        boolean match =
            (name == null) ?
            cl == entry.loader :
            name.equals(entry.name);
        if (match) {
            LoaderEntry[] newloaders = new LoaderEntry[size - 1];
            System.arraycopy(loaders, 0, newloaders, 0, i);
            System.arraycopy(loaders, i + 1, newloaders, i,
                             size - 1 - i);
            loaders = newloaders;
            return true;
        }
    }
    return false;
}
 
Example 5
Source File: JMXManagementService.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
public synchronized void stopManagement() {
    
    // Has this service been shut down?
    if (registeredMbeans == null)
        return;
    
    checkJMXControl();
    
    if (isManagementActive()) {
        for (ObjectName mbeanName : registeredMbeans.keySet())
        {
            // If we registered this as a management bean
            // then leave it registered to allow the mbeans
            // to be re-registered with JMX
            if (mbeanName.equals(myManagementBean))
                continue;
            jmxUnregister(mbeanName);
        }
        mbeanServer = null;
    }
}
 
Example 6
Source File: NotificationEmissionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public int checkNotifs(int size,
                       List<Notification> received,
                       List<ObjectName> expected) {
    if (received.size() != size) {
        echo("Error: expecting " + size + " notifications, got " +
                received.size());
        return 1;
    } else {
        for (Notification n : received) {
            echo("Received notification: " + n);
            if (!n.getType().equals("nb")) {
                echo("Notification type must be \"nb\"");
                return 1;
            }
            ObjectName o = (ObjectName) n.getSource();
            int index = (int) n.getSequenceNumber();
            ObjectName nb = expected.get(index);
            if (!o.equals(nb)) {
                echo("Notification source must be " + nb);
                return 1;
            }
        }
    }
    return 0;
}
 
Example 7
Source File: JMXManagementService.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public synchronized void stopManagement() {
    
    // Has this service been shut down?
    if (registeredMbeans == null)
        return;
    
    checkJMXControl();
    
    if (isManagementActive()) {
        for (ObjectName mbeanName : registeredMbeans.keySet())
        {
            // If we registered this as a management bean
            // then leave it registered to allow the mbeans
            // to be re-registered with JMX
            if (mbeanName.equals(myManagementBean))
                continue;
            jmxUnregister(mbeanName);
        }
        mbeanServer = null;
    }
}
 
Example 8
Source File: ClassLoaderRepositorySupport.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Same behavior as remove(Object o) in {@link java.util.List}.
 * Replace the loader list with a new one in which the old loader
 * has been removed.
 *
 * The ObjectName may be null, in which case the entry to
 * be removed must also have a null ObjectName and the ClassLoader
 * values must match.  If the ObjectName is not null, then
 * the first entry with a matching ObjectName is removed,
 * regardless of whether ClassLoader values match.  (In fact,
 * the ClassLoader parameter will usually be null in this case.)
 **/
private synchronized boolean remove(ObjectName name, ClassLoader cl) {
    final int size = loaders.length;
    for (int i = 0; i < size; i++) {
        LoaderEntry entry = loaders[i];
        boolean match =
            (name == null) ?
            cl == entry.loader :
            name.equals(entry.name);
        if (match) {
            LoaderEntry[] newloaders = new LoaderEntry[size - 1];
            System.arraycopy(loaders, 0, newloaders, 0, i);
            System.arraycopy(loaders, i + 1, newloaders, i,
                             size - 1 - i);
            loaders = newloaders;
            return true;
        }
    }
    return false;
}
 
Example 9
Source File: DelegateNameWildcardNameTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        System.out.println(
            "Test that <MBeanServerDelegate.DELEGATE_NAME> equals " +
            "<new ObjectName(\"JMImplementation:type=MBeanServerDelegate\")>");
        final ObjectName delegateName =
                new ObjectName("JMImplementation:type=MBeanServerDelegate");
        if (!delegateName.equals(MBeanServerDelegate.DELEGATE_NAME))
            throw new AssertionError("Unexpected value: " +
                    "MBeanServerDelegate.DELEGATE_NAME = " +
                    MBeanServerDelegate.DELEGATE_NAME);
        System.out.println("MBeanServerDelegate.DELEGATE_NAME = " +
                "new ObjectName(\"" + delegateName + "\")");

        System.out.println("Test that <ObjectName.WILDCARD> " +
                           "equals <new ObjectName(\"*:*\")>");
        final ObjectName wildcardName = new ObjectName("*:*");
        if (!wildcardName.equals(ObjectName.WILDCARD))
            throw new AssertionError("Unexpected value: " +
                    "ObjectName.WILDCARD = " +
                    ObjectName.WILDCARD);
        System.out.println("ObjectName.WILDCARD = " +
                "new ObjectName(\"" + wildcardName + "\")");

        System.out.println("Test passes: constants were initialized properly");
    }
 
Example 10
Source File: MXBeanLookup.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
synchronized boolean removeReference(ObjectName name, Object mxbean) {
    if (name.equals(mxbeanToObjectName.get(mxbean))) {
        mxbeanToObjectName.remove(mxbean);
        return true;
    } else
        return false;
    /* removeReference can be called when the above condition fails,
     * notably if you try to register the same MXBean twice.
     */
}
 
Example 11
Source File: MXBeanLookup.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
synchronized boolean removeReference(ObjectName name, Object mxbean) {
    if (name.equals(mxbeanToObjectName.get(mxbean))) {
        mxbeanToObjectName.remove(mxbean);
        return true;
    } else
        return false;
    /* removeReference can be called when the above condition fails,
     * notably if you try to register the same MXBean twice.
     */
}
 
Example 12
Source File: JMXManagementService.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public synchronized void startManagement() {
    
    //Has this service been shut down?
    if (registeredMbeans == null)
        return;
    
    checkJMXControl();
    
    // Already active?
    if (isManagementActive())
        return;
    
    findServer();
    
    // If we can't find the server then we can't register.
    if (mbeanServer == null)
        return;
    
    for (ObjectName mbeanName : registeredMbeans.keySet())
    {
        // If we registered this as a management bean
        // then leave it registered to allow the mbeans
        // to be re-registered with JMX
        if (mbeanName.equals(myManagementBean) &&
                mbeanServer.isRegistered(myManagementBean))
            continue;
        
        try {
            jmxRegister(registeredMbeans.get(mbeanName), mbeanName);
        } catch (JMException e) {
            // TODO - what to do here?
        }
    }
}
 
Example 13
Source File: MXBeanLookup.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
synchronized boolean removeReference(ObjectName name, Object mxbean) {
    if (name.equals(mxbeanToObjectName.get(mxbean))) {
        mxbeanToObjectName.remove(mxbean);
        return true;
    } else
        return false;
    /* removeReference can be called when the above condition fails,
     * notably if you try to register the same MXBean twice.
     */
}
 
Example 14
Source File: JMXValidator.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private List<JMXEvent> getEventForThisMbean(List<JMXEvent> events, ObjectName name) {
  List<JMXEvent> eventList = new ArrayList<JMXEvent>();
  logInfo("Filtering out events for mbean objectName " + name);
  for (JMXEvent event : events) {
    if (name.equals(event.getObjectName()))
      eventList.add(event);
  }
  logInfo("Filtered " + eventList.size() + " events out of " + events.size());
  return eventList;
}
 
Example 15
Source File: PreRegisterNameTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    for (Class<?> c : new Class<?>[] {
            Spume.class, Thing.class, XSpume.class, XThing.class
         }) {
        for (ObjectName n : new ObjectName[] {null, new ObjectName("a:b=c")}) {
            System.out.println("Class " + c.getName() + " with name " + n +
                    "...");
            ObjectName realName = new ObjectName("a:type=" + c.getName());
            Constructor<?> constr = c.getConstructor(ObjectName.class);
            Object mbean = constr.newInstance(realName);
            ObjectInstance oi;
            String what =
                "Registering MBean of type " + c.getName() + " under name " +
                "<" + n + ">: ";
            try {
                oi = mbs.registerMBean(mbean, n);
            } catch (Exception e) {
                e.printStackTrace();
                fail(what + " got " + e);
                continue;
            }
            ObjectName registeredName = oi.getObjectName();
            if (!registeredName.equals(realName))
                fail(what + " registered as " + registeredName);
            if (!mbs.isRegistered(realName)) {
                fail(what + " not registered as expected");
            }
            mbs.unregisterMBean(registeredName);
        }
    }
    System.err.flush();
    if (failures == 0)
        System.out.println("TEST PASSED");
    else
        throw new Exception("TEST FAILED: " + failure);
}
 
Example 16
Source File: OldMBeanServerTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public Object instantiate(
        String className, ObjectName loaderName,
        Object[] params, String[] signature)
throws ReflectionException, MBeanException, InstanceNotFoundException {

    if (params == null)
        params = new Object[0];
    if (signature == null)
        signature = new String[0];

    ClassLoader loader;
    if (loaderName == null)
        loader = this.getClass().getClassLoader();
    else if (loaderName.equals(clrName))
        loader = clr;
    else
        loader = (ClassLoader) getMBean(loaderName);

    Class<?> c;
    try {
        c = Class.forName(className, false, loader);
    } catch (ClassNotFoundException e) {
        throw new ReflectionException(e);
    }

    Constructor[] constrs = c.getConstructors();
    Constructor found = null;
    findconstr:
    for (Constructor constr : constrs) {
        Class<?>[] cTypes = constr.getParameterTypes();
        if (cTypes.length == signature.length) {
            for (int i = 0; i < cTypes.length; i++) {
                if (!cTypes[i].getName().equals(signature[i]))
                    continue findconstr;
            }
            found = constr;
            break findconstr;
        }
    }
    if (found == null) {
        Exception x = new NoSuchMethodException(
                className + Arrays.toString(signature));
        throw new ReflectionException(x);
    }
    return invokeSomething(found, null, params);
}
 
Example 17
Source File: MXBeanInteropTest2.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private final int doBasicMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- doBasicMXBeanTest") ;

    try {
        ObjectName objName =
                new ObjectName("sqe:type=BasicMXBean") ;
        mbsc.createMBean(BASIC_MXBEAN_CLASS_NAME, objName);
        MBeanInfo mbInfo = mbsc.getMBeanInfo(objName);
        printMBeanInfo(mbInfo);
        System.out.println("---- OK\n") ;
        System.out.println("getMBeanInfo\t\t"
                + mbInfo);
        System.out.println("---- OK\n") ;

        System.out.println("Check mxbean field in the MBeanInfo");
        String mxbeanField =
                (String)mbInfo.getDescriptor().getFieldValue(JMX.MXBEAN_FIELD);

        if ( mxbeanField == null || ! mxbeanField.equals("true")) {
            System.out.println("---- ERROR : Improper mxbean field value "
                    + mxbeanField);
            errorCount++;
        }
        System.out.println("---- OK\n") ;

        System.out.println("Set attribute ObjectNameAtt");
        Attribute att = new Attribute("ObjectNameAtt", objName);
        mbsc.setAttribute(objName, att);
        ObjectName value =
                (ObjectName)mbsc.getAttribute(objName, "ObjectNameAtt");

        if ( ! value.equals(objName) ) {
            errorCount++;
            System.out.println("---- ERROR : setAttribute failed, got "
                    + value
                    + " while expecting "
                    + objName);
        }
        System.out.println("---- OK\n") ;

        System.out.println("Call operation doNothing");
        mbsc.invoke(objName,  "doNothing", null, null);
        System.out.println("---- OK\n") ;

        System.out.println("Call operation getWeather");
        Object weather = mbsc.invoke(objName,
                "getWeather",
                new Object[]{Boolean.TRUE},
                new String[]{"boolean"});
        System.out.println("Weather is " + weather);
        System.out.println("---- OK\n") ;
    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
Example 18
Source File: OldMBeanServerTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public Object instantiate(
        String className, ObjectName loaderName,
        Object[] params, String[] signature)
throws ReflectionException, MBeanException, InstanceNotFoundException {

    if (params == null)
        params = new Object[0];
    if (signature == null)
        signature = new String[0];

    ClassLoader loader;
    if (loaderName == null)
        loader = this.getClass().getClassLoader();
    else if (loaderName.equals(clrName))
        loader = clr;
    else
        loader = (ClassLoader) getMBean(loaderName);

    Class<?> c;
    try {
        c = Class.forName(className, false, loader);
    } catch (ClassNotFoundException e) {
        throw new ReflectionException(e);
    }

    Constructor[] constrs = c.getConstructors();
    Constructor found = null;
    findconstr:
    for (Constructor constr : constrs) {
        Class<?>[] cTypes = constr.getParameterTypes();
        if (cTypes.length == signature.length) {
            for (int i = 0; i < cTypes.length; i++) {
                if (!cTypes[i].getName().equals(signature[i]))
                    continue findconstr;
            }
            found = constr;
            break findconstr;
        }
    }
    if (found == null) {
        Exception x = new NoSuchMethodException(
                className + Arrays.toString(signature));
        throw new ReflectionException(x);
    }
    return invokeSomething(found, null, params);
}
 
Example 19
Source File: OldMBeanServerTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public Object instantiate(
        String className, ObjectName loaderName,
        Object[] params, String[] signature)
throws ReflectionException, MBeanException, InstanceNotFoundException {

    if (params == null)
        params = new Object[0];
    if (signature == null)
        signature = new String[0];

    ClassLoader loader;
    if (loaderName == null)
        loader = this.getClass().getClassLoader();
    else if (loaderName.equals(clrName))
        loader = clr;
    else
        loader = (ClassLoader) getMBean(loaderName);

    Class<?> c;
    try {
        c = Class.forName(className, false, loader);
    } catch (ClassNotFoundException e) {
        throw new ReflectionException(e);
    }

    Constructor[] constrs = c.getConstructors();
    Constructor found = null;
    findconstr:
    for (Constructor constr : constrs) {
        Class<?>[] cTypes = constr.getParameterTypes();
        if (cTypes.length == signature.length) {
            for (int i = 0; i < cTypes.length; i++) {
                if (!cTypes[i].getName().equals(signature[i]))
                    continue findconstr;
            }
            found = constr;
            break findconstr;
        }
    }
    if (found == null) {
        Exception x = new NoSuchMethodException(
                className + Arrays.toString(signature));
        throw new ReflectionException(x);
    }
    return invokeSomething(found, null, params);
}
 
Example 20
Source File: MXBeanInteropTest2.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private final int doBasicMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- doBasicMXBeanTest") ;

    try {
        ObjectName objName =
                new ObjectName("sqe:type=BasicMXBean") ;
        mbsc.createMBean(BASIC_MXBEAN_CLASS_NAME, objName);
        MBeanInfo mbInfo = mbsc.getMBeanInfo(objName);
        printMBeanInfo(mbInfo);
        System.out.println("---- OK\n") ;
        System.out.println("getMBeanInfo\t\t"
                + mbInfo);
        System.out.println("---- OK\n") ;

        System.out.println("Check mxbean field in the MBeanInfo");
        String mxbeanField =
                (String)mbInfo.getDescriptor().getFieldValue(JMX.MXBEAN_FIELD);

        if ( mxbeanField == null || ! mxbeanField.equals("true")) {
            System.out.println("---- ERROR : Improper mxbean field value "
                    + mxbeanField);
            errorCount++;
        }
        System.out.println("---- OK\n") ;

        System.out.println("Set attribute ObjectNameAtt");
        Attribute att = new Attribute("ObjectNameAtt", objName);
        mbsc.setAttribute(objName, att);
        ObjectName value =
                (ObjectName)mbsc.getAttribute(objName, "ObjectNameAtt");

        if ( ! value.equals(objName) ) {
            errorCount++;
            System.out.println("---- ERROR : setAttribute failed, got "
                    + value
                    + " while expecting "
                    + objName);
        }
        System.out.println("---- OK\n") ;

        System.out.println("Call operation doNothing");
        mbsc.invoke(objName,  "doNothing", null, null);
        System.out.println("---- OK\n") ;

        System.out.println("Call operation getWeather");
        Object weather = mbsc.invoke(objName,
                "getWeather",
                new Object[]{Boolean.TRUE},
                new String[]{"boolean"});
        System.out.println("Weather is " + weather);
        System.out.println("---- OK\n") ;
    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}