Storage servlet update
This commit is contained in:
parent
d6ef1d994c
commit
e727235f12
@ -63,6 +63,7 @@ import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.text.ParseException;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
@ -309,7 +310,7 @@ public class MspViewController implements Initializable, MspListener {
|
||||
|
||||
@FXML
|
||||
private void onAutoRangeChange(DragEvent event) {
|
||||
plottables.setMaxAge((int) (this.autoRangeSlider.getValue() * 60 * 1000));
|
||||
plottables.setMaxAge(Duration.ofMinutes((long) this.autoRangeSlider.getValue()));
|
||||
}
|
||||
|
||||
@FXML
|
||||
|
@ -171,7 +171,7 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
|
||||
});
|
||||
plottables.setEachConfigValue("thickness", 3);
|
||||
//TODO make history length edittable
|
||||
plottables.setMaxAge(3 * 60 * 60 * 1000);
|
||||
plottables.setMaxAge(java.time.Duration.ofHours(3));
|
||||
plotContainer.setPlot(setupPlot(plottables));
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2015 Alexander Nozik.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package inr.numass.server;
|
||||
|
||||
import ratpack.handling.Context;
|
||||
import ratpack.handling.Handler;
|
||||
|
||||
/**
|
||||
* A handler to evaluate server actions via http post
|
||||
* Created by darksnake on 02-Oct-16.
|
||||
*/
|
||||
public class NumassActionHandler implements Handler {
|
||||
|
||||
@Override
|
||||
public void handle(Context ctx) throws Exception {
|
||||
|
||||
}
|
||||
}
|
@ -28,14 +28,15 @@ import hep.dataforge.storage.commons.LoaderFactory;
|
||||
import hep.dataforge.storage.commons.MessageFactory;
|
||||
import hep.dataforge.values.Value;
|
||||
import inr.numass.storage.NumassStorage;
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.Comparator;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static inr.numass.server.NumassServerUtils.getNotes;
|
||||
|
||||
/**
|
||||
* This object governs remote access to numass storage and performs reading and
|
||||
* writing to default StateLoader
|
||||
@ -58,12 +59,12 @@ public class NumassRun implements Annotated, Responder {
|
||||
*/
|
||||
private final StateLoader states;
|
||||
|
||||
private final ObjectLoader noteLoader;
|
||||
private final ObjectLoader<NumassNote> noteLoader;
|
||||
private final MessageFactory factory;
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
// /**
|
||||
// /**
|
||||
// * A set with inverted order of elements (last note first)
|
||||
// */
|
||||
// private final Set<NumassNote> notes = new TreeSet<>((NumassNote o1, NumassNote o2) -> -o1.time().compareTo(o2.time()));
|
||||
@ -132,30 +133,6 @@ public class NumassRun implements Annotated, Responder {
|
||||
noteLoader.push(note.ref(), note);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stream of notes in the last to first order
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Stream<NumassNote> getNotes() {
|
||||
return noteLoader.fragmentNames().stream().<NumassNote>map(new Function<String, NumassNote>() {
|
||||
@Override
|
||||
public NumassNote apply(String name) {
|
||||
try {
|
||||
return (NumassNote) noteLoader.pull(name);
|
||||
} catch (StorageException ex) {
|
||||
return (NumassNote) null;
|
||||
}
|
||||
}
|
||||
}).sorted(new Comparator<NumassNote>() {
|
||||
@Override
|
||||
public int compare(NumassNote o1, NumassNote o2) {
|
||||
return -o1.time().compareTo(o2.time());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private synchronized Envelope pushNote(Envelope message) {
|
||||
try {
|
||||
if (message.meta().hasNode("note")) {
|
||||
@ -176,7 +153,7 @@ public class NumassRun implements Annotated, Responder {
|
||||
EnvelopeBuilder envelope = factory.okResponseBase(message, true, false);
|
||||
int limit = message.meta().getInt("limit", -1);
|
||||
//TODO add time window and search conditions here
|
||||
Stream<NumassNote> stream = getNotes();
|
||||
Stream<NumassNote> stream = getNotes(noteLoader);
|
||||
if (limit > 0) {
|
||||
stream = stream.limit(limit);
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2015 Alexander Nozik.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package inr.numass.server;
|
||||
|
||||
import hep.dataforge.exceptions.StorageException;
|
||||
import hep.dataforge.storage.api.ObjectLoader;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Created by darksnake on 02-Oct-16.
|
||||
*/
|
||||
public class NumassServerUtils {
|
||||
/**
|
||||
* Stream of notes in the last to first order
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Stream<NumassNote> getNotes(ObjectLoader<NumassNote> noteLoader) {
|
||||
return noteLoader.fragmentNames().stream().map(name -> {
|
||||
try {
|
||||
return noteLoader.pull(name);
|
||||
} catch (StorageException ex) {
|
||||
return null;
|
||||
}
|
||||
}).sorted((o1, o2) -> -o1.time().compareTo(o2.time()));
|
||||
}
|
||||
}
|
@ -6,7 +6,6 @@
|
||||
package inr.numass.server;
|
||||
|
||||
import freemarker.template.Template;
|
||||
import hep.dataforge.exceptions.StorageException;
|
||||
import hep.dataforge.meta.MetaBuilder;
|
||||
import hep.dataforge.storage.api.ObjectLoader;
|
||||
import hep.dataforge.storage.api.PointLoader;
|
||||
@ -20,10 +19,13 @@ import java.io.StringWriter;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.FormatStyle;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static inr.numass.server.NumassServerUtils.getNotes;
|
||||
|
||||
/**
|
||||
* @author Alexander Nozik
|
||||
@ -40,14 +42,14 @@ public class NumassStorageHandler extends StorageRatpackHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void renderObjects(Context ctx, ObjectLoader loader) {
|
||||
protected void renderObjects(Context ctx, ObjectLoader<?> loader) {
|
||||
if (NumassRun.RUN_NOTES.equals(loader.getName())) {
|
||||
try {
|
||||
ObjectLoader<NumassNote> noteLoader = (ObjectLoader<NumassNote>) loader;
|
||||
ctx.getResponse().contentType("text/html");
|
||||
Template template = Utils.freemarkerConfig().getTemplate("NoteLoader.ftl");
|
||||
|
||||
List<String> notes = getNotes(loader).limit(100).map(note -> render(note)).collect(Collectors.toList());
|
||||
List<String> notes = getNotes(noteLoader).limit(100).map(note -> render(note)).collect(Collectors.toList());
|
||||
|
||||
Map data = new HashMap(2);
|
||||
data.put("notes", notes);
|
||||
@ -84,28 +86,4 @@ public class NumassStorageHandler extends StorageRatpackHandler {
|
||||
return String.format("<strong id=\"%s\">%s</strong> %s", note.ref(), formatter.format(note.time()), note.content());
|
||||
}
|
||||
|
||||
/**
|
||||
* Stream of notes in the last to first order
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private Stream<NumassNote> getNotes(ObjectLoader noteLoader) {
|
||||
return noteLoader.fragmentNames().stream().map(new Function<String, NumassNote>() {
|
||||
@Override
|
||||
public NumassNote apply(String name) {
|
||||
try {
|
||||
return (NumassNote) noteLoader.pull(name);
|
||||
} catch (StorageException ex) {
|
||||
return (NumassNote) null;
|
||||
}
|
||||
}
|
||||
}).sorted(new Comparator<NumassNote>() {
|
||||
@Override
|
||||
public int compare(NumassNote o1, NumassNote o2) {
|
||||
return -o1.time().compareTo(o2.time());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user