1 23 24 29 30 package com.sun.enterprise.admin.selfmanagement.event; 31 32 import javax.management.ObjectName ; 33 import javax.management.MBeanNotificationInfo ; 34 import com.sun.appserv.management.event.StatisticMonitorNotification; 35 import static com.sun.appserv.management.event.StatisticMonitorNotification.*; 36 import java.util.logging.Logger ; 37 import java.util.logging.Level ; 38 import com.sun.logging.LogDomains; 39 40 64 public class StringStatisticMonitor extends StatisticMonitor implements StringStatisticMonitorMBean { 65 66 protected static Logger _logger = LogDomains.getLogger(LogDomains.SELF_MANAGEMENT_LOGGER); 69 70 75 76 80 private String stringToCompare = ""; 81 82 87 private boolean notifyMatch = false; 88 89 94 private boolean notifyDiffer = false; 95 96 101 private int status[] = new int[capacityIncrement]; 102 103 private static final String [] types = { 104 RUNTIME_ERROR, 105 OBSERVED_OBJECT_ERROR, 106 OBSERVED_ATTRIBUTE_ERROR, 107 OBSERVED_ATTRIBUTE_TYPE_ERROR, 108 STRING_TO_COMPARE_VALUE_MATCHED, 109 STRING_TO_COMPARE_VALUE_DIFFERED 110 }; 111 112 private static final MBeanNotificationInfo [] notifsInfo = { 113 new MBeanNotificationInfo ( 114 types, 115 "com.sun.appserv.management.event.StatisticMonitorNotification", 116 "Notifications sent by the StringStatisticMonitor MBean") 117 }; 118 119 private static final int MATCHING = 0; 122 private static final int DIFFERING = 1; 123 private static final int MATCHING_OR_DIFFERING = 2; 124 125 130 131 134 public StringStatisticMonitor() { 135 } 136 137 142 143 146 public synchronized void start() { 147 for (int i = 0; i < elementCount; i++) { 150 status[i] = MATCHING_OR_DIFFERING; 151 } 152 doStart(); 153 } 154 155 158 public synchronized void stop() { 159 doStop(); 160 } 161 162 165 175 public synchronized String getDerivedGauge(ObjectName object) { 176 return (String ) super.getDerivedGauge(object); 177 } 178 179 191 public synchronized long getDerivedGaugeTimeStamp(ObjectName object) { 192 return super.getDerivedGaugeTimeStamp(object); 193 } 194 195 204 @Deprecated 205 public synchronized String getDerivedGauge() { 206 return (String ) derivedGauge[0]; 207 } 208 209 218 @Deprecated 219 public synchronized long getDerivedGaugeTimeStamp() { 220 return derivedGaugeTimestamp[0]; 221 } 222 223 231 public synchronized String getStringToCompare() { 232 return stringToCompare; 233 } 234 235 246 public synchronized void setStringToCompare(String value) 247 throws IllegalArgumentException { 248 249 if (value == null) { 250 throw new IllegalArgumentException ("Null string to compare"); 251 } 252 253 stringToCompare = value; 254 255 for (int i = 0; i < elementCount; i++) { 258 status[i] = MATCHING_OR_DIFFERING; 259 } 260 } 261 262 271 public synchronized boolean getNotifyMatch() { 272 return notifyMatch; 273 } 274 275 283 public synchronized void setNotifyMatch(boolean value) { 284 notifyMatch = value; 285 } 286 287 296 public synchronized boolean getNotifyDiffer() { 297 return notifyDiffer; 298 } 299 300 308 public synchronized void setNotifyDiffer(boolean value) { 309 notifyDiffer = value; 310 } 311 312 317 public MBeanNotificationInfo [] getNotificationInfo() { 318 return notifsInfo; 319 } 320 321 326 327 331 boolean isComparableTypeValid(ObjectName object, 332 String attribute, 333 Comparable <?> value) { 334 if (value instanceof String ) { 337 return true; 338 } 339 return false; 340 } 341 342 void onErrorNotification(StatisticMonitorNotification notification) { 343 int index = indexOf(notification.getObservedObject()); 344 synchronized(this) { 345 status[index] = MATCHING_OR_DIFFERING; 348 } 349 } 350 351 StatisticMonitorNotification buildAlarmNotification(ObjectName object, 352 String attribute, 353 Comparable <?> value) { 354 String type = null; 355 String msg = null; 356 Object trigger = null; 357 358 int index = indexOf(object); 359 360 synchronized(this) { 361 362 if (status[index] == MATCHING_OR_DIFFERING) { 366 if (derivedGauge[index].equals(stringToCompare)) { 367 if (notifyMatch) { 368 type = STRING_TO_COMPARE_VALUE_MATCHED; 369 msg = ""; 370 trigger = stringToCompare; 371 } 372 status[index] = DIFFERING; 373 } else { 374 if (notifyDiffer) { 375 type = STRING_TO_COMPARE_VALUE_DIFFERED; 376 msg = ""; 377 trigger = stringToCompare; 378 } 379 status[index] = MATCHING; 380 } 381 } else { 382 if (status[index] == MATCHING) { 383 if (derivedGauge[index].equals(stringToCompare)) { 384 if (notifyMatch) { 385 type = STRING_TO_COMPARE_VALUE_MATCHED; 386 msg = ""; 387 trigger = stringToCompare; 388 } 389 status[index] = DIFFERING; 390 } 391 } else if (status[index] == DIFFERING) { 392 if (!derivedGauge[index].equals(stringToCompare)) { 393 if (notifyDiffer) { 394 type = STRING_TO_COMPARE_VALUE_DIFFERED; 395 msg = ""; 396 trigger = stringToCompare; 397 } 398 status[index] = MATCHING; 399 } 400 } 401 } 402 } 403 404 return new StatisticMonitorNotification(type, 405 this, 406 0, 407 0, 408 msg, 409 null, 410 null, 411 null, 412 trigger); 413 } 414 415 420 synchronized void insertSpecificElementAt(int index) { 421 if (elementCount >= status.length) { 424 status = expandArray(status); 425 } 426 status[index] = MATCHING_OR_DIFFERING; 427 } 428 429 434 synchronized void removeSpecificElementAt(int index) { 435 removeElementAt(status, index); 438 } 439 } 440 | Popular Tags |