1 23 24 31 package com.sun.enterprise.admin.event; 32 33 import java.util.List ; 34 import java.util.ArrayList ; 35 import java.util.Iterator ; 36 import javax.management.Notification ; 37 import com.sun.enterprise.config.ConfigChange; 38 import com.sun.enterprise.config.ConfigContext; 39 40 import com.sun.enterprise.util.i18n.StringManager; 42 43 47 public class AdminEvent extends Notification implements Cloneable { 48 49 private EventKey eKey = null; 50 51 private static long eventCounter = 0; 52 53 54 private String targetDest; 55 56 61 private String effectiveDest; 62 63 67 private int hops = 0; 68 69 70 private static final int MAX_HOPS = 3; 71 72 77 static final String eventType = AdminEvent.class.getName(); 78 79 84 transient private ConfigContext configContext; 85 86 90 transient private ConfigContext oldConfigContext; 91 92 private static StringManager localStrings = 94 StringManager.getManager( AdminEvent.class ); 95 96 99 ArrayList configChangeList; 100 101 104 List dependentChangeList; 105 106 110 public AdminEvent(String instanceName) { 111 this(eventType, instanceName); 112 } 113 114 119 public AdminEvent(String eventType, String instanceName) { 120 super(eventType, instanceName, ++eventCounter, 121 System.currentTimeMillis()); 122 } 123 124 protected AdminEvent(String type, Object source, 125 long seqNumber, long time) { 126 super(type, source, seqNumber, time); 127 } 128 129 136 public Object getSource() { 137 return super.getSource(); 138 } 139 140 147 public String getInstanceName() { 148 return (String )getSource(); 149 } 150 151 157 void setContext(ConfigContext ctx) { 158 configContext = ctx; 159 } 160 161 166 void setOldContext(ConfigContext ctx) { 167 oldConfigContext = ctx; 168 } 169 170 180 public ConfigContext getConfigContext() { 181 return configContext; 182 } 183 184 193 public ConfigContext getOldConfigContext() { 194 return oldConfigContext; 195 } 196 197 200 public String toString() { 201 int numChg = (configChangeList == null) ? 0 : configChangeList.size(); 202 return this.getClass().getName() + " -- " + this.getInstanceName() 203 + " [" + numChg + " Change(s), Id:" + this.getSequenceNumber() 204 + ", ts:" + this.getTimeStamp() + "]"; 205 } 206 207 214 public String getEventInfo() { 215 return toString() + getConfigChangeInfo(); 216 } 217 218 223 public String getConfigChangeInfo() { 224 StringBuffer buf = new StringBuffer (); 225 if (configChangeList != null) { 226 Iterator iter = configChangeList.iterator(); 227 while (iter.hasNext()) { 228 ConfigChange change = (ConfigChange)iter.next(); 229 buf.append(change.toString()); 230 } 231 } 232 return buf.toString(); 233 } 234 235 239 synchronized void addConfigChange(ConfigChange change) { 240 assertNotNull(change); 241 if (configChangeList == null) { 242 configChangeList = new ArrayList (); 243 } 244 configChangeList.add(change); 245 } 246 247 251 public synchronized void addConfigChange(ArrayList changeList) { 252 if (changeList == null) { 253 String msg = localStrings.getString( "admin.event.null_configchangelist" ); 254 throw new IllegalArgumentException ( msg ); 255 } 256 if (configChangeList == null) { 257 configChangeList = new ArrayList (); 258 } 259 configChangeList.addAll(changeList); 260 } 261 262 public synchronized void addDependentConfigChange(List list) { 263 if (list == null) { 264 String msg = localStrings.getString( "admin.event.null_configchangelist" ); 265 throw new IllegalArgumentException ( msg ); 266 } 267 268 if (dependentChangeList == null) { 269 dependentChangeList = new ArrayList (); 270 } 271 dependentChangeList.addAll(list); 272 } 273 274 public List getDependentChangeList() { 275 return dependentChangeList; 276 } 277 278 public ArrayList getConfigChangeList() { 279 return configChangeList; 280 } 281 282 286 synchronized void removeConfigChange(ConfigChange change) { 287 assertNotNull(change); 288 if (configChangeList != null) { 289 int ndx = configChangeList.indexOf(change); 290 if (ndx != -1) { 291 configChangeList.remove(ndx); 292 } 293 } 294 } 295 296 302 boolean isNoOp() { 303 return false; 304 } 305 306 310 private void assertNotNull(ConfigChange change) { 312 if (change == null) { 313 String msg = localStrings.getString( "admin.event.null_configchange" ); 314 throw new IllegalArgumentException ( msg ); 315 } 316 } 317 318 325 public String getTargetDestination() { 326 return targetDest; 327 } 328 329 334 public void setTargetDestination(String tarDest) { 335 targetDest = tarDest; 336 } 337 338 343 public String getEffectiveDestination() { 344 return effectiveDest; 345 } 346 347 352 public void setEffectiveDestination(String eDest) { 353 effectiveDest = eDest; 354 } 355 356 359 public void setEventId(EventKey ek) { 360 eKey = ek; 361 } 362 363 366 public EventKey getEventId() { 367 return eKey; 368 } 369 370 375 public Object clone() throws CloneNotSupportedException { 376 return super.clone(); 377 } 378 379 385 public int getHopCount() { 386 return hops; 387 } 388 389 394 public int incrementHopCount() { 395 return ++hops; 396 } 397 398 405 public boolean isValidHopCount() { 406 return (hops <= MAX_HOPS) ? true : false; 407 } 408 409 412 415 public int getActionType() { 416 return 0; 417 } 418 419 422 private void setAction(int action) { 423 return; 424 } 425 426 } 427 | Popular Tags |