diff --git a/src/main/java/org/cryptomator/common/vaults/Vault.java b/src/main/java/org/cryptomator/common/vaults/Vault.java index a48c5d0ac..89e1d5002 100644 --- a/src/main/java/org/cryptomator/common/vaults/Vault.java +++ b/src/main/java/org/cryptomator/common/vaults/Vault.java @@ -10,7 +10,7 @@ package org.cryptomator.common.vaults; import org.apache.commons.lang3.SystemUtils; import org.cryptomator.common.Constants; -import org.cryptomator.event.FileSystemEventRegistry; +import org.cryptomator.event.FileSystemEventAggregator; import org.cryptomator.common.mount.Mounter; import org.cryptomator.common.settings.Settings; import org.cryptomator.common.settings.VaultSettings; @@ -76,7 +76,7 @@ public class Vault { private final ObjectBinding mountPoint; private final Mounter mounter; private final Settings settings; - private final FileSystemEventRegistry fileSystemEventRegistry; + private final FileSystemEventAggregator fileSystemEventAggregator; private final BooleanProperty showingStats; private final AtomicReference mountHandle = new AtomicReference<>(null); @@ -89,7 +89,7 @@ public class Vault { @Named("lastKnownException") ObjectProperty lastKnownException, // VaultStats stats, // Mounter mounter, Settings settings, // - FileSystemEventRegistry fileSystemEventRegistry) { + FileSystemEventAggregator fileSystemEventAggregator) { this.vaultSettings = vaultSettings; this.configCache = configCache; this.cryptoFileSystem = cryptoFileSystem; @@ -106,7 +106,7 @@ public class Vault { this.mountPoint = Bindings.createObjectBinding(this::getMountPoint, state); this.mounter = mounter; this.settings = settings; - this.fileSystemEventRegistry = fileSystemEventRegistry; + this.fileSystemEventAggregator = fileSystemEventAggregator; this.showingStats = new SimpleBooleanProperty(false); this.quickAccessEntry = new AtomicReference<>(null); } @@ -259,7 +259,7 @@ public class Vault { private void consumeVaultEvent(FilesystemEvent e) { - fileSystemEventRegistry.enqueue(this, e); + fileSystemEventAggregator.enqueue(this, e); } // ****************************************************************************** diff --git a/src/main/java/org/cryptomator/event/FileSystemEventRegistry.java b/src/main/java/org/cryptomator/event/FileSystemEventAggregator.java similarity index 77% rename from src/main/java/org/cryptomator/event/FileSystemEventRegistry.java rename to src/main/java/org/cryptomator/event/FileSystemEventAggregator.java index db9d9ed23..a1db4138d 100644 --- a/src/main/java/org/cryptomator/event/FileSystemEventRegistry.java +++ b/src/main/java/org/cryptomator/event/FileSystemEventAggregator.java @@ -14,12 +14,11 @@ import java.nio.file.Path; import java.util.Collection; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.atomic.AtomicBoolean; //TODO: Rename to aggregator @Singleton -public class FileSystemEventRegistry { +public class FileSystemEventAggregator { public record Key(Vault vault, Path idPath, Class c) {}; @@ -29,7 +28,7 @@ public class FileSystemEventRegistry { private final AtomicBoolean hasUpdates; @Inject - public FileSystemEventRegistry(ScheduledExecutorService scheduledExecutorService) { + public FileSystemEventAggregator() { this.map = new ConcurrentHashMap<>(); this.hasUpdates = new AtomicBoolean(false); } @@ -54,12 +53,7 @@ public class FileSystemEventRegistry { } /** - * Removes an event from the map. - *

- * To identify the event, a similar event (in the sense of map key) is given. - * - * @return the removed {@link Value} - * @implNote Method is not synchronized, because it is only executed if executed by JavaFX application thread + * Removes an event bucket from the map. */ public Value remove(Key key) { hasUpdates.set(true); @@ -68,10 +62,6 @@ public class FileSystemEventRegistry { /** * Clears the event map. - *

- * Must be executed on the JavaFX application thread - * - * @implNote Method is not synchronized, because it is only executed if executed by JavaFX application thread */ public void clear() { hasUpdates.set(true); @@ -88,12 +78,12 @@ public class FileSystemEventRegistry { *

* The collection is first cleared, then all map entries are added in one bulk operation. Cleans the hasUpdates status. * - * @param targetCollection + * @param target collection which is first cleared and then the EntrySet copied to. */ - public void cloneTo(Collection> targetCollection) { + public void cloneTo(Collection> target) { hasUpdates.set(false); - targetCollection.clear(); - targetCollection.addAll(map.entrySet()); + target.clear(); + target.addAll(map.entrySet()); } /** diff --git a/src/main/java/org/cryptomator/ui/eventview/EventListCellController.java b/src/main/java/org/cryptomator/ui/eventview/EventListCellController.java index d5c404348..c1abaddac 100644 --- a/src/main/java/org/cryptomator/ui/eventview/EventListCellController.java +++ b/src/main/java/org/cryptomator/ui/eventview/EventListCellController.java @@ -1,6 +1,6 @@ package org.cryptomator.ui.eventview; -import org.cryptomator.event.FileSystemEventRegistry; +import org.cryptomator.event.FileSystemEventAggregator; import org.cryptomator.common.Nullable; import org.cryptomator.common.ObservableUtil; import org.cryptomator.cryptofs.CryptoPath; @@ -51,11 +51,11 @@ public class EventListCellController implements FxController { private static final DateTimeFormatter LOCAL_DATE_FORMATTER = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).withZone(ZoneId.systemDefault()); private static final DateTimeFormatter LOCAL_TIME_FORMATTER = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).withZone(ZoneId.systemDefault()); - private final FileSystemEventRegistry fileSystemEventRegistry; + private final FileSystemEventAggregator fileSystemEventAggregator; @Nullable private final RevealPathService revealService; private final ResourceBundle resourceBundle; - private final ObjectProperty> eventEntry; + private final ObjectProperty> eventEntry; private final StringProperty eventMessage; private final StringProperty eventDescription; private final ObjectProperty eventIcon; @@ -77,8 +77,8 @@ public class EventListCellController implements FxController { Button eventActionsButton; @Inject - public EventListCellController(FileSystemEventRegistry fileSystemEventRegistry, Optional revealService, ResourceBundle resourceBundle) { - this.fileSystemEventRegistry = fileSystemEventRegistry; + public EventListCellController(FileSystemEventAggregator fileSystemEventAggregator, Optional revealService, ResourceBundle resourceBundle) { + this.fileSystemEventAggregator = fileSystemEventAggregator; this.revealService = revealService.orElseGet(() -> null); this.resourceBundle = resourceBundle; this.eventEntry = new SimpleObjectProperty<>(null); @@ -108,12 +108,14 @@ public class EventListCellController implements FxController { return vaultUnlocked.getValue() && (eventActionsMenu.isShowing() || root.isHover()); } - public void setEventEntry(@NotNull Map.Entry item) { + public void setEventEntry(@NotNull Map.Entry item) { eventEntry.set(item); eventActionsMenu.hide(); eventActionsMenu.getItems().clear(); eventTooltip.setText(item.getKey().vault().getDisplayName()); - addAction("generic.action.dismiss", () -> fileSystemEventRegistry.remove(item.getKey())); + addAction("generic.action.dismiss", () -> { + fileSystemEventAggregator.remove(item.getKey()); + }); switch (item.getValue().mostRecentEvent()) { case ConflictResolvedEvent fse -> this.adjustToConflictResolvedEvent(fse); case ConflictResolutionFailedEvent fse -> this.adjustToConflictEvent(fse); diff --git a/src/main/java/org/cryptomator/ui/eventview/EventListCellFactory.java b/src/main/java/org/cryptomator/ui/eventview/EventListCellFactory.java index 405e5f307..558803968 100644 --- a/src/main/java/org/cryptomator/ui/eventview/EventListCellFactory.java +++ b/src/main/java/org/cryptomator/ui/eventview/EventListCellFactory.java @@ -1,6 +1,6 @@ package org.cryptomator.ui.eventview; -import org.cryptomator.event.FileSystemEventRegistry; +import org.cryptomator.event.FileSystemEventAggregator; import org.cryptomator.ui.common.FxmlLoaderFactory; import javax.inject.Inject; @@ -15,7 +15,7 @@ import java.io.UncheckedIOException; import java.util.Map; @EventViewScoped -public class EventListCellFactory implements Callback>, ListCell>> { +public class EventListCellFactory implements Callback>, ListCell>> { private static final String FXML_PATH = "/fxml/eventview_cell.fxml"; @@ -28,7 +28,7 @@ public class EventListCellFactory implements Callback> call(ListView> eventListView) { + public ListCell> call(ListView> eventListView) { try { FXMLLoader fxmlLoader = fxmlLoaders.load(FXML_PATH); return new Cell(fxmlLoader.getRoot(), fxmlLoader.getController()); @@ -37,7 +37,7 @@ public class EventListCellFactory implements Callback> { + private static class Cell extends ListCell> { private final Parent root; private final EventListCellController controller; @@ -48,7 +48,7 @@ public class EventListCellFactory implements Callback item, boolean empty) { + protected void updateItem(Map.Entry item, boolean empty) { super.updateItem(item, empty); if (empty || item == null) { diff --git a/src/main/java/org/cryptomator/ui/eventview/EventViewController.java b/src/main/java/org/cryptomator/ui/eventview/EventViewController.java index 65298ea97..bba62605b 100644 --- a/src/main/java/org/cryptomator/ui/eventview/EventViewController.java +++ b/src/main/java/org/cryptomator/ui/eventview/EventViewController.java @@ -1,7 +1,7 @@ package org.cryptomator.ui.eventview; import org.cryptomator.common.vaults.Vault; -import org.cryptomator.event.FileSystemEventRegistry; +import org.cryptomator.event.FileSystemEventAggregator; import org.cryptomator.ui.common.FxController; import org.cryptomator.ui.fxapp.EventsUpdateCheck; @@ -22,9 +22,9 @@ import java.util.ResourceBundle; @EventViewScoped public class EventViewController implements FxController { - private final FilteredList> filteredEventList; + private final FilteredList> filteredEventList; private final ObservableList vaults; - private final SortedList> sortedEventList; + private final SortedList> sortedEventList; private final ObservableList choiceBoxEntries; private final ResourceBundle resourceBundle; private final EventListCellFactory cellFactory; @@ -32,7 +32,7 @@ public class EventViewController implements FxController { @FXML ChoiceBox vaultFilterChoiceBox; @FXML - ListView> eventListView; + ListView> eventListView; @Inject public EventViewController(EventsUpdateCheck eventsUpdateCheck, ObservableList vaults, ResourceBundle resourceBundle, EventListCellFactory cellFactory) { @@ -48,11 +48,11 @@ public class EventViewController implements FxController { * Comparsion method for the lru cache. During comparsion the map is accessed. * First the entries are compared by the event timestamp, then vaultId, then identifying path and lastly by class name. * - * @param left a {@link FileSystemEventRegistry.Key} object - * @param right another {@link FileSystemEventRegistry.Key} object, compared to {@code left} + * @param left a {@link FileSystemEventAggregator.Key} object + * @param right another {@link FileSystemEventAggregator.Key} object, compared to {@code left} * @return a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second. */ - private int compareBuckets(Map.Entry left, Map.Entry right) { + private int compareBuckets(Map.Entry left, Map.Entry right) { var t1 = left.getValue().mostRecentEvent().getTimestamp(); var t2 = right.getValue().mostRecentEvent().getTimestamp(); var timeComparison = t1.compareTo(t2); diff --git a/src/main/java/org/cryptomator/ui/fxapp/EventsUpdateCheck.java b/src/main/java/org/cryptomator/ui/fxapp/EventsUpdateCheck.java index a02316699..948e8f09e 100644 --- a/src/main/java/org/cryptomator/ui/fxapp/EventsUpdateCheck.java +++ b/src/main/java/org/cryptomator/ui/fxapp/EventsUpdateCheck.java @@ -1,10 +1,9 @@ package org.cryptomator.ui.fxapp; -import org.cryptomator.event.FileSystemEventRegistry; +import org.cryptomator.event.FileSystemEventAggregator; import javax.inject.Inject; import javax.inject.Named; -import javax.inject.Singleton; import javafx.application.Platform; import javafx.beans.property.BooleanProperty; import javafx.collections.FXCollections; @@ -18,13 +17,13 @@ import java.util.concurrent.TimeUnit; @FxApplicationScoped public class EventsUpdateCheck { - private final ObservableList> events; - private final FileSystemEventRegistry eventRegistry; + private final ObservableList> events; + private final FileSystemEventAggregator eventRegistry; private final ScheduledFuture scheduledTask; private final BooleanProperty unreadEvents; @Inject - public EventsUpdateCheck(FileSystemEventRegistry eventRegistry, ScheduledExecutorService scheduler, @Named("unreadEventsAvailable") BooleanProperty unreadEvents) { + public EventsUpdateCheck(FileSystemEventAggregator eventRegistry, ScheduledExecutorService scheduler, @Named("unreadEventsAvailable") BooleanProperty unreadEvents) { this.events = FXCollections.observableArrayList(); this.eventRegistry = eventRegistry; this.unreadEvents = unreadEvents; @@ -36,7 +35,7 @@ public class EventsUpdateCheck { //TODO: allow the task to be canceled (to enable ui actions, e.g. when the contextMenu is open, the list should not be updated } - public ObservableList> getList() { + public ObservableList> getList() { return events; }