Java 类javax.management.openmbean.InvalidKeyException 实例源码

项目:Ultrastructure    文件:WorkspaceImporter.java   
private UUID resolve(QualifiedNameContext qualifiedName) {
    if (qualifiedName == null) {
        throw new IllegalArgumentException("Qualified name is null");
    }
    UUID id;
    if (qualifiedName.namespace != null) {
        return scope.lookupId(qualifiedName.namespace.getText(),
                              qualifiedName.member.getText());
    } else if (qualifiedName.member.getText()
                                   .equals(THIS)) {
        return workspace.getDefiningProduct()
                        .getId();
    } else {
        id = scope.lookupId(qualifiedName.member.getText());
        if (id != null) {
            return id;
        }
    }
    throw new InvalidKeyException(String.format("Cannot resolve %s:%s",
                                                qualifiedName.namespace == null ? ""
                                                                                : qualifiedName.namespace.getText(),
                                                qualifiedName.member.getText()));
}
项目:mxcache    文件:MxCacheJConsolePlugin.java   
private void fillRow(CompositeData cache, Object[] row) {
    for (com.maxifier.mxcache.jconsoleplugin.Attribute attr : com.maxifier.mxcache.jconsoleplugin.Attribute.values()) {
        try {
            Object v = cache.get(attr.getKey());
            Object s = v == null ? "" : attr.transform(v);
            // todo add posibility to switch shortcutting off
            row[attr.ordinal()] = attr.isShortcutable() ? com.maxifier.mxcache.jconsoleplugin.Attribute.shortcutClassNames(s) : s;
        } catch (InvalidKeyException e) {
            // some attributes were added lately, so they may be missing
            row[attr.ordinal()] = "";
        }
    }
}
项目:swutils    文件:OpenMBeanSupportTest.java   
@Test
public void test_toCompositeData() throws Exception {
    Source source = new Source();
    CompositeData compositeData = openMBeanSupport.toCompositeData(source, "NAME");

    assertThat(compositeData.get("attrLong")).isEqualTo(source.attrLong);
    assertThat(compositeData.get("attrBoolean")).isEqualTo(source.attrBoolean);
    assertThat(compositeData.get("attrString")).isEqualTo(source.attrString);
    assertThat(compositeData.get("attrStringArray")).isEqualTo(source.attrStringArray);
    assertThatThrownBy(() -> compositeData.get("attrObject")).isInstanceOf(InvalidKeyException.class);
}
项目:owncloud-gallery    文件:Properties.java   
public static Integer getAppInt(String key) {
    if(APP.containsKey(key)) {
        return Integer.parseInt(APP.getString(key));
    } else {
        throw new InvalidKeyException(String.format("%s not found in app settings.", key));
    }
}
项目:holter    文件:JmxClient.java   
public Object getJmxItem(String serviceUrl, String objectName, String attributeName,
    String itemName) throws InvalidKeyException, AttributeNotFoundException, MBeanException,
    MalformedObjectNameException, InstanceNotFoundException, MalformedURLException, IOException,
    Exception {

  try (JMXConnector jmxc = JMXConnectorFactory.connect(new JMXServiceURL(serviceUrl), null)) {

    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

    ObjectName mbeanName = new ObjectName(objectName);

    Object returnedObject = mbsc.getAttribute(mbeanName, attributeName);

    if (returnedObject instanceof CompositeDataSupport) {
      // logger.error("item name info:");
      // if (itemName.isEmpty()) {
      // logger.error("item name is empty");
      // }
      // if (itemName == "") {
      // logger.error("item name == \"\"");
      // }
      // logger.error("item name length is " + itemName.length());

      CompositeData compositeDataObject = (CompositeData) returnedObject;

      if (!itemName.isEmpty()) {
        return compositeDataObject.get(itemName);
      } else {
        return compositeDataObject.values().toString();
      }
    } else {
      return returnedObject;
    }
  } catch (Exception exc) {
    logger.error("Exception caught: " + exc.getMessage());
    return exc.getMessage();
  }
}
项目:freeVM    文件:TabularDataSupportTest.java   
/**
 * Verify that get (values of elements which is not index names) method of
 * CompositeDataSupport throws InvalidKeyException.
 */
public Result testInvalidKey() throws Exception {
    TabularData tabularData = getTabularData();
    try {
        tabularData.get(new Object[] { CompositeDataSupportTest
            .getCompositeData().get(indexNames[0]) });
        assertTrue(false);
    } catch (InvalidKeyException e) {
    }
    return result();
}
项目:jmxfetch    文件:JMXTabularAttribute.java   
private Object getValue(String key, String subAttribute) throws AttributeNotFoundException,
        InstanceNotFoundException,
        MBeanException, ReflectionException, IOException {

    try{
        Object value = this.getJmxValue();
        String attributeType = getAttribute().getType();

        TabularData data = (TabularData) value;
        for (Object rowKey : data.keySet()) {
            Collection keys = (Collection) rowKey;
            String pathKey = getMultiKey(keys);
            if (key.equals(pathKey)) {
                CompositeData compositeData = data.get(keys.toArray());
                if (subAttribute.contains(".")) {
                    // walk down the path
                    Object o;
                    for (String subPathKey : subAttribute.split("\\.")) {
                        o = compositeData.get(subPathKey);
                        if (o instanceof CompositeData) {
                            compositeData = (CompositeData) o;
                        } else {
                            return compositeData.get(subPathKey);
                        }
                    }
                } else {
                    return compositeData.get(subAttribute);
                }
            }
        }
    }
    catch (InvalidKeyException e){
        LOGGER.warn("`"+getAttribute().getName()+"` attribute does not have a `"+subAttribute+"` key.");
        return null;
    }

    throw new NumberFormatException();
}
项目:dsl-devkit    文件:VirtualMachineTracer.java   
/**
 * Installs a listener that will publish all full GC events as {@link FullGarbageCollectionEvent} objects.
 */
public void start() {
  // This code only works with Oracle HotSpot JVM as there is no standard API to retrieve information about GC events
  if (!isHotSpotVM()) {
    return;
  }

  long vmStartTime = getApproximateNanoStartTime();

  for (GarbageCollectorMXBean gcBean : ManagementFactory.getGarbageCollectorMXBeans()) {
    Class<? extends TraceEvent> eventType = gcBean.getName().equals("ConcurrentMarkSweep") || gcBean.getName().equals("MarkSweepCompact") //$NON-NLS-1$ //$NON-NLS-2$
        ? FullGarbageCollectionEvent.class
        : MinorGarbageCollectionEvent.class;
    NotificationEmitter emitter = (NotificationEmitter) gcBean;
    NotificationListener listener = new NotificationListener() {

      @Override
      public void handleNotification(final Notification notification, final Object handback) {
        try {
          // we only handle GARBAGE_COLLECTION_NOTIFICATION notifications here
          if (notification.getType().equals("com.sun.management.gc.notification")) { //$NON-NLS-1$
            CompositeData cd = (CompositeData) notification.getUserData();
            String gcAction = (String) cd.get("gcAction"); //$NON-NLS-1$
            String gcCause = (String) cd.get("gcCause"); //$NON-NLS-1$
            CompositeData gcInfo = (CompositeData) cd.get("gcInfo"); //$NON-NLS-1$
            long startTime = TimeUnit.NANOSECONDS.convert((Long) gcInfo.get("startTime"), TimeUnit.MILLISECONDS); //$NON-NLS-1$
            long duration = TimeUnit.NANOSECONDS.convert((Long) gcInfo.get("duration"), TimeUnit.MILLISECONDS); //$NON-NLS-1$
            if (duration > 0) {
              // "startTime" and "duration" are relative to VM start time
              traceSet.started(eventType, vmStartTime + startTime, gcAction, gcCause);
              traceSet.ended(eventType, vmStartTime + startTime + duration);
            }
          }
        } catch (InvalidKeyException e) {
          // ignore
        }
      };
    };
    emitter.addNotificationListener(listener, null, null);
    gcListenerMap.put(emitter, listener);
  }
}