use of gov.sandia.n2a.plugins.ExtensionPoint in project n2a by frothga.
the class PanelEquationTree method importFile.
public static void importFile(File path) {
Importer bestImporter = null;
float bestP = 0;
for (ExtensionPoint exp : PluginManager.getExtensionsForPoint(Importer.class)) {
float P = ((Importer) exp).isIn(path);
if (P > bestP) {
bestP = P;
bestImporter = (Importer) exp;
}
}
if (bestImporter != null)
bestImporter.process(path);
}
use of gov.sandia.n2a.plugins.ExtensionPoint in project n2a by frothga.
the class UIController method prepareAndSubmitRunEnsemble.
public boolean prepareAndSubmitRunEnsemble(Component parentComponent, MNode model) throws Exception {
// Set up simulators.
List<ExtensionPoint> simEP = PluginManager.getExtensionsForPoint(Backend.class);
Backend[] simulators = new Backend[simEP.size()];
int s = 0;
for (ExtensionPoint ep : simEP) {
simulators[s++] = (Backend) ep;
}
// Set up execution environments.
// Hack to suppress errors in this outdated code.
HostSystem[] envs = new HostSystem[0];
// TODO: Fix this with appropriate interfaces.
String name = (String) ReflectionUtil.invoke("getName", model);
String owner = (String) ReflectionUtil.invoke("getOwner", model);
CreateRunEnsembleDialog dlg = new CreateRunEnsembleDialog((JFrame) SwingUtilities.getRoot(parentComponent), // TODO change from -1
-1, /*TEMP*/
name, owner, 12342347483L, /*TEMP until appropriate interfaces*/
model, simulators, simulators[0], envs, HostSystem.get("localhost"), false);
dlg.setVisible(true);
if (dlg.getResult() == CreateRunEnsembleDialog.CREATE) {
String label = dlg.getLabel();
HostSystem env = dlg.getEnvironment();
Backend simulator = dlg.getSimulator();
ParameterSpecGroupSet groups = dlg.getParameterSpecGroupSet();
ParameterSpecGroupSet simHandledGroups;
try {
// next line modifies groups to remove any that the Simulator will handle
simHandledGroups = divideEnsembleParams(model, groups, simulator);
} catch (RuntimeException e) {
Dialogs.showDetails(MainFrame.instance, "could not create run ensemble", e);
return false;
}
List<String> outputExpressions = dlg.getSelectedOutputExpressions();
/*
int runNum = 0;
for(ParameterSet set : groups.generateAllSetsFromSpecs(false)) {
ParameterSet modelParamSet = set.subset("Model");
ParameterSet simParamSet = set.subset("Simulator");
modelParamSet.sliceKeyPathKeys();
simParamSet.sliceKeyPathKeys();
Run run = model.addRun(modelParamSet, re);
re.addRun(run);
Simulation simulation = simulator.createSimulation();
ParameterDomain domain = new ParameterDomain(simParamSet);
simulation.setSelectedParameters(domain);
try {
RunState runState;
logger.debug(System.currentTimeMillis() + " before execute for run " +
runNum++);
// quick and dirty attempt at batch script version of doing ensemble
runState = simulation.prepare(run, simHandledGroups, env);
// runState = simulation.execute(run, simHandledGroups, env);
run.setState(XStreamWrapper.writeToString(runState));
run.save();
} catch(Exception e1) {
UMF.handleUnexpectedError(null, e1, "Could not create the run. An error occurred.");
return false;
}
}
env.submitBatch(re);
*/
return true;
}
return false;
}
use of gov.sandia.n2a.plugins.ExtensionPoint in project n2a by frothga.
the class N2APlugin method getExtensions.
@Override
public ExtensionPoint[] getExtensions() {
List<ExtensionPoint> result = new ArrayList<ExtensionPoint>();
Collections.addAll(result, Unix.factory(), Windows.factory(), RemoteUnix.factory(), RemoteSlurm.factory());
if (!AppData.properties.getBoolean("headless")) {
Collections.addAll(result, new ExportNative(), gov.sandia.n2a.ui.ref.PanelSearch.exportBibTeX, new ImportNative(), new ImportBibTeX(), new ImportEndNote(), new ImportPubMed(), new ImportRIS(), new ActivityModel(), new ActivityRun(), new ActivityReference(), new ActivityStudy(), new ActivitySettings(), new SettingsAbout(), new SettingsGeneral(), new SettingsHost(), new SettingsLookAndFeel(), new SettingsRepo());
}
return result.toArray(new ExtensionPoint[result.size()]);
}
use of gov.sandia.n2a.plugins.ExtensionPoint in project n2a by frothga.
the class Backend method getBackend.
/**
* Finds the Backend instance that matches the given name.
* If no match is found, returns the Internal backend.
* If Internal is missing, the system is too broken to run.
*/
public static Backend getBackend(String name) {
Backend result = null;
Backend internal = null;
for (ExtensionPoint ext : PluginManager.getExtensionsForPoint(Backend.class)) {
Backend s = (Backend) ext;
if (s.getName().equalsIgnoreCase(name)) {
result = s;
break;
}
if (s.getName().equals("Internal"))
internal = s;
}
if (result == null)
result = internal;
if (result == null)
throw new RuntimeException("Couldn't find internal simulator!");
return result;
}
use of gov.sandia.n2a.plugins.ExtensionPoint in project n2a by frothga.
the class PanelModel method importFile.
public static void importFile(Path path) {
Import bestImporter = null;
float bestP = 0;
for (ExtensionPoint exp : PluginManager.getExtensionsForPoint(Import.class)) {
float P = ((Import) exp).matches(path);
if (P > bestP) {
bestP = P;
bestImporter = (Import) exp;
}
}
if (bestImporter != null)
bestImporter.process(path);
}
Aggregations