1
1
/*
2
- * Copyright 2002-2018 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -99,7 +99,7 @@ public class SubProtocolWebSocketHandler
99
99
100
100
private final ReentrantLock sessionCheckLock = new ReentrantLock ();
101
101
102
- private final Stats stats = new Stats ();
102
+ private final DefaultStats stats = new DefaultStats ();
103
103
104
104
private volatile boolean running = false ;
105
105
@@ -253,6 +253,15 @@ public String getStatsInfo() {
253
253
return this .stats .toString ();
254
254
}
255
255
256
+ /**
257
+ * Return a {@link Stats} object that containers various session counters.
258
+ * @since 5.2
259
+ */
260
+ public Stats getStats () {
261
+ return this .stats ;
262
+ }
263
+
264
+
256
265
257
266
@ Override
258
267
public final void start () {
@@ -560,7 +569,28 @@ public String toString() {
560
569
}
561
570
562
571
563
- private class Stats {
572
+ /**
573
+ * Contract for access to session counters.
574
+ * @since 5.2
575
+ */
576
+ public interface Stats {
577
+
578
+ int getTotalSessions ();
579
+
580
+ int getWebSocketSessions ();
581
+
582
+ int getHttpStreamingSessions ();
583
+
584
+ int getHttpPollingSessions ();
585
+
586
+ int getLimitExceededSessions ();
587
+
588
+ int getNoMessagesReceivedSessions ();
589
+
590
+ int getTransportErrorSessions ();
591
+ }
592
+
593
+ private class DefaultStats implements Stats {
564
594
565
595
private final AtomicInteger total = new AtomicInteger ();
566
596
@@ -576,28 +606,64 @@ private class Stats {
576
606
577
607
private final AtomicInteger transportError = new AtomicInteger ();
578
608
579
- public void incrementSessionCount (WebSocketSession session ) {
609
+
610
+ @ Override
611
+ public int getTotalSessions () {
612
+ return this .total .get ();
613
+ }
614
+
615
+ @ Override
616
+ public int getWebSocketSessions () {
617
+ return this .webSocket .get ();
618
+ }
619
+
620
+ @ Override
621
+ public int getHttpStreamingSessions () {
622
+ return this .httpStreaming .get ();
623
+ }
624
+
625
+ @ Override
626
+ public int getHttpPollingSessions () {
627
+ return this .httpPolling .get ();
628
+ }
629
+
630
+ @ Override
631
+ public int getLimitExceededSessions () {
632
+ return this .limitExceeded .get ();
633
+ }
634
+
635
+ @ Override
636
+ public int getNoMessagesReceivedSessions () {
637
+ return this .noMessagesReceived .get ();
638
+ }
639
+
640
+ @ Override
641
+ public int getTransportErrorSessions () {
642
+ return this .transportError .get ();
643
+ }
644
+
645
+ void incrementSessionCount (WebSocketSession session ) {
580
646
getCountFor (session ).incrementAndGet ();
581
647
this .total .incrementAndGet ();
582
648
}
583
649
584
- public void decrementSessionCount (WebSocketSession session ) {
650
+ void decrementSessionCount (WebSocketSession session ) {
585
651
getCountFor (session ).decrementAndGet ();
586
652
}
587
653
588
- public void incrementLimitExceededCount () {
654
+ void incrementLimitExceededCount () {
589
655
this .limitExceeded .incrementAndGet ();
590
656
}
591
657
592
- public void incrementNoMessagesReceivedCount () {
658
+ void incrementNoMessagesReceivedCount () {
593
659
this .noMessagesReceived .incrementAndGet ();
594
660
}
595
661
596
- public void incrementTransportError () {
662
+ void incrementTransportError () {
597
663
this .transportError .incrementAndGet ();
598
664
}
599
665
600
- private AtomicInteger getCountFor (WebSocketSession session ) {
666
+ AtomicInteger getCountFor (WebSocketSession session ) {
601
667
if (session instanceof PollingSockJsSession ) {
602
668
return this .httpPolling ;
603
669
}
0 commit comments