Skip to content

Commit

Permalink
Server: Extract isStopped check to method
Browse files Browse the repository at this point in the history
  • Loading branch information
alvasw committed Feb 11, 2023
1 parent 3cd24d6 commit 2127e07
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions p2p/src/main/java/bisq/network/p2p/network/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ public void start() {
public void run() {
try {
try {
while (!isStopped.get() && !Thread.currentThread().isInterrupted()) {
while (isServerActive()) {
log.debug("Ready to accept new clients on port " + localPort);
final Socket socket = serverSocket.accept();

if (!isStopped.get() && !Thread.currentThread().isInterrupted()) {
if (isServerActive()) {
log.debug("Accepted new client on localPort/port " + socket.getLocalPort() + "/" + socket.getPort());
InboundConnection connection = new InboundConnection(socket,
messageListener,
Expand All @@ -90,7 +90,7 @@ public void run() {
+ "\nconnection.uid={}", serverSocket.getLocalPort(), socket.getPort(), connection.getUid()
+ "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");

if (!isStopped.get())
if (isServerActive())
connections.add(connection);
else
connection.shutDown(CloseConnectionReason.APP_SHUT_DOWN);
Expand Down Expand Up @@ -130,4 +130,8 @@ public void shutDown() {
log.warn("stopped already called ast shutdown");
}
}

private boolean isServerActive() {
return !isStopped.get() && !Thread.currentThread().isInterrupted();
}
}

0 comments on commit 2127e07

Please sign in to comment.