88import java .util .function .Predicate ;
99
1010/**
11- * Limits connections per http session.
11+ * Limits connections per http session. This can be used to limit simultaneous downloads.
1212 *
1313 * @see ThrottledHandler
1414 * @see ServerThrottler
@@ -26,32 +26,86 @@ public class SessionThrottler extends ConnectionThrottler {
2626
2727 private final AtomicInteger maxConnections = new AtomicInteger (0 );
2828
29+ /**
30+ * Creates a throttler that allows no connections.
31+ *
32+ * @param sessionHandler session handler
33+ *
34+ * @see HttpSessionHandler
35+ * @since 03.03.00
36+ * @author Ktt Development
37+ */
2938 public SessionThrottler (final HttpSessionHandler sessionHandler ){
3039 this .sessionHandler = sessionHandler ;
3140 countsTowardsLimit = (exchange ) -> true ;
3241 }
3342
43+ /**
44+ * Creates a throttler that limits the amount of simultaneous connections a user can have.
45+ *
46+ * @param sessionHandler session handler
47+ * @param maxConnections maximum simultaneous connections (per user)
48+ *
49+ * @see HttpSessionHandler
50+ * @since 03.03.00
51+ * @author Ktt Development
52+ */
3453 public SessionThrottler (final HttpSessionHandler sessionHandler , final int maxConnections ){
3554 this .sessionHandler = sessionHandler ;
3655 countsTowardsLimit = (exchange ) -> true ;
3756 this .maxConnections .set (maxConnections );
3857 }
3958
59+ /**
60+ * Creates a throttler that limits the amount of simultaneous connections a user can have and exempt connections.
61+ *
62+ * @param sessionHandler session handler
63+ * @param countsTowardsLimit determines which users are subject to the limit
64+ *
65+ * @see HttpSessionHandler
66+ * @since 03.03.00
67+ * @author Ktt Development
68+ */
4069 public SessionThrottler (final HttpSessionHandler sessionHandler , final Predicate <HttpSession > countsTowardsLimit ){
4170 this .sessionHandler = sessionHandler ;
4271 this .countsTowardsLimit = countsTowardsLimit ;
4372 }
4473
74+ /**
75+ * Creates a throttler that limits the amount of simultaneous connections a user can have and exempt connections.
76+ *
77+ * @param sessionHandler session handler
78+ * @param countsTowardsLimit determines which users are subject to the limit
79+ * @param maxConnections maximum simultaneous connections (per user)
80+ */
4581 public SessionThrottler (final HttpSessionHandler sessionHandler , final Predicate <HttpSession > countsTowardsLimit , final int maxConnections ){
4682 this .sessionHandler = sessionHandler ;
4783 this .countsTowardsLimit = countsTowardsLimit ;
4884 this .maxConnections .set (maxConnections );
4985 }
5086
87+ /**
88+ * Returns the maximum allowed connections.
89+ *
90+ * @return maximum allowed connections (per user)
91+ *
92+ * @see #setMaxConnections(int)
93+ * @since 03.03.00
94+ * @author Ktt Development
95+ */
5196 public final int getMaxConnections (){
5297 return maxConnections .get ();
5398 }
5499
100+ /**
101+ * Sets the maximum allowed connections. Must be a positive number.
102+ *
103+ * @param maxConnections maximum allowed connections (per user)
104+ *
105+ * @see #getMaxConnections()
106+ * @since 03.03.00
107+ * @author Ktt Development
108+ */
55109 public synchronized final void setMaxConnections (final int maxConnections ){
56110 if (maxConnections >= 0 )
57111 this .maxConnections .set (maxConnections );
0 commit comments