01: package net.sf.ehcache.distribution;
02:
03: import net.sf.ehcache.CacheManager;
04: import net.sf.ehcache.Ehcache;
05:
06: /**
07: * A distributed testing tool for manual distributed testing of ehcache on cluster nodes.
08: * <p/>
09: * It is passed the ehcache configuration to use and cache to monitor
10: *
11: * @author Greg Luck
12: * @version $Id: RemoteDebugger.java 331 2007-01-29 09:38:41Z gregluck $
13: */
14: public final class RemoteDebugger {
15: private static final int TWO_SECONDS = 2000;
16:
17: /**
18: * Utility class. No constructor
19: */
20: private RemoteDebugger() {
21: //noop
22: }
23:
24: /**
25: * A Remote Debugger which prints out the cache size of the monitored cache.
26: * Additional logging messages can be observed by setting the logging level to debug
27: * or trace for net.sf.ehcache.distribution
28: *
29: * @param args path_to_ehcache.xml and a cache name
30: * @throws InterruptedException thrown when it is interrupted. It will keep going until then.
31: */
32: public static void main(String[] args) throws InterruptedException {
33:
34: if (args.length < 1 || args.length > 2) {
35: System.out
36: .println("Command line to list caches to monitor: java -jar ehcache-remote-debugger.jar path_to_ehcache.xml\n"
37: + "Command line to monitor a specific cache: java -jar ehcache-remote-debugger.jar path_to_ehcache.xml"
38: + " cacheName");
39: System.exit(2);
40: }
41:
42: System.out
43: .println("Increase the net.sf.ehcache.distribution logging level to debug or trace to see distributed"
44: + " cache operations as they occur.");
45:
46: CacheManager manager = new CacheManager(args[0]);
47: String[] cacheNames = manager.getCacheNames();
48: StringBuffer availableCaches = new StringBuffer();
49: if (args.length == 1) {
50: for (int i = 0; i < cacheNames.length; i++) {
51: String name = cacheNames[i];
52: availableCaches.append(name).append(' ');
53: }
54: System.out.println("Available caches are: "
55: + availableCaches
56: + ". Choose one and add it to the command line.");
57: System.exit(1);
58: } else {
59: String cacheName = args[1];
60: Ehcache cache = manager.getCache(cacheName);
61: if (cache == null) {
62: System.err.println("No cache named " + cacheName
63: + " exists. Available caches are: "
64: + availableCaches);
65: } else {
66: System.out.println("Monitoring cache: " + cacheName);
67:
68: while (true) {
69: Thread.sleep(TWO_SECONDS);
70: System.out
71: .println("Cache size: " + cache.getSize());
72: }
73: }
74: }
75: }
76: }
|