8
8
import java .util .function .Predicate ;
9
9
10
10
/**
11
- * Limits connections per http session.
11
+ * Limits connections per http session. This can be used to limit simultaneous downloads.
12
12
*
13
13
* @see ThrottledHandler
14
14
* @see ServerThrottler
@@ -26,32 +26,86 @@ public class SessionThrottler extends ConnectionThrottler {
26
26
27
27
private final AtomicInteger maxConnections = new AtomicInteger (0 );
28
28
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
+ */
29
38
public SessionThrottler (final HttpSessionHandler sessionHandler ){
30
39
this .sessionHandler = sessionHandler ;
31
40
countsTowardsLimit = (exchange ) -> true ;
32
41
}
33
42
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
+ */
34
53
public SessionThrottler (final HttpSessionHandler sessionHandler , final int maxConnections ){
35
54
this .sessionHandler = sessionHandler ;
36
55
countsTowardsLimit = (exchange ) -> true ;
37
56
this .maxConnections .set (maxConnections );
38
57
}
39
58
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
+ */
40
69
public SessionThrottler (final HttpSessionHandler sessionHandler , final Predicate <HttpSession > countsTowardsLimit ){
41
70
this .sessionHandler = sessionHandler ;
42
71
this .countsTowardsLimit = countsTowardsLimit ;
43
72
}
44
73
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
+ */
45
81
public SessionThrottler (final HttpSessionHandler sessionHandler , final Predicate <HttpSession > countsTowardsLimit , final int maxConnections ){
46
82
this .sessionHandler = sessionHandler ;
47
83
this .countsTowardsLimit = countsTowardsLimit ;
48
84
this .maxConnections .set (maxConnections );
49
85
}
50
86
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
+ */
51
96
public final int getMaxConnections (){
52
97
return maxConnections .get ();
53
98
}
54
99
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
+ */
55
109
public synchronized final void setMaxConnections (final int maxConnections ){
56
110
if (maxConnections >= 0 )
57
111
this .maxConnections .set (maxConnections );
0 commit comments