1 23 package com.sun.appserv.management.util.jmx; 24 25 import java.util.Map ; 26 import java.util.HashMap ; 27 import java.io.Serializable ; 28 29 import javax.management.Notification ; 30 import javax.management.ObjectName ; 31 32 41 public class NotificationBuilder 42 { 43 private long mSequenceNumber = 0; 44 private final String mNotificationType; 45 private final Object mSource; 46 47 protected synchronized long 48 nextSequenceNumber( ) 49 { 50 return( mSequenceNumber++ ); 51 } 52 53 public 54 NotificationBuilder( 55 final String notificationType, 56 final Object source ) 57 { 58 mNotificationType = notificationType; 59 mSource = source; 60 } 61 62 public final String 63 getNotificationType() 64 { 65 return( mNotificationType ); 66 } 67 68 public final Object 69 getSource() 70 { 71 return( mSource ); 72 } 73 74 75 protected final long 76 now() 77 { 78 return( System.currentTimeMillis() ); 79 } 80 81 84 public Notification 85 buildNewWithMap( 86 final String message, 87 final Map <String ,Serializable > userDataMap ) 88 { 89 final Notification notif = new Notification ( 90 mNotificationType, 91 mSource, 92 nextSequenceNumber(), 93 now(), 94 message); 95 96 if ( userDataMap != null ) 97 { 98 notif.setUserData( userDataMap ); 99 } 100 else 101 { 102 notif.setUserData( new HashMap <String ,Serializable >() ); 103 } 104 105 return( notif ); 106 } 107 108 109 110 114 public Notification 115 buildNew() 116 { 117 return buildNew( mNotificationType ); 118 } 119 120 121 125 public Notification 126 buildNew( final String message ) 127 { 128 return buildNewWithMap( message, null ); 129 } 130 131 153 154 172 173 174 175 176 177 180 public static final void 181 putMapData( 182 final Notification notif, 183 final String keyToInsert, 184 final Serializable valueToInsert ) 185 { 186 final Map <String ,Serializable > userData = 187 JMXUtil.getUserDataMapString_Serializable( notif ); 188 189 userData.put( keyToInsert, valueToInsert ); 190 } 191 192 195 public static final <T extends Serializable > void 196 putAllMapData( 197 final Notification notif, 198 final Map <String ,T> additionalUserData ) 199 { 200 final Map <String ,Serializable > userData = 201 JMXUtil.getUserDataMapString_Serializable( notif ); 202 203 userData.putAll( additionalUserData ); 204 } 205 206 207 } 208 209 210 211 212 213 | Popular Tags |