1 20 21 22 23 package org.snmp4j.mp; 24 25 import org.snmp4j.event.*; 26 import java.util.*; 27 28 34 public class CounterSupport { 35 36 protected static CounterSupport instance = null; 37 private transient Vector counterListeners; 38 39 protected CounterSupport() { 40 } 41 42 47 public static CounterSupport getInstance() { 48 if (instance == null) { 49 instance = new CounterSupport(); 50 } 51 return instance; 52 } 53 54 60 public synchronized void addCounterListener(CounterListener listener) { 61 Vector v = (counterListeners == null) ? 62 new Vector(2) : (Vector) counterListeners.clone(); 63 if (!v.contains(listener)) { 64 v.addElement(listener); 65 counterListeners = v; 66 } 67 } 68 69 74 public synchronized void removeCounterListener(CounterListener listener) { 75 if (counterListeners != null && counterListeners.contains(listener)) { 76 Vector v = (Vector) counterListeners.clone(); 77 v.removeElement(listener); 78 counterListeners = v; 79 } 80 } 81 82 89 public void fireIncrementCounter(CounterEvent event) { 90 if (counterListeners != null) { 91 Vector listeners = counterListeners; 92 int count = listeners.size(); 93 for (int i = 0; i < count; i++) { 94 ((CounterListener) listeners.elementAt(i)).incrementCounter(event); 95 } 96 } 97 } 98 } 99 | Popular Tags |