Numass control room global update
This commit is contained in:
parent
0c8fe56f78
commit
b43267bded
@ -49,4 +49,28 @@ task debugWithDevice(dependsOn: classes, type: JavaExec) {
|
|||||||
group "debug"
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package inr.numass.control
|
package inr.numass.control
|
||||||
|
|
||||||
import hep.dataforge.context.Context
|
import hep.dataforge.context.Context
|
||||||
|
import hep.dataforge.context.Global
|
||||||
import hep.dataforge.control.connections.Roles
|
import hep.dataforge.control.connections.Roles
|
||||||
import hep.dataforge.control.connections.StorageConnection
|
import hep.dataforge.control.connections.StorageConnection
|
||||||
import hep.dataforge.meta.Meta
|
import hep.dataforge.meta.Meta
|
||||||
@ -9,52 +10,82 @@ import hep.dataforge.storage.api.Storage
|
|||||||
import hep.dataforge.storage.commons.StorageFactory
|
import hep.dataforge.storage.commons.StorageFactory
|
||||||
import inr.numass.client.ClientUtils
|
import inr.numass.client.ClientUtils
|
||||||
import inr.numass.server.NumassStorageServerObject
|
import inr.numass.server.NumassStorageServerObject
|
||||||
|
import javafx.application.Application
|
||||||
|
import javafx.application.Platform
|
||||||
import javafx.beans.property.SimpleObjectProperty
|
import javafx.beans.property.SimpleObjectProperty
|
||||||
import javafx.collections.FXCollections
|
import javafx.collections.FXCollections
|
||||||
import javafx.collections.ObservableList
|
import javafx.collections.ObservableList
|
||||||
import tornadofx.*
|
import tornadofx.*
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by darksnake on 12-May-17.
|
* Created by darksnake on 12-May-17.
|
||||||
*/
|
*/
|
||||||
class BoardController() : Controller() {
|
class BoardController() : Controller(), AutoCloseable {
|
||||||
val devices: ObservableList<DeviceViewConnection<*>> = FXCollections.observableArrayList<DeviceViewConnection<*>>();
|
val devices: ObservableList<DeviceViewConnection<*>> = FXCollections.observableArrayList<DeviceViewConnection<*>>();
|
||||||
|
|
||||||
|
val contextProperty = SimpleObjectProperty<Context>(Global.instance())
|
||||||
|
var context: Context by contextProperty
|
||||||
|
private set
|
||||||
|
|
||||||
val storageProperty = SimpleObjectProperty<Storage>()
|
val storageProperty = SimpleObjectProperty<Storage>()
|
||||||
var storage by storageProperty
|
var storage: Storage? by storageProperty
|
||||||
private set
|
private set
|
||||||
|
|
||||||
val serverManagerProperty = SimpleObjectProperty<ServerManager>()
|
val serverManagerProperty = SimpleObjectProperty<ServerManager>()
|
||||||
var serverManager: ServerManager by serverManagerProperty
|
var serverManager: ServerManager? by serverManagerProperty
|
||||||
private set
|
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();
|
devices.clear();
|
||||||
meta.getMetaList("device").forEach {
|
meta.getMetaList("device").forEach {
|
||||||
try {
|
try {
|
||||||
devices.add(buildDeviceView(context, it));
|
Platform.runLater { devices.add(buildDeviceView(context, it)) };
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
context.logger.error("Can't build device view", ex);
|
context.logger.error("Can't build device view", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (meta.hasMeta("storage")) {
|
if (meta.hasMeta("storage")) {
|
||||||
storage = buildStorage(context, meta);
|
val st = buildStorage(context, meta);
|
||||||
val storageConnection = StorageConnection(storage);
|
val storageConnection = StorageConnection(storage);
|
||||||
devices.forEach {
|
devices.forEach {
|
||||||
if (it.device.acceptsRole(Roles.STORAGE_ROLE)) {
|
if (it.device.acceptsRole(Roles.STORAGE_ROLE)) {
|
||||||
it.device.connect(storageConnection, Roles.STORAGE_ROLE);
|
it.device.connect(storageConnection, Roles.STORAGE_ROLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
Platform.runLater {
|
||||||
|
storage = st
|
||||||
meta.optMeta("server").ifPresent { serverMeta ->
|
meta.optMeta("server").ifPresent { serverMeta ->
|
||||||
serverManager = context.pluginManager().getOrLoad(ServerManager::class.java);
|
val sm = context.pluginManager().getOrLoad(ServerManager::class.java);
|
||||||
serverManager.configure(serverMeta)
|
sm.configure(serverMeta)
|
||||||
|
|
||||||
serverManager.bind(NumassStorageServerObject(serverManager, storage, "numass-storage"));
|
sm.bind(NumassStorageServerObject(serverManager, storage, "numass-storage"));
|
||||||
|
serverManager = sm
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private fun buildDeviceView(context: Context, deviceMeta: Meta): DeviceViewConnection<*> {
|
private fun buildDeviceView(context: Context, deviceMeta: Meta): DeviceViewConnection<*> {
|
||||||
context.logger.info("Building device with meta: {}", deviceMeta)
|
context.logger.info("Building device with meta: {}", deviceMeta)
|
||||||
@ -88,4 +119,11 @@ class BoardController() : Controller() {
|
|||||||
}
|
}
|
||||||
return storage;
|
return storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun close() {
|
||||||
|
devices.forEach {
|
||||||
|
it.close()
|
||||||
|
}
|
||||||
|
context.close();
|
||||||
|
}
|
||||||
}
|
}
|
@ -38,11 +38,11 @@ class BoardView : View("Numass control board", ImageView(getDFIcon())) {
|
|||||||
action {
|
action {
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
text = "Stop"
|
text = "Stop"
|
||||||
controller.serverManager.startServer()
|
controller.serverManager?.startServer()
|
||||||
serverLabel.text = controller.serverManager.link;
|
serverLabel.text = controller.serverManager?.link;
|
||||||
} else {
|
} else {
|
||||||
text = "Start"
|
text = "Start"
|
||||||
controller.serverManager.stopServer()
|
controller.serverManager?.stopServer()
|
||||||
serverLabel.text = ""
|
serverLabel.text = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -51,13 +51,13 @@ class BoardView : View("Numass control board", ImageView(getDFIcon())) {
|
|||||||
paddingHorizontal = 5
|
paddingHorizontal = 5
|
||||||
}
|
}
|
||||||
indicator {
|
indicator {
|
||||||
bind(controller.serverManager.isStarted)
|
bind(controller.serverManagerProperty.select { it.isStarted })
|
||||||
}
|
}
|
||||||
separator(Orientation.VERTICAL)
|
separator(Orientation.VERTICAL)
|
||||||
text("Address: ")
|
text("Address: ")
|
||||||
serverLabel = hyperlink {
|
serverLabel = hyperlink {
|
||||||
action {
|
action {
|
||||||
hostServices.showDocument(controller.serverManager.link);
|
hostServices.showDocument(controller.serverManager?.link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -67,12 +67,16 @@ class BoardView : View("Numass control board", ImageView(getDFIcon())) {
|
|||||||
hbox {
|
hbox {
|
||||||
alignment = Pos.CENTER_LEFT
|
alignment = Pos.CENTER_LEFT
|
||||||
prefHeight = 40.0
|
prefHeight = 40.0
|
||||||
label(stringBinding(controller.storage) {
|
label(stringBinding(controller.storageProperty) {
|
||||||
val storage = controller.storage
|
val storage = controller.storage
|
||||||
|
if (storage == null) {
|
||||||
|
"Storage not initialized"
|
||||||
|
} else {
|
||||||
if (storage is FileStorage) {
|
if (storage is FileStorage) {
|
||||||
"Path: " + storage.dataDir;
|
"Path: " + storage.dataDir;
|
||||||
} else {
|
} else {
|
||||||
"Name: " + controller.storage.fullPath
|
"Name: " + storage.fullPath
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -87,7 +91,7 @@ class BoardView : View("Numass control board", ImageView(getDFIcon())) {
|
|||||||
hbox {
|
hbox {
|
||||||
alignment = Pos.CENTER_LEFT
|
alignment = Pos.CENTER_LEFT
|
||||||
vgrow = Priority.ALWAYS;
|
vgrow = Priority.ALWAYS;
|
||||||
deviceStateIndicator(connection,Device.INITIALIZED_STATE)
|
deviceStateIndicator(connection, Device.INITIALIZED_STATE)
|
||||||
deviceStateIndicator(connection, PortSensor.CONNECTED_STATE)
|
deviceStateIndicator(connection, PortSensor.CONNECTED_STATE)
|
||||||
deviceStateIndicator(connection, Sensor.MEASURING_STATE)
|
deviceStateIndicator(connection, Sensor.MEASURING_STATE)
|
||||||
deviceStateIndicator(connection, "storing")
|
deviceStateIndicator(connection, "storing")
|
||||||
|
@ -40,9 +40,11 @@ class Indicator(radius: Double = 10.0) : Circle(radius, Color.GRAY) {
|
|||||||
/**
|
/**
|
||||||
* bind indicator to the boolean value using default colours
|
* bind indicator to the boolean value using default colours
|
||||||
*/
|
*/
|
||||||
fun bind(booleanValue: ObservableValue<Boolean>) {
|
fun bind(booleanValue: ObservableValue<Boolean?>) {
|
||||||
bind(booleanValue) {
|
bind(booleanValue) {
|
||||||
if (it) {
|
if (it == null) {
|
||||||
|
Color.GRAY
|
||||||
|
} else if (it) {
|
||||||
Color.GREEN;
|
Color.GREEN;
|
||||||
} else {
|
} else {
|
||||||
Color.RED;
|
Color.RED;
|
||||||
|
@ -1,39 +1,23 @@
|
|||||||
package inr.numass.control
|
package inr.numass.control
|
||||||
|
|
||||||
import hep.dataforge.context.Context
|
|
||||||
import hep.dataforge.context.Global
|
|
||||||
import javafx.stage.Stage
|
import javafx.stage.Stage
|
||||||
import tornadofx.*
|
import tornadofx.*
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by darksnake on 19-May-17.
|
* Created by darksnake on 19-May-17.
|
||||||
*/
|
*/
|
||||||
class ServerApp : App(BoardView::class) {
|
class ServerApp : App(BoardView::class) {
|
||||||
val controller: BoardController by inject();
|
val controller: BoardController by inject();
|
||||||
var context: Context by singleAssign();
|
|
||||||
|
|
||||||
override fun start(stage: Stage) {
|
override fun start(stage: Stage) {
|
||||||
NumassControlUtils.getConfig(this).ifPresent {
|
controller.load(this)
|
||||||
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);
|
|
||||||
}
|
|
||||||
super.start(stage)
|
super.start(stage)
|
||||||
NumassControlUtils.setDFStageIcon(stage)
|
NumassControlUtils.setDFStageIcon(stage)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun stop() {
|
override fun stop() {
|
||||||
controller.devices.forEach {
|
controller.close()
|
||||||
it.device.shutdown()
|
|
||||||
}
|
|
||||||
super.stop()
|
super.stop()
|
||||||
context.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user