Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
JAliEn
JAliEn
Commits
50548f45
Commit
50548f45
authored
May 07, 2021
by
Costin Grigoras
Browse files
Close idle connections, similar to the legacy implementation
parent
d6cb1da2
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/alien/api/DispatchSSLServerNIO.java
View file @
50548f45
...
...
@@ -79,9 +79,13 @@ public class DispatchSSLServerNIO implements Runnable {
/**
* Thread pool handling messages
*/
private
static
ThreadPoolExecutor
executor
=
new
CachedThreadPool
(
200
,
1
,
TimeUnit
.
MINUTES
,
(
r
)
->
new
Thread
(
r
,
"DispatchSSLServerNIO - "
+
threadNo
.
incrementAndGet
())
);
private
static
final
int
executorMaxSize
=
ConfigUtils
.
getConfig
().
geti
(
DispatchSSLServerNIO
.
class
.
getCanonicalName
()
+
".executorMaxSize"
,
100
);
private
static
ThreadPoolExecutor
sslExecutor
=
new
CachedThreadPool
(
32
,
1
,
TimeUnit
.
MINUTES
,
(
r
)
->
new
Thread
(
r
,
"SSLNegociator- "
+
sslThreadNo
.
incrementAndGet
()));
private
static
final
int
sslExecutorMaxSize
=
ConfigUtils
.
getConfig
().
geti
(
DispatchSSLServerNIO
.
class
.
getCanonicalName
()
+
".sslExecutorMaxSize"
,
16
);
private
static
ThreadPoolExecutor
executor
=
new
CachedThreadPool
(
executorMaxSize
,
1
,
TimeUnit
.
MINUTES
,
(
r
)
->
new
Thread
(
r
,
"DispatchSSLServerNIO - "
+
threadNo
.
incrementAndGet
()));
private
static
ThreadPoolExecutor
sslExecutor
=
new
CachedThreadPool
(
sslExecutorMaxSize
,
1
,
TimeUnit
.
MINUTES
,
(
r
)
->
new
Thread
(
r
,
"SSLNegociator- "
+
sslThreadNo
.
incrementAndGet
()));
private
static
final
int
defaultPort
=
8098
;
private
static
String
serviceName
=
"apiService"
;
...
...
@@ -156,6 +160,8 @@ public class DispatchSSLServerNIO implements Runnable {
private
PipedOutputStream
pos
=
null
;
private
PipedInputStream
pis
=
null
;
private
long
lastActive
=
System
.
currentTimeMillis
();
private
class
ByteBufferOutputStream
extends
OutputStream
{
private
ByteBuffer
buffer
=
ByteBuffer
.
allocate
(
1024
);
...
...
@@ -456,6 +462,8 @@ public class DispatchSSLServerNIO implements Runnable {
}
finally
{
isActive
.
set
(
false
);
lastActive
=
System
.
currentTimeMillis
();
}
}
...
...
@@ -670,7 +678,25 @@ public class DispatchSSLServerNIO implements Runnable {
return
;
}
// serverSelector.wakeup();
Thread
.
sleep
(
60000
);
final
long
maxIdleTime
=
ConfigUtils
.
getConfig
().
geti
(
"alien.api.DispatchSSLServer.idleTimeout_seconds"
,
900
)
*
1000L
;
final
long
referenceTime
=
System
.
currentTimeMillis
()
-
maxIdleTime
;
for
(
DispatchSSLServerNIO
instance
:
sessionMap
.
values
())
{
if
(
instance
.
lastActive
<
referenceTime
&&
!
instance
.
isActive
.
get
())
{
try
{
logger
.
log
(
Level
.
WARNING
,
"Closing idle connection: "
+
instance
.
remoteIdentity
.
getName
()
+
"@"
+
instance
.
remoteIdentity
.
getRemoteEndpoint
());
instance
.
cleanup
();
}
catch
(
Throwable
t
)
{
logger
.
log
(
Level
.
WARNING
,
"Exception closing an idle connection"
,
t
);
}
}
}
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment