01: package com.jamonapi;
02:
03: import com.jamonapi.utils.BufferList;
04:
05: /** Class that works like JAMonBufferListeners but allows users to share buffers
06: * between monitors with the jamon gui...
07: * @author steve souza
08: *
09: */
10:
11: public class SharedJAMonBufferListener extends JAMonBufferListener {
12: private int ID = 1;
13: private boolean factory = true;
14:
15: public SharedJAMonBufferListener() {
16: super ("SharedJAMonBufferListener");
17: }
18:
19: /** Pass in the jamonListener name */
20:
21: public SharedJAMonBufferListener(String name) {
22: super (name);
23: }
24:
25: /** Name the listener and pass in the jamon BufferList to use */
26: public SharedJAMonBufferListener(String name, BufferList list) {
27: super (name, list);
28: }
29:
30: /** Returns a usable copy of this object and puts that object into the JAMonListenerFactory so it can be used
31: * by other Monitor's
32: */
33: public JAMonListener copy() {
34: // If this is a factory creator it creates a numbered version and it
35: // can be used to share between different monitors
36: if (factory) {
37: SharedJAMonBufferListener listener = new SharedJAMonBufferListener(
38: "_" + getName() + getNextID(), getBufferList()
39: .copy());
40: listener.setFactoryInstance(false);
41: JAMonListenerFactory.put(listener);
42: return listener;
43: } else
44: return this ;
45:
46: }
47:
48: private synchronized int getNextID() {
49: return ID++;
50: }
51:
52: private void setFactoryInstance(boolean factoryInstance) {
53: factory = factoryInstance;
54: }
55:
56: }
|