- java.lang.Object
-
- org.snmp4j.mp.DefaultCounterListener
-
- All Implemented Interfaces:
java.util.EventListener
,CounterListener
public class DefaultCounterListener extends java.lang.Object implements CounterListener
TheDefaultCounterListener
is the default implementation of theCounterListener
interface. For any counter incrementation event it checks whether the referenced counter object already exists. If not, it will be created and initialized with one. Otherwise, the current value will be incremented by one. In either case, the current value will be returned in the event object.To use a
DefaultCounterListener
with SNMP4J, add it to the defaultCounterSupport
by:CounterSupport.getInstance().addCounterListener(new DefaultCounterListener());
- Version:
- 2.0
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<OID,Counter32>
counters
private boolean
countRegisteredOnly
-
Constructor Summary
Constructors Constructor Description DefaultCounterListener()
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Counter32
add(OID oid, Counter32 counter)
Adds a counter to this counter listener.void
incrementCounter(CounterEvent event)
Increment the supplied counter instance and return the current value (after incrementation) in the event object if the event receiver is the maintainer of the counter value.boolean
isCountRegisteredOnly()
Counter32
remove(OID oid)
Removes a counter from this listener and returns it.void
setCountRegisteredOnly(boolean countRegisteredOnly)
Sets the flag which indicates how unregistered counter events should be handled.
-
-
-
Method Detail
-
incrementCounter
public void incrementCounter(CounterEvent event)
Description copied from interface:CounterListener
Increment the supplied counter instance and return the current value (after incrementation) in the event object if the event receiver is the maintainer of the counter value.- Specified by:
incrementCounter
in interfaceCounterListener
- Parameters:
event
- aCounterEvent
instance.
-
add
public Counter32 add(OID oid, Counter32 counter)
Adds a counter to this counter listener. If counter events have been received already for the givenoid
the provided counter will be incremented by the number of events already counted and thencounter
replaces the old counter.- Parameters:
oid
- the object identifier of the counter instance (thus including the .0 suffix).counter
- the counter to register.- Returns:
- the counter previously associated with
oid
ornull
if no such counter exist. - Since:
- 2.0
-
remove
public Counter32 remove(OID oid)
Removes a counter from this listener and returns it.- Parameters:
oid
- the object identifier of the counter instance (thus including the .0 suffix).- Returns:
- the counter previously associated with
oid
ornull
if no such counter exist. - Since:
- 2.0
-
isCountRegisteredOnly
public boolean isCountRegisteredOnly()
-
setCountRegisteredOnly
public void setCountRegisteredOnly(boolean countRegisteredOnly)
Sets the flag which indicates how unregistered counter events should be handled.- Parameters:
countRegisteredOnly
- iftrue
counter events for OIDs which have not been added byadd(org.snmp4j.smi.OID, org.snmp4j.smi.Counter32)
will be ignored, otherwise aCounter32
will be registered to count corresponding events.- Since:
- 2.0
-
-