SharedJAMonBufferListener.java :  » Profiler » JAMon » com » jamonapi » Java Open Source

Java Open Source » Profiler » JAMon 
JAMon » com » jamonapi » SharedJAMonBufferListener.java
package com.jamonapi;

import com.jamonapi.utils.BufferList;


/** Class that works like JAMonBufferListeners but allows users to share buffers
 *  between monitors with the jamon gui...
 * @author steve souza
 *
 */

public class SharedJAMonBufferListener extends JAMonBufferListener {
  private int ID=1;
  private boolean factory=true;
  
  public SharedJAMonBufferListener() {
    super("SharedJAMonBufferListener");
  }
  
  /** Pass in the jamonListener name */
  
  public SharedJAMonBufferListener(String name){
    super(name);
  }
  
  /** Name the listener and pass in the jamon BufferList to use */
  public SharedJAMonBufferListener(String name, BufferList list) {
    super(name, list);
  }
  
  /** Returns a usable copy of this object and puts that object into the JAMonListenerFactory so it can be used 
   * by other Monitor's
   */
  public JAMonListener copy() {
    // If this is a factory creator it creates a numbered version and it 
    // can be used to share between different monitors
    if (factory) {
      SharedJAMonBufferListener listener=new SharedJAMonBufferListener("_"+getName()+getNextID(), getBufferList().copy());
            listener.setFactoryInstance(false);
      JAMonListenerFactory.put(listener);
      return listener;
    } else
      return this;

  }
  
  private synchronized int getNextID() {
    return ID++;
  }
  
  private void setFactoryInstance(boolean factoryInstance) {
    factory=factoryInstance;
  }
  

  
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.