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

Commit 6417f08

Browse files
committed
bug fixes
1 parent 9484b89 commit 6417f08

File tree

6 files changed

+75
-16
lines changed

6 files changed

+75
-16
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ abstract class ConnectionThrottler {
5555
* @since 03.05.00
5656
* @author Ktt Development
5757
*/
58-
abstract int getMaxConnections(final HttpExchange exchange);
58+
public abstract int getMaxConnections(final HttpExchange exchange);
5959

6060
}

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
*
1414
* @see HttpExchange
1515
* @see ThrottledHandler
16-
* @see ServerThrottler
16+
* @see ServerExchangeThrottler
1717
* @see SessionThrottler
18+
* @see ServerSessionThrottler
1819
* @since 03.05.00
1920
* @version 03.05.00
2021
* @author Ktt Development
@@ -23,6 +24,14 @@ public class ExchangeThrottler extends ConnectionThrottler {
2324

2425
private final Map<InetAddress,AtomicInteger> connections = new ConcurrentHashMap<>();
2526

27+
/**
28+
* Creates a throttler with limits on each exchange.
29+
*
30+
* @since 03.05.00
31+
* @author Ktt Development
32+
*/
33+
public ExchangeThrottler(){ }
34+
2635
@Override
2736
final boolean addConnection(final HttpExchange exchange){
2837
final InetAddress address = exchange.getRemoteAddress().getAddress();
@@ -54,7 +63,7 @@ final void deleteConnection(final HttpExchange exchange){
5463
}
5564

5665
@Override
57-
int getMaxConnections(final HttpExchange exchange){
66+
public int getMaxConnections(final HttpExchange exchange){
5867
return -1;
5968
}
6069

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* @see HttpExchange
1515
* @see ThrottledHandler
1616
* @see ExchangeThrottler
17+
* @see SessionThrottler
18+
* @see ServerSessionThrottler
1719
* @since 03.05.00
1820
* @version 03.05.00
1921
* @author Ktt Development
@@ -23,7 +25,27 @@ public class ServerExchangeThrottler extends ConnectionThrottler {
2325
private final Map<InetAddress, AtomicInteger> connections = new ConcurrentHashMap<>();
2426

2527
private final AtomicInteger uConn = new AtomicInteger(0);
26-
private final AtomicInteger uConnMax = new AtomicInteger(0);
28+
private final AtomicInteger uConnMax = new AtomicInteger(-1);
29+
30+
/**
31+
* Creates a throttler with connection limits on user and total connections.
32+
*
33+
* @since 03.05.00
34+
* @author Ktt Development
35+
*/
36+
public ServerExchangeThrottler(){ }
37+
38+
/**
39+
* Creates a throttler with connection limits on user and total connections.
40+
*
41+
* @param maxConnections maximum allowed server connections
42+
*
43+
* @since 03.05.00
44+
* @author Ktt Development
45+
*/
46+
public ServerExchangeThrottler(final int maxConnections){
47+
uConnMax.set(maxConnections);
48+
}
2749

2850
@Override
2951
final boolean addConnection(final HttpExchange exchange){
@@ -84,7 +106,7 @@ final void deleteConnection(final HttpExchange exchange){
84106
}
85107

86108
@Override
87-
int getMaxConnections(final HttpExchange exchange){
109+
public int getMaxConnections(final HttpExchange exchange){
88110
return -1;
89111
}
90112

@@ -98,7 +120,7 @@ int getMaxConnections(final HttpExchange exchange){
98120
* @since 03.05.00
99121
* @author Ktt Development
100122
*/
101-
boolean canIgnoreConnectionLimit(final HttpExchange exchange){
123+
public boolean canIgnoreConnectionLimit(final HttpExchange exchange){
102124
return false;
103125
}
104126

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

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
* Limits connections per session to the server and total server sessions.
1414
*
1515
* @see HttpSession
16+
* @see HttpSessionHandler
1617
* @see ThrottledHandler
18+
* @see ExchangeThrottler
19+
* @see ServerExchangeThrottler
1720
* @see SessionThrottler
1821
* @since 03.05.00
1922
* @version 03.05.00
@@ -25,12 +28,36 @@ public class ServerSessionThrottler extends ConnectionThrottler{
2528
private final Map<HttpSession,AtomicInteger> connections = new ConcurrentHashMap<>();
2629

2730
private final AtomicInteger uConn = new AtomicInteger(0);
28-
private final AtomicInteger uConnMax = new AtomicInteger(0);
31+
private final AtomicInteger uConnMax = new AtomicInteger(-1);
2932

33+
/**
34+
* Creates a throttler with limits on session and total connections.
35+
*
36+
* @param sessionHandler http session handler
37+
*
38+
* @see HttpSessionHandler
39+
* @since 03.05.00
40+
* @author Ktt Development
41+
*/
3042
public ServerSessionThrottler(final HttpSessionHandler sessionHandler){
3143
this.sessionHandler = sessionHandler;
3244
}
3345

46+
/**
47+
* Creates a throttler with limits on session and total connections.
48+
*
49+
* @param sessionHandler http session handler
50+
* @param maxConnections maximum allowed server connections
51+
*
52+
* @see HttpSessionHandler
53+
* @since 03.05.00
54+
* @author Ktt Development
55+
*/
56+
public ServerSessionThrottler(final HttpSessionHandler sessionHandler, final int maxConnections){
57+
this.sessionHandler = sessionHandler;
58+
uConnMax.set(maxConnections);
59+
}
60+
3461
@Override
3562
final boolean addConnection(final HttpExchange exchange){
3663
final HttpSession session = sessionHandler.getSession(exchange);
@@ -90,7 +117,7 @@ final void deleteConnection(final HttpExchange exchange){
90117
}
91118

92119
@Override
93-
final int getMaxConnections(final HttpExchange exchange){
120+
public final int getMaxConnections(final HttpExchange exchange){
94121
return getMaxConnections(sessionHandler.getSession(exchange),exchange);
95122
}
96123

@@ -104,7 +131,7 @@ final int getMaxConnections(final HttpExchange exchange){
104131
* @since 03.05.00
105132
* @author Ktt Development
106133
*/
107-
int getMaxConnections(final HttpSession session, final HttpExchange exchange){
134+
public int getMaxConnections(final HttpSession session, final HttpExchange exchange){
108135
return -1;
109136
}
110137

@@ -119,7 +146,7 @@ int getMaxConnections(final HttpSession session, final HttpExchange exchange){
119146
* @since 03.05.00
120147
* @author Ktt Development
121148
*/
122-
boolean canIgnoreConnectionLimit(final HttpSession session, final HttpExchange exchange){
149+
public boolean canIgnoreConnectionLimit(final HttpSession session, final HttpExchange exchange){
123150
return false;
124151
}
125152

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ final void deleteConnection(final HttpExchange exchange){
124124
}
125125

126126
@Override
127-
int getMaxConnections(final HttpExchange exchange){
127+
public int getMaxConnections(final HttpExchange exchange){
128128
return getMaxConnections();
129129
}
130130

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
* @see HttpSession
1616
* @see ThrottledHandler
1717
* @see ExchangeThrottler
18-
* @see ServerThrottler
18+
* @see ServerExchangeThrottler
19+
* @see ServerSessionThrottler
1920
* @since 03.03.00
2021
* @version 03.05.00
2122
* @author Ktt Development
@@ -43,7 +44,7 @@ public class SessionThrottler extends ConnectionThrottler {
4344
*/
4445
public SessionThrottler(final HttpSessionHandler sessionHandler){
4546
this.sessionHandler = sessionHandler;
46-
countsTowardsLimit = (exchange) -> true;
47+
countsTowardsLimit = (exchange) -> true; // @depreciated
4748
}
4849

4950
/**
@@ -158,7 +159,7 @@ final void deleteConnection(final HttpExchange exchange){
158159
}
159160

160161
@Override
161-
final int getMaxConnections(final HttpExchange exchange){
162+
public final int getMaxConnections(final HttpExchange exchange){
162163
return getMaxConnections(sessionHandler.getSession(exchange),exchange);
163164
}
164165

@@ -172,7 +173,7 @@ final int getMaxConnections(final HttpExchange exchange){
172173
* @since 03.05.00
173174
* @author Ktt Development
174175
*/
175-
int getMaxConnections(final HttpSession session, final HttpExchange exchange){
176+
public int getMaxConnections(final HttpSession session, final HttpExchange exchange){
176177
return countsTowardsLimit.test(session) ? getMaxConnections() : -1;
177178
}
178179

@@ -186,7 +187,7 @@ public String toString(){
186187
"sessions@depreciated" + '=' + connections.toString() + ", " +
187188
"maxConnections@depreciated" + '=' + maxConnections.get() + ", " +
188189
"sessionHandler" + '=' + sessionHandler + ", " +
189-
"connections" + '=' + connections.toString() + ", " +
190+
"connections" + '=' + connections.toString() +
190191
'}';
191192
}
192193

0 commit comments

Comments
 (0)