diff --git a/numass-client/src/main/java/inr/numass/client/RemoteNumassStorage.java b/numass-client/src/main/java/inr/numass/client/RemoteNumassStorage.java deleted file mode 100644 index 1b5eb93e..00000000 --- a/numass-client/src/main/java/inr/numass/client/RemoteNumassStorage.java +++ /dev/null @@ -1,50 +0,0 @@ -package inr.numass.client; - -import hep.dataforge.exceptions.StorageException; -import hep.dataforge.meta.Meta; -import hep.dataforge.storage.api.Loader; -import hep.dataforge.storage.api.Storage; -import hep.dataforge.storage.commons.AbstractStorage; - -import java.io.IOException; - -/** - * Created by darksnake on 09-Oct-16. - */ -public class RemoteNumassStorage extends AbstractStorage { - private NumassClient client; - - - private RemoteNumassStorage(Storage parent, String name, Meta annotation) { - super(parent, name, annotation); - } - - public RemoteNumassStorage(String name) { - super(name); - } - - private String getIP() { - return meta().getString("numass.server.ip", "192.168.111.1"); - } - - private int getPort() { - return meta().getInt("numass.server.port", 8335); - } - - private NumassClient getClient() throws IOException { - if (client == null) { - client = new NumassClient(getIP(), getPort()); - } - return client; - } - - @Override - public Loader buildLoader(Meta loaderConfiguration) throws StorageException { - throw new UnsupportedOperationException(); - } - - @Override - public Storage buildShelf(String shelfName, Meta shelfConfiguration) throws StorageException { - return new RemoteNumassStorage(this, shelfName, shelfConfiguration); - } -} diff --git a/numass-control/control-room/src/main/kotlin/inr/numass/control/BoardView.kt b/numass-control/control-room/src/main/kotlin/inr/numass/control/BoardView.kt index 2e70a4ac..1b939b0e 100644 --- a/numass-control/control-room/src/main/kotlin/inr/numass/control/BoardView.kt +++ b/numass-control/control-room/src/main/kotlin/inr/numass/control/BoardView.kt @@ -15,7 +15,6 @@ class BoardView : View("Numass control board") { deviceList = vbox { bindChildren(controller.devices) { DeviceInfoView(it).root } } - } } diff --git a/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8Device.java b/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8Device.java index e8161910..71824381 100644 --- a/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8Device.java +++ b/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8Device.java @@ -16,11 +16,11 @@ package inr.numass.cryotemp; import hep.dataforge.context.Context; +import hep.dataforge.control.RoleDef; import hep.dataforge.control.collectors.RegularPointCollector; import hep.dataforge.control.connections.Roles; import hep.dataforge.control.connections.StorageConnection; import hep.dataforge.control.devices.PortSensor; -import hep.dataforge.control.devices.annotations.RoleDef; import hep.dataforge.control.measurements.AbstractMeasurement; import hep.dataforge.control.measurements.Measurement; import hep.dataforge.control.ports.PortHandler; @@ -77,7 +77,7 @@ public class PKT8Device extends PortSensor { public PKT8Device(Context context, Meta meta) { setContext(context); - setMetaBase(meta); + setMeta(meta); } private PointLoader buildLoader(StorageConnection connection) { diff --git a/numass-control/msp/src/main/java/inr/numass/control/msp/MspDevice.java b/numass-control/msp/src/main/java/inr/numass/control/msp/MspDevice.java index ab3ffd60..8bbc46be 100644 --- a/numass-control/msp/src/main/java/inr/numass/control/msp/MspDevice.java +++ b/numass-control/msp/src/main/java/inr/numass/control/msp/MspDevice.java @@ -16,11 +16,11 @@ package inr.numass.control.msp; import hep.dataforge.context.Context; +import hep.dataforge.control.RoleDef; import hep.dataforge.control.connections.Roles; import hep.dataforge.control.connections.StorageConnection; import hep.dataforge.control.devices.SingleMeasurementDevice; -import hep.dataforge.control.devices.annotations.RoleDef; -import hep.dataforge.control.devices.annotations.StateDef; +import hep.dataforge.control.devices.StateDef; import hep.dataforge.control.measurements.AbstractMeasurement; import hep.dataforge.control.measurements.Measurement; import hep.dataforge.control.ports.PortHandler; @@ -75,7 +75,7 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po public MspDevice(Context context, Meta meta) { setContext(context); - setMetaBase(meta); + setMeta(meta); } // public MspDevice(String name, Context context, Meta config) { diff --git a/numass-control/src/main/java/inr/numass/control/NumassControlUtils.java b/numass-control/src/main/java/inr/numass/control/NumassControlUtils.java index f62782c2..8ccbc216 100644 --- a/numass-control/src/main/java/inr/numass/control/NumassControlUtils.java +++ b/numass-control/src/main/java/inr/numass/control/NumassControlUtils.java @@ -39,15 +39,18 @@ public class NumassControlUtils { String numassRun = ClientUtils.getRunName(config); config.getMetaList("storage").forEach(node -> { device.getContext().getLogger().debug("Creating storage for device with meta: {}", node); - Storage storage = StorageFactory.buildStorage(device.getContext(), node); - if (!numassRun.isEmpty()) { - try { - storage = storage.buildShelf(numassRun, Meta.empty()); - } catch (StorageException e) { - device.getContext().getLogger().error("Failed to build shelf", e); + //building storage in a separate thread + new Thread(() -> { + Storage storage = StorageFactory.buildStorage(device.getContext(), node); + if (!numassRun.isEmpty()) { + try { + storage = storage.buildShelf(numassRun, Meta.empty()); + } catch (StorageException e) { + device.getContext().getLogger().error("Failed to build shelf", e); + } } - } - device.connect(new StorageConnection(storage), Roles.STORAGE_ROLE); + device.connect(new StorageConnection(storage), Roles.STORAGE_ROLE); + }).start(); }); } } diff --git a/numass-control/vac/src/main/java/inr/numass/readvac/CM32Device.java b/numass-control/vac/src/main/java/inr/numass/readvac/CM32Device.java index 6df83ebc..6b122b21 100644 --- a/numass-control/vac/src/main/java/inr/numass/readvac/CM32Device.java +++ b/numass-control/vac/src/main/java/inr/numass/readvac/CM32Device.java @@ -28,7 +28,7 @@ public class CM32Device extends PortSensor { public CM32Device(Context context, Meta meta) { setContext(context); - setMetaBase(meta); + setMeta(meta); } @Override diff --git a/numass-control/vac/src/main/java/inr/numass/readvac/MKSBaratronDevice.java b/numass-control/vac/src/main/java/inr/numass/readvac/MKSBaratronDevice.java index 8f09c746..39110336 100644 --- a/numass-control/vac/src/main/java/inr/numass/readvac/MKSBaratronDevice.java +++ b/numass-control/vac/src/main/java/inr/numass/readvac/MKSBaratronDevice.java @@ -25,7 +25,7 @@ public class MKSBaratronDevice extends PortSensor { public MKSBaratronDevice(Context context, Meta meta) { setContext(context); - setMetaBase(meta); + setMeta(meta); } diff --git a/numass-control/vac/src/main/java/inr/numass/readvac/MKSVacDevice.java b/numass-control/vac/src/main/java/inr/numass/readvac/MKSVacDevice.java index 29f5a904..1640c9e8 100644 --- a/numass-control/vac/src/main/java/inr/numass/readvac/MKSVacDevice.java +++ b/numass-control/vac/src/main/java/inr/numass/readvac/MKSVacDevice.java @@ -7,7 +7,7 @@ package inr.numass.readvac; import hep.dataforge.context.Context; import hep.dataforge.control.devices.PortSensor; -import hep.dataforge.control.devices.annotations.StateDef; +import hep.dataforge.control.devices.StateDef; import hep.dataforge.control.measurements.Measurement; import hep.dataforge.control.measurements.SimpleMeasurement; import hep.dataforge.control.ports.PortHandler; @@ -35,7 +35,7 @@ public class MKSVacDevice extends PortSensor { public MKSVacDevice(Context context, Meta meta) { setContext(context); - setMetaBase(meta); + setMeta(meta); } private String talk(String requestContent) throws ControlException { diff --git a/numass-control/vac/src/main/java/inr/numass/readvac/MeradatVacDevice.java b/numass-control/vac/src/main/java/inr/numass/readvac/MeradatVacDevice.java index 09d536be..0b76afba 100644 --- a/numass-control/vac/src/main/java/inr/numass/readvac/MeradatVacDevice.java +++ b/numass-control/vac/src/main/java/inr/numass/readvac/MeradatVacDevice.java @@ -30,7 +30,7 @@ public class MeradatVacDevice extends PortSensor { public MeradatVacDevice(Context context, Meta meta) { setContext(context); - setMetaBase(meta); + setMeta(meta); } @Override diff --git a/numass-control/vac/src/main/java/inr/numass/readvac/VacCollectorDevice.java b/numass-control/vac/src/main/java/inr/numass/readvac/VacCollectorDevice.java index c81b79ca..49601d69 100644 --- a/numass-control/vac/src/main/java/inr/numass/readvac/VacCollectorDevice.java +++ b/numass-control/vac/src/main/java/inr/numass/readvac/VacCollectorDevice.java @@ -5,17 +5,19 @@ */ package inr.numass.readvac; +import hep.dataforge.context.Context; +import hep.dataforge.control.RoleDef; import hep.dataforge.control.collectors.PointCollector; import hep.dataforge.control.collectors.ValueCollector; import hep.dataforge.control.connections.Roles; import hep.dataforge.control.connections.StorageConnection; -import hep.dataforge.control.devices.annotations.RoleDef; -import hep.dataforge.control.devices.annotations.StateDef; +import hep.dataforge.control.devices.StateDef; import hep.dataforge.control.measurements.AbstractMeasurement; import hep.dataforge.control.measurements.Measurement; import hep.dataforge.control.measurements.Sensor; import hep.dataforge.exceptions.ControlException; import hep.dataforge.exceptions.MeasurementException; +import hep.dataforge.meta.Meta; import hep.dataforge.storage.api.PointLoader; import hep.dataforge.storage.commons.LoaderFactory; import hep.dataforge.tables.DataPoint; @@ -45,6 +47,16 @@ import java.util.concurrent.TimeUnit; public class VacCollectorDevice extends Sensor { private Map> sensorMap = new LinkedHashMap<>(); + private int delay = 5000; + + public VacCollectorDevice() { + } + + public VacCollectorDevice(Context context, Meta meta) { + setContext(context); + setMeta(meta); + } + public void setSensors(Iterable> sensors) { sensorMap = new LinkedHashMap<>(); @@ -84,7 +96,7 @@ public class VacCollectorDevice extends Sensor { } public void setDelay(int delay) throws MeasurementException { - getConfig().setValue("delay", delay); + this.delay = 5000; if (isMeasuring()) { getMeasurement().stop(false); getMeasurement().start(); @@ -119,7 +131,7 @@ public class VacCollectorDevice extends Sensor { sensorMap.values().forEach((sensor) -> { try { Object value; - if(sensor.optBooleanState("disabled").orElse(false)){ + if (sensor.optBooleanState("disabled").orElse(false)) { value = null; } else { value = sensor.read(); @@ -129,7 +141,7 @@ public class VacCollectorDevice extends Sensor { collector.put(sensor.getName(), Value.NULL); } }); - }, 0, meta().getInt("delay", 5000), TimeUnit.MILLISECONDS); + }, 0, delay, TimeUnit.MILLISECONDS); } @Override diff --git a/numass-control/vac/src/main/java/inr/numass/readvac/VacDeviceFactory.java b/numass-control/vac/src/main/java/inr/numass/readvac/VacDeviceFactory.java index fe8bf54d..816eb609 100644 --- a/numass-control/vac/src/main/java/inr/numass/readvac/VacDeviceFactory.java +++ b/numass-control/vac/src/main/java/inr/numass/readvac/VacDeviceFactory.java @@ -38,8 +38,7 @@ public class VacDeviceFactory implements DeviceFactory { List> sensors = config.getMetaList("sensor").stream() .map(sensorConfig -> buildSensor(context, sensorConfig)).collect(Collectors.toList()); - VacCollectorDevice collector = new VacCollectorDevice(); - collector.configure(config); + VacCollectorDevice collector = new VacCollectorDevice(context, config); collector.setSensors(sensors); return collector; } diff --git a/numass-core/src/main/java/inr/numass/storage/NumassDataFactory.java b/numass-core/src/main/java/inr/numass/storage/NumassDataFactory.java index 13083bca..0fd2e870 100644 --- a/numass-core/src/main/java/inr/numass/storage/NumassDataFactory.java +++ b/numass-core/src/main/java/inr/numass/storage/NumassDataFactory.java @@ -24,11 +24,7 @@ public class NumassDataFactory extends DataFactory { @Override protected void buildChildren(Context context, DataTree.Builder builder, DataFilter filter, Meta meta) { - NumassStorage storage = NumassStorage.buildNumassRoot( - meta.getString("path"), - meta.getBoolean("readOnly", true), - meta.getBoolean("monitor", false) - ); + NumassStorage storage = new NumassStorage(context,meta); StorageUtils.loaderStream(storage).forEach(pair -> { if (pair.getValue() instanceof NumassData) { builder.putStatic(pair.getKey(), (NumassData) pair.getValue()); diff --git a/numass-core/src/main/java/inr/numass/storage/NumassStorage.java b/numass-core/src/main/java/inr/numass/storage/NumassStorage.java index 9d02c3cb..439adb88 100644 --- a/numass-core/src/main/java/inr/numass/storage/NumassStorage.java +++ b/numass-core/src/main/java/inr/numass/storage/NumassStorage.java @@ -15,14 +15,13 @@ */ package inr.numass.storage; +import hep.dataforge.context.Context; import hep.dataforge.events.BasicEvent; import hep.dataforge.events.EventBuilder; import hep.dataforge.exceptions.StorageException; import hep.dataforge.meta.Meta; -import hep.dataforge.meta.MetaBuilder; import hep.dataforge.storage.filestorage.FilePointLoader; import hep.dataforge.storage.filestorage.FileStorage; -import hep.dataforge.storage.filestorage.VFSUtils; import inr.numass.data.NMFile; import inr.numass.data.NumassData; import org.apache.commons.io.FilenameUtils; @@ -35,7 +34,6 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.net.URI; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; @@ -56,87 +54,17 @@ public class NumassStorage extends FileStorage { public static final String NUMASS_ZIP_EXTENSION = ".nm.zip"; public static final String NUMASS_DATA_LOADER_TYPE = "numassData"; - public static final String GROUP_META_FILE = "numass_group_meta"; protected NumassStorage(FileStorage parent, String path, Meta config) throws StorageException { super(parent, path, config); super.refresh(); - //TODO read meta from numass_group_meta to .numass element } - protected NumassStorage(FileObject dir, Meta config) throws StorageException { - super(dir, config); + public NumassStorage(Context context, Meta config) throws StorageException { + super(context, config); super.refresh(); } - /** - * Create root numass storage - * - * @param dir - * @param readOnly - * @return - * @throws StorageException - */ - public static NumassStorage buildLocalNumassRoot(File dir, boolean readOnly, boolean monitor) throws StorageException { - try { - Meta meta = new MetaBuilder("storage") - .setValue("type", "file.numass") - .setValue("readOnly", readOnly) - .setValue("monitor", monitor); - return new NumassStorage(VFSUtils.getLocalFile(dir), meta); - } catch (FileSystemException ex) { - throw new RuntimeException(ex); - } - } - - public static NumassStorage buildLocalNumassRoot(File dir, boolean readOnly) throws StorageException { - return buildLocalNumassRoot(dir, readOnly, false); - } - - public static NumassStorage buildRemoteNumassRoot(String ip, int port, String login, String password, String path) throws StorageException { - try { - Meta meta = new MetaBuilder("storage") - .setValue("type", "file.numass") - .setValue("readOnly", true) - .setValue("monitor", false); - return new NumassStorage(VFSUtils.getRemoteFile(ip, port, login, password, path), meta); - } catch (FileSystemException ex) { - throw new RuntimeException(ex); - } - } - - public static NumassStorage buildNumassStorage(FileStorage parent, String path, boolean readOnly, boolean monitor) throws StorageException { - Meta meta = new MetaBuilder("storage") - .setValue("type", "file.numass") - .setValue("readOnly", readOnly) - .setValue("monitor", monitor); - return new NumassStorage(parent, path, meta); - } - - public static NumassStorage buildNumassRoot(String uri, boolean readOnly, boolean monitor) { - try { - Meta meta = new MetaBuilder("storage") - .setValue("type", "file.numass") - .setValue("readOnly", readOnly) - .setValue("monitor", monitor); - return new NumassStorage(VFSUtils.getFile(uri), meta); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - public static NumassStorage buildNumassRoot(URI uri, boolean readOnly, boolean monitor) { - try { - Meta meta = new MetaBuilder("storage") - .setValue("type", "file.numass") - .setValue("readOnly", readOnly) - .setValue("monitor", monitor); - return new NumassStorage(VFSUtils.getFile(uri), meta); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - @Override protected void updateDirectoryLoaders() { try { diff --git a/numass-core/src/main/java/inr/numass/storage/NumassStorageFactory.java b/numass-core/src/main/java/inr/numass/storage/NumassStorageFactory.java new file mode 100644 index 00000000..e6460f2d --- /dev/null +++ b/numass-core/src/main/java/inr/numass/storage/NumassStorageFactory.java @@ -0,0 +1,90 @@ +package inr.numass.storage; + +import hep.dataforge.context.Context; +import hep.dataforge.meta.Meta; +import hep.dataforge.storage.api.Storage; +import hep.dataforge.storage.api.StorageType; + +/** + * Created by darksnake on 17-May-17. + */ +public class NumassStorageFactory implements StorageType { +// /** +// * Create root numass storage +// * +// * @param dir +// * @param readOnly +// * @return +// * @throws StorageException +// */ +// public static NumassStorage buildLocalNumassRoot(File dir, boolean readOnly, boolean monitor) throws StorageException { +// try { +// Meta meta = new MetaBuilder("storage") +// .setValue("type", "file.numass") +// .setValue("readOnly", readOnly) +// .setValue("monitor", monitor); +// return new NumassStorage(VFSUtils.getLocalFile(dir), meta); +// } catch (FileSystemException ex) { +// throw new RuntimeException(ex); +// } +// } +// +// public static NumassStorage buildLocalNumassRoot(File dir, boolean readOnly) throws StorageException { +// return buildLocalNumassRoot(dir, readOnly, false); +// } +// +// public static NumassStorage buildRemoteNumassRoot(String ip, int port, String login, String password, String path) throws StorageException { +// try { +// Meta meta = new MetaBuilder("storage") +// .setValue("type", "file.numass") +// .setValue("readOnly", true) +// .setValue("monitor", false); +// return new NumassStorage(VFSUtils.getRemoteFile(ip, port, login, password, path), meta); +// } catch (FileSystemException ex) { +// throw new RuntimeException(ex); +// } +// } +// +// public static NumassStorage buildNumassStorage(FileStorage parent, String path, boolean readOnly, boolean monitor) throws StorageException { +// Meta meta = new MetaBuilder("storage") +// .setValue("type", "file.numass") +// .setValue("readOnly", readOnly) +// .setValue("monitor", monitor); +// return new NumassStorage(parent, path, meta); +// } +// +// public static NumassStorage buildNumassRoot(String uri, boolean readOnly, boolean monitor) { +// try { +// Meta meta = new MetaBuilder("storage") +// .setValue("type", "file.numass") +// .setValue("readOnly", readOnly) +// .setValue("monitor", monitor); +// return new NumassStorage(VFSUtils.getFile(uri), meta); +// } catch (Exception ex) { +// throw new RuntimeException(ex); +// } +// } +// +// public static NumassStorage buildNumassRoot(URI uri, boolean readOnly, boolean monitor) { +// try { +// Meta meta = new MetaBuilder("storage") +// .setValue("type", "file.numass") +// .setValue("readOnly", readOnly) +// .setValue("monitor", monitor); +// return new NumassStorage(VFSUtils.getFile(uri), meta); +// } catch (Exception ex) { +// throw new RuntimeException(ex); +// } +// } + + + @Override + public String type() { + return "numass"; + } + + @Override + public Storage build(Context context, Meta meta) { + return new NumassStorage(context, meta); + } +} diff --git a/numass-core/src/main/resources/META-INF/services/hep.dataforge.storage.api.StorageType b/numass-core/src/main/resources/META-INF/services/hep.dataforge.storage.api.StorageType new file mode 100644 index 00000000..e69de29b diff --git a/numass-main/src/main/java/inr/numass/actions/BuildStorageAction.java b/numass-main/src/main/java/inr/numass/actions/BuildStorageAction.java deleted file mode 100644 index 7921608c..00000000 --- a/numass-main/src/main/java/inr/numass/actions/BuildStorageAction.java +++ /dev/null @@ -1,22 +0,0 @@ -package inr.numass.actions; - -import hep.dataforge.actions.OneToOneAction; -import hep.dataforge.context.Context; -import hep.dataforge.description.TypedActionDef; -import hep.dataforge.meta.Laminate; -import inr.numass.storage.NumassStorage; - -import java.net.URI; - -/** - * TODO generalize and move to dataforge-stoage - * Create a Storage from given URI object - * Created by darksnake on 29-Jan-17. - */ -@TypedActionDef(name = "buildStorage", inputType = URI.class, outputType = NumassStorage.class) -public class BuildStorageAction extends OneToOneAction { - @Override - protected NumassStorage execute(Context context, String name, URI input, Laminate inputMeta) { - return NumassStorage.buildNumassRoot(input, inputMeta.getBoolean("readOnly", true), inputMeta.getBoolean("monitor", false)); - } -} 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 33f82693..1ae053e8 100644 --- a/numass-server/src/main/java/inr/numass/server/NumassRun.java +++ b/numass-server/src/main/java/inr/numass/server/NumassRun.java @@ -24,6 +24,7 @@ import hep.dataforge.meta.Meta; import hep.dataforge.meta.Metoid; 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; @@ -52,7 +53,7 @@ public class NumassRun implements Metoid, Responder { /** * The Numass storage for this run (it could be not root) */ - private final NumassStorage storage; + private final Storage storage; /** * Default state loader for this run @@ -68,7 +69,7 @@ public class NumassRun implements Metoid, Responder { // * A set with inverted order of elements (last note first) // */ // private final Set notes = new TreeSet<>((NumassNote o1, NumassNote o2) -> -o1.time().compareTo(o2.time())); - public NumassRun(String path, NumassStorage workStorage, MessageFactory factory) throws StorageException { + public NumassRun(String path, Storage workStorage, MessageFactory factory) throws StorageException { this.storage = workStorage; this.states = LoaderFactory.buildStateLoder(storage, RUN_STATE, null); this.noteLoader = LoaderFactory.buildObjectLoder(storage, RUN_NOTES, null); @@ -167,7 +168,11 @@ public class NumassRun implements Metoid, Responder { String filePath = message.meta().getString("path", ""); String fileName = message.meta().getString("name") .replace(NumassStorage.NUMASS_ZIP_EXTENSION, "");// removing .nm.zip if it is present - storage.pushNumassData(filePath, fileName, Binary.readToBuffer(message.getData())); + if(storage instanceof NumassStorage) { + ((NumassStorage) storage).pushNumassData(filePath, fileName, Binary.readToBuffer(message.getData())); + } else { + throw new StorageException("Storage does not support numass point push"); + } //TODO add checksum here return factory.okResponseBase("numass.data.push.response", false, false).build(); } catch (StorageException | IOException ex) { @@ -181,7 +186,7 @@ public class NumassRun implements Metoid, Responder { return storage.meta(); } - public NumassStorage getStorage() { + public Storage getStorage() { return storage; } 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 22d86f77..64d7c7e1 100644 --- a/numass-server/src/main/java/inr/numass/server/NumassServer.java +++ b/numass-server/src/main/java/inr/numass/server/NumassServer.java @@ -15,15 +15,17 @@ */ package inr.numass.server; +import hep.dataforge.context.Context; +import hep.dataforge.context.Encapsulated; import hep.dataforge.exceptions.StorageException; import hep.dataforge.io.envelopes.Envelope; import hep.dataforge.meta.Meta; import hep.dataforge.meta.MetaBuilder; import hep.dataforge.storage.api.StateLoader; +import hep.dataforge.storage.api.Storage; import hep.dataforge.storage.commons.AbstractNetworkListener; import hep.dataforge.storage.commons.LoaderFactory; import hep.dataforge.storage.commons.StorageManager; -import hep.dataforge.storage.filestorage.FileStorage; import inr.numass.storage.NumassStorage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,17 +37,17 @@ import java.io.IOException; * * @author darksnake */ -public class NumassServer extends AbstractNetworkListener { +public class NumassServer extends AbstractNetworkListener implements Encapsulated { public static final String DEFAULT_RUN_PATH = "default"; private final Logger logger = LoggerFactory.getLogger("NUMASS-STORAGE"); private RatpackServer ratpack; - private FileStorage root; + private NumassStorage root; private StateLoader rootState; private NumassRun run; - public NumassServer(FileStorage storage, Meta listenerConfig) { + public NumassServer(NumassStorage storage, Meta listenerConfig) { super(listenerConfig); init(storage); } @@ -61,7 +63,7 @@ public class NumassServer extends AbstractNetworkListener { * * @param storage */ - private void init(FileStorage storage) { + private void init(NumassStorage storage) { new StorageManager().startGlobal(); this.root = storage; try { @@ -90,10 +92,15 @@ public class NumassServer extends AbstractNetworkListener { // ); } - private void startRun(Meta annotation) throws StorageException { - String path = annotation.getString("path", DEFAULT_RUN_PATH); - //Meta meta = annotation.getMeta("meta", null); - run = new NumassRun(path, NumassStorage.buildNumassStorage(root, path, false, true), getResponseFactory()); + @Override + public Context getContext() { + return root.getContext(); + } + + private void startRun(Meta meta) throws StorageException { + String path = meta.getString("path", DEFAULT_RUN_PATH); + NumassStorage storage = root.buildShelf(path,meta); + run = new NumassRun(path, storage, getResponseFactory()); getRootState().setValue("numass.current.run", path); } @@ -137,7 +144,8 @@ public class NumassServer extends AbstractNetworkListener { */ private void updateRun() throws StorageException { String currentRun = getRootState().getString("numass.current.run", DEFAULT_RUN_PATH); - this.run = new NumassRun(currentRun, NumassStorage.buildNumassStorage(root, currentRun, false, true), getResponseFactory()); + Storage storage = root.optShelf(currentRun).get(); + this.run = new NumassRun(currentRun, storage, getResponseFactory()); } /** diff --git a/numass-server/src/main/java/inr/numass/server/ServerRunner.java b/numass-server/src/main/java/inr/numass/server/ServerRunner.java index f6453c9a..58e04f3b 100644 --- a/numass-server/src/main/java/inr/numass/server/ServerRunner.java +++ b/numass-server/src/main/java/inr/numass/server/ServerRunner.java @@ -1,10 +1,11 @@ package inr.numass.server; +import hep.dataforge.context.Context; +import hep.dataforge.context.Global; import hep.dataforge.io.MetaFileReader; import hep.dataforge.meta.Meta; import hep.dataforge.meta.SimpleConfigurable; import inr.numass.storage.NumassStorage; -import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; @@ -18,17 +19,17 @@ public class ServerRunner extends SimpleConfigurable implements AutoCloseable { public static final String SERVER_CONFIG_PATH = "numass-server.xml"; private static final String NUMASS_REPO_ELEMENT = "numass.repository"; private static final String LISTENER_ELEMENT = "listener"; - private static final String NUMASS_REPO_PATH_PROPERTY = "numass.repository.path"; - private final static Logger logger = LoggerFactory.getLogger("NUMASS-SERVER"); +// private static final String NUMASS_REPO_PATH_PROPERTY = "numass.repository.path"; NumassStorage root; NumassServer listener; + Context context = Global.getContext("NUMASS_SERVER"); public ServerRunner() throws IOException, ParseException { // Global.instance().pluginManager().load(StorageManager.class); File configFile = new File(SERVER_CONFIG_PATH); if (configFile.exists()) { - logger.info("Trying to read server configuration from {}", SERVER_CONFIG_PATH); + context.getLogger().info("Trying to read server configuration from {}", SERVER_CONFIG_PATH); configure(MetaFileReader.read(configFile)); } } @@ -38,7 +39,7 @@ public class ServerRunner extends SimpleConfigurable implements AutoCloseable { r.start(); Runtime.getRuntime().addShutdownHook(new Thread(() -> { - logger.info("Shutting down"); + LoggerFactory.getLogger("NUMASS-SERVER").info("Shutting down"); r.close(); })); @@ -51,15 +52,13 @@ public class ServerRunner extends SimpleConfigurable implements AutoCloseable { } public ServerRunner start() throws Exception { - String repoPath = meta().getString(NUMASS_REPO_PATH_PROPERTY, "."); -// Meta repoConfig = null; -// if (meta().hasMeta(NUMASS_REPO_ELEMENT)) { -// repoConfig = meta().getMeta(NUMASS_REPO_ELEMENT); -// } - logger.info("Initializing file storage in {}", repoPath); - root = NumassStorage.buildLocalNumassRoot(new File(repoPath), true, true);//in(new File(repoPath), repoConfig); +// String repoPath = meta().getString(NUMASS_REPO_PATH_PROPERTY, "."); - logger.info("Starting numass server"); + Meta storageMeta = meta().getMetaOrEmpty(NUMASS_REPO_ELEMENT); + context.getLogger().info("Initializing file storage with meta: {}",storageMeta); + root = new NumassStorage(context,storageMeta); + + context.getLogger().info("Starting numass server"); if (root != null) { root.open(); Meta listenerConfig = null; @@ -69,9 +68,9 @@ public class ServerRunner extends SimpleConfigurable implements AutoCloseable { listener = new NumassServer(root, listenerConfig); listener.open(); - logger.info("Successfully started numass server"); + context.getLogger().info("Successfully started numass server"); } else { - logger.error("Root storage not initialized"); + context.getLogger().error("Root storage not initialized"); } return this; @@ -79,12 +78,12 @@ public class ServerRunner extends SimpleConfigurable implements AutoCloseable { @Override public void close() { - logger.info("Stopping numass server"); + context.getLogger().info("Stopping numass server"); if (listener != null) { try { listener.close(); } catch (Exception e) { - logger.error("Failed to close listener", e); + context.getLogger().error("Failed to close listener", e); } } @@ -92,7 +91,7 @@ public class ServerRunner extends SimpleConfigurable implements AutoCloseable { try { root.close(); } catch (Exception ex) { - logger.error("Error while closing storage", ex); + context.getLogger().error("Error while closing storage", ex); } } } diff --git a/numass-server/src/main/java/inr/numass/server/TestServer.java b/numass-server/src/main/java/inr/numass/server/TestServer.java index b2875e80..d1316de0 100644 --- a/numass-server/src/main/java/inr/numass/server/TestServer.java +++ b/numass-server/src/main/java/inr/numass/server/TestServer.java @@ -9,10 +9,10 @@ import hep.dataforge.context.Context; import hep.dataforge.context.Global; import hep.dataforge.server.ServerManager; import hep.dataforge.storage.commons.StorageManager; +import hep.dataforge.storage.filestorage.FileStorageFactory; import inr.numass.storage.NumassStorage; import java.io.BufferedReader; -import java.io.File; import java.io.InputStreamReader; /** @@ -34,7 +34,7 @@ public class TestServer { String path = "D:/temp/test"; context.getLogger().info("Starting test numass storage servlet in '{}'", path); - NumassStorage storage = NumassStorage.buildLocalNumassRoot(new File(path), true, true); + NumassStorage storage = new NumassStorage(context, FileStorageFactory.buildStorageMeta(path, true, true)); serverManager.addObject("numass", storage, NumassStorageHandler::new); serverManager.startSetver(); diff --git a/numass-viewer/build.gradle b/numass-viewer/build.gradle index bc1cdf69..25e26b31 100644 --- a/numass-viewer/build.gradle +++ b/numass-viewer/build.gradle @@ -27,8 +27,10 @@ dependencies { compile 'org.controlsfx:controlsfx:8.40.12' - compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:'1.1.2-2" + compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:'1.1.2-3" compile "no.tornado:tornadofx:1.7.4" } +apply plugin: 'kotlin' + diff --git a/numass-viewer/src/main/kotlin/inr/numass/viewer/MainView.kt b/numass-viewer/src/main/kotlin/inr/numass/viewer/MainView.kt index 75a53bed..c1258e53 100644 --- a/numass-viewer/src/main/kotlin/inr/numass/viewer/MainView.kt +++ b/numass-viewer/src/main/kotlin/inr/numass/viewer/MainView.kt @@ -12,6 +12,7 @@ import hep.dataforge.meta.Metoid import hep.dataforge.names.AlphanumComparator import hep.dataforge.names.Named import hep.dataforge.storage.api.Storage +import hep.dataforge.storage.filestorage.FileStorageFactory import inr.numass.NumassProperties import inr.numass.data.NumassData import inr.numass.storage.NumassStorage @@ -134,7 +135,7 @@ class MainView : View() { work.progress = -1.0 work.status = "Building numass storage tree..." try { - val root = NumassStorage.buildNumassRoot(path, true, false) + val root = NumassStorage(context,FileStorageFactory.buildStorageMeta(path,true, true)); setRootStorage(root) Platform.runLater { storagePathLabel.text = "Storage: " + path } } catch (ex: Exception) {