Skip to content

Commit

Permalink
Rename "Remote" to "Tele" (#9270)
Browse files Browse the repository at this point in the history
* Rename "Remote" to "Tele"

* more renames

* fix style

* Revert renaming from Remote to Tele

* further renamings revert

* checkstyle

Co-authored-by: Siedlerchr <siedlerkiller@gmail.com>
  • Loading branch information
tobiasdiez and Siedlerchr authored Nov 5, 2022
1 parent 141c3e9 commit de57f7f
Show file tree
Hide file tree
Showing 17 changed files with 155 additions and 173 deletions.
5 changes: 0 additions & 5 deletions src/main/java/org/jabref/cli/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import org.jabref.gui.Globals;
import org.jabref.gui.MainApplication;
import org.jabref.gui.remote.JabRefMessageHandler;
import org.jabref.logic.exporter.ExporterFactory;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.l10n.Localization;
Expand Down Expand Up @@ -134,10 +133,6 @@ private static boolean handleMultipleAppInstances(String[] args, PreferencesServ
} else {
LOGGER.warn("Could not communicate with other running JabRef instance.");
}
} else {
// We are alone, so we start the server
Globals.REMOTE_LISTENER.openAndStart(new JabRefMessageHandler(), remotePreferences.getPort(),
preferences);
}
}
return true;
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/org/jabref/gui/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.jabref.architecture.AllowedToUseAwt;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.remote.CLIMessageHandler;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.undo.CountingUndoManager;
import org.jabref.gui.util.DefaultFileUpdateMonitor;
Expand All @@ -16,7 +17,8 @@
import org.jabref.logic.importer.ImportFormatReader;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.protectedterms.ProtectedTermsLoader;
import org.jabref.logic.remote.server.RemoteListenerServerLifecycle;
import org.jabref.logic.remote.RemotePreferences;
import org.jabref.logic.remote.server.RemoteListenerServerManager;
import org.jabref.logic.util.BuildInfo;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.strings.StringUtil;
Expand All @@ -41,9 +43,7 @@ public class Globals {
*/
public static final BuildInfo BUILD_INFO = new BuildInfo();

// Remote listener
public static final RemoteListenerServerLifecycle REMOTE_LISTENER = new RemoteListenerServerLifecycle();

public static final RemoteListenerServerManager REMOTE_LISTENER = new RemoteListenerServerManager();
/**
* Manager for the state of the GUI.
*/
Expand Down Expand Up @@ -118,6 +118,10 @@ public static void startBackgroundTasks() {
/* if (Globals.prefs.getTelemetryPreferences().shouldCollectTelemetry() && !GraphicsEnvironment.isHeadless()) {
startTelemetryClient();
} */
RemotePreferences remotePreferences = prefs.getRemotePreferences();
if (remotePreferences.useRemoteServer()) {
Globals.REMOTE_LISTENER.openAndStart(new CLIMessageHandler(prefs), remotePreferences.getPort());
}
}

private static void stopTelemetryClient() {
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/jabref/gui/JabRefExecutorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ public void executeInterruptableTaskAndWait(Runnable runnable) {
}
}

public void manageRemoteThread(Thread thread) {
public void startRemoteThread(Thread thread) {
if (this.remoteThread != null) {
throw new IllegalStateException("Remote thread is already attached");
throw new IllegalStateException("Tele thread is already attached");
} else {
this.remoteThread = thread;
remoteThread.start();
Expand All @@ -141,7 +141,6 @@ public void submit(TimerTask timerTask, long millisecondsDelay) {
* Shuts everything down. After termination, this method returns.
*/
public void shutdownEverything() {
// kill the remote thread
stopRemoteThread();

gracefullyShutdown(this.executorService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.jabref.gui.DialogService;
import org.jabref.gui.Globals;
import org.jabref.gui.preferences.PreferenceTabViewModel;
import org.jabref.gui.remote.JabRefMessageHandler;
import org.jabref.gui.remote.CLIMessageHandler;
import org.jabref.gui.util.FileDialogConfiguration;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.net.ProxyPreferences;
Expand Down Expand Up @@ -73,7 +73,7 @@ public class NetworkTabViewModel implements PreferenceTabViewModel {

private final TrustStoreManager trustStoreManager;

private AtomicBoolean sslCertificatesChanged = new AtomicBoolean(false);
private final AtomicBoolean sslCertificatesChanged = new AtomicBoolean(false);

public NetworkTabViewModel(DialogService dialogService, PreferencesService preferences) {
this.dialogService = dialogService;
Expand Down Expand Up @@ -139,6 +139,7 @@ public NetworkTabViewModel(DialogService dialogService, PreferencesService prefe
this.trustStoreManager = new TrustStoreManager(Path.of(sslPreferences.getTruststorePath()));
}

@Override
public void setValues() {
remoteServerProperty.setValue(remotePreferences.useRemoteServer());
remotePortProperty.setValue(String.valueOf(remotePreferences.getPort()));
Expand Down Expand Up @@ -174,6 +175,7 @@ private void setSSLValues() {
});
}

@Override
public void storeSettings() {
storeRemoteSettings();
storeProxySettings(new ProxyPreferences(
Expand Down Expand Up @@ -201,7 +203,7 @@ private void storeRemoteSettings() {

if (remoteServerProperty.getValue()) {
remotePreferences.setUseRemoteServer(true);
Globals.REMOTE_LISTENER.openAndStart(new JabRefMessageHandler(), remotePreferences.getPort(), preferences);
Globals.REMOTE_LISTENER.openAndStart(new CLIMessageHandler(preferences), remotePreferences.getPort());
} else {
remotePreferences.setUseRemoteServer(false);
Globals.REMOTE_LISTENER.stop();
Expand Down Expand Up @@ -256,6 +258,7 @@ public ValidationStatus proxyPasswordValidationStatus() {
return proxyPasswordValidator.getValidationStatus();
}

@Override
public boolean validateSettings() {
CompositeValidator validator = new CompositeValidator();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@
import org.jabref.cli.ArgumentProcessor;
import org.jabref.gui.JabRefGUI;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.remote.server.MessageHandler;
import org.jabref.logic.remote.server.RemoteMessageHandler;
import org.jabref.preferences.PreferencesService;

import org.apache.commons.cli.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class JabRefMessageHandler implements MessageHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(JabRefMessageHandler.class);
public class CLIMessageHandler implements RemoteMessageHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(CLIMessageHandler.class);

private final PreferencesService preferencesService;

public CLIMessageHandler(PreferencesService preferencesService) {
this.preferencesService = preferencesService;
}

@Override
public void handleCommandLineArguments(String[] message, PreferencesService preferencesService) {
public void handleCommandLineArguments(String[] message) {
try {
ArgumentProcessor argumentProcessor = new ArgumentProcessor(message, ArgumentProcessor.Mode.REMOTE_START, preferencesService);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jabref.logic.remote.shared;
package org.jabref.logic.remote;

import java.io.IOException;
import java.io.ObjectInputStream;
Expand All @@ -10,9 +10,6 @@

import javafx.util.Pair;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* @implNote The first byte of every message identifies its type as a {@link RemoteMessage}.
* Every message is terminated with '\0'.
Expand All @@ -21,8 +18,6 @@ public class Protocol implements AutoCloseable {

public static final String IDENTIFIER = "jabref";

private static final Logger LOGGER = LoggerFactory.getLogger(Protocol.class);

private final Socket socket;
private final ObjectOutputStream out;
private final ObjectInputStream in;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jabref.logic.remote.shared;
package org.jabref.logic.remote;

public enum RemoteMessage {
/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/logic/remote/RemotePreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
*/
public class RemotePreferences {

private IntegerProperty port;
private BooleanProperty useRemoteServer;
private final IntegerProperty port;
private final BooleanProperty useRemoteServer;

public RemotePreferences(int port, boolean useRemoteServer) {
this.port = new SimpleIntegerProperty(port);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import javafx.util.Pair;

import org.jabref.logic.l10n.Localization;
import org.jabref.logic.remote.Protocol;
import org.jabref.logic.remote.RemoteMessage;
import org.jabref.logic.remote.RemotePreferences;
import org.jabref.logic.remote.shared.Protocol;
import org.jabref.logic.remote.shared.RemoteMessage;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -30,7 +30,7 @@ public boolean ping() {
protocol.sendMessage(RemoteMessage.PING);
Pair<RemoteMessage, Object> response = protocol.receiveMessage();

if (response.getKey() == RemoteMessage.PONG && Protocol.IDENTIFIER.equals(response.getValue())) {
if ((response.getKey() == RemoteMessage.PONG) && Protocol.IDENTIFIER.equals(response.getValue())) {
return true;
} else {
String port = String.valueOf(this.port);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@

import javafx.util.Pair;

import org.jabref.logic.remote.Protocol;
import org.jabref.logic.remote.RemoteMessage;
import org.jabref.logic.remote.RemotePreferences;
import org.jabref.logic.remote.shared.Protocol;
import org.jabref.logic.remote.shared.RemoteMessage;
import org.jabref.preferences.PreferencesService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -22,14 +21,12 @@ public class RemoteListenerServer implements Runnable {

private static final int TIMEOUT = 1000;

private final MessageHandler messageHandler;
private final RemoteMessageHandler messageHandler;
private final ServerSocket serverSocket;
private final PreferencesService preferencesService;

public RemoteListenerServer(MessageHandler messageHandler, int port, PreferencesService preferencesService) throws IOException {
public RemoteListenerServer(RemoteMessageHandler messageHandler, int port) throws IOException {
this.serverSocket = new ServerSocket(port, BACKLOG, RemotePreferences.getIpAddress());
this.messageHandler = messageHandler;
this.preferencesService = preferencesService;
}

@Override
Expand Down Expand Up @@ -61,7 +58,7 @@ private void handleMessage(Protocol protocol, RemoteMessage type, Object argumen
break;
case SEND_COMMAND_LINE_ARGUMENTS:
if (argument instanceof String[]) {
messageHandler.handleCommandLineArguments((String[]) argument, preferencesService);
messageHandler.handleCommandLineArguments((String[]) argument);
protocol.sendMessage(RemoteMessage.OK);
} else {
throw new IOException("Argument for 'SEND_COMMAND_LINE_ARGUMENTS' is not of type String[]. Got " + argument);
Expand All @@ -75,8 +72,8 @@ private void handleMessage(Protocol protocol, RemoteMessage type, Object argumen
public void closeServerSocket() {
try {
serverSocket.close();
} catch (IOException ignored) {
// Ignored
} catch (IOException exception) {
LOGGER.error("Could not close server socket", exception);
}
}
}

This file was deleted.

Loading

0 comments on commit de57f7f

Please sign in to comment.