Skip to content
This repository was archived by the owner on Jul 31, 2022. It is now read-only.

Commit d629ac3

Browse files
committed
More documentation
1 parent 2b6a61a commit d629ac3

File tree

2 files changed

+104
-1
lines changed

2 files changed

+104
-1
lines changed

src/main/java/com/kttdevelopment/simplehttpserver/handler/ServerThrottler.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,77 @@ public class ServerThrottler extends ConnectionThrottler {
2121

2222
private final AtomicInteger maxConnections = new AtomicInteger(0);
2323

24+
/**
25+
* Creates a throttler that allows no connections.
26+
*
27+
* @since 03.03.00
28+
* @author Ktt Development
29+
*/
2430
public ServerThrottler(){
2531
countsTowardsLimit = exchange -> true;
2632
}
2733

34+
/**
35+
* Creates a throttler that allows a certain amount of simultaneous connections.
36+
*
37+
* @param maxConnections maximum simultaneous connections
38+
*
39+
* @since 03.03.00
40+
* @author Ktt Development
41+
*/
2842
public ServerThrottler(final int maxConnections){
2943
countsTowardsLimit = exchange -> true;
3044
this.maxConnections.set(maxConnections);
3145
}
3246

47+
/**
48+
* Creates a throttler that allows a certain amount of simultaneous connections and exempt connections.
49+
*
50+
* @param countsTowardsLimit determines which exchanges count towards the connection limit
51+
*
52+
* @since 03.03.00
53+
* @author Ktt Development
54+
*/
3355
public ServerThrottler(final Predicate<HttpExchange> countsTowardsLimit){
3456
this.countsTowardsLimit = countsTowardsLimit;
3557
}
3658

59+
/**
60+
* Creates a throttler that allows a certain amount of simultaneous connections and exempt connections.
61+
*
62+
* @param countsTowardsLimit determines which exchanges count towards the connection limit
63+
* @param maxConnections maximum simultaneous connections
64+
*
65+
* @since 03.03.00
66+
* @author Ktt Development
67+
*/
3768
public ServerThrottler(final Predicate<HttpExchange> countsTowardsLimit, final int maxConnections){
3869
this.countsTowardsLimit = countsTowardsLimit;
3970
this.maxConnections.set(maxConnections);
4071
}
4172

73+
/**
74+
* Returns the maximum allowed connections.
75+
*
76+
* @return maximum allowed connections
77+
*
78+
* @see #setMaxConnections(int)
79+
* @since 03.03.00
80+
* @author Ktt Development
81+
*/
4282
public final int getMaxConnections(){
4383
return maxConnections.get();
4484
}
4585

86+
/**
87+
* Sets the maximum allowed connections. Must be a positive number.
88+
*
89+
* @param maxConnections maximum allowed connections
90+
*
91+
* @see #getMaxConnections()
92+
* @since 03.03.00
93+
* @author Ktt Development
94+
*/
4695
public synchronized final void setMaxConnections(final int maxConnections){
4796
if(maxConnections >= 0)
4897
this.maxConnections.set(maxConnections);

src/main/java/com/kttdevelopment/simplehttpserver/handler/SessionThrottler.java

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import 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

Comments
 (0)