Skip to content

Commit

Permalink
Fixes #4023: Correctly recognize running remote server
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasdiez authored and koppor committed Jun 4, 2018
1 parent 9b2fedc commit 6f130bd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/main/java/org/jabref/JabRefMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,19 @@ private static void start(String[] args) {
private static boolean handleMultipleAppInstances(String[] args) {
RemotePreferences remotePreferences = Globals.prefs.getRemotePreferences();
if (remotePreferences.useRemoteServer()) {
Globals.REMOTE_LISTENER.open(new JabRefMessageHandler(), remotePreferences.getPort());

if (!Globals.REMOTE_LISTENER.isOpen()) {
// we are not alone, there is already a server out there, try to contact already running JabRef:
if (new RemoteClient(remotePreferences.getPort()).sendCommandLineArguments(args)) {
// We have successfully sent our command line options through the socket to another JabRef instance.
// Try to contact already running JabRef
RemoteClient remoteClient = new RemoteClient(remotePreferences.getPort());
if (remoteClient.ping()) {
// We are not alone, there is already a server out there, send command line arguments to other instance
if (remoteClient.sendCommandLineArguments(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 {
// We are alone, so we start the server
Globals.REMOTE_LISTENER.openAndStart(new JabRefMessageHandler(), remotePreferences.getPort());
}
// we are alone, we start the server
Globals.REMOTE_LISTENER.start();
}
return true;
}
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/org/jabref/logic/remote/RemoteSetupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,15 @@ void pingReturnsFalseForNoServerListening() throws IOException, InterruptedExcep

assertFalse(new RemoteClient(port).ping());
}

@Test
void pingReturnsTrueWhenServerIsRunning() {
final int port = 34567;

try (RemoteListenerServerLifecycle server = new RemoteListenerServerLifecycle()) {
server.openAndStart(messageHandler, port);

assertTrue(new RemoteClient(port).ping());
}
}
}

0 comments on commit 6f130bd

Please sign in to comment.