Completed action result caching. Fixed goals parallelism.

This commit is contained in:
Alexander Nozik 2016-07-23 20:09:13 +03:00
parent ea2aea0f54
commit 8c42e44c98
10 changed files with 72 additions and 88 deletions

View File

@ -6,13 +6,12 @@
package inr.numass.actions; package inr.numass.actions;
import hep.dataforge.actions.GenericAction; import hep.dataforge.actions.GenericAction;
import hep.dataforge.work.Work; import hep.dataforge.computation.Work;
import hep.dataforge.work.WorkManager.Callback; import hep.dataforge.computation.WorkManager.Callback;
import hep.dataforge.data.Data; import hep.dataforge.data.Data;
import hep.dataforge.data.DataFilter; import hep.dataforge.data.DataFilter;
import hep.dataforge.data.DataNode; import hep.dataforge.data.DataNode;
import hep.dataforge.data.DataSet; import hep.dataforge.data.DataSet;
import hep.dataforge.data.StaticData;
import hep.dataforge.description.TypedActionDef; import hep.dataforge.description.TypedActionDef;
import hep.dataforge.description.ValueDef; import hep.dataforge.description.ValueDef;
import hep.dataforge.meta.Meta; import hep.dataforge.meta.Meta;
@ -53,7 +52,7 @@ public class ReadNumassStorageAction extends GenericAction<Void, NumassData> {
Loader loader = pair.getValue(); Loader loader = pair.getValue();
if (loader instanceof NumassData) { if (loader instanceof NumassData) {
NumassDataLoader nd = (NumassDataLoader) loader; NumassDataLoader nd = (NumassDataLoader) loader;
Data<NumassData> datum = new StaticData<>(nd); Data<NumassData> datum = Data.buildStatic(nd);
if (filter.acceptData(pair.getKey(), datum)) { if (filter.acceptData(pair.getKey(), datum)) {
boolean accept = true; boolean accept = true;
if (forwardOnly || reverseOnly) { if (forwardOnly || reverseOnly) {
@ -71,7 +70,7 @@ public class ReadNumassStorageAction extends GenericAction<Void, NumassData> {
if (actionMeta.getBoolean("loadLegacy", false)) { if (actionMeta.getBoolean("loadLegacy", false)) {
logger().info("Loading legacy files"); logger().info("Loading legacy files");
storage.legacyFiles().forEach(nd -> { storage.legacyFiles().forEach(nd -> {
Data<NumassData> datum = new StaticData<>(nd); Data<NumassData> datum = Data.buildStatic(nd);
if (filter.acceptData(nd.getName(), datum)) { if (filter.acceptData(nd.getName(), datum)) {
builder.putData("legacy." + nd.getName(), datum); builder.putData("legacy." + nd.getName(), datum);
} }

View File

@ -51,7 +51,7 @@ public class TransmissionInterpolator implements UnivariateFunction {
public static TransmissionInterpolator fromAction(Context context, Meta actionAnnotation, public static TransmissionInterpolator fromAction(Context context, Meta actionAnnotation,
String xName, String yName, int nSmooth, double w, double border) throws InterruptedException { String xName, String yName, int nSmooth, double w, double border) throws InterruptedException {
DataNode<Table> node = ActionUtils.runConfig(context, actionAnnotation); DataNode<Table> node = ActionUtils.runConfig(context, actionAnnotation);
PointSource data = node.getData().getNow(); PointSource data = node.getData().get();
return new TransmissionInterpolator(data, xName, yName, nSmooth, w, border); return new TransmissionInterpolator(data, xName, yName, nSmooth, w, border);
} }

View File

@ -7,7 +7,7 @@ package inr.numass.tasks;
import hep.dataforge.actions.Action; import hep.dataforge.actions.Action;
import hep.dataforge.context.Context; import hep.dataforge.context.Context;
import hep.dataforge.work.WorkManager; import hep.dataforge.computation.WorkManager;
import hep.dataforge.data.DataNode; import hep.dataforge.data.DataNode;
import hep.dataforge.data.DataTree; import hep.dataforge.data.DataTree;
import hep.dataforge.meta.Meta; import hep.dataforge.meta.Meta;

View File

@ -1,41 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package inr.numass.test;
import hep.dataforge.actions.ActionController;
import java.util.concurrent.CompletableFuture;
/**
*
* @author Alexander Nozik
*/
public class TestLazyData {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
ActionController lock = new ActionController();
CompletableFuture<String> future = lock.hold(() -> {
System.out.println(" I am initialized");
return "abcd";
});
future = future.<String>thenCompose((String res) -> CompletableFuture.supplyAsync(() -> {
System.out.println(" I am capitalized");
return res.toUpperCase();
}));
future = future.handleAsync((res, err) -> {
System.out.println(" I am handled");
return "handled " + res;
});
System.out.println("Releasing hold");
lock.release();
// dat1.getInFuture().thenRunAsync(() -> System.out.println(" I am finished"));
// dat1.getInFuture().thenAcceptAsync((res) -> System.out.println(" I am finished"));
}
}

View File

@ -20,7 +20,7 @@ import hep.dataforge.fx.ConsoleFragment;
import hep.dataforge.fx.FXDataOutputPane; import hep.dataforge.fx.FXDataOutputPane;
import hep.dataforge.fx.FXReportListener; import hep.dataforge.fx.FXReportListener;
import hep.dataforge.fx.configuration.MetaEditor; import hep.dataforge.fx.configuration.MetaEditor;
import hep.dataforge.fx.process.ProcessManagerFragment; import hep.dataforge.fx.work.WorkManagerFragment;
import hep.dataforge.io.IOManager; import hep.dataforge.io.IOManager;
import hep.dataforge.io.MetaFileReader; import hep.dataforge.io.MetaFileReader;
import hep.dataforge.meta.ConfigChangeListener; import hep.dataforge.meta.ConfigChangeListener;
@ -45,13 +45,15 @@ import java.util.ResourceBundle;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.control.Accordion; import javafx.scene.control.Accordion;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Tab; import javafx.scene.control.Tab;
import javafx.scene.control.TabPane; import javafx.scene.control.TabPane;
import javafx.scene.control.TitledPane; import javafx.scene.control.TitledPane;
@ -78,10 +80,12 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
Map<String, StagePane> stages = new ConcurrentHashMap<>(); Map<String, StagePane> stages = new ConcurrentHashMap<>();
ProcessManagerFragment processWindow; WorkManagerFragment processWindow;
FXDataOutputPane logPane; FXDataOutputPane logPane;
BooleanProperty isRunning = new SimpleBooleanProperty(false);
@FXML @FXML
private StatusBar statusBar; private StatusBar statusBar;
@FXML @FXML
@ -91,7 +95,7 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
@FXML @FXML
private Tab logTab; private Tab logTab;
@FXML @FXML
private Button runButton; private ToggleButton runButton;
@FXML @FXML
private ToggleButton consoleButton; private ToggleButton consoleButton;
@FXML @FXML
@ -121,14 +125,23 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
consoleWindow.addRootLogHandler(); consoleWindow.addRootLogHandler();
consoleWindow.hookStd(); consoleWindow.hookStd();
processWindow = new ProcessManagerFragment(); processWindow = new WorkManagerFragment();
processWindow.bindTo(processButton); processWindow.bindTo(processButton);
isRunning.addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
runButton.setSelected(newValue);
if (newValue) {
runButton.setText("Stop");
} else {
runButton.setText("Run");
}
});
} }
public Context getContext() { public Context getContext() {
if (context == null) { if (context == null) {
return GlobalContext.instance(); throw new RuntimeException("Context not defined");
} else { } else {
return context; return context;
} }
@ -158,7 +171,6 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
context.setIO(new WorkbenchIOManager(new NumassIO(), this)); context.setIO(new WorkbenchIOManager(new NumassIO(), this));
buildContextPane(); buildContextPane();
context.getReport().addReportListener(new FXReportListener(logPane)); context.getReport().addReportListener(new FXReportListener(logPane));
// display plots iside workbench // display plots iside workbench
PlotsPlugin.buildFrom(context).setPlotHolderDelegate(this); PlotsPlugin.buildFrom(context).setPlotHolderDelegate(this);
@ -322,9 +334,13 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
@FXML @FXML
private void onRunButtonClick(ActionEvent event) { private void onRunButtonClick(ActionEvent event) {
if (getContext() != null && !actionsConfig.isEmpty()) { if (!isRunning.get()) {
statusBar.setText("Starting action execution"); if (context != null && !actionsConfig.isEmpty()) {
runActions(); statusBar.setText("Starting action execution");
runActions();
}
} else {
this.context.workManager().shutdown();
} }
} }
@ -341,27 +357,42 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
clearAllStages(); clearAllStages();
// processWindow.show(); // processWindow.show();
new Thread(() -> { new Thread(() -> {
Platform.runLater(() -> {
isRunning.set(true);
statusBar.setProgress(-1);
});
DataNode data = new FileDataFactory().build(getContext(), getDataConfiguration()); DataNode data = new FileDataFactory().build(getContext(), getDataConfiguration());
Platform.runLater(() -> statusBar.setProgress(-1));
try { try {
ActionUtils.runAction(getContext(), data, getActionConfiguration()).compute(); ActionUtils.runAction(getContext(), data, getActionConfiguration()).compute();
Platform.runLater(() -> statusBar.setText("Execution complete")); Platform.runLater(() -> statusBar.setText("Execution complete"));
} catch (Exception ex) { } catch (Exception ex) {
GlobalContext.instance().getLogger().error("Exception while executing action chain", ex); if (ex instanceof java.util.concurrent.CancellationException) {
Platform.runLater(() -> { //cach cancelation exception
//printing stack trace to the default output GlobalContext.instance().getLogger().info("Interrupted by user");
Platform.runLater(() -> {
statusBar.setText("Execution interrupted by user");
});
} else {
//cach all other exceptions
GlobalContext.instance().getLogger().error("Exception while executing action chain", ex);
ex.printStackTrace(System.err); ex.printStackTrace(System.err);
// ex.printStackTrace();//?? Platform.runLater(() -> {
statusBar.setText("Execution failed"); //printing stack trace to the default output
Alert alert = new Alert(Alert.AlertType.ERROR); statusBar.setText("Execution failed");
alert.setTitle("Exception!"); Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setHeaderText("Action execution failure"); alert.setTitle("Exception!");
alert.setContentText(ex.getMessage()); alert.setHeaderText("Action execution failure");
alert.show(); alert.setContentText(ex.getMessage());
alert.show();
}); });
}
} finally { } finally {
Platform.runLater(() -> statusBar.setProgress(0)); Platform.runLater(() -> {
isRunning.set(false);
statusBar.setProgress(0);
});
} }
}, "actions").start(); }, "actions").start();

View File

@ -9,14 +9,13 @@
<?import javafx.scene.control.TabPane?> <?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.ToggleButton?> <?import javafx.scene.control.ToggleButton?>
<?import javafx.scene.control.ToolBar?> <?import javafx.scene.control.ToolBar?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?> <?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?> <?import javafx.scene.layout.Pane?>
<?import javafx.scene.text.Font?>
<?import org.controlsfx.control.StatusBar?> <?import org.controlsfx.control.StatusBar?>
<AnchorPane id="AnchorPane" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="inr.numass.workbench.NumassWorkbenchController"> <AnchorPane id="AnchorPane" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="inr.numass.workbench.NumassWorkbenchController">
<children> <children>
<BorderPane layoutX="-165.0" layoutY="100.0" prefHeight="200.0" prefWidth="765.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <BorderPane layoutX="-165.0" layoutY="100.0" prefHeight="200.0" prefWidth="765.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<bottom> <bottom>
@ -44,14 +43,10 @@
<ToggleButton fx:id="consoleButton" mnemonicParsing="false" text="Console" /> <ToggleButton fx:id="consoleButton" mnemonicParsing="false" text="Console" />
<ToggleButton fx:id="processButton" mnemonicParsing="false" text="Processes" /> <ToggleButton fx:id="processButton" mnemonicParsing="false" text="Processes" />
<Separator orientation="VERTICAL" /> <Separator orientation="VERTICAL" />
<Pane HBox.hgrow = "ALWAYS"/> <Pane HBox.hgrow="ALWAYS" />
<Separator orientation="VERTICAL" /> <Separator orientation="VERTICAL" />
<Button mnemonicParsing="false" onAction="#onLoadConfigClick" text="Load" /> <Button mnemonicParsing="false" onAction="#onLoadConfigClick" text="Load" />
<Button fx:id="runButton" disable="true" mnemonicParsing="false" onAction="#onRunButtonClick" text="Run"> <ToggleButton fx:id="runButton" disable="true" mnemonicParsing="false" onAction="#onRunButtonClick" text="Run" />
<font>
<Font name="System Bold" size="12.0" />
</font>
</Button>
</items> </items>
</ToolBar> </ToolBar>
</top> </top>

View File

@ -17,10 +17,10 @@ package inr.numass.viewer;
import hep.dataforge.context.Context; import hep.dataforge.context.Context;
import hep.dataforge.context.GlobalContext; import hep.dataforge.context.GlobalContext;
import hep.dataforge.work.WorkManager; import hep.dataforge.computation.WorkManager;
import hep.dataforge.exceptions.StorageException; import hep.dataforge.exceptions.StorageException;
import hep.dataforge.fx.ConsoleFragment; import hep.dataforge.fx.ConsoleFragment;
import hep.dataforge.fx.process.ProcessManagerFragment; import hep.dataforge.fx.work.WorkManagerFragment;
import inr.numass.NumassProperties; import inr.numass.NumassProperties;
import inr.numass.storage.NumassData; import inr.numass.storage.NumassData;
import inr.numass.storage.NumassStorage; import inr.numass.storage.NumassStorage;
@ -66,7 +66,7 @@ public class MainViewerController implements Initializable {
} }
// private ConsoleFragment consoleFragment; // private ConsoleFragment consoleFragment;
// private ProcessManagerFragment processFragment = ProcessManagerFragment.attachToContext(GlobalContext.instance()); // private WorkManagerFragment processFragment = WorkManagerFragment.attachToContext(GlobalContext.instance());
@FXML @FXML
private ToggleButton consoleButton; private ToggleButton consoleButton;
@FXML @FXML
@ -115,7 +115,7 @@ public class MainViewerController implements Initializable {
ConsoleFragment consoleFragment = new ConsoleFragment(); ConsoleFragment consoleFragment = new ConsoleFragment();
consoleFragment.hookStd(); consoleFragment.hookStd();
consoleFragment.bindTo(consoleButton); consoleFragment.bindTo(consoleButton);
ProcessManagerFragment.attachToContext(GlobalContext.instance()).bindTo(processManagerButton); WorkManagerFragment.attachToContext(GlobalContext.instance()).bindTo(processManagerButton);
} }
@FXML @FXML

View File

@ -21,7 +21,7 @@ package inr.numass.viewer;
* and open the template in the editor. * and open the template in the editor.
*/ */
import hep.dataforge.context.Context; import hep.dataforge.context.Context;
import hep.dataforge.work.WorkManager; import hep.dataforge.computation.WorkManager;
import hep.dataforge.exceptions.StorageException; import hep.dataforge.exceptions.StorageException;
import hep.dataforge.plots.PlotUtils; import hep.dataforge.plots.PlotUtils;
import hep.dataforge.plots.data.DynamicPlottable; import hep.dataforge.plots.data.DynamicPlottable;

View File

@ -15,7 +15,7 @@
*/ */
package inr.numass.viewer; package inr.numass.viewer;
import hep.dataforge.work.WorkManager; import hep.dataforge.computation.WorkManager;
import hep.dataforge.exceptions.StorageException; import hep.dataforge.exceptions.StorageException;
import inr.numass.storage.NumassData; import inr.numass.storage.NumassData;
import inr.numass.storage.NumassStorage; import inr.numass.storage.NumassStorage;

View File

@ -21,7 +21,7 @@ package inr.numass.viewer;
* and open the template in the editor. * and open the template in the editor.
*/ */
import hep.dataforge.context.Context; import hep.dataforge.context.Context;
import hep.dataforge.work.WorkManager; import hep.dataforge.computation.WorkManager;
import hep.dataforge.io.ColumnedDataWriter; import hep.dataforge.io.ColumnedDataWriter;
import hep.dataforge.meta.Meta; import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaBuilder; import hep.dataforge.meta.MetaBuilder;