1 20 package org.jboss.jmx.adaptor.snmp.agent; 21 22 import java.util.Date ; 23 import java.util.HashMap ; 24 import java.util.Map ; 25 26 import javax.management.Notification ; 27 28 37 public class NotificationWrapperSupport 38 implements NotificationWrapper 39 { 40 41 protected Map payload = new HashMap (); 42 43 44 protected Clock clock; 45 46 47 protected Counter trapCount; 48 49 52 public NotificationWrapperSupport() 53 { 54 } 56 57 61 public void set(Clock uptime, Counter count) 62 { 63 this.clock = uptime; 64 this.trapCount = count; 65 66 this.payload.put(STARTTIME_TAG, 67 new Date (this.clock.instantiationTime())); 68 69 this.payload.put(UPTIME_TAG, new DynamicContentAccessor() { 71 public Object get() 72 { 73 return new Long (NotificationWrapperSupport.this.clock.uptime()); 74 } 75 }); 76 77 this.payload.put(TRAPCOUNT_TAG, new DynamicContentAccessor() { 79 public Object get() 80 { 81 return new Long (NotificationWrapperSupport.this.trapCount.peek()); 82 } 83 }); 84 } 85 86 94 public void prime(Notification n) 95 { 96 this.payload.put(MESSAGE_TAG, n.getMessage()); 98 this.payload.put(SEQNO_TAG, new Long (n.getSequenceNumber())); 99 this.payload.put(TSTAMP_TAG, new Long (n.getTimeStamp())); 100 this.payload.put(TYPE_TAG, n.getType()); 101 this.payload.put(ALL_TAG, n.toString()); 102 this.payload.put(CLASS_TAG, n.getClass().getName()); 103 104 Object userData = n.getUserData(); 109 if (userData instanceof HashMap ) { 110 this.payload.putAll((HashMap )userData); 112 } 113 } 115 123 public Object get(String tagName) 124 throws MappingFailedException 125 { 126 Object o = this.payload.get(tagName); 127 128 if (o == null) 129 throw new MappingFailedException("Tag \"" + tagName + "\" not found"); 130 131 if (o instanceof DynamicContentAccessor) { 134 DynamicContentAccessor d = (DynamicContentAccessor)o; 135 136 return d.get(); 137 } 138 else { 139 return o; 140 } 141 } 143 } | Popular Tags |