/** * JMX operation - returns all the queries we have collected. * @return - the slow query report as composite data. */ @Override public CompositeData[] getSlowQueriesCD() throws OpenDataException { CompositeDataSupport[] result = null; ConcurrentHashMap<String,QueryStats> queries = perPoolStats.get(poolName); if (queries!=null) { Set<Map.Entry<String,QueryStats>> stats = queries.entrySet(); if (stats!=null) { result = new CompositeDataSupport[stats.size()]; Iterator<Map.Entry<String,QueryStats>> it = stats.iterator(); int pos = 0; while (it.hasNext()) { Map.Entry<String,QueryStats> entry = it.next(); QueryStats qs = entry.getValue(); result[pos++] = qs.getCompositeData(getCompositeType()); } } } return result; }
public static CompositeData toCompositeData(Trigger trigger) { try { return new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES, new Object[] { trigger.getKey().getName(), trigger.getKey().getGroup(), trigger.getJobKey().getName(), trigger.getJobKey().getGroup(), trigger.getDescription(), JobDataMapSupport.toTabularData(trigger .getJobDataMap()), trigger.getCalendarName(), ((OperableTrigger)trigger).getFireInstanceId(), trigger.getMisfireInstruction(), trigger.getPriority(), trigger.getStartTime(), trigger.getEndTime(), trigger.getNextFireTime(), trigger.getPreviousFireTime(), trigger.getFinalFireTime() }); } catch (OpenDataException e) { throw new RuntimeException(e); } }
private static void installGCMonitoring() { List<GarbageCollectorMXBean> gcbeans = java.lang.management.ManagementFactory.getGarbageCollectorMXBeans(); for (GarbageCollectorMXBean gcbean : gcbeans) { NotificationEmitter emitter = (NotificationEmitter) gcbean; System.out.println(gcbean.getName()); NotificationListener listener = (notification, handback) -> { if (notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) { GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData()); long duration = info.getGcInfo().getDuration(); String gctype = info.getGcAction(); System.out.println(gctype + ": - " + info.getGcInfo().getId() + ", " + info.getGcName() + " (from " + info.getGcCause() + ") " + duration + " milliseconds"); } }; emitter.addNotificationListener(listener, null, null); } }
Object fromCompositeData(CompositeData cd, String[] itemNames, OpenTypeConverter[] converters) throws InvalidObjectException { Object o; try { o = getTargetClass().newInstance(); for (int i = 0; i < itemNames.length; i++) { if (cd.containsKey(itemNames[i])) { Object openItem = cd.get(itemNames[i]); Object javaItem = converters[i].fromOpenValue(openItem); setters[i].invoke(o, javaItem); } } } catch (Exception e) { throw invalidObjectException(e); } return o; }
protected CompositeData getCompositeData() { // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH // memoryUsageItemNames! final Object[] memoryUsageItemValues = { usage.getInit(), usage.getUsed(), usage.getCommitted(), usage.getMax(), }; try { return new CompositeDataSupport(memoryUsageCompositeType, memoryUsageItemNames, memoryUsageItemValues); } catch (OpenDataException e) { // Should never reach here throw new AssertionError(e); } }
public static MonitorInfo from(CompositeData cd) { try { CompositeData stecd = (CompositeData) cd.get("lockedStackFrame"); StackTraceElement ste = new StackTraceElement( (String) stecd.get("className"), (String) stecd.get("methodName"), (String) stecd.get("fileName"), (Integer) stecd.get("lineNumber")); return new MonitorInfo( (String) cd.get("className"), (Integer) cd.get("identityHashCode"), (Integer) cd.get("lockedStackDepth"), ste); } catch (Exception e) { throw new RuntimeException(e); } }
protected CompositeData getCompositeData() { // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH // gcNotifInfoItemNames! final Object[] gcNotifInfoItemValues; gcNotifInfoItemValues = new Object[] { gcNotifInfo.getGcName(), gcNotifInfo.getGcAction(), gcNotifInfo.getGcCause(), GcInfoCompositeData.toCompositeData(gcNotifInfo.getGcInfo()) }; CompositeType gict = getCompositeTypeByBuilder(); try { return new CompositeDataSupport(gict, gcNotifInfoItemNames, gcNotifInfoItemValues); } catch (OpenDataException e) { // Should never reach here throw new AssertionError(e); } }
protected CompositeData getCompositeData() { // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH // lockInfoItemNames! final Object[] lockInfoItemValues = { new String(lock.getClassName()), new Integer(lock.getIdentityHashCode()), }; try { return new CompositeDataSupport(lockInfoCompositeType, lockInfoItemNames, lockInfoItemValues); } catch (OpenDataException e) { // Should never reach here throw Util.newException(e); } }
private static void printGcInfo(CompositeData cd) throws Exception { GcInfo info = GcInfo.from(cd); System.out.print("GC #" + info.getId()); System.out.print(" start:" + info.getStartTime()); System.out.print(" end:" + info.getEndTime()); System.out.println(" (" + info.getDuration() + "ms)"); Map<String,MemoryUsage> usage = info.getMemoryUsageBeforeGc(); for (Map.Entry<String,MemoryUsage> entry : usage.entrySet()) { String poolname = entry.getKey(); MemoryUsage busage = entry.getValue(); MemoryUsage ausage = info.getMemoryUsageAfterGc().get(poolname); if (ausage == null) { throw new RuntimeException("After Gc Memory does not exist" + " for " + poolname); } System.out.println("Usage for pool " + poolname); System.out.println(" Before GC: " + busage); System.out.println(" After GC: " + ausage); } }
/** * @param jobDetail * @return CompositeData */ public static CompositeData toCompositeData(JobDetail jobDetail) { try { return new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES, new Object[] { jobDetail.getKey().getName(), jobDetail.getKey().getGroup(), jobDetail.getDescription(), jobDetail.getJobClass().getName(), JobDataMapSupport.toTabularData(jobDetail .getJobDataMap()), jobDetail.isDurable(), jobDetail.requestsRecovery(), }); } catch (OpenDataException e) { throw new RuntimeException(e); } }
/** * @return composite data */ public static CompositeData toCompositeData(JobExecutionContext jec) throws SchedulerException { try { return new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES, new Object[] { jec.getScheduler().getSchedulerName(), jec.getTrigger().getKey().getName(), jec.getTrigger().getKey().getGroup(), jec.getJobDetail().getKey().getName(), jec.getJobDetail().getKey().getGroup(), JobDataMapSupport.toTabularData(jec .getMergedJobDataMap()), jec.getTrigger().getCalendarName(), jec.isRecovering(), jec.getRefireCount(), jec.getFireTime(), jec.getScheduledFireTime(), jec.getPreviousFireTime(), jec.getNextFireTime(), jec.getJobRunTime(), jec.getFireInstanceId() }); } catch (OpenDataException e) { throw new RuntimeException(e); } }
@Override final Object fromNonNullOpenValue(Object openValue) throws InvalidObjectException { final TabularData table = (TabularData) openValue; final Collection<CompositeData> rows = cast(table.values()); final Map<Object, Object> valueMap = sortedMap ? newSortedMap() : newInsertionOrderMap(); for (CompositeData row : rows) { final Object key = keyMapping.fromOpenValue(row.get("key")); final Object value = valueMapping.fromOpenValue(row.get("value")); if (valueMap.put(key, value) != null) { final String msg = "Duplicate entry in TabularData: key=" + key; throw new InvalidObjectException(msg); } } return valueMap; }
@Override public void handleNotification(Notification notif, Object handback) { String type = notif.getType(); if (MEMORY_THRESHOLD_EXCEEDED.equals(type) || MEMORY_COLLECTION_THRESHOLD_EXCEEDED.equals(type)) { MemoryNotificationInfo minfo = MemoryNotificationInfo. from((CompositeData) notif.getUserData()); MemoryUtil.printMemoryNotificationInfo(minfo, type); PoolRecord pr = (PoolRecord) result.get(minfo.getPoolName()); if (pr == null) { throw new RuntimeException("Pool " + minfo.getPoolName() + " is not selected"); } if (!MEMORY_COLLECTION_THRESHOLD_EXCEEDED.equals(type)) { throw new RuntimeException("Pool " + minfo.getPoolName() + " got unexpected notification type: " + type); } pr.addNotification(minfo); System.out.println("notifying the checker thread to check result"); signals.release(); } }
/** * @param cData * @return JobDetail */ public static JobDetail newJobDetail(CompositeData cData) { JobDetail jobDetail = new JobDetail(); int i = 0; jobDetail.setName((String) cData.get(ITEM_NAMES[i++])); jobDetail.setGroup((String) cData.get(ITEM_NAMES[i++])); jobDetail.setDescription((String) cData.get(ITEM_NAMES[i++])); try { Class c = Class.forName((String) cData.get(ITEM_NAMES[i++])); jobDetail.setJobClass(c); } catch (ClassNotFoundException cnfe) { /**/ } jobDetail.setJobDataMap(JobDataMapSupport .newJobDataMap((TabularData) cData.get(ITEM_NAMES[i++]))); jobDetail.setVolatility((Boolean) cData.get(ITEM_NAMES[i++])); jobDetail.setDurability((Boolean) cData.get(ITEM_NAMES[i++])); jobDetail.setRequestsRecovery((Boolean) cData.get(ITEM_NAMES[i++])); return jobDetail; }
/** * @param jobDetail * @return CompositeData */ public static CompositeData toCompositeData(JobDetail jobDetail) { try { return new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES, new Object[] { jobDetail.getName(), jobDetail.getGroup(), jobDetail.getDescription(), jobDetail.getJobClass().getName(), JobDataMapSupport.toTabularData(jobDetail .getJobDataMap()), jobDetail.isVolatile(), jobDetail.isDurable(), jobDetail.requestsRecovery(), }); } catch (OpenDataException e) { throw new RuntimeException(e); } }
Object fromCompositeData(CompositeData cd, String[] itemNames, MXBeanMapping[] converters) throws InvalidObjectException { Object o; try { final Class<?> targetClass = getTargetClass(); ReflectUtil.checkPackageAccess(targetClass); o = targetClass.newInstance(); for (int i = 0; i < itemNames.length; i++) { if (cd.containsKey(itemNames[i])) { Object openItem = cd.get(itemNames[i]); Object javaItem = converters[i].fromOpenValue(openItem); MethodUtil.invoke(setters[i], o, new Object[] {javaItem}); } } } catch (Exception e) { throw invalidObjectException(e); } return o; }
protected void addOpenAttribute(String csDescription, Class cls, String csMethodName, CompositeType compositeType) { Method methodGet = MethodFinder.getMethod(cls, "get"+csMethodName); boolean bCanGet = true; if(methodGet == null) bCanGet = false; Method methodSet = MethodFinder.getMethod(cls, "set"+csMethodName, CompositeData.class); boolean bCanSet = true; if(methodSet == null) bCanSet = false; OpenMBeanAttributeInfoSupport attrOpen = new OpenMBeanAttributeInfoSupport(csMethodName, csDescription, compositeType, bCanGet, bCanSet, false); OpenMBeanAttributeInfoWrapper attr = new OpenMBeanAttributeInfoWrapper(csMethodName, csDescription, attrOpen, methodGet, methodSet); if(m_arrOpenMBeanAttributeInfosWrapper == null) m_arrOpenMBeanAttributeInfosWrapper = new ArrayList<OpenMBeanAttributeInfoWrapper>(); m_arrOpenMBeanAttributeInfosWrapper.add(attr); }
/** Validate if the input CompositeData has the expected * CompositeType (i.e. contain all attributes with expected * names and types). */ public static void validateCompositeData(CompositeData cd) { if (cd == null) { throw new NullPointerException("Null CompositeData"); } if (!isTypeMatched(stackTraceElementCompositeType, cd.getCompositeType())) { throw new IllegalArgumentException( "Unexpected composite type for StackTraceElement"); } }
public static Map<String, MemoryUsage> getMemoryUsageBeforeGc(CompositeData cd) { try { TabularData td = (TabularData) cd.get(MEMORY_USAGE_BEFORE_GC); return cast(memoryUsageMapType.toJavaTypeData(td)); } catch (InvalidObjectException | OpenDataException e) { // Should never reach here throw new AssertionError(e); } }
public static StackTraceElement getLockedStackFrame(CompositeData cd) { CompositeData ste = (CompositeData) cd.get(LOCKED_STACK_FRAME); if (ste != null) { return StackTraceElementCompositeData.from(ste); } else { return null; } }
public static String getPoolName(CompositeData cd) { String poolname = getString(cd, POOL_NAME); if (poolname == null) { throw new IllegalArgumentException("Invalid composite data: " + "Attribute " + POOL_NAME + " has null value"); } return poolname; }
public static void main(String[] args) { try { String host = "localhost"; host = "csseredapp-dev-03"; String port = "8356"; //port = "8356"; String mbeanName = "java.lang:type=Memory"; String attributeName = "HeapMemoryUsage"; JMXServiceURL jmxUrl = new JMXServiceURL( "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi" ); // jmxUrl = new JMXServiceURL( // "service:jmx:rmi://localhost/jndi/rmi://" + host + ":" + port + "/jmxrmi" ); logger.info("Target: " + jmxUrl ) ; JMXConnector jmxConnection = JMXConnectorFactory.connect( jmxUrl ); logger.info("Got connections") ; CompositeData resultData = (CompositeData) jmxConnection.getMBeanServerConnection() .getAttribute( new ObjectName(mbeanName), attributeName) ; logger.log(Level.INFO, "Got mbean: heapUsed: {0}", resultData.get( "used")) ; Thread.sleep( 5000 ); } catch ( Exception ex ) { logger.log( Level.SEVERE, "Failed connection", ex ); } }
private static void printThreadInfo(CompositeData cd) { ThreadInfo info = ThreadInfo.from(cd); if (info == null) { throw new RuntimeException("TEST FAILED: " + " Null ThreadInfo"); } System.out.print(info.getThreadName()); System.out.print(" id=" + info.getThreadId()); System.out.println(" " + info.getThreadState()); for (StackTraceElement s : info.getStackTrace()) { System.out.println(s); } }
public static String getGcAction(CompositeData cd) { String gcaction = getString(cd, GC_ACTION); if (gcaction == null) { throw new IllegalArgumentException("Invalid composite data: " + "Attribute " + GC_ACTION + " has null value"); } return gcaction; }
public CompositeData toCompositeData(CompositeType ct) { try { return new CompositeDataSupport(ct, new String[] {"whatsit"}, new String[] {"!" + whatsit}); } catch (Exception e) { throw new RuntimeException(e); } }
private JvmReadingInstance getHeapCodeCache( MBeanServerConnection connection, ReadingBean reading ) { String jvmPort = reading.getParameter("JMX_PORT"); final MBeanWrapper mbeanWrapper = mbeanWrappers.get(jvmPort); return new JvmReadingInstance(connection, String.valueOf(reading.getDbId()), reading.getMonitorName(), getName(reading, jvmPort), reading.getUnit(), 0) { private static final long serialVersionUID = 1L; @Override public void init() { applyMemoryNormalizationFactor(); mBeanName = mbeanWrapper.getObjectName("java.lang:name=Code Cache,type=MemoryPool"); } @Override public float poll() { CompositeData attribute = (CompositeData) mbeanWrapper.getMBeanAttribute(mBeanName, "Usage"); return fixLongValue(Long.valueOf( (attribute).get("used").toString())) * normalizationFactor; } }; }
/** Validate if the input CompositeData has the expected * CompositeType (i.e. contain all attributes with expected * names and types). */ public static void validateCompositeData(CompositeData cd) { if (cd == null) { throw new NullPointerException("Null CompositeData"); } if (!isTypeMatched(monitorInfoCompositeType, cd.getCompositeType())) { throw new IllegalArgumentException( "Unexpected composite type for MonitorInfo"); } }
/** * <p> * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>, * passing the <code>SchedulingContext</code> associated with this * instance. * </p> */ public JobDetail getJobDetail(JobKey jobKey) throws SchedulerException { try { return JobDetailSupport.newJobDetail((CompositeData)invoke( "getJobDetail", new Object[] { jobKey.getName(), jobKey.getGroup() }, new String[] { String.class.getName(), String.class.getName() })); } catch (ClassNotFoundException e) { throw new SchedulerException("Unable to resolve job class", e); } }
/** * Returns true if the input CompositeData has the expected * CompositeType (i.e. contain all attributes with expected * names and types). Otherwise, return false. */ public static void validateCompositeData(CompositeData cd) { if (cd == null) { throw new NullPointerException("Null CompositeData"); } if (!isTypeMatched(getBaseGcInfoCompositeType(), cd.getCompositeType())) { throw new IllegalArgumentException( "Unexpected composite type for GcInfo"); } }
@Override final Object fromNonNullOpenValue(Object value) throws InvalidObjectException { makeCompositeBuilder(); return compositeBuilder.fromCompositeData((CompositeData) value, itemNames, getterMappings); }
public static CompositeData toCompositeData(LockInfo li) { if (li == null) { return null; } LockInfoCompositeData licd = new LockInfoCompositeData(li); return licd.getCompositeData(); }
public static TabularData toTabularData(JobDetail[] jobDetails) { TabularData tData = new TabularDataSupport(TABULAR_TYPE); if (jobDetails != null) { ArrayList<CompositeData> list = new ArrayList<CompositeData>(); for (JobDetail jobDetail : jobDetails) { list.add(toCompositeData(jobDetail)); } tData.putAll(list.toArray(new CompositeData[list.size()])); } return tData; }
public static TabularData toTabularData(List<? extends CronTrigger> triggers) { TabularData tData = new TabularDataSupport(TABULAR_TYPE); if (triggers != null) { ArrayList<CompositeData> list = new ArrayList<CompositeData>(); for (CronTrigger trigger : triggers) { list.add(toCompositeData(trigger)); } tData.putAll(list.toArray(new CompositeData[list.size()])); } return tData; }
/** Validate if the input CompositeData has the expected * CompositeType (i.e. contain all attributes with expected * names and types). */ public static void validateCompositeData(CompositeData cd) { if (cd == null) { throw new NullPointerException("Null CompositeData"); } if (!isTypeMatched(memoryUsageCompositeType, cd.getCompositeType())) { throw new IllegalArgumentException( "Unexpected composite type for MemoryUsage"); } }
public static boolean isCurrentVersion(CompositeData cd) { if (cd == null) { throw new NullPointerException("Null CompositeData"); } return isTypeMatched(threadInfoCompositeType, cd.getCompositeType()); }
public static TabularData toTabularData(List<? extends SimpleTrigger> triggers) { TabularData tData = new TabularDataSupport(TABULAR_TYPE); if (triggers != null) { ArrayList<CompositeData> list = new ArrayList<CompositeData>(); for (SimpleTrigger trigger : triggers) { list.add(toCompositeData(trigger)); } tData.putAll(list.toArray(new CompositeData[list.size()])); } return tData; }
public static OperableTrigger newTrigger(CompositeData cData) throws ParseException { SimpleTriggerImpl result = new SimpleTriggerImpl(); result.setRepeatCount(((Integer) cData.get("repeatCount")).intValue()); result.setRepeatInterval(((Long) cData.get("repeatInterval")).longValue()); result.setTimesTriggered(((Integer) cData.get("timesTriggered")).intValue()); TriggerSupport.initializeTrigger(result, cData); return result; }