From bc05ae5006de61445b95b34acbdd58dd775b48c7 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 17 Jul 2016 22:28:43 +0300 Subject: [PATCH] Trying to implement caching --- .../src/main/java/inr/numass/Main.java | 8 +++++ .../actions/ReadNumassStorageAction.java | 6 ++-- .../inr/numass/models/GaussResolution.java | 8 +++++ .../java/inr/numass/tasks/PrepareTask.java | 8 ++--- .../java/inr/numass/utils/OldDataReader.java | 16 ++++++++++ .../workbench/NumassWorkbenchController.java | 2 +- .../java/inr/numass/workbench/Workbench.java | 2 +- .../inr/numass/run/NumassSpectrumTest.java | 32 +++++++++++++++++++ .../numass/viewer/MainViewerController.java | 8 ++--- .../inr/numass/viewer/MspViewController.java | 4 +-- .../viewer/NumassLoaderTreeBuilder.java | 8 ++--- .../viewer/NumassLoaderViewComponent.java | 8 ++--- 12 files changed, 87 insertions(+), 23 deletions(-) diff --git a/numass-main/src/main/java/inr/numass/Main.java b/numass-main/src/main/java/inr/numass/Main.java index a1792370..d3573849 100644 --- a/numass-main/src/main/java/inr/numass/Main.java +++ b/numass-main/src/main/java/inr/numass/Main.java @@ -47,6 +47,14 @@ import static java.util.Locale.setDefault; import static java.util.Locale.setDefault; import static java.util.Locale.setDefault; import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; /** * diff --git a/numass-main/src/main/java/inr/numass/actions/ReadNumassStorageAction.java b/numass-main/src/main/java/inr/numass/actions/ReadNumassStorageAction.java index c4055fe4..d1d29ba9 100644 --- a/numass-main/src/main/java/inr/numass/actions/ReadNumassStorageAction.java +++ b/numass-main/src/main/java/inr/numass/actions/ReadNumassStorageAction.java @@ -6,8 +6,8 @@ package inr.numass.actions; import hep.dataforge.actions.GenericAction; -import hep.dataforge.context.DFProcess; -import hep.dataforge.context.ProcessManager.Callback; +import hep.dataforge.work.Work; +import hep.dataforge.work.WorkManager.Callback; import hep.dataforge.data.Data; import hep.dataforge.data.DataFilter; import hep.dataforge.data.DataNode; @@ -42,7 +42,7 @@ public class ReadNumassStorageAction extends GenericAction { boolean forwardOnly = actionMeta.getBoolean("forwardOnly", false); boolean reverseOnly = actionMeta.getBoolean("reverseOnly", false); - DFProcess> process = getContext().processManager() + Work> process = getContext().workManager() .>post(getName(), (Callback callback) -> { //FIXME remove in later revisions SetDirectionUtility.load(getContext()); diff --git a/numass-main/src/main/java/inr/numass/models/GaussResolution.java b/numass-main/src/main/java/inr/numass/models/GaussResolution.java index 5b598cec..ace44434 100644 --- a/numass-main/src/main/java/inr/numass/models/GaussResolution.java +++ b/numass-main/src/main/java/inr/numass/models/GaussResolution.java @@ -35,6 +35,14 @@ import static java.lang.Double.isNaN; import static java.lang.Math.abs; import static java.lang.Double.isNaN; import static java.lang.Math.abs; +import static java.lang.Double.isNaN; +import static java.lang.Math.abs; +import static java.lang.Double.isNaN; +import static java.lang.Math.abs; +import static java.lang.Double.isNaN; +import static java.lang.Math.abs; +import static java.lang.Double.isNaN; +import static java.lang.Math.abs; /** * diff --git a/numass-main/src/main/java/inr/numass/tasks/PrepareTask.java b/numass-main/src/main/java/inr/numass/tasks/PrepareTask.java index b93442c0..ee21eec5 100644 --- a/numass-main/src/main/java/inr/numass/tasks/PrepareTask.java +++ b/numass-main/src/main/java/inr/numass/tasks/PrepareTask.java @@ -7,7 +7,7 @@ package inr.numass.tasks; import hep.dataforge.actions.Action; import hep.dataforge.context.Context; -import hep.dataforge.context.ProcessManager; +import hep.dataforge.work.WorkManager; import hep.dataforge.data.DataNode; import hep.dataforge.data.DataTree; import hep.dataforge.meta.Meta; @@ -44,7 +44,7 @@ public class PrepareTask extends GenericTask { */ @Override @SuppressWarnings("unchecked") - protected TaskState transform(ProcessManager.Callback callback, Context context, TaskState state, Meta config) { + protected TaskState transform(WorkManager.Callback callback, Context context, TaskState state, Meta config) { //acquiring initial data. Data node could not be empty Meta dataMeta = Template.compileTemplate(config.getNode("data"), config); DataNode data = runAction(new ReadNumassStorageAction(), callback, context, DataNode.empty(), dataMeta); @@ -70,8 +70,8 @@ public class PrepareTask extends GenericTask { return state; } - private DataNode runAction(Action action, ProcessManager.Callback callback, Context context, DataNode data, Meta meta) { - return action.withContext(context).withParentProcess(callback.processName()).run(data, meta); + private DataNode runAction(Action action, WorkManager.Callback callback, Context context, DataNode data, Meta meta) { + return action.withContext(context).withParentProcess(callback.workName()).run(data, meta); } @Override diff --git a/numass-main/src/main/java/inr/numass/utils/OldDataReader.java b/numass-main/src/main/java/inr/numass/utils/OldDataReader.java index 297498a3..abf4c874 100644 --- a/numass-main/src/main/java/inr/numass/utils/OldDataReader.java +++ b/numass-main/src/main/java/inr/numass/utils/OldDataReader.java @@ -41,6 +41,22 @@ import static java.util.Locale.setDefault; import static java.util.Locale.setDefault; import static java.util.Locale.setDefault; import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; /** * diff --git a/numass-main/src/main/java/inr/numass/workbench/NumassWorkbenchController.java b/numass-main/src/main/java/inr/numass/workbench/NumassWorkbenchController.java index 93c765f7..3b19fc97 100644 --- a/numass-main/src/main/java/inr/numass/workbench/NumassWorkbenchController.java +++ b/numass-main/src/main/java/inr/numass/workbench/NumassWorkbenchController.java @@ -152,7 +152,7 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder this.context = this.contextFactory.build(parentContext, config); // attachig visual process manager - processWindow.setManager(context.processManager()); + processWindow.setManager(context.workManager()); // setting io manager context.setIO(new WorkbenchIOManager(new NumassIO(), this)); diff --git a/numass-main/src/main/java/inr/numass/workbench/Workbench.java b/numass-main/src/main/java/inr/numass/workbench/Workbench.java index b46be037..fe776ddb 100644 --- a/numass-main/src/main/java/inr/numass/workbench/Workbench.java +++ b/numass-main/src/main/java/inr/numass/workbench/Workbench.java @@ -37,7 +37,7 @@ public class Workbench extends Application { primaryStage.show(); scene.getWindow().setOnCloseRequest((WindowEvent event) -> { - controller.getContext().processManager().getRootProcess().cancel(true); + controller.getContext().workManager().getRoot().cancel(true); }); } diff --git a/numass-main/src/test/java/inr/numass/run/NumassSpectrumTest.java b/numass-main/src/test/java/inr/numass/run/NumassSpectrumTest.java index ade7388c..b5a30342 100644 --- a/numass-main/src/test/java/inr/numass/run/NumassSpectrumTest.java +++ b/numass-main/src/test/java/inr/numass/run/NumassSpectrumTest.java @@ -56,6 +56,38 @@ import static java.util.Locale.setDefault; import static java.util.Locale.setDefault; import static java.util.Locale.setDefault; import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; +import static java.util.Locale.setDefault; /** * diff --git a/numass-viewer/src/main/java/inr/numass/viewer/MainViewerController.java b/numass-viewer/src/main/java/inr/numass/viewer/MainViewerController.java index 32eb20f6..b67bbeba 100644 --- a/numass-viewer/src/main/java/inr/numass/viewer/MainViewerController.java +++ b/numass-viewer/src/main/java/inr/numass/viewer/MainViewerController.java @@ -17,7 +17,7 @@ package inr.numass.viewer; import hep.dataforge.context.Context; import hep.dataforge.context.GlobalContext; -import hep.dataforge.context.ProcessManager; +import hep.dataforge.work.WorkManager; import hep.dataforge.exceptions.StorageException; import hep.dataforge.fx.ConsoleFragment; import hep.dataforge.fx.process.ProcessManagerFragment; @@ -139,7 +139,7 @@ public class MainViewerController implements Initializable { } private void loadDirectory(String path) { - getContext().processManager().post("viewer.loadDirectory", (ProcessManager.Callback callback) -> { + getContext().workManager().post("viewer.loadDirectory", (WorkManager.Callback callback) -> { callback.updateTitle("Load storage (" + path + ")"); callback.setProgress(-1); callback.updateMessage("Building numass storage tree..."); @@ -161,8 +161,8 @@ public class MainViewerController implements Initializable { public void setRootStorage(NumassStorage root) { - getContext().processManager().cleanup(); - getContext().processManager().post("viewer.storage.load", (ProcessManager.Callback callback) -> { + getContext().workManager().cleanup(); + getContext().workManager().post("viewer.storage.load", (WorkManager.Callback callback) -> { callback.updateTitle("Fill data to UI (" + root.getName() + ")"); callback.setProgress(-1); Platform.runLater(() -> statusBar.setProgress(-1)); diff --git a/numass-viewer/src/main/java/inr/numass/viewer/MspViewController.java b/numass-viewer/src/main/java/inr/numass/viewer/MspViewController.java index b23d4100..84b2d1d1 100644 --- a/numass-viewer/src/main/java/inr/numass/viewer/MspViewController.java +++ b/numass-viewer/src/main/java/inr/numass/viewer/MspViewController.java @@ -21,7 +21,7 @@ package inr.numass.viewer; * and open the template in the editor. */ import hep.dataforge.context.Context; -import hep.dataforge.context.ProcessManager; +import hep.dataforge.work.WorkManager; import hep.dataforge.exceptions.StorageException; import hep.dataforge.plots.PlotUtils; import hep.dataforge.plots.data.DynamicPlottable; @@ -85,7 +85,7 @@ public class MspViewController { public void fillMspData(Storage rootStorage) { if (rootStorage != null) { - context.processManager().post("viewer.msp.fill", (ProcessManager.Callback callback) -> { + context.workManager().post("viewer.msp.fill", (WorkManager.Callback callback) -> { try { // callback.updateTitle("Fill msp data (" + rootStorage.getName() + ")"); diff --git a/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderTreeBuilder.java b/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderTreeBuilder.java index 5a00ffdb..d3b2dac7 100644 --- a/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderTreeBuilder.java +++ b/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderTreeBuilder.java @@ -15,7 +15,7 @@ */ package inr.numass.viewer; -import hep.dataforge.context.ProcessManager; +import hep.dataforge.work.WorkManager; import hep.dataforge.exceptions.StorageException; import inr.numass.storage.NumassData; import inr.numass.storage.NumassStorage; @@ -38,7 +38,7 @@ import org.slf4j.LoggerFactory; */ public class NumassLoaderTreeBuilder { - public void build(ProcessManager.Callback callback, + public void build(WorkManager.Callback callback, TreeTableView numassLoaderDataTree, NumassStorage rootStorage, Consumer numassViewBuilder) throws StorageException { @@ -81,7 +81,7 @@ public class NumassLoaderTreeBuilder { } private TreeItem buildNode(NumassStorage storage, - Consumer numassViewBuilder, ProcessManager.Callback callback) throws StorageException { + Consumer numassViewBuilder, WorkManager.Callback callback) throws StorageException { TreeItem node = new TreeItem<>(buildValue(storage)); node.getChildren().setAll(buildChildren(storage, numassViewBuilder, callback)); return node; @@ -92,7 +92,7 @@ public class NumassLoaderTreeBuilder { } private List> buildChildren(NumassStorage storage, - Consumer numassViewBuilder, ProcessManager.Callback callback) throws StorageException { + Consumer numassViewBuilder, WorkManager.Callback callback) throws StorageException { List> list = new ArrayList<>(); storage.shelves().values().stream().forEach(subStorage -> { diff --git a/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderViewComponent.java b/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderViewComponent.java index 247b770f..6c808a75 100644 --- a/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderViewComponent.java +++ b/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderViewComponent.java @@ -21,7 +21,7 @@ package inr.numass.viewer; * and open the template in the editor. */ import hep.dataforge.context.Context; -import hep.dataforge.context.ProcessManager; +import hep.dataforge.work.WorkManager; import hep.dataforge.io.ColumnedDataWriter; import hep.dataforge.meta.Meta; import hep.dataforge.meta.MetaBuilder; @@ -227,7 +227,7 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab public void loadData(NumassData data) { this.data = data; if (data != null) { - context.processManager().>post("viewer.numass.load", (ProcessManager.Callback callback) -> { + context.workManager().>post("viewer.numass.load", (WorkManager.Callback callback) -> { callback.updateTitle("Load numass data (" + data.getName() + ")"); points = data.getNMPoints(); @@ -252,7 +252,7 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab } private void setupHVPane(Supplier hvData) { - context.processManager().post("viewer.numass.hv", (ProcessManager.Callback callback) -> { + context.workManager().post("viewer.numass.hv", (WorkManager.Callback callback) -> { Table t = hvData.get(); Platform.runLater(() -> { if (t != null) { @@ -356,7 +356,7 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab detectorPlot.removePlot(); } - context.processManager().post("viewer.numass.load.detector", (ProcessManager.Callback callback) -> { + context.workManager().post("viewer.numass.load.detector", (WorkManager.Callback callback) -> { Meta plottableConfig = new MetaBuilder("plot") .setValue("connectionType", "step") .setValue("thickness", 2)