Skip to content

Commit

Permalink
Migrate TaskExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
calixtus committed May 23, 2024
1 parent 6d34bae commit 3d58c7f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 47 deletions.
5 changes: 1 addition & 4 deletions src/main/java/org/jabref/gui/DefaultInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.function.Function;

import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.protectedterms.ProtectedTermsLoader;
import org.jabref.model.util.FileUpdateMonitor;
Expand All @@ -23,9 +22,7 @@ public class DefaultInjector implements PresenterFactory {
* Dependencies without default constructor are constructed by hand.
*/
private static Object createDependency(Class<?> clazz) {
if (clazz == TaskExecutor.class) {
return Globals.TASK_EXECUTOR;
} else if (clazz == KeyBindingRepository.class) {
if (clazz == KeyBindingRepository.class) {
return Globals.getKeyPrefs();
} else if (clazz == JournalAbbreviationRepository.class) {
return Globals.journalAbbreviationRepository;
Expand Down
17 changes: 0 additions & 17 deletions src/main/java/org/jabref/gui/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.util.DefaultDirectoryMonitor;
import org.jabref.gui.util.DefaultFileUpdateMonitor;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.protectedterms.ProtectedTermsLoader;
import org.jabref.logic.remote.server.RemoteListenerServerManager;
Expand All @@ -30,8 +28,6 @@ public class Globals {

public static final RemoteListenerServerManager REMOTE_LISTENER = new RemoteListenerServerManager();

public static final TaskExecutor TASK_EXECUTOR = new DefaultTaskExecutor();

/**
* This field is initialized upon startup.
* <p>
Expand Down Expand Up @@ -84,17 +80,4 @@ public static DirectoryMonitor getDirectoryMonitor() {
}
return directoryMonitor;
}

public static void shutdownThreadPools() {
TASK_EXECUTOR.shutdown();
if (fileUpdateMonitor != null) {
fileUpdateMonitor.shutdown();
}

if (directoryMonitor != null) {
directoryMonitor.shutdown();
}

JabRefExecutorService.INSTANCE.shutdownEverything();
}
}
32 changes: 23 additions & 9 deletions src/main/java/org/jabref/gui/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.jabref.gui.telemetry.Telemetry;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.undo.CountingUndoManager;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.UiCommand;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.net.ProxyRegisterer;
Expand Down Expand Up @@ -55,6 +57,7 @@ public class JabRefGUI extends Application {
private static StateManager stateManager;

private static CountingUndoManager countingUndoManager;
private static TaskExecutor taskExecutor;

private boolean correctedWindowPos = false;
private Stage mainStage;
Expand Down Expand Up @@ -91,6 +94,9 @@ public void start(Stage stage) {
Injector.setModelOrService(UndoManager.class, countingUndoManager);
Injector.setModelOrService(CountingUndoManager.class, countingUndoManager);

JabRefGUI.taskExecutor = new DefaultTaskExecutor();
Injector.setModelOrService(TaskExecutor.class, taskExecutor);

JabRefGUI.mainFrame = new JabRefFrame(
mainStage,
dialogService,
Expand All @@ -99,7 +105,7 @@ public void start(Stage stage) {
stateManager,
countingUndoManager,
Injector.instantiateModelOrService(BibEntryTypesManager.class),
Globals.TASK_EXECUTOR);
taskExecutor);

openWindow();

Expand All @@ -114,7 +120,7 @@ public void start(Stage stage) {
if (enabled) {
new VersionWorker(Globals.BUILD_INFO.version,
dialogService,
Globals.TASK_EXECUTOR,
taskExecutor,
preferencesService)
.checkForNewVersionDelayed();
}
Expand All @@ -123,13 +129,6 @@ public void start(Stage stage) {
setupProxy();
}

@Override
public void stop() {
OOBibBaseConnect.closeOfficeConnection();
stopBackgroundTasks();
Globals.shutdownThreadPools();
}

private void setupProxy() {
if (!preferencesService.getProxyPreferences().shouldUseProxy()
|| !preferencesService.getProxyPreferences().shouldUseAuthentication()) {
Expand Down Expand Up @@ -267,6 +266,7 @@ private boolean isWindowPositionOutOfBounds() {
preferencesService.getGuiPreferences().getPositionY());
}


// Background tasks
public void startBackgroundTasks() {
// TODO Currently deactivated due to incompatibilities in XML
Expand All @@ -284,11 +284,25 @@ public void startBackgroundTasks() {
}
}

@Override
public void stop() {
OOBibBaseConnect.closeOfficeConnection();
stopBackgroundTasks();
shutdownThreadPools();
}

public void stopBackgroundTasks() {
Telemetry.shutdown();
Unirest.shutDown();
}

public static void shutdownThreadPools() {
taskExecutor.shutdown();
Globals.getFileUpdateMonitor().shutdown();
Globals.getDirectoryMonitor().shutdown();
JabRefExecutorService.INSTANCE.shutdownEverything();
}

public static JabRefFrame getMainFrame() {
return mainFrame;
}
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,15 @@ private List<EntryEditorTab> createTabs() {
entryEditorTabs.add(new MathSciNetTab());
entryEditorTabs.add(new FileAnnotationTab(libraryTab.getAnnotationCache()));
entryEditorTabs.add(new SciteTab(preferencesService, taskExecutor, dialogService));
entryEditorTabs.add(new CitationRelationsTab(entryEditorPreferences, dialogService, databaseContext,
undoManager, stateManager, fileMonitor, preferencesService, libraryTab, taskExecutor));
entryEditorTabs.add(new CitationRelationsTab(
dialogService,
databaseContext,
undoManager,
stateManager,
fileMonitor,
preferencesService,
libraryTab,
taskExecutor));
entryEditorTabs.add(new RelatedArticlesTab(entryEditorPreferences, preferencesService, dialogService, taskExecutor));
sourceTab = new SourceTab(
databaseContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@
import javafx.scene.layout.VBox;

import org.jabref.gui.DialogService;
import org.jabref.gui.Globals;
import org.jabref.gui.LibraryTab;
import org.jabref.gui.StateManager;
import org.jabref.gui.desktop.JabRefDesktop;
import org.jabref.gui.entryeditor.EntryEditorPreferences;
import org.jabref.gui.entryeditor.EntryEditorTab;
import org.jabref.gui.entryeditor.citationrelationtab.semanticscholar.CitationFetcher;
import org.jabref.gui.entryeditor.citationrelationtab.semanticscholar.SemanticScholarFetcher;
Expand Down Expand Up @@ -66,29 +64,25 @@ public class CitationRelationsTab extends EntryEditorTab {
// Tasks used to implement asynchronous fetching of related articles
private static BackgroundTask<List<BibEntry>> citingTask;
private static BackgroundTask<List<BibEntry>> citedByTask;
private final EntryEditorPreferences preferences;
private final DialogService dialogService;
private final BibDatabaseContext databaseContext;
private final UndoManager undoManager;
private final StateManager stateManager;
private final FileUpdateMonitor fileUpdateMonitor;
private final PreferencesService preferencesService;
private final LibraryTab libraryTab;
private final TaskExecutor taskExecutor;
private final BibEntryRelationsRepository bibEntryRelationsRepository;
private final CitationsRelationsTabViewModel citationsRelationsTabViewModel;
private final DuplicateCheck duplicateCheck;

public CitationRelationsTab(EntryEditorPreferences preferences, DialogService dialogService,
BibDatabaseContext databaseContext, UndoManager undoManager,
StateManager stateManager, FileUpdateMonitor fileUpdateMonitor,
PreferencesService preferencesService, LibraryTab lTab, TaskExecutor taskExecutor) {
this.preferences = preferences;
public CitationRelationsTab(DialogService dialogService,
BibDatabaseContext databaseContext,
UndoManager undoManager,
StateManager stateManager,
FileUpdateMonitor fileUpdateMonitor,
PreferencesService preferencesService,
LibraryTab lTab,
TaskExecutor taskExecutor) {
this.dialogService = dialogService;
this.databaseContext = databaseContext;
this.undoManager = undoManager;
this.stateManager = stateManager;
this.fileUpdateMonitor = fileUpdateMonitor;
this.preferencesService = preferencesService;
this.libraryTab = lTab;
this.taskExecutor = taskExecutor;
Expand All @@ -98,7 +92,7 @@ public CitationRelationsTab(EntryEditorPreferences preferences, DialogService di
this.duplicateCheck = new DuplicateCheck(new BibEntryTypesManager());
this.bibEntryRelationsRepository = new BibEntryRelationsRepository(new SemanticScholarFetcher(preferencesService.getImporterPreferences()),
new BibEntryRelationsCache());
citationsRelationsTabViewModel = new CitationsRelationsTabViewModel(databaseContext, preferencesService, undoManager, stateManager, dialogService, fileUpdateMonitor, Globals.TASK_EXECUTOR);
citationsRelationsTabViewModel = new CitationsRelationsTabViewModel(databaseContext, preferencesService, undoManager, stateManager, dialogService, fileUpdateMonitor, taskExecutor);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2159,6 +2159,7 @@ public WorkspacePreferences getWorkspacePreferences() {
Localization.setLanguage(newValue);
}
});

EasyBind.listen(workspacePreferences.shouldOverrideDefaultFontSizeProperty(), (obs, oldValue, newValue) -> putBoolean(OVERRIDE_DEFAULT_FONT_SIZE, newValue));
EasyBind.listen(workspacePreferences.mainFontSizeProperty(), (obs, oldValue, newValue) -> putInt(MAIN_FONT_SIZE, newValue));
EasyBind.listen(workspacePreferences.themeProperty(), (obs, oldValue, newValue) -> put(THEME, newValue.getName()));
Expand Down

0 comments on commit 3d58c7f

Please sign in to comment.