javax.management.openmbean.InvalidKeyException Java Examples

The following examples show how to use javax.management.openmbean.InvalidKeyException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StreamsProxy.java    From cassandra-reaper with Apache License 2.0 6 votes vote down vote up
private Set<StreamState> parseCompositeData(Set<CompositeData> payload) {
  Set<StreamState> result = Sets.newHashSet();

  for (CompositeData compositeData : payload) {

    try {
      // start by trying to parse with classes coming from Reaper's C* dependency
      StreamState streamState = StreamStateCompositeData.fromCompositeData(compositeData);
      result.add(streamState);
    } catch (AssertionError | InvalidKeyException e) {
      try {
        // if that fails, try the old version
        StreamState olderStreamState = parseStreamStatePre2_1(compositeData);
        result.add(olderStreamState);
      } catch (InvalidKeyException ie) {
        // and if even that fails, try the new version
        // if that still fails, exception goes up
        StreamState newerStreamState = parseStreamState4_0_0(compositeData);
        result.add(newerStreamState);
      }
    }
  }
  return result;
}
 
Example #2
Source File: VirtualMachineTracer.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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);
  }
}