This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit e2f00c48d881d8d9a23d5411d61bbd339996e034 Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Thu Nov 4 10:15:40 2021 +0100 Do not interrupt threads that are blocked on I/O operations. This is necessary for avoiding to close InterruptibleChannel. --- .../src/main/java/org/apache/sis/gui/coverage/GridView.java | 4 ++-- .../main/java/org/apache/sis/gui/dataset/FeatureList.java | 4 ++-- .../org/apache/sis/gui/metadata/IdentificationInfo.java | 2 +- .../java/org/apache/sis/gui/metadata/MetadataSummary.java | 2 +- .../java/org/apache/sis/internal/gui/BackgroundThreads.java | 13 +++++++++++++ .../main/java/org/apache/sis/internal/gui/PropertyView.java | 4 ++-- 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridView.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridView.java index bf6dd8c..057c7e7 100644 --- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridView.java +++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridView.java @@ -316,7 +316,7 @@ public class GridView extends Control { final ImageLoader previous = loader; loader = null; if (previous != null) { - previous.cancel(); + previous.cancel(BackgroundThreads.NO_INTERRUPT_DURING_IO); } loader = new ImageLoader(source, true); BackgroundThreads.execute(loader); @@ -444,7 +444,7 @@ public class GridView extends Control { */ private void onImageSpecified(final RenderedImage image) { if (loader != null) { - loader.cancel(); + loader.cancel(BackgroundThreads.NO_INTERRUPT_DURING_IO); loader = null; } tiles.clear(); // Let garbage collector dispose the rasters. diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/FeatureList.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/FeatureList.java index ab8b9cc..5c1ef2c 100644 --- a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/FeatureList.java +++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/FeatureList.java @@ -149,7 +149,7 @@ final class FeatureList extends ObservableListBase<Feature> { final FeatureLoader previous = nextPageLoader; if (previous != null) { nextPageLoader = null; - previous.cancel(); + previous.cancel(BackgroundThreads.NO_INTERRUPT_DURING_IO); } if (features != null) { nextPageLoader = new FeatureLoader(table, features); @@ -333,7 +333,7 @@ final class FeatureList extends ObservableListBase<Feature> { final FeatureLoader loader = nextPageLoader; nextPageLoader = null; if (loader != null) { - loader.cancel(); + loader.cancel(BackgroundThreads.NO_INTERRUPT_DURING_IO); BackgroundThreads.execute(loader::waitAndClose); } } diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/IdentificationInfo.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/IdentificationInfo.java index 1c83184..8da5616 100644 --- a/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/IdentificationInfo.java +++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/IdentificationInfo.java @@ -238,7 +238,7 @@ final class IdentificationInfo extends Section<Identification> { @Override void setInformation(final Metadata metadata) { if (aggregateWalker != null) { - aggregateWalker.cancel(); + aggregateWalker.cancel(BackgroundThreads.NO_INTERRUPT_DURING_IO); aggregateWalker = null; } final Collection<? extends Identification> info; diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataSummary.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataSummary.java index dee04f1..b17445e 100644 --- a/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataSummary.java +++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataSummary.java @@ -200,7 +200,7 @@ public class MetadataSummary extends Widget { public void setMetadata(final Resource resource) { assert Platform.isFxApplicationThread(); if (getter != null) { - getter.cancel(); + getter.cancel(BackgroundThreads.NO_INTERRUPT_DURING_IO); getter = null; } if (resource == null) { diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/BackgroundThreads.java b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/BackgroundThreads.java index 1251829..116ca02 100644 --- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/BackgroundThreads.java +++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/BackgroundThreads.java @@ -53,6 +53,19 @@ import org.apache.sis.util.logging.Logging; @SuppressWarnings("serial") // Not intended to be serialized. public final class BackgroundThreads extends AtomicInteger implements ThreadFactory { /** + * The {@code mayInterruptIfRunning} argument value to give to calls to + * {@link java.util.concurrent.Future#cancel(boolean)} if the background task + * may be doing I/O operations on a {@link java.nio.channels.InterruptibleChannel}. + * Interruption must be disabled for avoiding the channel to be closed. + * + * <p>Note that the default value of {@link javafx.concurrent.Task#cancel()} is {@code true}. + * So task doing I/O operations should be cancelled with {@code cancel(NO_INTERRUPT_DURING_IO)}. + * This flag is defined mostly for tracking places in the code where tasks doing I/O operations + * may be interrupted.</p> + */ + public static final boolean NO_INTERRUPT_DURING_IO = false; + + /** * The executor for background tasks. This is actually an {@link ExecutorService} instance, * but only the {@link Executor} method should be used according JavaFX documentation. */ diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/PropertyView.java b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/PropertyView.java index 36f854f..9543886 100644 --- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/PropertyView.java +++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/PropertyView.java @@ -55,7 +55,7 @@ import org.apache.sis.util.resources.Vocabulary; * <p>This class extends {@link CompoundFormat} for implementation convenience only.</p> * * @author Martin Desruisseaux (Geomatys) - * @version 1.1 + * @version 1.2 * @since 1.1 * @module */ @@ -212,7 +212,7 @@ public final class PropertyView extends CompoundFormat<Object> { public void set(final Object newValue, final Rectangle visibleBounds) { if (newValue != value || !Objects.equals(visibleBounds, visibleImageBounds)) { if (runningTask != null) { - runningTask.cancel(); + runningTask.cancel(BackgroundThreads.NO_INTERRUPT_DURING_IO); runningTask = null; } visibleImageBounds = visibleBounds;