1 20 21 22 23 24 25 package org.snmp4j.mp; 26 27 import org.snmp4j.event.CounterListener; 28 import org.snmp4j.event.CounterEvent; 29 import java.util.Hashtable ; 30 import org.snmp4j.smi.OID; 31 import org.snmp4j.smi.VariableBinding; 32 import org.snmp4j.smi.Counter32; 33 import org.snmp4j.smi.Variable; 34 35 52 public class DefaultCounterListener implements CounterListener { 53 54 private Hashtable counters = new Hashtable (50); 55 56 59 public DefaultCounterListener() { 60 } 61 62 public synchronized void incrementCounter(CounterEvent event) { 63 OID id = event.getOid(); 64 VariableBinding counter = (VariableBinding) counters.get(id); 65 if (counter == null) { 66 counter = new VariableBinding(id, new Counter32(1)); 67 counters.put(id, counter); 68 } 69 else { 70 ((Counter32)counter.getVariable()).increment(); 71 } 72 event.setCurrentValue((Variable) 74 ((VariableBinding)counter).getVariable().clone()); 75 } 76 } 77 | Popular Tags |