1 23 package com.sun.enterprise.web.stats; 24 25 import java.util.LinkedList ; 26 import javax.management.j2ee.statistics.Statistic ; 27 import javax.management.j2ee.statistics.CountStatistic ; 28 import com.sun.logging.LogDomains; 29 import com.sun.enterprise.admin.monitor.stats.PWCRequestStats; 30 import com.sun.enterprise.admin.monitor.stats.MutableCountStatistic; 31 import com.sun.enterprise.admin.monitor.stats.MutableCountStatisticImpl; 32 import com.sun.enterprise.admin.monitor.stats.GenericStatsImpl; 33 import com.sun.enterprise.admin.monitor.stats.CountStatisticImpl; 34 import com.sun.enterprise.admin.monitor.stats.StringStatistic; 35 import com.sun.enterprise.admin.monitor.stats.StringStatisticImpl; 36 37 42 public class PWCRequestStatsImpl implements PWCRequestStats { 43 44 private GenericStatsImpl baseStatsImpl; 45 46 private long startTime; 47 48 52 private LinkedList <HTTPListenerStatsImpl> httpListenerStats; 53 54 private StringStatistic lastMethod; 55 private StringStatistic lastUri; 56 private MutableCountStatistic countRequests; 57 private MutableCountStatistic countBytesReceived; 58 private MutableCountStatistic countBytesTransmitted; 59 private MutableCountStatistic rateBytesTransmitted; 60 private MutableCountStatistic maxByteTransmissionRate; 61 private MutableCountStatistic countOpenConnections; 62 private MutableCountStatistic maxOpenConnections; 63 private MutableCountStatistic count2xx; 64 private MutableCountStatistic count3xx; 65 private MutableCountStatistic count4xx; 66 private MutableCountStatistic count5xx; 67 private MutableCountStatistic countOther; 68 private MutableCountStatistic count200; 69 private MutableCountStatistic count302; 70 private MutableCountStatistic count304; 71 private MutableCountStatistic count400; 72 private MutableCountStatistic count401; 73 private MutableCountStatistic count403; 74 private MutableCountStatistic count404; 75 private MutableCountStatistic count503; 76 77 78 83 public PWCRequestStatsImpl(String domain) { 84 85 httpListenerStats = new LinkedList (); 86 87 baseStatsImpl = new GenericStatsImpl( 88 com.sun.enterprise.admin.monitor.stats.PWCRequestStats.class, 89 this); 90 91 initializeStatistics(); 93 } 94 95 103 public void addHttpListenerStats(HTTPListenerStatsImpl stats) { 104 httpListenerStats.add(stats); 105 } 106 107 112 public StringStatistic getMethod() { 113 114 String lastMethod = "unknown"; 115 long lastRequestTime = 0; 116 117 int size = httpListenerStats.size(); 118 for (int i=0; i<size; i++) { 119 HTTPListenerStatsImpl listener = httpListenerStats.get(i); 120 if (listener.getLastRequestCompletionTime() > lastRequestTime) { 121 lastRequestTime = listener.getLastRequestCompletionTime(); 122 lastMethod = listener.getLastRequestMethod(); 123 } 124 } 125 126 return new StringStatisticImpl( 127 lastMethod, 128 "method", 129 "String", 130 "Method of the last request serviced", 131 startTime, 132 System.currentTimeMillis()); 133 } 134 135 140 public StringStatistic getUri() { 141 142 String lastURI = "unknown"; 143 long lastRequestTime = 0; 144 145 int size = httpListenerStats.size(); 146 for (int i=0; i<size; i++) { 147 HTTPListenerStatsImpl listener = httpListenerStats.get(i); 148 if (listener.getLastRequestCompletionTime() > lastRequestTime) { 149 lastRequestTime = listener.getLastRequestCompletionTime(); 150 lastURI = listener.getLastRequestURI(); 151 } 152 } 153 154 return new StringStatisticImpl( 155 lastURI, 156 "uri", 157 "String", 158 "URI of the last request serviced", 159 startTime, 160 System.currentTimeMillis()); 161 } 162 163 168 public CountStatistic getCountRequests() { 169 170 long count = 0; 171 int size = httpListenerStats.size(); 172 for (int i=0; i<size; i++) { 173 count += httpListenerStats.get(i).getRequestCountLong(); 174 } 175 176 countRequests.setCount(count); 177 return (CountStatistic )countRequests.unmodifiableView(); 178 } 179 180 186 public CountStatistic getCountBytesReceived() { 187 188 long count = 0; 189 int size = httpListenerStats.size(); 190 for (int i=0; i<size; i++) { 191 count += httpListenerStats.get(i).getBytesReceivedLong(); 192 } 193 194 countBytesReceived.setCount(count); 195 return (CountStatistic )countBytesReceived.unmodifiableView(); 196 } 197 198 204 public CountStatistic getCountBytesTransmitted() { 205 206 long count = 0; 207 int size = httpListenerStats.size(); 208 for (int i=0; i<size; i++) { 209 count += httpListenerStats.get(i).getBytesSentLong(); 210 } 211 212 countBytesTransmitted.setCount(count); 213 return (CountStatistic )countBytesTransmitted.unmodifiableView(); 214 } 215 216 224 public CountStatistic getRateBytesTransmitted() { 225 rateBytesTransmitted.setCount(0); 226 return (CountStatistic )rateBytesTransmitted.unmodifiableView(); 227 } 228 229 236 public CountStatistic getMaxByteTransmissionRate() { 237 maxByteTransmissionRate.setCount(0); 238 return (CountStatistic )maxByteTransmissionRate.unmodifiableView(); 239 } 240 241 247 public CountStatistic getCountOpenConnections() { 248 249 long count = 0; 250 int size = httpListenerStats.size(); 251 for (int i=0; i<size; i++) { 252 count += httpListenerStats.get(i).getCountOpenConnectionsLong(); 253 } 254 255 countOpenConnections.setCount(count); 256 return (CountStatistic )countOpenConnections.unmodifiableView(); 257 } 258 259 265 public CountStatistic getMaxOpenConnections() { 266 267 long count = 0; 268 int size = httpListenerStats.size(); 269 for (int i=0; i<size; i++) { 270 count += httpListenerStats.get(i).getMaxOpenConnectionsLong(); 271 } 272 273 maxOpenConnections.setCount(count); 274 return (CountStatistic )maxOpenConnections.unmodifiableView(); 275 } 276 277 282 public CountStatistic getCount2xx() { 283 284 long count = 0; 285 int size = httpListenerStats.size(); 286 for (int i=0; i<size; i++) { 287 count += httpListenerStats.get(i).getCount2xxLong(); 288 } 289 290 count2xx.setCount(count); 291 return (CountStatistic )count2xx.unmodifiableView(); 292 } 293 294 299 public CountStatistic getCount3xx() { 300 301 long count = 0; 302 int size = httpListenerStats.size(); 303 for (int i=0; i<size; i++) { 304 count += httpListenerStats.get(i).getCount3xxLong(); 305 } 306 307 count3xx.setCount(count); 308 return (CountStatistic )count3xx.unmodifiableView(); 309 } 310 311 316 public CountStatistic getCount4xx() { 317 318 long count = 0; 319 int size = httpListenerStats.size(); 320 for (int i=0; i<size; i++) { 321 count += httpListenerStats.get(i).getCount4xxLong(); 322 } 323 324 count4xx.setCount(count); 325 return (CountStatistic )count4xx.unmodifiableView(); 326 } 327 328 333 public CountStatistic getCount5xx() { 334 335 long count = 0; 336 int size = httpListenerStats.size(); 337 for (int i=0; i<size; i++) { 338 count += httpListenerStats.get(i).getCount5xxLong(); 339 } 340 341 count5xx.setCount(count); 342 return (CountStatistic )count5xx.unmodifiableView(); 343 } 344 345 352 public CountStatistic getCountOther() { 353 354 long count = 0; 355 int size = httpListenerStats.size(); 356 for (int i=0; i<size; i++) { 357 count += httpListenerStats.get(i).getCountOtherLong(); 358 } 359 360 countOther.setCount(count); 361 return (CountStatistic )countOther.unmodifiableView(); 362 } 363 364 369 public CountStatistic getCount200() { 370 371 long count = 0; 372 int size = httpListenerStats.size(); 373 for (int i=0; i<size; i++) { 374 count += httpListenerStats.get(i).getCount200Long(); 375 } 376 377 count200.setCount(count); 378 return (CountStatistic )count200.unmodifiableView(); 379 } 380 381 386 public CountStatistic getCount302() { 387 388 long count = 0; 389 int size = httpListenerStats.size(); 390 for (int i=0; i<size; i++) { 391 count += httpListenerStats.get(i).getCount302Long(); 392 } 393 394 count302.setCount(count); 395 return (CountStatistic )count302.unmodifiableView(); 396 } 397 398 403 public CountStatistic getCount304() { 404 405 long count = 0; 406 int size = httpListenerStats.size(); 407 for (int i=0; i<size; i++) { 408 count += httpListenerStats.get(i).getCount304Long(); 409 } 410 411 count304.setCount(count); 412 return (CountStatistic )count304.unmodifiableView(); 413 } 414 415 420 public CountStatistic getCount400() { 421 422 long count = 0; 423 int size = httpListenerStats.size(); 424 for (int i=0; i<size; i++) { 425 count += httpListenerStats.get(i).getCount400Long(); 426 } 427 428 count400.setCount(count); 429 return (CountStatistic )count400.unmodifiableView(); 430 } 431 432 437 public CountStatistic getCount401() { 438 439 long count = 0; 440 int size = httpListenerStats.size(); 441 for (int i=0; i<size; i++) { 442 count += httpListenerStats.get(i).getCount401Long(); 443 } 444 445 count401.setCount(count); 446 return (CountStatistic )count401.unmodifiableView(); 447 } 448 449 454 public CountStatistic getCount403() { 455 456 long count = 0; 457 int size = httpListenerStats.size(); 458 for (int i=0; i<size; i++) { 459 count += httpListenerStats.get(i).getCount403Long(); 460 } 461 462 count403.setCount(count); 463 return (CountStatistic )count403.unmodifiableView(); 464 } 465 466 471 public CountStatistic getCount404() { 472 473 long count = 0; 474 int size = httpListenerStats.size(); 475 for (int i=0; i<size; i++) { 476 count += httpListenerStats.get(i).getCount404Long(); 477 } 478 479 count404.setCount(count); 480 return (CountStatistic )count404.unmodifiableView(); 481 } 482 483 488 public CountStatistic getCount503() { 489 490 long count = 0; 491 int size = httpListenerStats.size(); 492 for (int i=0; i<size; i++) { 493 count += httpListenerStats.get(i).getCount503Long(); 494 } 495 496 count503.setCount(count); 497 return (CountStatistic )count503.unmodifiableView(); 498 } 499 500 505 public Statistic [] getStatistics() { 506 return baseStatsImpl.getStatistics(); 507 } 508 509 516 public Statistic getStatistic(String name) { 517 return baseStatsImpl.getStatistic(name); 518 } 519 520 526 public String [] getStatisticNames() { 527 return baseStatsImpl.getStatisticNames(); 528 } 529 530 531 private void initializeStatistics() { 532 533 startTime = System.currentTimeMillis(); 534 535 CountStatistic c = new CountStatisticImpl("CountRequests"); 536 countRequests = new MutableCountStatisticImpl(c); 537 538 c = new CountStatisticImpl("CountBytesReceived"); 539 countBytesReceived = new MutableCountStatisticImpl(c); 540 541 c = new CountStatisticImpl("CountBytesTransmitted"); 542 countBytesTransmitted = new MutableCountStatisticImpl(c); 543 544 c = new CountStatisticImpl("RateBytesTransmitted"); 545 rateBytesTransmitted = new MutableCountStatisticImpl(c); 546 547 c = new CountStatisticImpl("MaxByteTransmissionRate"); 548 maxByteTransmissionRate = new MutableCountStatisticImpl(c); 549 550 c = new CountStatisticImpl("CountOpenConnections"); 551 countOpenConnections = new MutableCountStatisticImpl(c); 552 553 c = new CountStatisticImpl("MaxOpenConnections"); 554 maxOpenConnections = new MutableCountStatisticImpl(c); 555 556 c = new CountStatisticImpl("Count2xx"); 557 count2xx = new MutableCountStatisticImpl(c); 558 559 c = new CountStatisticImpl("Count3xx"); 560 count3xx = new MutableCountStatisticImpl(c); 561 562 c = new CountStatisticImpl("Count4xx"); 563 count4xx = new MutableCountStatisticImpl(c); 564 565 c = new CountStatisticImpl("Count5xx"); 566 count5xx = new MutableCountStatisticImpl(c); 567 568 c = new CountStatisticImpl("CountOther"); 569 countOther = new MutableCountStatisticImpl(c); 570 571 c = new CountStatisticImpl("Count200"); 572 count200 = new MutableCountStatisticImpl(c); 573 574 c = new CountStatisticImpl("Count302"); 575 count302 = new MutableCountStatisticImpl(c); 576 577 c = new CountStatisticImpl("Count304"); 578 count304 = new MutableCountStatisticImpl(c); 579 580 c = new CountStatisticImpl("Count400"); 581 count400 = new MutableCountStatisticImpl(c); 582 583 c = new CountStatisticImpl("Count401"); 584 count401 = new MutableCountStatisticImpl(c); 585 586 c = new CountStatisticImpl("Count403"); 587 count403 = new MutableCountStatisticImpl(c); 588 589 c = new CountStatisticImpl("Count404"); 590 count404 = new MutableCountStatisticImpl(c); 591 592 c = new CountStatisticImpl("Count503"); 593 count503 = new MutableCountStatisticImpl(c); 594 } 595 596 } 597 | Popular Tags |