javax.management.ObjectName#equals ( )源码实例Demo

下面列出了javax.management.ObjectName#equals ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: spliceengine   文件: JMXManagementService.java
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;
    }
}
 
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");
    }
 
/**
 * 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;
}
 
源代码4 项目: gemfirexd-oss   文件: JMXManagementService.java
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;
    }
}
 
源代码5 项目: openjdk-jdk9   文件: NotificationEmissionTest.java
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;
}
 
/**
 * 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;
}
 
/**
 * 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;
}
 
源代码8 项目: jdk8u60   文件: ClassLoaderRepositorySupport.java
/**
 * 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;
}
 
源代码9 项目: openjdk-jdk8u   文件: NotificationEmissionTest.java
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;
}
 
源代码10 项目: jdk8u-dev-jdk   文件: PreRegisterNameTest.java
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);
}
 
源代码11 项目: jdk8u-dev-jdk   文件: MXBeanLookup.java
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.
     */
}
 
源代码12 项目: openjdk-jdk8u-backup   文件: MXBeanLookup.java
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.
     */
}
 
源代码13 项目: jdk8u-jdk   文件: MXBeanLookup.java
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.
     */
}
 
源代码14 项目: gemfirexd-oss   文件: JMXManagementService.java
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?
        }
    }
}
 
源代码15 项目: gemfirexd-oss   文件: JMXValidator.java
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;
}
 
源代码16 项目: jdk8u-jdk   文件: MXBeanInteropTest2.java
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 ;
}
 
源代码17 项目: openjdk-jdk8u-backup   文件: OldMBeanServerTest.java
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);
}
 
源代码18 项目: jdk8u_jdk   文件: OldMBeanServerTest.java
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);
}
 
源代码19 项目: openjdk-jdk9   文件: OldMBeanServerTest.java
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);
}
 
源代码20 项目: openjdk-jdk9   文件: MXBeanInteropTest2.java
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 ;
}