From 89e8ed10f3be0fb24780a9ba26831bc106ec256f Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 5 Mar 2018 10:41:45 +0300 Subject: [PATCH] Moving storage to kotlin --- build.gradle | 4 ++-- .../main/java/inr/numass/client/NumassClient.java | 11 +++++------ .../kotlin/inr/numass/control/cryotemp/PKT8Device.kt | 8 ++++---- .../kotlin/inr/numass/control/magnet/LambdaHub.kt | 2 +- .../kotlin/inr/numass/control/magnet/LambdaMagnet.kt | 7 ++++++- .../main/kotlin/inr/numass/control/msp/MspDevice.kt | 12 ++++++------ .../main/kotlin/inr/numass/control/msp/MspDisplay.kt | 2 +- .../main/kotlin/inr/numass/control/DeviceDisplay.kt | 2 +- .../inr/numass/control/readvac/MKSVacDevice.kt | 4 ++-- .../inr/numass/control/readvac/VacCollectorDevice.kt | 9 ++++----- .../numass/control/readvac/VacCollectorDisplay.kt | 2 +- .../src/main/java/inr/numass/NumassEnvelopeType.java | 8 ++++---- .../src/main/java/inr/numass/server/NumassRun.java | 5 ++--- .../main/java/inr/numass/server/NumassServer.java | 4 ++-- .../inr/numass/scripts/TestStorageAccess.groovy | 2 +- 15 files changed, 42 insertions(+), 40 deletions(-) diff --git a/build.gradle b/build.gradle index 28e103b9..67fc2383 100644 --- a/build.gradle +++ b/build.gradle @@ -1,9 +1,9 @@ buildscript { - ext.kotlin_version = "1.2.21" + ext.kotlin_version = "1.2.30" } plugins { - id "org.jetbrains.kotlin.jvm" version "1.2.21" apply false + id "org.jetbrains.kotlin.jvm" version "1.2.30" apply false } allprojects{ diff --git a/numass-client/src/main/java/inr/numass/client/NumassClient.java b/numass-client/src/main/java/inr/numass/client/NumassClient.java index d0cc07c4..354dafcc 100644 --- a/numass-client/src/main/java/inr/numass/client/NumassClient.java +++ b/numass-client/src/main/java/inr/numass/client/NumassClient.java @@ -22,7 +22,6 @@ import hep.dataforge.io.envelopes.EnvelopeBuilder; import hep.dataforge.io.messages.Responder; import hep.dataforge.meta.Meta; import hep.dataforge.meta.MetaBuilder; -import hep.dataforge.storage.commons.MessageFactory; import hep.dataforge.storage.commons.StorageUtils; import hep.dataforge.values.Value; import hep.dataforge.values.Values; @@ -97,7 +96,7 @@ public class NumassClient implements AutoCloseable, Responder { public Meta startRun(String name) { return respond(requestActionBase("numass.run", "start") - .putMetaValue("path", name) + .setMetaValue("path", name) .build()).getMeta(); } @@ -154,7 +153,7 @@ public class NumassClient implements AutoCloseable, Responder { EnvelopeBuilder env = requestActionBase("numass.state", "get"); if (stateNames.length > 0) { - env.putMetaValue("name", Arrays.asList(stateNames)); + env.setMetaValue("name", Arrays.asList(stateNames)); } Meta response = respond(env.build()).getMeta(); @@ -205,9 +204,9 @@ public class NumassClient implements AutoCloseable, Responder { public Meta addNote(String text, Instant time) { EnvelopeBuilder env = requestActionBase("numass.notes", "push"); - env.putMetaValue("note.text", text); + env.setMetaValue("note.text", text); if (time != null) { - env.putMetaValue("note.time", time); + env.setMetaValue("note.time", time); } return respond(env.build()).getMeta(); } @@ -215,7 +214,7 @@ public class NumassClient implements AutoCloseable, Responder { public Meta getNotes(int limit) { EnvelopeBuilder env = requestActionBase("numass.notes", "pull"); if (limit > 0) { - env.putMetaValue("limit", limit); + env.setMetaValue("limit", limit); } return respond(env.build()).getMeta(); } diff --git a/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Device.kt b/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Device.kt index 578933a9..d43daecb 100644 --- a/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Device.kt +++ b/numass-control/cryotemp/src/main/kotlin/inr/numass/control/cryotemp/PKT8Device.kt @@ -15,19 +15,19 @@ */ package inr.numass.control.cryotemp +import hep.dataforge.connections.RoleDef +import hep.dataforge.connections.RoleDefs import hep.dataforge.context.Context -import hep.dataforge.control.RoleDef -import hep.dataforge.control.RoleDefs import hep.dataforge.control.connections.Roles import hep.dataforge.control.devices.PortSensor import hep.dataforge.control.devices.Sensor -import hep.dataforge.control.devices.StateDef import hep.dataforge.control.devices.stringState import hep.dataforge.control.ports.Port import hep.dataforge.description.ValueDef import hep.dataforge.exceptions.ControlException import hep.dataforge.exceptions.StorageException import hep.dataforge.meta.Meta +import hep.dataforge.states.StateDef import hep.dataforge.storage.api.TableLoader import hep.dataforge.storage.commons.LoaderFactory import hep.dataforge.storage.commons.StorageConnection @@ -89,7 +89,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor(context, val suffix = DateTimeUtils.fileSuffix() try { - return LoaderFactory.buildPointLoder(storage, "cryotemp_" + suffix, "", "timestamp", tableFormat) + return LoaderFactory.buildPointLoader(storage, "cryotemp_" + suffix, "", "timestamp", tableFormat) } catch (e: StorageException) { throw RuntimeException("Failed to builder loader from storage", e) } diff --git a/numass-control/magnet/src/main/kotlin/inr/numass/control/magnet/LambdaHub.kt b/numass-control/magnet/src/main/kotlin/inr/numass/control/magnet/LambdaHub.kt index 2ae153e2..7874dc02 100644 --- a/numass-control/magnet/src/main/kotlin/inr/numass/control/magnet/LambdaHub.kt +++ b/numass-control/magnet/src/main/kotlin/inr/numass/control/magnet/LambdaHub.kt @@ -4,13 +4,13 @@ import hep.dataforge.context.Context import hep.dataforge.control.devices.AbstractDevice import hep.dataforge.control.devices.Device import hep.dataforge.control.devices.DeviceHub -import hep.dataforge.control.devices.StateDef import hep.dataforge.control.ports.Port import hep.dataforge.control.ports.PortFactory import hep.dataforge.description.ValueDef import hep.dataforge.kodex.useEachMeta import hep.dataforge.meta.Meta import hep.dataforge.names.Name +import hep.dataforge.states.StateDef import hep.dataforge.values.ValueType import java.util.* import java.util.stream.Stream diff --git a/numass-control/magnet/src/main/kotlin/inr/numass/control/magnet/LambdaMagnet.kt b/numass-control/magnet/src/main/kotlin/inr/numass/control/magnet/LambdaMagnet.kt index 01199df0..16dd9631 100644 --- a/numass-control/magnet/src/main/kotlin/inr/numass/control/magnet/LambdaMagnet.kt +++ b/numass-control/magnet/src/main/kotlin/inr/numass/control/magnet/LambdaMagnet.kt @@ -16,12 +16,17 @@ package inr.numass.control.magnet import hep.dataforge.context.Context -import hep.dataforge.control.devices.* +import hep.dataforge.control.devices.AbstractDevice +import hep.dataforge.control.devices.booleanState +import hep.dataforge.control.devices.doubleState +import hep.dataforge.control.devices.timeState import hep.dataforge.control.ports.PortFactory import hep.dataforge.description.ValueDef import hep.dataforge.exceptions.ControlException import hep.dataforge.exceptions.PortException import hep.dataforge.meta.Meta +import hep.dataforge.states.StateDef +import hep.dataforge.states.StateDefs import hep.dataforge.utils.DateTimeUtils import hep.dataforge.values.Value import hep.dataforge.values.ValueType.* diff --git a/numass-control/msp/src/main/kotlin/inr/numass/control/msp/MspDevice.kt b/numass-control/msp/src/main/kotlin/inr/numass/control/msp/MspDevice.kt index d1a0040e..c592c58e 100644 --- a/numass-control/msp/src/main/kotlin/inr/numass/control/msp/MspDevice.kt +++ b/numass-control/msp/src/main/kotlin/inr/numass/control/msp/MspDevice.kt @@ -15,16 +15,14 @@ */ package inr.numass.control.msp +import hep.dataforge.connections.NamedValueListener +import hep.dataforge.connections.RoleDef +import hep.dataforge.connections.RoleDefs import hep.dataforge.context.Context -import hep.dataforge.control.NamedValueListener -import hep.dataforge.control.RoleDef -import hep.dataforge.control.RoleDefs import hep.dataforge.control.collectors.RegularPointCollector import hep.dataforge.control.connections.Roles import hep.dataforge.control.devices.Device import hep.dataforge.control.devices.PortSensor -import hep.dataforge.control.devices.StateDef -import hep.dataforge.control.devices.StateDefs import hep.dataforge.control.measurements.AbstractMeasurement import hep.dataforge.control.ports.Port import hep.dataforge.description.ValueDef @@ -32,6 +30,8 @@ import hep.dataforge.exceptions.ControlException import hep.dataforge.exceptions.MeasurementException import hep.dataforge.exceptions.PortException import hep.dataforge.meta.Meta +import hep.dataforge.states.StateDef +import hep.dataforge.states.StateDefs import hep.dataforge.storage.api.TableLoader import hep.dataforge.storage.commons.LoaderFactory import hep.dataforge.storage.commons.StorageConnection @@ -369,7 +369,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta val suffix = DateTimeUtils.fileSuffix() return LoaderFactory - .buildPointLoder(storage, "msp_" + suffix, "", "timestamp", format) + .buildPointLoader(storage, "msp_" + suffix, "", "timestamp", format) } diff --git a/numass-control/msp/src/main/kotlin/inr/numass/control/msp/MspDisplay.kt b/numass-control/msp/src/main/kotlin/inr/numass/control/msp/MspDisplay.kt index 959b4b87..db7cf2a7 100644 --- a/numass-control/msp/src/main/kotlin/inr/numass/control/msp/MspDisplay.kt +++ b/numass-control/msp/src/main/kotlin/inr/numass/control/msp/MspDisplay.kt @@ -15,7 +15,7 @@ */ package inr.numass.control.msp -import hep.dataforge.control.NamedValueListener +import hep.dataforge.connections.NamedValueListener import hep.dataforge.control.devices.DeviceListener import hep.dataforge.control.devices.PortSensor import hep.dataforge.control.devices.Sensor diff --git a/numass-control/src/main/kotlin/inr/numass/control/DeviceDisplay.kt b/numass-control/src/main/kotlin/inr/numass/control/DeviceDisplay.kt index 5a7d5486..e1bf192e 100644 --- a/numass-control/src/main/kotlin/inr/numass/control/DeviceDisplay.kt +++ b/numass-control/src/main/kotlin/inr/numass/control/DeviceDisplay.kt @@ -1,6 +1,6 @@ package inr.numass.control -import hep.dataforge.control.Connection +import hep.dataforge.connections.Connection import hep.dataforge.control.connections.Roles import hep.dataforge.control.devices.Device import hep.dataforge.control.devices.DeviceListener diff --git a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MKSVacDevice.kt b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MKSVacDevice.kt index 575124c8..ebb3e197 100644 --- a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MKSVacDevice.kt +++ b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MKSVacDevice.kt @@ -8,8 +8,6 @@ package inr.numass.control.readvac import hep.dataforge.context.Context import hep.dataforge.control.devices.Device import hep.dataforge.control.devices.PortSensor -import hep.dataforge.control.devices.StateDef -import hep.dataforge.control.devices.StateDefs import hep.dataforge.control.measurements.Measurement import hep.dataforge.control.measurements.SimpleMeasurement import hep.dataforge.control.ports.Port @@ -17,6 +15,8 @@ import hep.dataforge.description.ValueDef import hep.dataforge.description.ValueDefs import hep.dataforge.exceptions.ControlException import hep.dataforge.meta.Meta +import hep.dataforge.states.StateDef +import hep.dataforge.states.StateDefs import hep.dataforge.values.Value import hep.dataforge.values.ValueType.BOOLEAN import inr.numass.control.DeviceView diff --git a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacCollectorDevice.kt b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacCollectorDevice.kt index 732d81ab..09ab213f 100644 --- a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacCollectorDevice.kt +++ b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacCollectorDevice.kt @@ -5,22 +5,21 @@ */ package inr.numass.control.readvac +import hep.dataforge.connections.Connection +import hep.dataforge.connections.RoleDef import hep.dataforge.context.Context -import hep.dataforge.control.Connection -import hep.dataforge.control.RoleDef import hep.dataforge.control.collectors.RegularPointCollector import hep.dataforge.control.connections.Roles import hep.dataforge.control.devices.Device import hep.dataforge.control.devices.DeviceHub -import hep.dataforge.control.devices.PortSensor.CONNECTED_STATE import hep.dataforge.control.devices.Sensor -import hep.dataforge.control.devices.StateDef import hep.dataforge.control.measurements.AbstractMeasurement import hep.dataforge.control.measurements.Measurement import hep.dataforge.description.ValueDef import hep.dataforge.exceptions.ControlException import hep.dataforge.meta.Meta import hep.dataforge.names.Name +import hep.dataforge.states.StateDef import hep.dataforge.storage.api.TableLoader import hep.dataforge.storage.commons.LoaderFactory import hep.dataforge.storage.commons.StorageConnection @@ -88,7 +87,7 @@ class VacCollectorDevice(context: Context, meta: Meta, val sensors: Collection res = new HashMap<>(); int type = buffer.getInt(2); - res.put(Envelope.Companion.TYPE_KEY, Value.of(type)); + res.put(Envelope.Companion.TYPE_PROPERTY, Value.of(type)); short metaTypeCode = buffer.getShort(10); MetaType metaType = MetaType.Companion.resolve(metaTypeCode); if (metaType != null) { - res.put(Envelope.Companion.META_TYPE_KEY, Value.of(metaType.getName())); + res.put(Envelope.Companion.META_TYPE_PROPERTY, Value.of(metaType.getName())); } else { LoggerFactory.getLogger(EnvelopeTag.class).warn("Could not resolve meta type. Using default"); } long metaLength = Integer.toUnsignedLong(buffer.getInt(14)); - res.put(Envelope.Companion.META_LENGTH_KEY, Value.of(metaLength)); + res.put(Envelope.Companion.META_LENGTH_PROPERTY, Value.of(metaLength)); long dataLength = Integer.toUnsignedLong(buffer.getInt(22)); - res.put(Envelope.Companion.DATA_LENGTH_KEY, Value.of(dataLength)); + res.put(Envelope.Companion.DATA_LENGTH_PROPERTY, Value.of(dataLength)); return res; } } diff --git a/numass-server/src/main/java/inr/numass/server/NumassRun.java b/numass-server/src/main/java/inr/numass/server/NumassRun.java index 81d8b451..f77af2ef 100644 --- a/numass-server/src/main/java/inr/numass/server/NumassRun.java +++ b/numass-server/src/main/java/inr/numass/server/NumassRun.java @@ -25,7 +25,6 @@ import hep.dataforge.storage.api.ObjectLoader; import hep.dataforge.storage.api.StateLoader; import hep.dataforge.storage.api.Storage; import hep.dataforge.storage.commons.LoaderFactory; -import hep.dataforge.storage.commons.MessageFactory; import hep.dataforge.values.Value; import inr.numass.data.storage.NumassStorage; import org.slf4j.Logger; @@ -82,11 +81,11 @@ public class NumassRun implements Metoid, Responder { } public void setState(String name, Value value) throws StorageException { - states.pushState(name, value); + states.push(name, value); } public void setState(String name, Object value) throws StorageException { - states.pushState(name, Value.of(value)); + states.push(name, Value.of(value)); } public boolean hasState(String name) { diff --git a/numass-server/src/main/java/inr/numass/server/NumassServer.java b/numass-server/src/main/java/inr/numass/server/NumassServer.java index 9c32c5f8..ee0bab18 100644 --- a/numass-server/src/main/java/inr/numass/server/NumassServer.java +++ b/numass-server/src/main/java/inr/numass/server/NumassServer.java @@ -101,7 +101,7 @@ public class NumassServer extends AbstractNetworkListener implements ContextAwar String path = meta.getString("path", DEFAULT_RUN_PATH); Storage storage = StorageUtils.getOrBuildShelf(root, path, meta); run = new NumassRun(path, storage, getResponseFactory()); - getRootState().pushState("numass.current.run", path); + getRootState().push("numass.current.run", path); } /** @@ -167,7 +167,7 @@ public class NumassServer extends AbstractNetworkListener implements ContextAwar * Reset run to default */ public void resetRun() throws StorageException { - getRootState().pushState("numass.current.run", DEFAULT_RUN_PATH); + getRootState().push("numass.current.run", DEFAULT_RUN_PATH); updateRun(); } diff --git a/numass-test/src/main/groovy/inr/numass/scripts/TestStorageAccess.groovy b/numass-test/src/main/groovy/inr/numass/scripts/TestStorageAccess.groovy index 21850ad8..2b0dd426 100644 --- a/numass-test/src/main/groovy/inr/numass/scripts/TestStorageAccess.groovy +++ b/numass-test/src/main/groovy/inr/numass/scripts/TestStorageAccess.groovy @@ -30,7 +30,7 @@ new NumassClient("127.0.0.1",8335).withCloseable{ MetaBuilder target = new MetaBuilder("target") .setValue("type","loader") .setValue("name", "testPointLoader") - .putNode(LoaderFactory.buildDataPointLoaderMeta("testPointLoader","a", DataFormat.forNames("a", "b", "c")).rename("meta")) + .putNode(LoaderFactory.buildTableLoaderMeta("testPointLoader","a", DataFormat.forNames("a", "b", "c")).rename("meta")) MetaBuilder data = new MetaBuilder("data");