[no commit message]
This commit is contained in:
parent
243f9f541c
commit
be0ed3e128
@ -15,7 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package inr.numass.storage;
|
package inr.numass.storage;
|
||||||
|
|
||||||
import hep.dataforge.events.Event;
|
import hep.dataforge.events.BasicEvent;
|
||||||
|
import hep.dataforge.events.EventBuilder;
|
||||||
import hep.dataforge.exceptions.StorageException;
|
import hep.dataforge.exceptions.StorageException;
|
||||||
import hep.dataforge.meta.Meta;
|
import hep.dataforge.meta.Meta;
|
||||||
import hep.dataforge.meta.MetaBuilder;
|
import hep.dataforge.meta.MetaBuilder;
|
||||||
@ -28,7 +29,6 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.apache.commons.vfs2.FileObject;
|
import org.apache.commons.vfs2.FileObject;
|
||||||
@ -78,7 +78,7 @@ public class NumassStorage extends FileStorage {
|
|||||||
Meta meta = new MetaBuilder("storage")
|
Meta meta = new MetaBuilder("storage")
|
||||||
.setValue("type", "file.numass")
|
.setValue("type", "file.numass")
|
||||||
.setValue("readOnly", true)
|
.setValue("readOnly", true)
|
||||||
.setValue("monitor", false);
|
.setValue("monitor", false);
|
||||||
return new NumassStorage(VFSUtils.getRemoteFile(ip, port, login, password, path), meta);
|
return new NumassStorage(VFSUtils.getRemoteFile(ip, port, login, password, path), meta);
|
||||||
} catch (FileSystemException ex) {
|
} catch (FileSystemException ex) {
|
||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
@ -90,7 +90,7 @@ public class NumassStorage extends FileStorage {
|
|||||||
Meta meta = new MetaBuilder("storage")
|
Meta meta = new MetaBuilder("storage")
|
||||||
.setValue("type", "file.numass")
|
.setValue("type", "file.numass")
|
||||||
.setValue("readOnly", readOnly)
|
.setValue("readOnly", readOnly)
|
||||||
.setValue("monitor", monitor);
|
.setValue("monitor", monitor);
|
||||||
return new NumassStorage(VFSUtils.getRemoteFile(uri), meta);
|
return new NumassStorage(VFSUtils.getRemoteFile(uri), meta);
|
||||||
} catch (FileSystemException ex) {
|
} catch (FileSystemException ex) {
|
||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
@ -174,7 +174,7 @@ public class NumassStorage extends FileStorage {
|
|||||||
try (OutputStream os = nmFile.getContent().getOutputStream(false)) {
|
try (OutputStream os = nmFile.getContent().getOutputStream(false)) {
|
||||||
os.write(data.array());
|
os.write(data.array());
|
||||||
}
|
}
|
||||||
getDefaultEventLoader().push(new NumassDataPointEvent(getName(), fileName, (int) nmFile.getContent().getSize()));
|
getDefaultEventLoader().push(NumassDataPointEvent.build(getName(), fileName, (int) nmFile.getContent().getSize()));
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw new StorageException(ex);
|
throw new StorageException(ex);
|
||||||
}
|
}
|
||||||
@ -218,51 +218,38 @@ public class NumassStorage extends FileStorage {
|
|||||||
return meta().getString("description", "");
|
return meta().getString("description", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class NumassDataPointEvent implements Event {
|
public static class NumassDataPointEvent extends BasicEvent {
|
||||||
|
|
||||||
private final String source;
|
public static final String FILE_NAME_KEY = "fileName";
|
||||||
private final String fileName;
|
public static final String FILE_SIZE_KEY = "fileSize";
|
||||||
private final int fileSize;
|
|
||||||
private final Instant time = Instant.now();
|
|
||||||
|
|
||||||
public NumassDataPointEvent(String source, String fileName, int fileSize) {
|
public static NumassDataPointEvent build(String source, String fileName, int fileSize) {
|
||||||
this.fileName = fileName;
|
return new NumassDataPointEvent(builder(source, fileName, fileSize).buildEventMeta());
|
||||||
this.fileSize = fileSize;
|
|
||||||
this.source = source;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static EventBuilder builder(String source, String fileName, int fileSize) {
|
||||||
public int priority() {
|
return new EventBuilder("numass.storage.pushData")
|
||||||
return 0;
|
.setSource(source)
|
||||||
|
.setMetaValue(FILE_NAME_KEY, fileName)
|
||||||
|
.setMetaValue(FILE_SIZE_KEY, fileSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public NumassDataPointEvent(Meta meta) {
|
||||||
public String type() {
|
super(meta);
|
||||||
return "numass.storage.pushData";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String source() {
|
|
||||||
return source;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Instant time() {
|
|
||||||
return time;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFileSize() {
|
public int getFileSize() {
|
||||||
return fileSize;
|
return meta().getInt(FILE_SIZE_KEY, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFileName() {
|
public String getFileName() {
|
||||||
return fileName;
|
return meta().getString(FILE_NAME_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("(%s) [%s] : pushed numass data file with name '%s' and size '%d'",
|
return String.format("(%s) [%s] : pushed numass data file with name '%s' and size '%d'",
|
||||||
time().toString(), source(), getFileName(), getFileSize());
|
time().toString(), sourceTag(), getFileName(), getFileSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user