Numass control room global update

This commit is contained in:
Alexander Nozik 2017-05-28 16:47:11 +03:00
parent 0c8fe56f78
commit b43267bded
5 changed files with 94 additions and 42 deletions

View File

@ -49,4 +49,28 @@ task debugWithDevice(dependsOn: classes, type: JavaExec) {
group "debug"
}
task startScriptWithDevices(type: CreateStartScripts){
applicationName = "control-room-devices"
mainClassName = mainClass
outputDir = new File(project.buildDir, 'scripts')
classpath = jar.outputs.files + project.configurations.devices
}
distributions{
devices{
contents {
into("lib") {
from jar
from configurations.devices
}
into("bin"){
from startScriptWithDevices
}
}
}
}

View File

@ -1,6 +1,7 @@
package inr.numass.control
import hep.dataforge.context.Context
import hep.dataforge.context.Global
import hep.dataforge.control.connections.Roles
import hep.dataforge.control.connections.StorageConnection
import hep.dataforge.meta.Meta
@ -9,51 +10,81 @@ import hep.dataforge.storage.api.Storage
import hep.dataforge.storage.commons.StorageFactory
import inr.numass.client.ClientUtils
import inr.numass.server.NumassStorageServerObject
import javafx.application.Application
import javafx.application.Platform
import javafx.beans.property.SimpleObjectProperty
import javafx.collections.FXCollections
import javafx.collections.ObservableList
import tornadofx.*
import java.io.File
/**
* Created by darksnake on 12-May-17.
*/
class BoardController() : Controller() {
class BoardController() : Controller(), AutoCloseable {
val devices: ObservableList<DeviceViewConnection<*>> = FXCollections.observableArrayList<DeviceViewConnection<*>>();
val contextProperty = SimpleObjectProperty<Context>(Global.instance())
var context: Context by contextProperty
private set
val storageProperty = SimpleObjectProperty<Storage>()
var storage by storageProperty
var storage: Storage? by storageProperty
private set
val serverManagerProperty = SimpleObjectProperty<ServerManager>()
var serverManager: ServerManager by serverManagerProperty
var serverManager: ServerManager? by serverManagerProperty
private set
fun load(context: Context, meta: Meta) {
fun load(app: Application) {
runAsync {
NumassControlUtils.getConfig(app).ifPresent {
val libDir = File(app.parameters.named.getOrDefault("libPath", "../lib"));
val contextBuilder = Context
.builder("NUMASS-SERVER");
if (libDir.exists()) {
Global.logger().info("Found library directory {}. Loading it into server context", libDir)
contextBuilder.classPath(libDir.listFiles { _, name -> name.endsWith(".jar") }.map { it.toURI().toURL() })
}
context = contextBuilder.build();
load(context, it);
}
}
}
private fun load(context: Context, meta: Meta) {
this.context = context;
devices.clear();
meta.getMetaList("device").forEach {
try {
devices.add(buildDeviceView(context, it));
Platform.runLater { devices.add(buildDeviceView(context, it)) };
} catch (ex: Exception) {
context.logger.error("Can't build device view", ex);
}
}
if (meta.hasMeta("storage")) {
storage = buildStorage(context, meta);
val st = buildStorage(context, meta);
val storageConnection = StorageConnection(storage);
devices.forEach {
if (it.device.acceptsRole(Roles.STORAGE_ROLE)) {
it.device.connect(storageConnection, Roles.STORAGE_ROLE);
}
}
Platform.runLater {
storage = st
meta.optMeta("server").ifPresent { serverMeta ->
val sm = context.pluginManager().getOrLoad(ServerManager::class.java);
sm.configure(serverMeta)
sm.bind(NumassStorageServerObject(serverManager, storage, "numass-storage"));
serverManager = sm
}
}
}
meta.optMeta("server").ifPresent { serverMeta ->
serverManager = context.pluginManager().getOrLoad(ServerManager::class.java);
serverManager.configure(serverMeta)
serverManager.bind(NumassStorageServerObject(serverManager, storage, "numass-storage"));
}
}
private fun buildDeviceView(context: Context, deviceMeta: Meta): DeviceViewConnection<*> {
@ -88,4 +119,11 @@ class BoardController() : Controller() {
}
return storage;
}
override fun close() {
devices.forEach {
it.close()
}
context.close();
}
}

View File

@ -38,11 +38,11 @@ class BoardView : View("Numass control board", ImageView(getDFIcon())) {
action {
if (isSelected) {
text = "Stop"
controller.serverManager.startServer()
serverLabel.text = controller.serverManager.link;
controller.serverManager?.startServer()
serverLabel.text = controller.serverManager?.link;
} else {
text = "Start"
controller.serverManager.stopServer()
controller.serverManager?.stopServer()
serverLabel.text = ""
}
}
@ -51,13 +51,13 @@ class BoardView : View("Numass control board", ImageView(getDFIcon())) {
paddingHorizontal = 5
}
indicator {
bind(controller.serverManager.isStarted)
bind(controller.serverManagerProperty.select { it.isStarted })
}
separator(Orientation.VERTICAL)
text("Address: ")
serverLabel = hyperlink {
action {
hostServices.showDocument(controller.serverManager.link);
hostServices.showDocument(controller.serverManager?.link);
}
}
}
@ -67,12 +67,16 @@ class BoardView : View("Numass control board", ImageView(getDFIcon())) {
hbox {
alignment = Pos.CENTER_LEFT
prefHeight = 40.0
label(stringBinding(controller.storage) {
label(stringBinding(controller.storageProperty) {
val storage = controller.storage
if (storage is FileStorage) {
"Path: " + storage.dataDir;
if (storage == null) {
"Storage not initialized"
} else {
"Name: " + controller.storage.fullPath
if (storage is FileStorage) {
"Path: " + storage.dataDir;
} else {
"Name: " + storage.fullPath
}
}
})
}
@ -87,7 +91,7 @@ class BoardView : View("Numass control board", ImageView(getDFIcon())) {
hbox {
alignment = Pos.CENTER_LEFT
vgrow = Priority.ALWAYS;
deviceStateIndicator(connection,Device.INITIALIZED_STATE)
deviceStateIndicator(connection, Device.INITIALIZED_STATE)
deviceStateIndicator(connection, PortSensor.CONNECTED_STATE)
deviceStateIndicator(connection, Sensor.MEASURING_STATE)
deviceStateIndicator(connection, "storing")

View File

@ -40,9 +40,11 @@ class Indicator(radius: Double = 10.0) : Circle(radius, Color.GRAY) {
/**
* bind indicator to the boolean value using default colours
*/
fun bind(booleanValue: ObservableValue<Boolean>) {
fun bind(booleanValue: ObservableValue<Boolean?>) {
bind(booleanValue) {
if (it) {
if (it == null) {
Color.GRAY
} else if (it) {
Color.GREEN;
} else {
Color.RED;

View File

@ -1,39 +1,23 @@
package inr.numass.control
import hep.dataforge.context.Context
import hep.dataforge.context.Global
import javafx.stage.Stage
import tornadofx.*
import java.io.File
/**
* Created by darksnake on 19-May-17.
*/
class ServerApp : App(BoardView::class) {
val controller: BoardController by inject();
var context: Context by singleAssign();
override fun start(stage: Stage) {
NumassControlUtils.getConfig(this).ifPresent {
val libDir = File(parameters.named.getOrDefault("libPath", "../lib"));
val contextBuilder = Context
.builder("NUMASS-SERVER");
if (libDir.exists()) {
Global.logger().info("Found library directory {}. Loading it into server context", libDir)
contextBuilder.classPath(libDir.listFiles { _, name -> name.endsWith(".jar") }.map { it.toURI().toURL() })
}
context = contextBuilder.build();
controller.load(context, it);
}
controller.load(this)
super.start(stage)
NumassControlUtils.setDFStageIcon(stage)
}
override fun stop() {
controller.devices.forEach {
it.device.shutdown()
}
controller.close()
super.stop()
context.close();
}
}