Skip to content

Commit

Permalink
Merge pull request #11 from avarlamov87/feature/termnate_existing_conns
Browse files Browse the repository at this point in the history
terminate existing connections, usually after stop.
  • Loading branch information
mohrezaei authored Jul 23, 2022
2 parents 70f1530 + ec46429 commit 11ef4e9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build/jrpip-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
under the License.
-->
<project name="jrpip-config">
<property name="jrpip.version" value="5.1.2"/>
<property name="jrpip.version" value="5.1.3"/>
<property name="snapshot" value=""/>
</project>
9 changes: 9 additions & 0 deletions dco/avarlamov.dco
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
1) I, Alexandr Varlamov, certify that all work committed with the commit message
"covered by: avarlamov.dco" is my original work and I own the copyright
to this work. I agree to contribute this code under the Apache 2.0 license.

2) I understand and agree all contribution including all personal
information I submit with it is maintained indefinitely and may be
redistributed consistent with the open source license(s) involved.

This certification is effective for all code contributed from 2022-07-23 to 9999-01-01.
26 changes: 26 additions & 0 deletions src/main/java/com/gs/jrpip/server/SocketServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
specific language governing permissions and limitations
under the License.
*/
//Portions copyright Alexandr Varlamov. Licensed under Apache 2.0 license

package com.gs.jrpip.server;

Expand Down Expand Up @@ -73,6 +74,8 @@ public class SocketServer
private SocketServerThread socketServerThread;
private ConcurrentHashMap<String, UserNonces> userNonces = new ConcurrentHashMap<>();

private ConcurrentHashMap<ServerSocketHandler, Object> hanlders = new ConcurrentHashMap();

public SocketServer(SocketServerConfig config)
{
this.config = config;
Expand Down Expand Up @@ -147,6 +150,20 @@ public void stop()
}
}

public void terminateConnections()
{
for (ServerSocketHandler ssh: this.hanlders.keySet())
{
try
{
ssh.socket.close();
} catch (Exception ignore)
{

}
}
}

public synchronized void waitForStartup()
{
while(!listening)
Expand Down Expand Up @@ -237,6 +254,7 @@ public void run()
incoming = serverSocket.accept();
ServerSocketHandler serverSocketHandler = new ServerSocketHandler(incoming);
serverSocketHandler.start();
SocketServer.this.hanlders.put(serverSocketHandler, "1");
}
catch (SocketTimeoutException e)
{
Expand Down Expand Up @@ -343,6 +361,14 @@ public void run()
finally
{
quietlyClose(socket);
try
{
SocketServer.this.hanlders.remove(this);
}
catch (Throwable ignore)
{

}
}
}

Expand Down

0 comments on commit 11ef4e9

Please sign in to comment.