/** * Count the thrown exception and put the stack trace in the details portion of the key. * This will allow the stack trace to be viewed in the JAMon web application. */ protected void trackException(MonKey key, Throwable ex) { String stackTrace = "stackTrace=" + Misc.getExceptionTrace(ex); key.setDetails(stackTrace); // Specific exception counter. Example: java.lang.RuntimeException MonitorFactory.add(new MonKeyImp(ex.getClass().getName(), stackTrace, "Exception"), 1); // General exception counter which is a total for all exceptions thrown MonitorFactory.add(new MonKeyImp(MonitorFactory.EXCEPTIONS_LABEL, stackTrace, "Exception"), 1); }
System.out.println("month="+getMonth(date)); System.out.println("dayofweek="+getDayOfWeek(date)); System.out.println("shortdate="+getShortDate(date)); System.out.println("formatteddate="+getFormattedDate("dd-MMM-yy",date)); System.out.println("month="+getMonth()); System.out.println("dayofweek="+getDayOfWeek()); System.out.println("shortdate="+getShortDate()); Map m=createCaseInsensitiveMap(); m.put("Steve", "Souza"); m.put("STEVE", "Souza");
public static String getAsString(Object obj) { try { if (obj==null) return null; else if (obj instanceof Collection) return getCollAsString((Collection)obj); else if (obj instanceof Object[]) return getArrAsString((Object[]) obj); else if (obj instanceof ToArray) return getArrAsString(((ToArray)obj).toArray()); else if (obj instanceof Throwable) return getExceptionTrace((Throwable)obj); else return obj.toString(); } catch(Throwable e) { // ignore any exception here since return "???"; } }
Object[][] data=Misc.sort(getBasicData(), sortCol, sortOrder); int rows=data.length; int cols=header.length;
/** Get the short date for Today. i.e 05/15/04 */ public static String getShortDate() { return getShortDate(new Date()); }
/** Formats todays date with the passed in date format String. See the main method for sample Formats */ public static String getFormattedDateNow(String format) { return getFormattedDate(format, new Date()); }
/** Get the day of week for today. For example Mon for Monday. */ public static String getDayOfWeek() { return getDayOfWeek(new Date()); }
/** Return the 2 digit month of todays date */ public static String getMonth() { return getMonth(new Date()); }
/** Reset all listeners in factory to default settings. Note this is required to get rid of shared buffer data in * memory. */ public static void reset() { // put factory instances into the JAMonListenerFactory map = Misc.createCaseInsensitiveMap(); put(getFIFO()); put(getNLargest()); put(getNSmallest()); put(getNLargest7Days()); put(getNLargest24Hrs()); put(getNSmallest7Days()); put(getNSmallest24Hrs()); // allows sharing buffers between monitors! put(getSharedFIFO()); put(getSharedNLargest()); put(getSharedNSmallest()); put(getSharedNLargest7Days()); put(getSharedNLargest24Hrs()); put(getSharedNSmallest7Days()); put(getSharedNSmallest24Hrs()); }
/** A basic report in html format that is sorted. It has summary info for all monitors but * no range info */ public String getReport(int sortCol, String sortOrder) { if (!hasData()) return ""; String[] header=getBasicHeader(); Object[][] data=Misc.sort(getBasicData(), sortCol, sortOrder); int rows=data.length; int cols=header.length; StringBuffer html=new StringBuffer(100000);// guess on report size html.append("\n<table border='1' rules='all'>\n"); for (int i=0;i<cols;i++) html.append("<th>"+header[i]+"</th>"); html.append("<th>"+header[0]+"</th>");//repeat first header html.append("\n"); for (int i=0;i<rows;i++) { html.append("<tr>"); for (int j=0;j<cols;j++) { html.append("<td>"+data[i][j]+"</td>"); } html.append("<td>"+data[i][0]+"</td>");// repeat first column html.append("</tr>\n"); } html.append("</table>"); return html.toString(); }
/** Get the short date for Today. i.e 05/15/04 */ public static String getShortDate() { return getShortDate(new Date()); }
/** Formats todays date with the passed in date format String. See the main method for sample Formats */ public static String getFormattedDateNow(String format) { return getFormattedDate(format, new Date()); }
/** Get the day of week for today. For example Mon for Monday. */ public static String getDayOfWeek() { return getDayOfWeek(new Date()); }
/** Return the 2 digit month of todays date */ public static String getMonth() { return getMonth(new Date()); }
private void addExceptionStackTraceToDetails(StringBuilder temp,Exception exception) { if(exception != null) { temp.append("=== Stack Trace ===").append(LINE_SEPARATOR); temp.append(Misc.getExceptionTrace(exception)); } }
Object[][] data = Misc.sort(MonitorFactory.getRootMonitor().getBasicData(), 3, "desc"); for (Object[] row : data) { if (((Double) row[1]) > 0) {
@Override public String getDetails(ProceedingJoinPoint proceedingJoinPoint, Throwable exception) { return new StringBuffer("stackTrace=") .append(Misc.getExceptionTrace(exception)) .toString(); }
private static String getArrAsString(Object[] arr) { int lastElement=arr.length-1; StringBuffer buff=new StringBuffer(); for (int i=0;i<arr.length;i++) { Object obj=arr[i]; if (obj instanceof Throwable) obj=getExceptionTrace((Throwable)obj); buff.append(obj); if (i!=lastElement) buff.append(",\n"); } return buff.toString(); }
private static String getCollAsString(Collection coll) { int currentElement=1; int lastElement=coll.size(); Iterator iter=coll.iterator(); StringBuffer buff=new StringBuffer(); // loop through elements creating a comma delimeted list of the values while(iter.hasNext()) { Object obj=iter.next(); if (obj instanceof Throwable) obj=getExceptionTrace((Throwable)obj); buff.append(obj); if (currentElement!=lastElement) buff.append(",\n"); currentElement++; } return buff.toString(); }
/** Create details for when an exception is thrown. This would be the stack trace and possibly the methods * arguments if useArgsWithExceptionDetails has been set. * * @param proceedingJoinPoint * @param exception * @return */ @Override public String getDetails(ProceedingJoinPoint proceedingJoinPoint, Throwable exception) { String detailMessage = createDetailMessage(proceedingJoinPoint, "", useArgsWithExceptionDetails); String stackTrace = new StringBuffer(detailMessage) .append("\n\nstackTrace=") .append(Misc.getExceptionTrace(exception)) .toString(); return stackTrace; }