From 0ba8fea70fcb480251269dfc0a34d180e60f8cbd Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 15 Nov 2021 15:06:34 +0300 Subject: [PATCH] Remove directory watching for now. --- numass-viewer/build.gradle.kts | 5 +- .../kotlin/inr/numass/viewer/PointCache.kt | 2 +- .../kotlin/inr/numass/viewer/StorageView.kt | 111 ++++++++---------- 3 files changed, 54 insertions(+), 64 deletions(-) diff --git a/numass-viewer/build.gradle.kts b/numass-viewer/build.gradle.kts index 9c6699d2..107a84e6 100644 --- a/numass-viewer/build.gradle.kts +++ b/numass-viewer/build.gradle.kts @@ -1,12 +1,13 @@ plugins { kotlin("jvm") id("org.openjfx.javafxplugin") + //id("com.github.johnrengelman.shadow") id("org.beryx.runtime") version "1.12.7" application } javafx { - modules = listOf("javafx.controls", "javafx.web") + modules = listOf("javafx.graphics", "javafx.controls", "javafx.web") version = "11" } @@ -57,7 +58,7 @@ runtime { ) jpackage { jvmArgs = addJvmArgs - imageOptions = listOf("--linux-deb-maintainer nozik.aa@mipt.ru", "--linux-menu-group Science") + //imageOptions = listOf("--linux-deb-maintainer", "nozik.aa@mipt.ru", "--linux-menu-group", "Science") } launcher { jvmArgs = addJvmArgs diff --git a/numass-viewer/src/main/kotlin/inr/numass/viewer/PointCache.kt b/numass-viewer/src/main/kotlin/inr/numass/viewer/PointCache.kt index e31bf667..e0b4f8dc 100644 --- a/numass-viewer/src/main/kotlin/inr/numass/viewer/PointCache.kt +++ b/numass-viewer/src/main/kotlin/inr/numass/viewer/PointCache.kt @@ -48,7 +48,7 @@ class PointCache : Controller() { } } - private val cache = Misc.getLRUCache(1000) + private val cache = Misc.getLRUCache(400) fun getCachedPoint(id: String,point: NumassPoint): CachedPoint = cache.getOrPut(id) { CachedPoint(point) } diff --git a/numass-viewer/src/main/kotlin/inr/numass/viewer/StorageView.kt b/numass-viewer/src/main/kotlin/inr/numass/viewer/StorageView.kt index b63c2eeb..e6c4b41e 100644 --- a/numass-viewer/src/main/kotlin/inr/numass/viewer/StorageView.kt +++ b/numass-viewer/src/main/kotlin/inr/numass/viewer/StorageView.kt @@ -2,16 +2,12 @@ package inr.numass.viewer import hep.dataforge.fx.dfIconView import hep.dataforge.fx.meta.MetaViewer -import hep.dataforge.io.envelopes.Envelope import hep.dataforge.meta.Meta import hep.dataforge.meta.Metoid import hep.dataforge.names.AlphanumComparator import hep.dataforge.storage.Storage -import hep.dataforge.storage.files.FileStorage import hep.dataforge.storage.files.FileTableLoader import hep.dataforge.storage.tables.TableLoader -import inr.numass.data.NumassDataUtils -import inr.numass.data.NumassEnvelopeType import inr.numass.data.api.NumassPoint import inr.numass.data.api.NumassSet import inr.numass.data.storage.NumassDataLoader @@ -20,15 +16,8 @@ import javafx.beans.property.SimpleObjectProperty import javafx.collections.ObservableList import javafx.scene.control.ContextMenu import javafx.scene.control.TreeItem -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job -import kotlinx.coroutines.isActive -import kotlinx.coroutines.launch import tornadofx.* -import java.nio.file.Path -import java.nio.file.StandardWatchEventKinds.ENTRY_CREATE -import java.nio.file.WatchKey -import java.nio.file.WatchService class StorageView : View(title = "Numass storage", icon = dfIconView) { @@ -44,11 +33,11 @@ class StorageView : View(title = "Numass storage", icon = dfIconView) { private val hvView: HVView by inject() private val scView: SlowControlView by inject() - private var watcher: WatchService? = null +// private var watcher: WatchService? = null fun clear() { - watcher?.close() + //watcher?.close() ampView.clear() timeView.clear() spectrumView.clear() @@ -68,7 +57,7 @@ class StorageView : View(title = "Numass storage", icon = dfIconView) { } } - val watchedProperty = SimpleBooleanProperty(false) + //val watchedProperty = SimpleBooleanProperty(false) init { checkedProperty.onChange { selected -> @@ -101,9 +90,9 @@ class StorageView : View(title = "Numass storage", icon = dfIconView) { } } - watchedProperty.onChange { - toggleWatch(it) - } +// watchedProperty.onChange { +// toggleWatch(it) +// } } val children: ObservableList? by lazy { @@ -114,7 +103,7 @@ class StorageView : View(title = "Numass storage", icon = dfIconView) { is NumassSet -> content.points .sortedBy { it.index } .map { buildContainer(it, this) } - .asObservable() + .toObservable() else -> null } } @@ -123,38 +112,38 @@ class StorageView : View(title = "Numass storage", icon = dfIconView) { private var watchJob: Job? = null - private fun toggleWatch(watch: Boolean) { - if (watch) { - if (watchJob != null && content is NumassDataLoader) { - watchJob = app.context.launch(Dispatchers.IO) { - val key: WatchKey = content.path.register(watcher!!, ENTRY_CREATE) - coroutineContext[Job]?.invokeOnCompletion { - key.cancel() - } - while (watcher != null && isActive) { - try { - key.pollEvents().forEach { event -> - if (event.kind() == ENTRY_CREATE) { - val path: Path = event.context() as Path - if (path.fileName.toString().startsWith(NumassDataLoader.POINT_FRAGMENT_NAME)) { - val envelope: Envelope = NumassEnvelopeType.infer(path)?.reader?.read(path) - ?: kotlin.error("Can't read point file") - val point = NumassDataUtils.read(envelope) - children!!.add(buildContainer(point, this@Container)) - } - } - } - } catch (x: Throwable) { - app.context.logger.error("Error during dynamic point read", x) - } - } - } - } - } else { - watchJob?.cancel() - watchJob = null - } - } +// private fun toggleWatch(watch: Boolean) { +// if (watch) { +// if (watchJob != null && content is NumassDataLoader) { +// watchJob = app.context.launch(Dispatchers.IO) { +// val key: WatchKey = content.path.register(watcher!!, ENTRY_CREATE) +// coroutineContext[Job]?.invokeOnCompletion { +// key.cancel() +// } +// while (watcher != null && isActive) { +// try { +// key.pollEvents().forEach { event -> +// if (event.kind() == ENTRY_CREATE) { +// val path: Path = event.context() as Path +// if (path.fileName.toString().startsWith(NumassDataLoader.POINT_FRAGMENT_NAME)) { +// val envelope: Envelope = NumassEnvelopeType.infer(path)?.reader?.read(path) +// ?: kotlin.error("Can't read point file") +// val point = NumassDataUtils.read(envelope) +// children!!.add(buildContainer(point, this@Container)) +// } +// } +// } +// } catch (x: Throwable) { +// app.context.logger.error("Error during dynamic point read", x) +// } +// } +// } +// } +// } else { +// watchJob?.cancel() +// watchJob = null +// } +// } } @@ -171,12 +160,12 @@ class StorageView : View(title = "Numass storage", icon = dfIconView) { }) { it.value.children } - watcher?.close() - watcher = if (storage is FileStorage) { - storage.path.fileSystem.newWatchService() - } else { - null - } +// watcher?.close() +// watcher = if (storage is FileStorage) { +// storage.path.fileSystem.newWatchService() +// } else { +// null +// } } cellFormat { value: Container -> @@ -219,11 +208,11 @@ class StorageView : View(title = "Numass storage", icon = dfIconView) { value.infoView.openModal(escapeClosesWindow = true) } } - if(value.content is NumassDataLoader) { - checkmenuitem("Watch") { - selectedProperty().bindBidirectional(value.watchedProperty) - } - } +// if(value.content is NumassDataLoader) { +// checkmenuitem("Watch") { +// selectedProperty().bindBidirectional(value.watchedProperty) +// } +// } } } }