Moving storage to kotlin

This commit is contained in:
Alexander Nozik 2018-03-05 10:41:45 +03:00
parent b2f0488a51
commit 89e8ed10f3
15 changed files with 42 additions and 40 deletions

View File

@ -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{

View File

@ -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();
}

View File

@ -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<PKT8Result>(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)
}

View File

@ -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

View File

@ -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.*

View File

@ -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<Values>(context, meta
val suffix = DateTimeUtils.fileSuffix()
return LoaderFactory
.buildPointLoder(storage, "msp_" + suffix, "", "timestamp", format)
.buildPointLoader(storage, "msp_" + suffix, "", "timestamp", format)
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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<S
val suffix = DateTimeUtils.fileSuffix()
return LoaderFactory.buildPointLoder(connection.storage, "vactms_" + suffix, "", "timestamp", format.build())
return LoaderFactory.buildPointLoader(connection.storage, "vactms_" + suffix, "", "timestamp", format.build())
}
override fun connectAll(connection: Connection, vararg roles: String) {

View File

@ -5,7 +5,7 @@
*/
package inr.numass.control.readvac
import hep.dataforge.control.Connection
import hep.dataforge.connections.Connection
import hep.dataforge.control.connections.Roles
import hep.dataforge.control.devices.Sensor
import hep.dataforge.control.measurements.Measurement

View File

@ -73,21 +73,21 @@ public class NumassEnvelopeType implements EnvelopeType {
Map<String, Value> 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;
}
}

View File

@ -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) {

View File

@ -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();
}

View File

@ -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");