View Javadoc

1   package net.sf.snmpadaptor4j.object;
2   
3   import java.util.Map;
4   import java.util.Map.Entry;
5   import org.apache.log4j.Logger;
6   
7   /**
8    * Object representing a generic SNMP trap.
9    * @author <a href="http://fr.linkedin.com/in/jpminetti/">Jean-Philippe MINETTI</a>
10   */
11  public final class GenericSnmpTrap
12  		extends SnmpTrap {
13  
14  	/**
15  	 * Serial number.
16  	 */
17  	private static final long serialVersionUID = -6485304599608042063L;
18  
19  	/**
20  	 * Trap type.
21  	 */
22  	private final GenericSnmpTrapType type;
23  
24  	/**
25  	 * Hidden constructor.
26  	 * @param timeStamp Elapsed time in <b>100th of second</b> since the application launch.
27  	 * @param source OID indexing the source of the trap.
28  	 * @param type Trap type.
29  	 * @param dataMap Map of "interesting" information.
30  	 * @see SnmpTrap#newInstance(long, SnmpOid, GenericSnmpTrapType, Map)
31  	 */
32  	protected GenericSnmpTrap (final long timeStamp, final SnmpOid source, final GenericSnmpTrapType type, final Map<SnmpOid, SnmpTrapData> dataMap) {
33  		super(timeStamp, source, dataMap);
34  		this.type = type;
35  	}
36  
37  	/**
38  	 * Returns the trap type.
39  	 * @return Trap type.
40  	 */
41  	public GenericSnmpTrapType getType () {
42  		return this.type;
43  	}
44  
45  	/*
46  	 * {@inheritDoc}
47  	 * @see net.sf.snmpadaptor4j.object.SnmpTrap#traceTo(org.apache.log4j.Logger)
48  	 */
49  	@Override
50  	public void traceTo (final Logger logger) {
51  		logger.trace("enterprise         = " + getSource());
52  		logger.trace("generic-trap       = " + this.type);
53  		logger.trace("specific-trap      = 0");
54  		logger.trace("time-stamp         = " + getTimeStamp());
55  		for (final Entry<SnmpOid, SnmpTrapData> data : getDataMap().entrySet()) {
56  			logger.trace("variable-bindings: " + data.getKey() + " = " + data.getValue());
57  		}
58  	}
59  
60  	/*
61  	 * {@inheritDoc}
62  	 * @see java.lang.Object#hashCode()
63  	 */
64  	@Override
65  	public int hashCode () {
66  		final int prime = 31;
67  		int result = super.hashCode();
68  		result = prime * result + ((this.type == null) ? 0 : this.type.hashCode());
69  		return result;
70  	}
71  
72  	/*
73  	 * {@inheritDoc}
74  	 * @see java.lang.Object#equals(java.lang.Object)
75  	 */
76  	@Override
77  	public boolean equals (final Object obj) {
78  		boolean result = false;
79  		if (obj == this) {
80  			result = true;
81  		}
82  		else {
83  			result = super.equals(obj);
84  			if (result) {
85  				final GenericSnmpTrap other = (GenericSnmpTrap) obj;
86  				result = (this.type == other.type);
87  			}
88  		}
89  		return result;
90  	}
91  
92  	/*
93  	 * {@inheritDoc}
94  	 * @see java.lang.Object#toString()
95  	 */
96  	@Override
97  	public String toString () {
98  		return "SNMP trap " + getSource() + " - Type " + this.type + "/0";
99  	}
100 
101 }