Prechádzať zdrojové kódy

rename EventRegistry to Aggregator

Armin Schrenk 6 mesiacov pred
rodič
commit
e8e2fcb0b3

+ 5 - 5
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> mountPoint;
 	private final Mounter mounter;
 	private final Settings settings;
-	private final FileSystemEventRegistry fileSystemEventRegistry;
+	private final FileSystemEventAggregator fileSystemEventAggregator;
 	private final BooleanProperty showingStats;
 
 	private final AtomicReference<Mounter.MountHandle> mountHandle = new AtomicReference<>(null);
@@ -89,7 +89,7 @@ public class Vault {
 		  @Named("lastKnownException") ObjectProperty<Exception> 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);
 	}
 
 	// ******************************************************************************

+ 7 - 17
src/main/java/org/cryptomator/event/FileSystemEventRegistry.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<? extends FilesystemEvent> 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.
-	 * <p>
-	 * 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.
-	 * <p>
-	 * 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 {
 	 * <p>
 	 * 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<Map.Entry<Key, Value>> targetCollection) {
+	public void cloneTo(Collection<Map.Entry<Key, Value>> target) {
 		hasUpdates.set(false);
-		targetCollection.clear();
-		targetCollection.addAll(map.entrySet());
+		target.clear();
+		target.addAll(map.entrySet());
 	}
 
 	/**

+ 9 - 7
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<Map.Entry<FileSystemEventRegistry.Key, FileSystemEventRegistry.Value>> eventEntry;
+	private final ObjectProperty<Map.Entry<FileSystemEventAggregator.Key, FileSystemEventAggregator.Value>> eventEntry;
 	private final StringProperty eventMessage;
 	private final StringProperty eventDescription;
 	private final ObjectProperty<FontAwesome5Icon> eventIcon;
@@ -77,8 +77,8 @@ public class EventListCellController implements FxController {
 	Button eventActionsButton;
 
 	@Inject
-	public EventListCellController(FileSystemEventRegistry fileSystemEventRegistry, Optional<RevealPathService> revealService, ResourceBundle resourceBundle) {
-		this.fileSystemEventRegistry = fileSystemEventRegistry;
+	public EventListCellController(FileSystemEventAggregator fileSystemEventAggregator, Optional<RevealPathService> 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<FileSystemEventRegistry.Key, FileSystemEventRegistry.Value> item) {
+	public void setEventEntry(@NotNull Map.Entry<FileSystemEventAggregator.Key, FileSystemEventAggregator.Value> 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);

+ 5 - 5
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<ListView<Map.Entry<FileSystemEventRegistry.Key, FileSystemEventRegistry.Value>>, ListCell<Map.Entry<FileSystemEventRegistry.Key, FileSystemEventRegistry.Value>>> {
+public class EventListCellFactory implements Callback<ListView<Map.Entry<FileSystemEventAggregator.Key, FileSystemEventAggregator.Value>>, ListCell<Map.Entry<FileSystemEventAggregator.Key, FileSystemEventAggregator.Value>>> {
 
 	private static final String FXML_PATH = "/fxml/eventview_cell.fxml";
 
@@ -28,7 +28,7 @@ public class EventListCellFactory implements Callback<ListView<Map.Entry<FileSys
 
 
 	@Override
-	public ListCell<Map.Entry<FileSystemEventRegistry.Key, FileSystemEventRegistry.Value>> call(ListView<Map.Entry<FileSystemEventRegistry.Key, FileSystemEventRegistry.Value>> eventListView) {
+	public ListCell<Map.Entry<FileSystemEventAggregator.Key, FileSystemEventAggregator.Value>> call(ListView<Map.Entry<FileSystemEventAggregator.Key, FileSystemEventAggregator.Value>> eventListView) {
 		try {
 			FXMLLoader fxmlLoader = fxmlLoaders.load(FXML_PATH);
 			return new Cell(fxmlLoader.getRoot(), fxmlLoader.getController());
@@ -37,7 +37,7 @@ public class EventListCellFactory implements Callback<ListView<Map.Entry<FileSys
 		}
 	}
 
-	private static class Cell extends ListCell<Map.Entry<FileSystemEventRegistry.Key, FileSystemEventRegistry.Value>> {
+	private static class Cell extends ListCell<Map.Entry<FileSystemEventAggregator.Key, FileSystemEventAggregator.Value>> {
 
 		private final Parent root;
 		private final EventListCellController controller;
@@ -48,7 +48,7 @@ public class EventListCellFactory implements Callback<ListView<Map.Entry<FileSys
 		}
 
 		@Override
-		protected void updateItem(Map.Entry<FileSystemEventRegistry.Key, FileSystemEventRegistry.Value> item, boolean empty) {
+		protected void updateItem(Map.Entry<FileSystemEventAggregator.Key, FileSystemEventAggregator.Value> item, boolean empty) {
 			super.updateItem(item, empty);
 
 			if (empty || item == null) {

+ 7 - 7
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<Map.Entry<FileSystemEventRegistry.Key, FileSystemEventRegistry.Value>> filteredEventList;
+	private final FilteredList<Map.Entry<FileSystemEventAggregator.Key, FileSystemEventAggregator.Value>> filteredEventList;
 	private final ObservableList<Vault> vaults;
-	private final SortedList<Map.Entry<FileSystemEventRegistry.Key, FileSystemEventRegistry.Value>> sortedEventList;
+	private final SortedList<Map.Entry<FileSystemEventAggregator.Key, FileSystemEventAggregator.Value>> sortedEventList;
 	private final ObservableList<Vault> choiceBoxEntries;
 	private final ResourceBundle resourceBundle;
 	private final EventListCellFactory cellFactory;
@@ -32,7 +32,7 @@ public class EventViewController implements FxController {
 	@FXML
 	ChoiceBox<Vault> vaultFilterChoiceBox;
 	@FXML
-	ListView<Map.Entry<FileSystemEventRegistry.Key, FileSystemEventRegistry.Value>> eventListView;
+	ListView<Map.Entry<FileSystemEventAggregator.Key, FileSystemEventAggregator.Value>> eventListView;
 
 	@Inject
 	public EventViewController(EventsUpdateCheck eventsUpdateCheck, ObservableList<Vault> 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<FileSystemEventRegistry.Key, FileSystemEventRegistry.Value> left, Map.Entry<FileSystemEventRegistry.Key, FileSystemEventRegistry.Value> right) {
+	private int compareBuckets(Map.Entry<FileSystemEventAggregator.Key, FileSystemEventAggregator.Value> left, Map.Entry<FileSystemEventAggregator.Key, FileSystemEventAggregator.Value> right) {
 		var t1 = left.getValue().mostRecentEvent().getTimestamp();
 		var t2 = right.getValue().mostRecentEvent().getTimestamp();
 		var timeComparison = t1.compareTo(t2);

+ 5 - 6
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<Map.Entry<FileSystemEventRegistry.Key, FileSystemEventRegistry.Value>> events;
-	private final FileSystemEventRegistry eventRegistry;
+	private final ObservableList<Map.Entry<FileSystemEventAggregator.Key, FileSystemEventAggregator.Value>> 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<Map.Entry<FileSystemEventRegistry.Key, FileSystemEventRegistry.Value>> getList() {
+	public ObservableList<Map.Entry<FileSystemEventAggregator.Key, FileSystemEventAggregator.Value>> getList() {
 		return events;
 	}