From 46d2c7dc2c0a584168840550808e4b2fc86754c6 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Fri, 15 Mar 2019 09:51:58 +0100 Subject: [PATCH] Improve Remote messaging (#4760) Fixes #4023 and should fix #4481. --- src/main/java/org/jabref/JabRefMain.java | 2 ++ .../java/org/jabref/gui/remote/JabRefMessageHandler.java | 4 ---- .../java/org/jabref/logic/remote/client/RemoteClient.java | 8 +++++--- .../jabref/logic/remote/server/RemoteListenerServer.java | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/jabref/JabRefMain.java b/src/main/java/org/jabref/JabRefMain.java index 249c97f8251..66e624a002d 100644 --- a/src/main/java/org/jabref/JabRefMain.java +++ b/src/main/java/org/jabref/JabRefMain.java @@ -141,6 +141,8 @@ private static boolean handleMultipleAppInstances(String[] args) { // So we assume it's all taken care of, and quit. LOGGER.info(Localization.lang("Arguments passed on to running JabRef instance. Shutting down.")); return false; + } else { + LOGGER.warn("Could not communicate with other running JabRef instance."); } } else { // We are alone, so we start the server diff --git a/src/main/java/org/jabref/gui/remote/JabRefMessageHandler.java b/src/main/java/org/jabref/gui/remote/JabRefMessageHandler.java index 8033c9343d9..9ddc9d5d96e 100644 --- a/src/main/java/org/jabref/gui/remote/JabRefMessageHandler.java +++ b/src/main/java/org/jabref/gui/remote/JabRefMessageHandler.java @@ -1,6 +1,5 @@ package org.jabref.gui.remote; -import java.util.Arrays; import java.util.List; import javafx.application.Platform; @@ -15,9 +14,6 @@ public class JabRefMessageHandler implements MessageHandler { @Override public void handleCommandLineArguments(String[] message) { ArgumentProcessor argumentProcessor = new ArgumentProcessor(message, ArgumentProcessor.Mode.REMOTE_START); - if (!(argumentProcessor.hasParserResults())) { - throw new IllegalStateException("Could not start JabRef with arguments " + Arrays.toString(message)); - } List loaded = argumentProcessor.getParserResults(); for (int i = 0; i < loaded.size(); i++) { diff --git a/src/main/java/org/jabref/logic/remote/client/RemoteClient.java b/src/main/java/org/jabref/logic/remote/client/RemoteClient.java index 5fc416da214..6942a902522 100644 --- a/src/main/java/org/jabref/logic/remote/client/RemoteClient.java +++ b/src/main/java/org/jabref/logic/remote/client/RemoteClient.java @@ -1,6 +1,7 @@ package org.jabref.logic.remote.client; import java.io.IOException; +import java.net.InetSocketAddress; import java.net.Socket; import javafx.util.Pair; @@ -17,8 +18,8 @@ public class RemoteClient { private static final Logger LOGGER = LoggerFactory.getLogger(RemoteClient.class); - private static final int TIMEOUT = 2000; - private int port; + private static final int TIMEOUT = 200; + private final int port; public RemoteClient(int port) { this.port = port; @@ -61,8 +62,9 @@ public boolean sendCommandLineArguments(String[] args) { } private Protocol openNewConnection() throws IOException { - Socket socket = new Socket(RemotePreferences.getIpAddress(), port); + Socket socket = new Socket(); socket.setSoTimeout(TIMEOUT); + socket.connect(new InetSocketAddress(RemotePreferences.getIpAddress(), port), TIMEOUT); return new Protocol(socket); } } diff --git a/src/main/java/org/jabref/logic/remote/server/RemoteListenerServer.java b/src/main/java/org/jabref/logic/remote/server/RemoteListenerServer.java index d87fa2d5b33..b0a4c6ebc29 100644 --- a/src/main/java/org/jabref/logic/remote/server/RemoteListenerServer.java +++ b/src/main/java/org/jabref/logic/remote/server/RemoteListenerServer.java @@ -19,7 +19,7 @@ public class RemoteListenerServer implements Runnable { private static final int BACKLOG = 1; - private static final int ONE_SECOND_TIMEOUT = 1000; + private static final int TIMEOUT = 1000; private final MessageHandler messageHandler; private final ServerSocket serverSocket; @@ -35,7 +35,7 @@ public void run() { try { while (!Thread.interrupted()) { try (Socket socket = serverSocket.accept()) { - socket.setSoTimeout(ONE_SECOND_TIMEOUT); + socket.setSoTimeout(TIMEOUT); try (Protocol protocol = new Protocol(socket)) { Pair input = protocol.receiveMessage();