01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.management.beans;
06:
07: import com.tc.management.AbstractTerracottaMBean;
08:
09: import java.lang.reflect.Method;
10:
11: import javax.management.NotCompliantMBeanException;
12:
13: public class L2Dumper extends AbstractTerracottaMBean implements
14: L2DumperMBean {
15: private static final boolean DEBUG = false;
16:
17: public static final String THREAD_DUMP_METHOD_NAME = "dumpThreadsMany";
18: public static final Class[] THREAD_DUMP_METHOD_PARAMETERS = new Class[] {
19: int.class, long.class };
20: public static final int DEFAULT_THREAD_DUMP_COUNT = 3;
21: public static final long DEFAULT_THREAD_DUMP_INTERVAL = 1000;
22:
23: public int threadDumpCount = DEFAULT_THREAD_DUMP_COUNT;
24: public long threadDumpInterval = DEFAULT_THREAD_DUMP_INTERVAL;
25:
26: private final TCDumper dumper;
27:
28: public L2Dumper(TCDumper dumper) throws NotCompliantMBeanException {
29: super (L2DumperMBean.class, false);
30: this .dumper = dumper;
31: }
32:
33: public void doServerDump() {
34: dumper.dump();
35: }
36:
37: public void setThreadDumpCount(int count) {
38: threadDumpCount = count;
39: }
40:
41: public void setThreadDumpInterval(long interval) {
42: threadDumpInterval = interval;
43: }
44:
45: public int doThreadDump() throws Exception {
46: debugPrintln("ThreadDumping: count=[" + threadDumpCount
47: + "] interval=[" + threadDumpInterval + "]");
48: Class threadDumpClass = getClass().getClassLoader().loadClass(
49: "com.tc.util.runtime.ThreadDump");
50: Method method = threadDumpClass.getMethod(
51: THREAD_DUMP_METHOD_NAME, THREAD_DUMP_METHOD_PARAMETERS);
52: Object[] args = { new Integer(threadDumpCount),
53: new Long(threadDumpInterval) };
54: int pid = ((Integer) method.invoke(null, args)).intValue();
55: return pid;
56: }
57:
58: public void reset() {
59: //
60: }
61:
62: private void debugPrintln(String s) {
63: if (DEBUG) {
64: System.err.println("##### L2Dumper: " + s);
65: }
66: }
67:
68: }
|