类javax.management.modelmbean.DescriptorSupport源码实例Demo

下面列出了怎么用javax.management.modelmbean.DescriptorSupport的API类实例代码及写法,或者点击链接到github查看源代码。

public static void main(String[] args) throws Exception {
    boolean failed = false;
    String xmlDesc = "<DESCRIPTOR>"
            + "<FIELD name=\"field1\" value=\"dummy\">"
            + "</FIELD>"
            + "</DESCRIPTOR>";
    Locale loc = Locale.getDefault();
    try {
        Locale.setDefault(new Locale("tr", "TR"));
        new DescriptorSupport(xmlDesc);
    } catch (Exception e) {
        e.printStackTrace(System.out);
        failed = true;
    }finally{
        Locale.setDefault(loc);
    }

    if (!failed) {
        System.out.println("OK: all tests passed");
    } else {
        System.out.println("TEST FAILED");
        throw new IllegalArgumentException("Test Failed");
    }
}
 
源代码2 项目: gemfirexd-oss   文件: ConfigAttributeInfo.java
@Override
public ModelMBeanAttributeInfo createAttributeInfo() {
  Descriptor desc = new DescriptorSupport(
      new String[] {
      "name=" + this.displayName,
      "descriptorType=attribute",
      "currencyTimeLimit=-1", // always stale
      "displayName=" + this.displayName,
      "getMethod=getJmxValue",
      "setMethod=setJmxValue" 
      });
      
  Assert.assertTrue(this.config != null, "Config target object is null!");
  desc.setField("targetObject", this.config);

  ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(
      this.displayName, // name
      this.type,        // type
      this.description, // description
      this.readable,    // isReadable
      this.writeable,   // isWritable
      this.is,          // isIs
      desc);
      
  return info;
}
 
源代码3 项目: gemfirexd-oss   文件: StatisticAttributeInfo.java
@Override
public ModelMBeanAttributeInfo createAttributeInfo() {
  Descriptor desc = new DescriptorSupport(
      new String[] {
      "name=" + this.displayName,
      "descriptorType=attribute",
      "currencyTimeLimit=-1", // always stale
      "displayName=" + this.displayName,
      "getMethod=getValue" });

  Assert.assertTrue(this.stat != null, "Stat target object is null!");
  desc.setField("targetObject", this.stat);

  ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(
      this.displayName, // name
      this.type,        // type
      this.description, // description
      this.readable,    // isReadable
      this.writeable,   // isWritable
      this.is,          // isIs
      desc);
      
  return info;
}
 
源代码4 项目: gemfirexd-oss   文件: ConfigAttributeInfo.java
@Override
public ModelMBeanAttributeInfo createAttributeInfo() {
  Descriptor desc = new DescriptorSupport(
      new String[] {
      "name=" + this.displayName,
      "descriptorType=attribute",
      "currencyTimeLimit=-1", // always stale
      "displayName=" + this.displayName,
      "getMethod=getJmxValue",
      "setMethod=setJmxValue" 
      });
      
  Assert.assertTrue(this.config != null, "Config target object is null!");
  desc.setField("targetObject", this.config);

  ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(
      this.displayName, // name
      this.type,        // type
      this.description, // description
      this.readable,    // isReadable
      this.writeable,   // isWritable
      this.is,          // isIs
      desc);
      
  return info;
}
 
源代码5 项目: gemfirexd-oss   文件: StatisticAttributeInfo.java
@Override
public ModelMBeanAttributeInfo createAttributeInfo() {
  Descriptor desc = new DescriptorSupport(
      new String[] {
      "name=" + this.displayName,
      "descriptorType=attribute",
      "currencyTimeLimit=-1", // always stale
      "displayName=" + this.displayName,
      "getMethod=getValue" });

  Assert.assertTrue(this.stat != null, "Stat target object is null!");
  desc.setField("targetObject", this.stat);

  ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(
      this.displayName, // name
      this.type,        // type
      this.description, // description
      this.readable,    // isReadable
      this.writeable,   // isWritable
      this.is,          // isIs
      desc);
      
  return info;
}
 
源代码6 项目: iaf   文件: JmxUtils.java
/**
 * Builds an AttributeInfo in a default way
 * @return the default modelMBeanAttributeInfo object
 */
public static ModelMBeanAttributeInfo buildAttributeInfo(String name, String displayName, String description, String deflt, String operName, String signature){
	Descriptor attrDesc = new DescriptorSupport();
	attrDesc.setField("name", name);
	attrDesc.setField("descriptorType", "attribute");
	attrDesc.setField("default", deflt);
	attrDesc.setField("displayName", displayName);
	attrDesc.setField(
		"getMethod",
		operName);

	ModelMBeanAttributeInfo result=new ModelMBeanAttributeInfo(name,
	signature,
	description,
	true,
	false,
	false,
	attrDesc);
	return result;
}
 
源代码7 项目: sakai   文件: ConfigurationMBean.java
@Override
public MBeanInfo getMBeanInfo() {
    List<MBeanAttributeInfo> attributeInfos = new ArrayList<>();
    for (ConfigItem item : serverConfigurationService.getConfigData().getItems()) {
        String type = item.getType();
        switch (type) {
            case ServerConfigurationService.TYPE_BOOLEAN:
                type = "boolean";
                break;
            case ServerConfigurationService.TYPE_INT:
                type = "int";
                break;
            case ServerConfigurationService.TYPE_STRING:
                type = "java.lang.String";
                break;
        }
        attributeInfos.add(new MBeanAttributeInfo(item.getName(), type, item.getDescription(), !item.isSecured(), true, false));
    }
    List<MBeanOperationInfo> operationInfos = new ArrayList<>();
    try {
        Method method = getClass().getMethod("addAttribute", String.class, String.class);
        operationInfos.add(new MBeanOperationInfo("addAttribute", method));
    } catch (NoSuchMethodException e) {
        // Ignore
    }
    Descriptor descriptor = new DescriptorSupport();
    descriptor.setField("immutableInfo", "false");
    return new MBeanInfo(getClass().getName(), "Sakai Server Configuration",
        attributeInfos.toArray(new MBeanAttributeInfo[]{}),
        null,
        operationInfos.toArray(new MBeanOperationInfo[]{}),
        null,
        descriptor);
}
 
源代码8 项目: sakai   文件: ConfigurationMBean.java
@Override
public MBeanInfo getMBeanInfo() {
    List<MBeanAttributeInfo> attributeInfos = new ArrayList<>();
    for (ConfigItem item : serverConfigurationService.getConfigData().getItems()) {
        String type = item.getType();
        switch (type) {
            case ServerConfigurationService.TYPE_BOOLEAN:
                type = "boolean";
                break;
            case ServerConfigurationService.TYPE_INT:
                type = "int";
                break;
            case ServerConfigurationService.TYPE_STRING:
                type = "java.lang.String";
                break;
        }
        attributeInfos.add(new MBeanAttributeInfo(item.getName(), type, item.getDescription(), !item.isSecured(), true, false));
    }
    List<MBeanOperationInfo> operationInfos = new ArrayList<>();
    try {
        Method method = getClass().getMethod("addAttribute", String.class, String.class);
        operationInfos.add(new MBeanOperationInfo("addAttribute", method));
    } catch (NoSuchMethodException e) {
        // Ignore
    }
    Descriptor descriptor = new DescriptorSupport();
    descriptor.setField("immutableInfo", "false");
    return new MBeanInfo(getClass().getName(), "Sakai Server Configuration",
        attributeInfos.toArray(new MBeanAttributeInfo[]{}),
        null,
        operationInfos.toArray(new MBeanOperationInfo[]{}),
        null,
        descriptor);
}
 
源代码9 项目: cxf   文件: ModelMBeanInfoSupporter.java
public Descriptor buildAttributeDescriptor(
    ManagedAttribute ma, String attributeName, boolean is, boolean read, boolean write) {

    Descriptor desc = new DescriptorSupport();

    desc.setField("name", attributeName);

    desc.setField("descriptorType", "attribute");

    if (read) {
        if (is) {
            desc.setField("getMethod", "is" + attributeName);
        } else {
            desc.setField("getMethod", "get" + attributeName);
        }
    }

    if (write) {
        desc.setField("setMethod", "set" + attributeName);
    }


    if (ma.currencyTimeLimit() >= -1) {
        desc.setField("currencyTimeLimit", ma.currencyTimeLimit());
    }

    if (ma.persistPolicy().length() > 0) {
        desc.setField("persistPolicy", ma.persistPolicy());
    }

    if (ma.persistPeriod() >= -1) {
        desc.setField("persistPeriod", ma.persistPeriod());
    }

    if (ma.defaultValue() != null) {
        desc.setField("default", ma.defaultValue());
    }

    return desc;
}
 
源代码10 项目: iaf   文件: JmxUtils.java
/**
 * Builds a default Descriptor object for getter operations
 * @param name the name of the getter
 * @param klass
 * @return the descriptor
 */
private static Descriptor buildGetterDescriptor(
	String name,
	String klass) {
	Descriptor resultDesc = new DescriptorSupport();
	resultDesc.setField("name", name);
	resultDesc.setField("descriptorType", "operation");
	resultDesc.setField("class", klass);
	resultDesc.setField("role", "getter");
	return resultDesc;
}
 
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    Resource resource1 = new Resource();
    Resource resource2 = new Resource();
    Resource resource3 = new Resource();
    Method operationMethod = Resource.class.getMethod("operation");
    Method getCountMethod = Resource.class.getMethod("getCount");
    Method setCountMethod = Resource.class.getMethod("setCount", int.class);
    Descriptor operationDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "operation", resource1
                              });
    Descriptor getCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "getCount", resource2
                              });
    Descriptor setCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "setCount", resource2
                              });
    Descriptor countDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "getMethod", "setMethod"
                              }, new Object[] {
                                "attribute", "Count", "getCount", "setCount"
                              });
    ModelMBeanOperationInfo operationInfo =
        new ModelMBeanOperationInfo("operation description",
                                    operationMethod, operationDescriptor);
    ModelMBeanOperationInfo getCountInfo =
        new ModelMBeanOperationInfo("getCount description",
                                    getCountMethod, getCountDescriptor);
    ModelMBeanOperationInfo setCountInfo =
        new ModelMBeanOperationInfo("setCount description",
                                    setCountMethod, setCountDescriptor);
    ModelMBeanAttributeInfo countInfo =
        new ModelMBeanAttributeInfo("Count", "Count description",
                                    getCountMethod, setCountMethod,
                                    countDescriptor);
    ModelMBeanInfo mmbi =
        new ModelMBeanInfoSupport(Resource.class.getName(),
                                  "ModelMBean to test targetObject",
                                  new ModelMBeanAttributeInfo[] {countInfo},
                                  null,  // no constructors
                                  new ModelMBeanOperationInfo[] {
                                      operationInfo, getCountInfo, setCountInfo
                                  },
                                  null); // no notifications
    ModelMBean mmb = new RequiredModelMBean(mmbi);
    mmb.setManagedResource(resource3, "ObjectReference");
    mbs.registerMBean(mmb, name);
    mbs.invoke(name, "operation", null, null);
    mbs.setAttribute(name, new Attribute("Count", 53));
    if (resource1.operationCount != 1)
        throw new Exception("operationCount: " + resource1.operationCount);
    if (resource2.count != 53)
        throw new Exception("count: " + resource2.count);
    int got = (Integer) mbs.getAttribute(name, "Count");
    if (got != 53)
        throw new Exception("got count: " + got);

    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();
    ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name);
    // Above gets NotSerializableException if resource included in
    // serialized form
    cc.close();
    cs.stop();
    System.out.println("TEST PASSED");
}
 
源代码12 项目: dragonwell8_jdk   文件: UnionTest.java
public static void main(String[] args) throws Exception {
    ImmutableDescriptor immutableEmpty = new ImmutableDescriptor();
    DescriptorSupport mutableEmpty = new DescriptorSupport();

    checkEmpty(union());
    checkEmpty(union(immutableEmpty));
    checkEmpty(union(mutableEmpty));
    checkEmpty(union(EMPTY_DESCRIPTOR, immutableEmpty, mutableEmpty));
    checkEmpty(union(null, immutableEmpty, null));

    ImmutableDescriptor immutableNumbers =
        new ImmutableDescriptor(new String[] {"one", "two", "three"},
                                new Object[] {1, 2, 3});
    final String[] noNames = null;
    DescriptorSupport mutableNumbers =
        new DescriptorSupport(immutableNumbers.getFieldNames(),
                              immutableNumbers.getFieldValues(noNames));
    ImmutableDescriptor immutableOne =
        new ImmutableDescriptor(Collections.singletonMap("one", 1));
    DescriptorSupport mutableOne =
        new DescriptorSupport(new String[] {"one"}, new Object[] {1});
    ImmutableDescriptor immutableTwo =
        new ImmutableDescriptor(Collections.singletonMap("two", 2));
    DescriptorSupport mutableTwo =
        new DescriptorSupport(new String[] {"two"}, new Object[] {2});
    ImmutableDescriptor immutableOneTwo =
        new ImmutableDescriptor(new String[] {"one", "two"},
                                new Object[] {1, 2});


    checkEqual(union(immutableNumbers), immutableNumbers);
    checkEqual(union(immutableNumbers, mutableNumbers), immutableNumbers);
    checkEqual(union(mutableNumbers, immutableNumbers), immutableNumbers);
    checkEqual(union(mutableEmpty, immutableEmpty, immutableNumbers,
                     mutableNumbers, immutableOne), immutableNumbers);
    checkEqual(union(immutableOne, immutableTwo, immutableNumbers),
               immutableNumbers);
    checkEquivalent(union(immutableOne, mutableNumbers), immutableNumbers);
    checkEquivalent(union(immutableOne, immutableTwo), immutableOneTwo);
    checkEquivalent(union(mutableOne, mutableTwo), immutableOneTwo);

    if (failure != null)
        throw new Exception("TEST FAILED: " + failure);
    System.out.println("TEST PASSED");
}
 
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    Resource resource1 = new Resource();
    Resource resource2 = new Resource();
    Resource resource3 = new Resource();
    Method operationMethod = Resource.class.getMethod("operation");
    Method getCountMethod = Resource.class.getMethod("getCount");
    Method setCountMethod = Resource.class.getMethod("setCount", int.class);
    Descriptor operationDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "operation", resource1
                              });
    Descriptor getCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "getCount", resource2
                              });
    Descriptor setCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "setCount", resource2
                              });
    Descriptor countDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "getMethod", "setMethod"
                              }, new Object[] {
                                "attribute", "Count", "getCount", "setCount"
                              });
    ModelMBeanOperationInfo operationInfo =
        new ModelMBeanOperationInfo("operation description",
                                    operationMethod, operationDescriptor);
    ModelMBeanOperationInfo getCountInfo =
        new ModelMBeanOperationInfo("getCount description",
                                    getCountMethod, getCountDescriptor);
    ModelMBeanOperationInfo setCountInfo =
        new ModelMBeanOperationInfo("setCount description",
                                    setCountMethod, setCountDescriptor);
    ModelMBeanAttributeInfo countInfo =
        new ModelMBeanAttributeInfo("Count", "Count description",
                                    getCountMethod, setCountMethod,
                                    countDescriptor);
    ModelMBeanInfo mmbi =
        new ModelMBeanInfoSupport(Resource.class.getName(),
                                  "ModelMBean to test targetObject",
                                  new ModelMBeanAttributeInfo[] {countInfo},
                                  null,  // no constructors
                                  new ModelMBeanOperationInfo[] {
                                      operationInfo, getCountInfo, setCountInfo
                                  },
                                  null); // no notifications
    ModelMBean mmb = new RequiredModelMBean(mmbi);
    mmb.setManagedResource(resource3, "ObjectReference");
    mbs.registerMBean(mmb, name);
    mbs.invoke(name, "operation", null, null);
    mbs.setAttribute(name, new Attribute("Count", 53));
    if (resource1.operationCount != 1)
        throw new Exception("operationCount: " + resource1.operationCount);
    if (resource2.count != 53)
        throw new Exception("count: " + resource2.count);
    int got = (Integer) mbs.getAttribute(name, "Count");
    if (got != 53)
        throw new Exception("got count: " + got);

    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();
    ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name);
    // Above gets NotSerializableException if resource included in
    // serialized form
    cc.close();
    cs.stop();
    System.out.println("TEST PASSED");
}
 
源代码14 项目: TencentKona-8   文件: UnionTest.java
public static void main(String[] args) throws Exception {
    ImmutableDescriptor immutableEmpty = new ImmutableDescriptor();
    DescriptorSupport mutableEmpty = new DescriptorSupport();

    checkEmpty(union());
    checkEmpty(union(immutableEmpty));
    checkEmpty(union(mutableEmpty));
    checkEmpty(union(EMPTY_DESCRIPTOR, immutableEmpty, mutableEmpty));
    checkEmpty(union(null, immutableEmpty, null));

    ImmutableDescriptor immutableNumbers =
        new ImmutableDescriptor(new String[] {"one", "two", "three"},
                                new Object[] {1, 2, 3});
    final String[] noNames = null;
    DescriptorSupport mutableNumbers =
        new DescriptorSupport(immutableNumbers.getFieldNames(),
                              immutableNumbers.getFieldValues(noNames));
    ImmutableDescriptor immutableOne =
        new ImmutableDescriptor(Collections.singletonMap("one", 1));
    DescriptorSupport mutableOne =
        new DescriptorSupport(new String[] {"one"}, new Object[] {1});
    ImmutableDescriptor immutableTwo =
        new ImmutableDescriptor(Collections.singletonMap("two", 2));
    DescriptorSupport mutableTwo =
        new DescriptorSupport(new String[] {"two"}, new Object[] {2});
    ImmutableDescriptor immutableOneTwo =
        new ImmutableDescriptor(new String[] {"one", "two"},
                                new Object[] {1, 2});


    checkEqual(union(immutableNumbers), immutableNumbers);
    checkEqual(union(immutableNumbers, mutableNumbers), immutableNumbers);
    checkEqual(union(mutableNumbers, immutableNumbers), immutableNumbers);
    checkEqual(union(mutableEmpty, immutableEmpty, immutableNumbers,
                     mutableNumbers, immutableOne), immutableNumbers);
    checkEqual(union(immutableOne, immutableTwo, immutableNumbers),
               immutableNumbers);
    checkEquivalent(union(immutableOne, mutableNumbers), immutableNumbers);
    checkEquivalent(union(immutableOne, immutableTwo), immutableOneTwo);
    checkEquivalent(union(mutableOne, mutableTwo), immutableOneTwo);

    if (failure != null)
        throw new Exception("TEST FAILED: " + failure);
    System.out.println("TEST PASSED");
}
 
源代码15 项目: jdk8u60   文件: UnserializableTargetObjectTest.java
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    Resource resource1 = new Resource();
    Resource resource2 = new Resource();
    Resource resource3 = new Resource();
    Method operationMethod = Resource.class.getMethod("operation");
    Method getCountMethod = Resource.class.getMethod("getCount");
    Method setCountMethod = Resource.class.getMethod("setCount", int.class);
    Descriptor operationDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "operation", resource1
                              });
    Descriptor getCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "getCount", resource2
                              });
    Descriptor setCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "setCount", resource2
                              });
    Descriptor countDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "getMethod", "setMethod"
                              }, new Object[] {
                                "attribute", "Count", "getCount", "setCount"
                              });
    ModelMBeanOperationInfo operationInfo =
        new ModelMBeanOperationInfo("operation description",
                                    operationMethod, operationDescriptor);
    ModelMBeanOperationInfo getCountInfo =
        new ModelMBeanOperationInfo("getCount description",
                                    getCountMethod, getCountDescriptor);
    ModelMBeanOperationInfo setCountInfo =
        new ModelMBeanOperationInfo("setCount description",
                                    setCountMethod, setCountDescriptor);
    ModelMBeanAttributeInfo countInfo =
        new ModelMBeanAttributeInfo("Count", "Count description",
                                    getCountMethod, setCountMethod,
                                    countDescriptor);
    ModelMBeanInfo mmbi =
        new ModelMBeanInfoSupport(Resource.class.getName(),
                                  "ModelMBean to test targetObject",
                                  new ModelMBeanAttributeInfo[] {countInfo},
                                  null,  // no constructors
                                  new ModelMBeanOperationInfo[] {
                                      operationInfo, getCountInfo, setCountInfo
                                  },
                                  null); // no notifications
    ModelMBean mmb = new RequiredModelMBean(mmbi);
    mmb.setManagedResource(resource3, "ObjectReference");
    mbs.registerMBean(mmb, name);
    mbs.invoke(name, "operation", null, null);
    mbs.setAttribute(name, new Attribute("Count", 53));
    if (resource1.operationCount != 1)
        throw new Exception("operationCount: " + resource1.operationCount);
    if (resource2.count != 53)
        throw new Exception("count: " + resource2.count);
    int got = (Integer) mbs.getAttribute(name, "Count");
    if (got != 53)
        throw new Exception("got count: " + got);

    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();
    ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name);
    // Above gets NotSerializableException if resource included in
    // serialized form
    cc.close();
    cs.stop();
    System.out.println("TEST PASSED");
}
 
源代码16 项目: jdk8u60   文件: UnionTest.java
public static void main(String[] args) throws Exception {
    ImmutableDescriptor immutableEmpty = new ImmutableDescriptor();
    DescriptorSupport mutableEmpty = new DescriptorSupport();

    checkEmpty(union());
    checkEmpty(union(immutableEmpty));
    checkEmpty(union(mutableEmpty));
    checkEmpty(union(EMPTY_DESCRIPTOR, immutableEmpty, mutableEmpty));
    checkEmpty(union(null, immutableEmpty, null));

    ImmutableDescriptor immutableNumbers =
        new ImmutableDescriptor(new String[] {"one", "two", "three"},
                                new Object[] {1, 2, 3});
    final String[] noNames = null;
    DescriptorSupport mutableNumbers =
        new DescriptorSupport(immutableNumbers.getFieldNames(),
                              immutableNumbers.getFieldValues(noNames));
    ImmutableDescriptor immutableOne =
        new ImmutableDescriptor(Collections.singletonMap("one", 1));
    DescriptorSupport mutableOne =
        new DescriptorSupport(new String[] {"one"}, new Object[] {1});
    ImmutableDescriptor immutableTwo =
        new ImmutableDescriptor(Collections.singletonMap("two", 2));
    DescriptorSupport mutableTwo =
        new DescriptorSupport(new String[] {"two"}, new Object[] {2});
    ImmutableDescriptor immutableOneTwo =
        new ImmutableDescriptor(new String[] {"one", "two"},
                                new Object[] {1, 2});


    checkEqual(union(immutableNumbers), immutableNumbers);
    checkEqual(union(immutableNumbers, mutableNumbers), immutableNumbers);
    checkEqual(union(mutableNumbers, immutableNumbers), immutableNumbers);
    checkEqual(union(mutableEmpty, immutableEmpty, immutableNumbers,
                     mutableNumbers, immutableOne), immutableNumbers);
    checkEqual(union(immutableOne, immutableTwo, immutableNumbers),
               immutableNumbers);
    checkEquivalent(union(immutableOne, mutableNumbers), immutableNumbers);
    checkEquivalent(union(immutableOne, immutableTwo), immutableOneTwo);
    checkEquivalent(union(mutableOne, mutableTwo), immutableOneTwo);

    if (failure != null)
        throw new Exception("TEST FAILED: " + failure);
    System.out.println("TEST PASSED");
}
 
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    Resource resource1 = new Resource();
    Resource resource2 = new Resource();
    Resource resource3 = new Resource();
    Method operationMethod = Resource.class.getMethod("operation");
    Method getCountMethod = Resource.class.getMethod("getCount");
    Method setCountMethod = Resource.class.getMethod("setCount", int.class);
    Descriptor operationDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "operation", resource1
                              });
    Descriptor getCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "getCount", resource2
                              });
    Descriptor setCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "setCount", resource2
                              });
    Descriptor countDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "getMethod", "setMethod"
                              }, new Object[] {
                                "attribute", "Count", "getCount", "setCount"
                              });
    ModelMBeanOperationInfo operationInfo =
        new ModelMBeanOperationInfo("operation description",
                                    operationMethod, operationDescriptor);
    ModelMBeanOperationInfo getCountInfo =
        new ModelMBeanOperationInfo("getCount description",
                                    getCountMethod, getCountDescriptor);
    ModelMBeanOperationInfo setCountInfo =
        new ModelMBeanOperationInfo("setCount description",
                                    setCountMethod, setCountDescriptor);
    ModelMBeanAttributeInfo countInfo =
        new ModelMBeanAttributeInfo("Count", "Count description",
                                    getCountMethod, setCountMethod,
                                    countDescriptor);
    ModelMBeanInfo mmbi =
        new ModelMBeanInfoSupport(Resource.class.getName(),
                                  "ModelMBean to test targetObject",
                                  new ModelMBeanAttributeInfo[] {countInfo},
                                  null,  // no constructors
                                  new ModelMBeanOperationInfo[] {
                                      operationInfo, getCountInfo, setCountInfo
                                  },
                                  null); // no notifications
    ModelMBean mmb = new RequiredModelMBean(mmbi);
    mmb.setManagedResource(resource3, "ObjectReference");
    mbs.registerMBean(mmb, name);
    mbs.invoke(name, "operation", null, null);
    mbs.setAttribute(name, new Attribute("Count", 53));
    if (resource1.operationCount != 1)
        throw new Exception("operationCount: " + resource1.operationCount);
    if (resource2.count != 53)
        throw new Exception("count: " + resource2.count);
    int got = (Integer) mbs.getAttribute(name, "Count");
    if (got != 53)
        throw new Exception("got count: " + got);

    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();
    ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name);
    // Above gets NotSerializableException if resource included in
    // serialized form
    cc.close();
    cs.stop();
    System.out.println("TEST PASSED");
}
 
源代码18 项目: openjdk-jdk8u   文件: UnionTest.java
public static void main(String[] args) throws Exception {
    ImmutableDescriptor immutableEmpty = new ImmutableDescriptor();
    DescriptorSupport mutableEmpty = new DescriptorSupport();

    checkEmpty(union());
    checkEmpty(union(immutableEmpty));
    checkEmpty(union(mutableEmpty));
    checkEmpty(union(EMPTY_DESCRIPTOR, immutableEmpty, mutableEmpty));
    checkEmpty(union(null, immutableEmpty, null));

    ImmutableDescriptor immutableNumbers =
        new ImmutableDescriptor(new String[] {"one", "two", "three"},
                                new Object[] {1, 2, 3});
    final String[] noNames = null;
    DescriptorSupport mutableNumbers =
        new DescriptorSupport(immutableNumbers.getFieldNames(),
                              immutableNumbers.getFieldValues(noNames));
    ImmutableDescriptor immutableOne =
        new ImmutableDescriptor(Collections.singletonMap("one", 1));
    DescriptorSupport mutableOne =
        new DescriptorSupport(new String[] {"one"}, new Object[] {1});
    ImmutableDescriptor immutableTwo =
        new ImmutableDescriptor(Collections.singletonMap("two", 2));
    DescriptorSupport mutableTwo =
        new DescriptorSupport(new String[] {"two"}, new Object[] {2});
    ImmutableDescriptor immutableOneTwo =
        new ImmutableDescriptor(new String[] {"one", "two"},
                                new Object[] {1, 2});


    checkEqual(union(immutableNumbers), immutableNumbers);
    checkEqual(union(immutableNumbers, mutableNumbers), immutableNumbers);
    checkEqual(union(mutableNumbers, immutableNumbers), immutableNumbers);
    checkEqual(union(mutableEmpty, immutableEmpty, immutableNumbers,
                     mutableNumbers, immutableOne), immutableNumbers);
    checkEqual(union(immutableOne, immutableTwo, immutableNumbers),
               immutableNumbers);
    checkEquivalent(union(immutableOne, mutableNumbers), immutableNumbers);
    checkEquivalent(union(immutableOne, immutableTwo), immutableOneTwo);
    checkEquivalent(union(mutableOne, mutableTwo), immutableOneTwo);

    if (failure != null)
        throw new Exception("TEST FAILED: " + failure);
    System.out.println("TEST PASSED");
}
 
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    Resource resource1 = new Resource();
    Resource resource2 = new Resource();
    Resource resource3 = new Resource();
    Method operationMethod = Resource.class.getMethod("operation");
    Method getCountMethod = Resource.class.getMethod("getCount");
    Method setCountMethod = Resource.class.getMethod("setCount", int.class);
    Descriptor operationDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "operation", resource1
                              });
    Descriptor getCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "getCount", resource2
                              });
    Descriptor setCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "setCount", resource2
                              });
    Descriptor countDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "getMethod", "setMethod"
                              }, new Object[] {
                                "attribute", "Count", "getCount", "setCount"
                              });
    ModelMBeanOperationInfo operationInfo =
        new ModelMBeanOperationInfo("operation description",
                                    operationMethod, operationDescriptor);
    ModelMBeanOperationInfo getCountInfo =
        new ModelMBeanOperationInfo("getCount description",
                                    getCountMethod, getCountDescriptor);
    ModelMBeanOperationInfo setCountInfo =
        new ModelMBeanOperationInfo("setCount description",
                                    setCountMethod, setCountDescriptor);
    ModelMBeanAttributeInfo countInfo =
        new ModelMBeanAttributeInfo("Count", "Count description",
                                    getCountMethod, setCountMethod,
                                    countDescriptor);
    ModelMBeanInfo mmbi =
        new ModelMBeanInfoSupport(Resource.class.getName(),
                                  "ModelMBean to test targetObject",
                                  new ModelMBeanAttributeInfo[] {countInfo},
                                  null,  // no constructors
                                  new ModelMBeanOperationInfo[] {
                                      operationInfo, getCountInfo, setCountInfo
                                  },
                                  null); // no notifications
    ModelMBean mmb = new RequiredModelMBean(mmbi);
    mmb.setManagedResource(resource3, "ObjectReference");
    mbs.registerMBean(mmb, name);
    mbs.invoke(name, "operation", null, null);
    mbs.setAttribute(name, new Attribute("Count", 53));
    if (resource1.operationCount != 1)
        throw new Exception("operationCount: " + resource1.operationCount);
    if (resource2.count != 53)
        throw new Exception("count: " + resource2.count);
    int got = (Integer) mbs.getAttribute(name, "Count");
    if (got != 53)
        throw new Exception("got count: " + got);

    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();
    ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name);
    // Above gets NotSerializableException if resource included in
    // serialized form
    cc.close();
    cs.stop();
    System.out.println("TEST PASSED");
}
 
源代码20 项目: openjdk-jdk8u-backup   文件: UnionTest.java
public static void main(String[] args) throws Exception {
    ImmutableDescriptor immutableEmpty = new ImmutableDescriptor();
    DescriptorSupport mutableEmpty = new DescriptorSupport();

    checkEmpty(union());
    checkEmpty(union(immutableEmpty));
    checkEmpty(union(mutableEmpty));
    checkEmpty(union(EMPTY_DESCRIPTOR, immutableEmpty, mutableEmpty));
    checkEmpty(union(null, immutableEmpty, null));

    ImmutableDescriptor immutableNumbers =
        new ImmutableDescriptor(new String[] {"one", "two", "three"},
                                new Object[] {1, 2, 3});
    final String[] noNames = null;
    DescriptorSupport mutableNumbers =
        new DescriptorSupport(immutableNumbers.getFieldNames(),
                              immutableNumbers.getFieldValues(noNames));
    ImmutableDescriptor immutableOne =
        new ImmutableDescriptor(Collections.singletonMap("one", 1));
    DescriptorSupport mutableOne =
        new DescriptorSupport(new String[] {"one"}, new Object[] {1});
    ImmutableDescriptor immutableTwo =
        new ImmutableDescriptor(Collections.singletonMap("two", 2));
    DescriptorSupport mutableTwo =
        new DescriptorSupport(new String[] {"two"}, new Object[] {2});
    ImmutableDescriptor immutableOneTwo =
        new ImmutableDescriptor(new String[] {"one", "two"},
                                new Object[] {1, 2});


    checkEqual(union(immutableNumbers), immutableNumbers);
    checkEqual(union(immutableNumbers, mutableNumbers), immutableNumbers);
    checkEqual(union(mutableNumbers, immutableNumbers), immutableNumbers);
    checkEqual(union(mutableEmpty, immutableEmpty, immutableNumbers,
                     mutableNumbers, immutableOne), immutableNumbers);
    checkEqual(union(immutableOne, immutableTwo, immutableNumbers),
               immutableNumbers);
    checkEquivalent(union(immutableOne, mutableNumbers), immutableNumbers);
    checkEquivalent(union(immutableOne, immutableTwo), immutableOneTwo);
    checkEquivalent(union(mutableOne, mutableTwo), immutableOneTwo);

    if (failure != null)
        throw new Exception("TEST FAILED: " + failure);
    System.out.println("TEST PASSED");
}
 
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    Resource resource1 = new Resource();
    Resource resource2 = new Resource();
    Resource resource3 = new Resource();
    Method operationMethod = Resource.class.getMethod("operation");
    Method getCountMethod = Resource.class.getMethod("getCount");
    Method setCountMethod = Resource.class.getMethod("setCount", int.class);
    Descriptor operationDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "operation", resource1
                              });
    Descriptor getCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "getCount", resource2
                              });
    Descriptor setCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "setCount", resource2
                              });
    Descriptor countDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "getMethod", "setMethod"
                              }, new Object[] {
                                "attribute", "Count", "getCount", "setCount"
                              });
    ModelMBeanOperationInfo operationInfo =
        new ModelMBeanOperationInfo("operation description",
                                    operationMethod, operationDescriptor);
    ModelMBeanOperationInfo getCountInfo =
        new ModelMBeanOperationInfo("getCount description",
                                    getCountMethod, getCountDescriptor);
    ModelMBeanOperationInfo setCountInfo =
        new ModelMBeanOperationInfo("setCount description",
                                    setCountMethod, setCountDescriptor);
    ModelMBeanAttributeInfo countInfo =
        new ModelMBeanAttributeInfo("Count", "Count description",
                                    getCountMethod, setCountMethod,
                                    countDescriptor);
    ModelMBeanInfo mmbi =
        new ModelMBeanInfoSupport(Resource.class.getName(),
                                  "ModelMBean to test targetObject",
                                  new ModelMBeanAttributeInfo[] {countInfo},
                                  null,  // no constructors
                                  new ModelMBeanOperationInfo[] {
                                      operationInfo, getCountInfo, setCountInfo
                                  },
                                  null); // no notifications
    ModelMBean mmb = new RequiredModelMBean(mmbi);
    mmb.setManagedResource(resource3, "ObjectReference");
    mbs.registerMBean(mmb, name);
    mbs.invoke(name, "operation", null, null);
    mbs.setAttribute(name, new Attribute("Count", 53));
    if (resource1.operationCount != 1)
        throw new Exception("operationCount: " + resource1.operationCount);
    if (resource2.count != 53)
        throw new Exception("count: " + resource2.count);
    int got = (Integer) mbs.getAttribute(name, "Count");
    if (got != 53)
        throw new Exception("got count: " + got);

    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();
    ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name);
    // Above gets NotSerializableException if resource included in
    // serialized form
    cc.close();
    cs.stop();
    System.out.println("TEST PASSED");
}
 
源代码22 项目: openjdk-jdk9   文件: UnionTest.java
public static void main(String[] args) throws Exception {
    ImmutableDescriptor immutableEmpty = new ImmutableDescriptor();
    DescriptorSupport mutableEmpty = new DescriptorSupport();

    checkEmpty(union());
    checkEmpty(union(immutableEmpty));
    checkEmpty(union(mutableEmpty));
    checkEmpty(union(EMPTY_DESCRIPTOR, immutableEmpty, mutableEmpty));
    checkEmpty(union(null, immutableEmpty, null));

    ImmutableDescriptor immutableNumbers =
        new ImmutableDescriptor(new String[] {"one", "two", "three"},
                                new Object[] {1, 2, 3});
    final String[] noNames = null;
    DescriptorSupport mutableNumbers =
        new DescriptorSupport(immutableNumbers.getFieldNames(),
                              immutableNumbers.getFieldValues(noNames));
    ImmutableDescriptor immutableOne =
        new ImmutableDescriptor(Collections.singletonMap("one", 1));
    DescriptorSupport mutableOne =
        new DescriptorSupport(new String[] {"one"}, new Object[] {1});
    ImmutableDescriptor immutableTwo =
        new ImmutableDescriptor(Collections.singletonMap("two", 2));
    DescriptorSupport mutableTwo =
        new DescriptorSupport(new String[] {"two"}, new Object[] {2});
    ImmutableDescriptor immutableOneTwo =
        new ImmutableDescriptor(new String[] {"one", "two"},
                                new Object[] {1, 2});


    checkEqual(union(immutableNumbers), immutableNumbers);
    checkEqual(union(immutableNumbers, mutableNumbers), immutableNumbers);
    checkEqual(union(mutableNumbers, immutableNumbers), immutableNumbers);
    checkEqual(union(mutableEmpty, immutableEmpty, immutableNumbers,
                     mutableNumbers, immutableOne), immutableNumbers);
    checkEqual(union(immutableOne, immutableTwo, immutableNumbers),
               immutableNumbers);
    checkEquivalent(union(immutableOne, mutableNumbers), immutableNumbers);
    checkEquivalent(union(immutableOne, immutableTwo), immutableOneTwo);
    checkEquivalent(union(mutableOne, mutableTwo), immutableOneTwo);

    if (failure != null)
        throw new Exception("TEST FAILED: " + failure);
    System.out.println("TEST PASSED");
}
 
源代码23 项目: jdk8u-jdk   文件: UnserializableTargetObjectTest.java
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    Resource resource1 = new Resource();
    Resource resource2 = new Resource();
    Resource resource3 = new Resource();
    Method operationMethod = Resource.class.getMethod("operation");
    Method getCountMethod = Resource.class.getMethod("getCount");
    Method setCountMethod = Resource.class.getMethod("setCount", int.class);
    Descriptor operationDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "operation", resource1
                              });
    Descriptor getCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "getCount", resource2
                              });
    Descriptor setCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "setCount", resource2
                              });
    Descriptor countDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "getMethod", "setMethod"
                              }, new Object[] {
                                "attribute", "Count", "getCount", "setCount"
                              });
    ModelMBeanOperationInfo operationInfo =
        new ModelMBeanOperationInfo("operation description",
                                    operationMethod, operationDescriptor);
    ModelMBeanOperationInfo getCountInfo =
        new ModelMBeanOperationInfo("getCount description",
                                    getCountMethod, getCountDescriptor);
    ModelMBeanOperationInfo setCountInfo =
        new ModelMBeanOperationInfo("setCount description",
                                    setCountMethod, setCountDescriptor);
    ModelMBeanAttributeInfo countInfo =
        new ModelMBeanAttributeInfo("Count", "Count description",
                                    getCountMethod, setCountMethod,
                                    countDescriptor);
    ModelMBeanInfo mmbi =
        new ModelMBeanInfoSupport(Resource.class.getName(),
                                  "ModelMBean to test targetObject",
                                  new ModelMBeanAttributeInfo[] {countInfo},
                                  null,  // no constructors
                                  new ModelMBeanOperationInfo[] {
                                      operationInfo, getCountInfo, setCountInfo
                                  },
                                  null); // no notifications
    ModelMBean mmb = new RequiredModelMBean(mmbi);
    mmb.setManagedResource(resource3, "ObjectReference");
    mbs.registerMBean(mmb, name);
    mbs.invoke(name, "operation", null, null);
    mbs.setAttribute(name, new Attribute("Count", 53));
    if (resource1.operationCount != 1)
        throw new Exception("operationCount: " + resource1.operationCount);
    if (resource2.count != 53)
        throw new Exception("count: " + resource2.count);
    int got = (Integer) mbs.getAttribute(name, "Count");
    if (got != 53)
        throw new Exception("got count: " + got);

    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();
    ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name);
    // Above gets NotSerializableException if resource included in
    // serialized form
    cc.close();
    cs.stop();
    System.out.println("TEST PASSED");
}
 
源代码24 项目: jdk8u-jdk   文件: UnionTest.java
public static void main(String[] args) throws Exception {
    ImmutableDescriptor immutableEmpty = new ImmutableDescriptor();
    DescriptorSupport mutableEmpty = new DescriptorSupport();

    checkEmpty(union());
    checkEmpty(union(immutableEmpty));
    checkEmpty(union(mutableEmpty));
    checkEmpty(union(EMPTY_DESCRIPTOR, immutableEmpty, mutableEmpty));
    checkEmpty(union(null, immutableEmpty, null));

    ImmutableDescriptor immutableNumbers =
        new ImmutableDescriptor(new String[] {"one", "two", "three"},
                                new Object[] {1, 2, 3});
    final String[] noNames = null;
    DescriptorSupport mutableNumbers =
        new DescriptorSupport(immutableNumbers.getFieldNames(),
                              immutableNumbers.getFieldValues(noNames));
    ImmutableDescriptor immutableOne =
        new ImmutableDescriptor(Collections.singletonMap("one", 1));
    DescriptorSupport mutableOne =
        new DescriptorSupport(new String[] {"one"}, new Object[] {1});
    ImmutableDescriptor immutableTwo =
        new ImmutableDescriptor(Collections.singletonMap("two", 2));
    DescriptorSupport mutableTwo =
        new DescriptorSupport(new String[] {"two"}, new Object[] {2});
    ImmutableDescriptor immutableOneTwo =
        new ImmutableDescriptor(new String[] {"one", "two"},
                                new Object[] {1, 2});


    checkEqual(union(immutableNumbers), immutableNumbers);
    checkEqual(union(immutableNumbers, mutableNumbers), immutableNumbers);
    checkEqual(union(mutableNumbers, immutableNumbers), immutableNumbers);
    checkEqual(union(mutableEmpty, immutableEmpty, immutableNumbers,
                     mutableNumbers, immutableOne), immutableNumbers);
    checkEqual(union(immutableOne, immutableTwo, immutableNumbers),
               immutableNumbers);
    checkEquivalent(union(immutableOne, mutableNumbers), immutableNumbers);
    checkEquivalent(union(immutableOne, immutableTwo), immutableOneTwo);
    checkEquivalent(union(mutableOne, mutableTwo), immutableOneTwo);

    if (failure != null)
        throw new Exception("TEST FAILED: " + failure);
    System.out.println("TEST PASSED");
}
 
源代码25 项目: hottub   文件: UnserializableTargetObjectTest.java
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    Resource resource1 = new Resource();
    Resource resource2 = new Resource();
    Resource resource3 = new Resource();
    Method operationMethod = Resource.class.getMethod("operation");
    Method getCountMethod = Resource.class.getMethod("getCount");
    Method setCountMethod = Resource.class.getMethod("setCount", int.class);
    Descriptor operationDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "operation", resource1
                              });
    Descriptor getCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "getCount", resource2
                              });
    Descriptor setCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "setCount", resource2
                              });
    Descriptor countDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "getMethod", "setMethod"
                              }, new Object[] {
                                "attribute", "Count", "getCount", "setCount"
                              });
    ModelMBeanOperationInfo operationInfo =
        new ModelMBeanOperationInfo("operation description",
                                    operationMethod, operationDescriptor);
    ModelMBeanOperationInfo getCountInfo =
        new ModelMBeanOperationInfo("getCount description",
                                    getCountMethod, getCountDescriptor);
    ModelMBeanOperationInfo setCountInfo =
        new ModelMBeanOperationInfo("setCount description",
                                    setCountMethod, setCountDescriptor);
    ModelMBeanAttributeInfo countInfo =
        new ModelMBeanAttributeInfo("Count", "Count description",
                                    getCountMethod, setCountMethod,
                                    countDescriptor);
    ModelMBeanInfo mmbi =
        new ModelMBeanInfoSupport(Resource.class.getName(),
                                  "ModelMBean to test targetObject",
                                  new ModelMBeanAttributeInfo[] {countInfo},
                                  null,  // no constructors
                                  new ModelMBeanOperationInfo[] {
                                      operationInfo, getCountInfo, setCountInfo
                                  },
                                  null); // no notifications
    ModelMBean mmb = new RequiredModelMBean(mmbi);
    mmb.setManagedResource(resource3, "ObjectReference");
    mbs.registerMBean(mmb, name);
    mbs.invoke(name, "operation", null, null);
    mbs.setAttribute(name, new Attribute("Count", 53));
    if (resource1.operationCount != 1)
        throw new Exception("operationCount: " + resource1.operationCount);
    if (resource2.count != 53)
        throw new Exception("count: " + resource2.count);
    int got = (Integer) mbs.getAttribute(name, "Count");
    if (got != 53)
        throw new Exception("got count: " + got);

    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();
    ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name);
    // Above gets NotSerializableException if resource included in
    // serialized form
    cc.close();
    cs.stop();
    System.out.println("TEST PASSED");
}
 
源代码26 项目: hottub   文件: UnionTest.java
public static void main(String[] args) throws Exception {
    ImmutableDescriptor immutableEmpty = new ImmutableDescriptor();
    DescriptorSupport mutableEmpty = new DescriptorSupport();

    checkEmpty(union());
    checkEmpty(union(immutableEmpty));
    checkEmpty(union(mutableEmpty));
    checkEmpty(union(EMPTY_DESCRIPTOR, immutableEmpty, mutableEmpty));
    checkEmpty(union(null, immutableEmpty, null));

    ImmutableDescriptor immutableNumbers =
        new ImmutableDescriptor(new String[] {"one", "two", "three"},
                                new Object[] {1, 2, 3});
    final String[] noNames = null;
    DescriptorSupport mutableNumbers =
        new DescriptorSupport(immutableNumbers.getFieldNames(),
                              immutableNumbers.getFieldValues(noNames));
    ImmutableDescriptor immutableOne =
        new ImmutableDescriptor(Collections.singletonMap("one", 1));
    DescriptorSupport mutableOne =
        new DescriptorSupport(new String[] {"one"}, new Object[] {1});
    ImmutableDescriptor immutableTwo =
        new ImmutableDescriptor(Collections.singletonMap("two", 2));
    DescriptorSupport mutableTwo =
        new DescriptorSupport(new String[] {"two"}, new Object[] {2});
    ImmutableDescriptor immutableOneTwo =
        new ImmutableDescriptor(new String[] {"one", "two"},
                                new Object[] {1, 2});


    checkEqual(union(immutableNumbers), immutableNumbers);
    checkEqual(union(immutableNumbers, mutableNumbers), immutableNumbers);
    checkEqual(union(mutableNumbers, immutableNumbers), immutableNumbers);
    checkEqual(union(mutableEmpty, immutableEmpty, immutableNumbers,
                     mutableNumbers, immutableOne), immutableNumbers);
    checkEqual(union(immutableOne, immutableTwo, immutableNumbers),
               immutableNumbers);
    checkEquivalent(union(immutableOne, mutableNumbers), immutableNumbers);
    checkEquivalent(union(immutableOne, immutableTwo), immutableOneTwo);
    checkEquivalent(union(mutableOne, mutableTwo), immutableOneTwo);

    if (failure != null)
        throw new Exception("TEST FAILED: " + failure);
    System.out.println("TEST PASSED");
}
 
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    Resource resource1 = new Resource();
    Resource resource2 = new Resource();
    Resource resource3 = new Resource();
    Method operationMethod = Resource.class.getMethod("operation");
    Method getCountMethod = Resource.class.getMethod("getCount");
    Method setCountMethod = Resource.class.getMethod("setCount", int.class);
    Descriptor operationDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "operation", resource1
                              });
    Descriptor getCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "getCount", resource2
                              });
    Descriptor setCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "setCount", resource2
                              });
    Descriptor countDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "getMethod", "setMethod"
                              }, new Object[] {
                                "attribute", "Count", "getCount", "setCount"
                              });
    ModelMBeanOperationInfo operationInfo =
        new ModelMBeanOperationInfo("operation description",
                                    operationMethod, operationDescriptor);
    ModelMBeanOperationInfo getCountInfo =
        new ModelMBeanOperationInfo("getCount description",
                                    getCountMethod, getCountDescriptor);
    ModelMBeanOperationInfo setCountInfo =
        new ModelMBeanOperationInfo("setCount description",
                                    setCountMethod, setCountDescriptor);
    ModelMBeanAttributeInfo countInfo =
        new ModelMBeanAttributeInfo("Count", "Count description",
                                    getCountMethod, setCountMethod,
                                    countDescriptor);
    ModelMBeanInfo mmbi =
        new ModelMBeanInfoSupport(Resource.class.getName(),
                                  "ModelMBean to test targetObject",
                                  new ModelMBeanAttributeInfo[] {countInfo},
                                  null,  // no constructors
                                  new ModelMBeanOperationInfo[] {
                                      operationInfo, getCountInfo, setCountInfo
                                  },
                                  null); // no notifications
    ModelMBean mmb = new RequiredModelMBean(mmbi);
    mmb.setManagedResource(resource3, "ObjectReference");
    mbs.registerMBean(mmb, name);
    mbs.invoke(name, "operation", null, null);
    mbs.setAttribute(name, new Attribute("Count", 53));
    if (resource1.operationCount != 1)
        throw new Exception("operationCount: " + resource1.operationCount);
    if (resource2.count != 53)
        throw new Exception("count: " + resource2.count);
    int got = (Integer) mbs.getAttribute(name, "Count");
    if (got != 53)
        throw new Exception("got count: " + got);

    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();
    ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name);
    // Above gets NotSerializableException if resource included in
    // serialized form
    cc.close();
    cs.stop();
    System.out.println("TEST PASSED");
}
 
源代码28 项目: openjdk-8-source   文件: UnionTest.java
public static void main(String[] args) throws Exception {
    ImmutableDescriptor immutableEmpty = new ImmutableDescriptor();
    DescriptorSupport mutableEmpty = new DescriptorSupport();

    checkEmpty(union());
    checkEmpty(union(immutableEmpty));
    checkEmpty(union(mutableEmpty));
    checkEmpty(union(EMPTY_DESCRIPTOR, immutableEmpty, mutableEmpty));
    checkEmpty(union(null, immutableEmpty, null));

    ImmutableDescriptor immutableNumbers =
        new ImmutableDescriptor(new String[] {"one", "two", "three"},
                                new Object[] {1, 2, 3});
    final String[] noNames = null;
    DescriptorSupport mutableNumbers =
        new DescriptorSupport(immutableNumbers.getFieldNames(),
                              immutableNumbers.getFieldValues(noNames));
    ImmutableDescriptor immutableOne =
        new ImmutableDescriptor(Collections.singletonMap("one", 1));
    DescriptorSupport mutableOne =
        new DescriptorSupport(new String[] {"one"}, new Object[] {1});
    ImmutableDescriptor immutableTwo =
        new ImmutableDescriptor(Collections.singletonMap("two", 2));
    DescriptorSupport mutableTwo =
        new DescriptorSupport(new String[] {"two"}, new Object[] {2});
    ImmutableDescriptor immutableOneTwo =
        new ImmutableDescriptor(new String[] {"one", "two"},
                                new Object[] {1, 2});


    checkEqual(union(immutableNumbers), immutableNumbers);
    checkEqual(union(immutableNumbers, mutableNumbers), immutableNumbers);
    checkEqual(union(mutableNumbers, immutableNumbers), immutableNumbers);
    checkEqual(union(mutableEmpty, immutableEmpty, immutableNumbers,
                     mutableNumbers, immutableOne), immutableNumbers);
    checkEqual(union(immutableOne, immutableTwo, immutableNumbers),
               immutableNumbers);
    checkEquivalent(union(immutableOne, mutableNumbers), immutableNumbers);
    checkEquivalent(union(immutableOne, immutableTwo), immutableOneTwo);
    checkEquivalent(union(mutableOne, mutableTwo), immutableOneTwo);

    if (failure != null)
        throw new Exception("TEST FAILED: " + failure);
    System.out.println("TEST PASSED");
}
 
源代码29 项目: openjdk-8   文件: UnserializableTargetObjectTest.java
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName name = new ObjectName("a:b=c");
    Resource resource1 = new Resource();
    Resource resource2 = new Resource();
    Resource resource3 = new Resource();
    Method operationMethod = Resource.class.getMethod("operation");
    Method getCountMethod = Resource.class.getMethod("getCount");
    Method setCountMethod = Resource.class.getMethod("setCount", int.class);
    Descriptor operationDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "operation", resource1
                              });
    Descriptor getCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "getCount", resource2
                              });
    Descriptor setCountDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "targetObject"
                              }, new Object[] {
                                "operation", "setCount", resource2
                              });
    Descriptor countDescriptor =
        new DescriptorSupport(new String[] {
                                "descriptorType", "name", "getMethod", "setMethod"
                              }, new Object[] {
                                "attribute", "Count", "getCount", "setCount"
                              });
    ModelMBeanOperationInfo operationInfo =
        new ModelMBeanOperationInfo("operation description",
                                    operationMethod, operationDescriptor);
    ModelMBeanOperationInfo getCountInfo =
        new ModelMBeanOperationInfo("getCount description",
                                    getCountMethod, getCountDescriptor);
    ModelMBeanOperationInfo setCountInfo =
        new ModelMBeanOperationInfo("setCount description",
                                    setCountMethod, setCountDescriptor);
    ModelMBeanAttributeInfo countInfo =
        new ModelMBeanAttributeInfo("Count", "Count description",
                                    getCountMethod, setCountMethod,
                                    countDescriptor);
    ModelMBeanInfo mmbi =
        new ModelMBeanInfoSupport(Resource.class.getName(),
                                  "ModelMBean to test targetObject",
                                  new ModelMBeanAttributeInfo[] {countInfo},
                                  null,  // no constructors
                                  new ModelMBeanOperationInfo[] {
                                      operationInfo, getCountInfo, setCountInfo
                                  },
                                  null); // no notifications
    ModelMBean mmb = new RequiredModelMBean(mmbi);
    mmb.setManagedResource(resource3, "ObjectReference");
    mbs.registerMBean(mmb, name);
    mbs.invoke(name, "operation", null, null);
    mbs.setAttribute(name, new Attribute("Count", 53));
    if (resource1.operationCount != 1)
        throw new Exception("operationCount: " + resource1.operationCount);
    if (resource2.count != 53)
        throw new Exception("count: " + resource2.count);
    int got = (Integer) mbs.getAttribute(name, "Count");
    if (got != 53)
        throw new Exception("got count: " + got);

    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();
    ModelMBeanInfo rmmbi = (ModelMBeanInfo) mbsc.getMBeanInfo(name);
    // Above gets NotSerializableException if resource included in
    // serialized form
    cc.close();
    cs.stop();
    System.out.println("TEST PASSED");
}
 
源代码30 项目: openjdk-8   文件: UnionTest.java
public static void main(String[] args) throws Exception {
    ImmutableDescriptor immutableEmpty = new ImmutableDescriptor();
    DescriptorSupport mutableEmpty = new DescriptorSupport();

    checkEmpty(union());
    checkEmpty(union(immutableEmpty));
    checkEmpty(union(mutableEmpty));
    checkEmpty(union(EMPTY_DESCRIPTOR, immutableEmpty, mutableEmpty));
    checkEmpty(union(null, immutableEmpty, null));

    ImmutableDescriptor immutableNumbers =
        new ImmutableDescriptor(new String[] {"one", "two", "three"},
                                new Object[] {1, 2, 3});
    final String[] noNames = null;
    DescriptorSupport mutableNumbers =
        new DescriptorSupport(immutableNumbers.getFieldNames(),
                              immutableNumbers.getFieldValues(noNames));
    ImmutableDescriptor immutableOne =
        new ImmutableDescriptor(Collections.singletonMap("one", 1));
    DescriptorSupport mutableOne =
        new DescriptorSupport(new String[] {"one"}, new Object[] {1});
    ImmutableDescriptor immutableTwo =
        new ImmutableDescriptor(Collections.singletonMap("two", 2));
    DescriptorSupport mutableTwo =
        new DescriptorSupport(new String[] {"two"}, new Object[] {2});
    ImmutableDescriptor immutableOneTwo =
        new ImmutableDescriptor(new String[] {"one", "two"},
                                new Object[] {1, 2});


    checkEqual(union(immutableNumbers), immutableNumbers);
    checkEqual(union(immutableNumbers, mutableNumbers), immutableNumbers);
    checkEqual(union(mutableNumbers, immutableNumbers), immutableNumbers);
    checkEqual(union(mutableEmpty, immutableEmpty, immutableNumbers,
                     mutableNumbers, immutableOne), immutableNumbers);
    checkEqual(union(immutableOne, immutableTwo, immutableNumbers),
               immutableNumbers);
    checkEquivalent(union(immutableOne, mutableNumbers), immutableNumbers);
    checkEquivalent(union(immutableOne, immutableTwo), immutableOneTwo);
    checkEquivalent(union(mutableOne, mutableTwo), immutableOneTwo);

    if (failure != null)
        throw new Exception("TEST FAILED: " + failure);
    System.out.println("TEST PASSED");
}
 
 类所在包
 类方法
 同包方法