Remove directory watching for now.

This commit is contained in:
Alexander Nozik 2021-11-15 15:06:34 +03:00
parent 6e62b57e0d
commit 0ba8fea70f
3 changed files with 54 additions and 64 deletions

View File

@ -1,12 +1,13 @@
plugins { plugins {
kotlin("jvm") kotlin("jvm")
id("org.openjfx.javafxplugin") id("org.openjfx.javafxplugin")
//id("com.github.johnrengelman.shadow")
id("org.beryx.runtime") version "1.12.7" id("org.beryx.runtime") version "1.12.7"
application application
} }
javafx { javafx {
modules = listOf("javafx.controls", "javafx.web") modules = listOf("javafx.graphics", "javafx.controls", "javafx.web")
version = "11" version = "11"
} }
@ -57,7 +58,7 @@ runtime {
) )
jpackage { jpackage {
jvmArgs = addJvmArgs 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 { launcher {
jvmArgs = addJvmArgs jvmArgs = addJvmArgs

View File

@ -48,7 +48,7 @@ class PointCache : Controller() {
} }
} }
private val cache = Misc.getLRUCache<String, CachedPoint>(1000) private val cache = Misc.getLRUCache<String, CachedPoint>(400)
fun getCachedPoint(id: String,point: NumassPoint): CachedPoint = cache.getOrPut(id) { CachedPoint(point) } fun getCachedPoint(id: String,point: NumassPoint): CachedPoint = cache.getOrPut(id) { CachedPoint(point) }

View File

@ -2,16 +2,12 @@ package inr.numass.viewer
import hep.dataforge.fx.dfIconView import hep.dataforge.fx.dfIconView
import hep.dataforge.fx.meta.MetaViewer import hep.dataforge.fx.meta.MetaViewer
import hep.dataforge.io.envelopes.Envelope
import hep.dataforge.meta.Meta import hep.dataforge.meta.Meta
import hep.dataforge.meta.Metoid import hep.dataforge.meta.Metoid
import hep.dataforge.names.AlphanumComparator import hep.dataforge.names.AlphanumComparator
import hep.dataforge.storage.Storage import hep.dataforge.storage.Storage
import hep.dataforge.storage.files.FileStorage
import hep.dataforge.storage.files.FileTableLoader import hep.dataforge.storage.files.FileTableLoader
import hep.dataforge.storage.tables.TableLoader 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.NumassPoint
import inr.numass.data.api.NumassSet import inr.numass.data.api.NumassSet
import inr.numass.data.storage.NumassDataLoader import inr.numass.data.storage.NumassDataLoader
@ -20,15 +16,8 @@ import javafx.beans.property.SimpleObjectProperty
import javafx.collections.ObservableList import javafx.collections.ObservableList
import javafx.scene.control.ContextMenu import javafx.scene.control.ContextMenu
import javafx.scene.control.TreeItem import javafx.scene.control.TreeItem
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import tornadofx.* 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) { 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 hvView: HVView by inject()
private val scView: SlowControlView by inject() private val scView: SlowControlView by inject()
private var watcher: WatchService? = null // private var watcher: WatchService? = null
fun clear() { fun clear() {
watcher?.close() //watcher?.close()
ampView.clear() ampView.clear()
timeView.clear() timeView.clear()
spectrumView.clear() spectrumView.clear()
@ -68,7 +57,7 @@ class StorageView : View(title = "Numass storage", icon = dfIconView) {
} }
} }
val watchedProperty = SimpleBooleanProperty(false) //val watchedProperty = SimpleBooleanProperty(false)
init { init {
checkedProperty.onChange { selected -> checkedProperty.onChange { selected ->
@ -101,9 +90,9 @@ class StorageView : View(title = "Numass storage", icon = dfIconView) {
} }
} }
watchedProperty.onChange { // watchedProperty.onChange {
toggleWatch(it) // toggleWatch(it)
} // }
} }
val children: ObservableList<Container>? by lazy { val children: ObservableList<Container>? by lazy {
@ -114,7 +103,7 @@ class StorageView : View(title = "Numass storage", icon = dfIconView) {
is NumassSet -> content.points is NumassSet -> content.points
.sortedBy { it.index } .sortedBy { it.index }
.map { buildContainer(it, this) } .map { buildContainer(it, this) }
.asObservable() .toObservable()
else -> null else -> null
} }
} }
@ -123,38 +112,38 @@ class StorageView : View(title = "Numass storage", icon = dfIconView) {
private var watchJob: Job? = null private var watchJob: Job? = null
private fun toggleWatch(watch: Boolean) { // private fun toggleWatch(watch: Boolean) {
if (watch) { // if (watch) {
if (watchJob != null && content is NumassDataLoader) { // if (watchJob != null && content is NumassDataLoader) {
watchJob = app.context.launch(Dispatchers.IO) { // watchJob = app.context.launch(Dispatchers.IO) {
val key: WatchKey = content.path.register(watcher!!, ENTRY_CREATE) // val key: WatchKey = content.path.register(watcher!!, ENTRY_CREATE)
coroutineContext[Job]?.invokeOnCompletion { // coroutineContext[Job]?.invokeOnCompletion {
key.cancel() // key.cancel()
} // }
while (watcher != null && isActive) { // while (watcher != null && isActive) {
try { // try {
key.pollEvents().forEach { event -> // key.pollEvents().forEach { event ->
if (event.kind() == ENTRY_CREATE) { // if (event.kind() == ENTRY_CREATE) {
val path: Path = event.context() as Path // val path: Path = event.context() as Path
if (path.fileName.toString().startsWith(NumassDataLoader.POINT_FRAGMENT_NAME)) { // if (path.fileName.toString().startsWith(NumassDataLoader.POINT_FRAGMENT_NAME)) {
val envelope: Envelope = NumassEnvelopeType.infer(path)?.reader?.read(path) // val envelope: Envelope = NumassEnvelopeType.infer(path)?.reader?.read(path)
?: kotlin.error("Can't read point file") // ?: kotlin.error("Can't read point file")
val point = NumassDataUtils.read(envelope) // val point = NumassDataUtils.read(envelope)
children!!.add(buildContainer(point, this@Container)) // children!!.add(buildContainer(point, this@Container))
} // }
} // }
} // }
} catch (x: Throwable) { // } catch (x: Throwable) {
app.context.logger.error("Error during dynamic point read", x) // app.context.logger.error("Error during dynamic point read", x)
} // }
} // }
} // }
} // }
} else { // } else {
watchJob?.cancel() // watchJob?.cancel()
watchJob = null // watchJob = null
} // }
} // }
} }
@ -171,12 +160,12 @@ class StorageView : View(title = "Numass storage", icon = dfIconView) {
}) { }) {
it.value.children it.value.children
} }
watcher?.close() // watcher?.close()
watcher = if (storage is FileStorage) { // watcher = if (storage is FileStorage) {
storage.path.fileSystem.newWatchService() // storage.path.fileSystem.newWatchService()
} else { // } else {
null // null
} // }
} }
cellFormat { value: Container -> cellFormat { value: Container ->
@ -219,11 +208,11 @@ class StorageView : View(title = "Numass storage", icon = dfIconView) {
value.infoView.openModal(escapeClosesWindow = true) value.infoView.openModal(escapeClosesWindow = true)
} }
} }
if(value.content is NumassDataLoader) { // if(value.content is NumassDataLoader) {
checkmenuitem("Watch") { // checkmenuitem("Watch") {
selectedProperty().bindBidirectional(value.watchedProperty) // selectedProperty().bindBidirectional(value.watchedProperty)
} // }
} // }
} }
} }
} }