use of au.gov.asd.tac.constellation.plugins.reporting.PluginReport in project constellation by constellation-app.
the class DefaultPluginEnvironment method executePluginLater.
@Override
public Future<?> executePluginLater(final Graph graph, final Plugin plugin, final PluginParameters parameters, final boolean interactive, final List<Future<?>> async, final PluginSynchronizer synchronizer) {
if (graph == null) {
LOGGER.log(Level.INFO, GRAPH_NULL_WARNING_MESSAGE, plugin.getName());
}
return getPluginExecutor().submit(() -> {
Thread.currentThread().setName(THREAD_POOL_NAME);
// vertices have been relocated is not sensible.
if (async != null) {
for (final Future<?> future : async) {
if (future != null) {
try {
future.get();
} catch (final InterruptedException ex) {
LOGGER.log(Level.SEVERE, "Execution interrupted", ex);
Thread.currentThread().interrupt();
} catch (final ExecutionException ex) {
LOGGER.log(Level.SEVERE, "Execution Exception", ex);
}
}
}
}
final ThreadConstraints callingConstraints = ThreadConstraints.getConstraints();
final boolean alwaysSilent = callingConstraints.isAlwaysSilent() || callingConstraints.getSilentCount() > 0;
PluginReport currentReport = null;
final GraphReport graphReport = graph == null ? null : GraphReportManager.getGraphReport(graph.getId());
if (graphReport != null) {
currentReport = graphReport.addPluginReport(plugin);
callingConstraints.setCurrentReport(currentReport);
}
try {
ConstellationLogger.getDefault().pluginStarted(plugin, parameters, graph);
} catch (final Exception ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage());
}
final PluginManager manager = new PluginManager(DefaultPluginEnvironment.this, plugin, graph, interactive, synchronizer);
final PluginGraphs graphs = new DefaultPluginGraphs(manager);
final PluginInteraction interaction = new DefaultPluginInteraction(manager, currentReport);
try {
if (parameters != null) {
plugin.updateParameters(graph, parameters);
}
if (interactive && parameters != null) {
if (interaction.prompt(plugin.getName(), parameters)) {
ThreadConstraints calledConstraints = ThreadConstraints.getConstraints();
calledConstraints.setAlwaysSilent(alwaysSilent);
try {
plugin.run(graphs, interaction, parameters);
} finally {
calledConstraints.setAlwaysSilent(false);
calledConstraints.setSilentCount(0);
if (synchronizer != null) {
synchronizer.finished();
}
}
}
} else {
final ThreadConstraints calledConstraints = ThreadConstraints.getConstraints();
calledConstraints.setAlwaysSilent(alwaysSilent);
try {
plugin.run(graphs, interaction, parameters);
} finally {
calledConstraints.setAlwaysSilent(false);
calledConstraints.setSilentCount(0);
if (synchronizer != null) {
synchronizer.finished();
}
}
}
} catch (final InterruptedException ex) {
auditPluginError(plugin, ex);
reportException(plugin.getName(), interaction, currentReport, null, ex);
Thread.currentThread().interrupt();
} catch (final PluginException ex) {
auditPluginError(plugin, ex);
reportException(plugin.getName(), interaction, currentReport, ex.getNotificationLevel(), ex);
} catch (final Exception ex) {
auditPluginError(plugin, ex);
reportException(plugin.getName(), interaction, currentReport, PluginNotificationLevel.ERROR, ex);
} finally {
if (currentReport != null) {
currentReport.stop();
callingConstraints.setCurrentReport(null);
currentReport.firePluginReportChangedEvent();
}
try {
ConstellationLogger.getDefault().pluginStopped(plugin, parameters);
} catch (final Exception ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage());
}
}
return null;
});
}
use of au.gov.asd.tac.constellation.plugins.reporting.PluginReport in project constellation by constellation-app.
the class DefaultPluginEnvironment method executeEditPluginNow.
@Override
public Object executeEditPluginNow(final GraphWriteMethods graph, final Plugin plugin, final PluginParameters parameters, final boolean interactive) throws InterruptedException, PluginException {
if (graph == null) {
LOGGER.log(Level.FINE, GRAPH_NULL_WARNING_MESSAGE, plugin.getName());
}
final ThreadConstraints callingConstraints = ThreadConstraints.getConstraints();
final int silentCount = callingConstraints.getSilentCount();
final boolean alwaysSilent = callingConstraints.isAlwaysSilent();
callingConstraints.setSilentCount(0);
callingConstraints.setAlwaysSilent(alwaysSilent || silentCount > 0);
final GraphReport graphReport = graph == null ? null : GraphReportManager.getGraphReport(graph.getId());
PluginReport parentReport = null;
PluginReport currentReport = null;
if (graphReport != null) {
parentReport = callingConstraints.getCurrentReport();
if (parentReport == null) {
currentReport = graphReport.addPluginReport(plugin);
} else {
currentReport = parentReport.addChildReport(plugin);
}
callingConstraints.setCurrentReport(currentReport);
}
final PluginManager manager = new PluginManager(DefaultPluginEnvironment.this, plugin, graph, interactive, null);
final PluginInteraction interaction = new DefaultPluginInteraction(manager, currentReport);
try {
ConstellationLogger.getDefault().pluginStarted(plugin, parameters, GraphNode.getGraph(graph != null ? graph.getId() : null));
} catch (final Exception ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage());
}
try {
plugin.run(graph, interaction, parameters);
} catch (final InterruptedException ex) {
auditPluginError(plugin, ex);
reportException(plugin.getName(), interaction, currentReport, null, ex);
Thread.currentThread().interrupt();
throw ex;
} catch (final PluginException ex) {
auditPluginError(plugin, ex);
reportException(plugin.getName(), interaction, currentReport, ex.getNotificationLevel(), ex);
throw ex;
} catch (final Exception ex) {
auditPluginError(plugin, ex);
reportException(plugin.getName(), interaction, currentReport, PluginNotificationLevel.ERROR, ex);
throw ex;
} finally {
callingConstraints.setSilentCount(silentCount);
callingConstraints.setAlwaysSilent(alwaysSilent);
if (currentReport != null) {
currentReport.stop();
callingConstraints.setCurrentReport(parentReport);
currentReport.firePluginReportChangedEvent();
}
try {
ConstellationLogger.getDefault().pluginStopped(plugin, parameters);
} catch (final Exception ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage());
}
}
return null;
}
use of au.gov.asd.tac.constellation.plugins.reporting.PluginReport in project constellation by constellation-app.
the class DefaultPluginInteractionNGTest method setUpMethod.
@BeforeMethod
public void setUpMethod() throws Exception {
environment = new DefaultPluginEnvironment();
plugin = new TestPlugin();
graph = new DualGraph(null);
synchroniser = new PluginSynchronizer(1);
graphReport = new GraphReport(graph.getId());
manager = new PluginManager(environment, plugin, graph, false, synchroniser);
report = new PluginReport(graphReport, plugin);
}
use of au.gov.asd.tac.constellation.plugins.reporting.PluginReport in project constellation by constellation-app.
the class DefaultPluginEnvironment method executePluginNow.
@Override
public Object executePluginNow(final Graph graph, final Plugin plugin, final PluginParameters parameters, final boolean interactive) throws InterruptedException, PluginException {
if (graph == null) {
LOGGER.log(Level.FINE, GRAPH_NULL_WARNING_MESSAGE, plugin.getName());
}
final ThreadConstraints callingConstraints = ThreadConstraints.getConstraints();
final int silentCount = callingConstraints.getSilentCount();
final boolean alwaysSilent = callingConstraints.isAlwaysSilent();
callingConstraints.setSilentCount(0);
callingConstraints.setAlwaysSilent(alwaysSilent || silentCount > 0);
final GraphReport graphReport = graph == null ? null : GraphReportManager.getGraphReport(graph.getId());
PluginReport parentReport = null;
PluginReport currentReport = null;
if (graphReport != null) {
parentReport = callingConstraints.getCurrentReport();
if (parentReport == null) {
currentReport = graphReport.addPluginReport(plugin);
} else {
currentReport = parentReport.addChildReport(plugin);
}
callingConstraints.setCurrentReport(currentReport);
}
final PluginManager manager = new PluginManager(DefaultPluginEnvironment.this, plugin, graph, interactive, null);
final PluginGraphs graphs = new DefaultPluginGraphs(manager);
final PluginInteraction interaction = new DefaultPluginInteraction(manager, currentReport);
try {
ConstellationLogger.getDefault().pluginStarted(plugin, parameters, graph);
} catch (final Exception ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage());
}
try {
if (parameters != null) {
plugin.updateParameters(graph, parameters);
}
if (interactive && parameters != null) {
if (interaction.prompt(plugin.getName(), parameters)) {
plugin.run(graphs, interaction, parameters);
}
} else {
plugin.run(graphs, interaction, parameters);
}
} catch (final InterruptedException ex) {
auditPluginError(plugin, ex);
reportException(plugin.getName(), interaction, currentReport, null, ex);
Thread.currentThread().interrupt();
throw ex;
} catch (final PluginException ex) {
auditPluginError(plugin, ex);
reportException(plugin.getName(), interaction, currentReport, ex.getNotificationLevel(), ex);
throw ex;
} catch (final Exception ex) {
auditPluginError(plugin, ex);
reportException(plugin.getName(), interaction, currentReport, PluginNotificationLevel.ERROR, ex);
throw ex;
} finally {
callingConstraints.setSilentCount(silentCount);
callingConstraints.setAlwaysSilent(alwaysSilent);
if (currentReport != null) {
currentReport.stop();
callingConstraints.setCurrentReport(parentReport);
currentReport.firePluginReportChangedEvent();
}
try {
ConstellationLogger.getDefault().pluginStopped(plugin, parameters);
} catch (final Exception ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage());
}
}
return null;
}
use of au.gov.asd.tac.constellation.plugins.reporting.PluginReport in project constellation by constellation-app.
the class DefaultPluginEnvironment method executeReadPluginNow.
@Override
public Object executeReadPluginNow(final GraphReadMethods graph, final Plugin plugin, final PluginParameters parameters, final boolean interactive) throws InterruptedException, PluginException {
if (graph == null) {
LOGGER.log(Level.FINE, GRAPH_NULL_WARNING_MESSAGE, plugin.getName());
}
final ThreadConstraints callingConstraints = ThreadConstraints.getConstraints();
final int silentCount = callingConstraints.getSilentCount();
final boolean alwaysSilent = callingConstraints.isAlwaysSilent();
callingConstraints.setSilentCount(0);
callingConstraints.setAlwaysSilent(alwaysSilent || silentCount > 0);
final GraphReport graphReport = graph == null ? null : GraphReportManager.getGraphReport(graph.getId());
PluginReport parentReport = null;
PluginReport currentReport = null;
if (graphReport != null) {
parentReport = callingConstraints.getCurrentReport();
if (parentReport == null) {
currentReport = graphReport.addPluginReport(plugin);
} else {
currentReport = parentReport.addChildReport(plugin);
}
callingConstraints.setCurrentReport(currentReport);
}
final PluginManager manager = new PluginManager(DefaultPluginEnvironment.this, plugin, graph, interactive, null);
final PluginInteraction interaction = new DefaultPluginInteraction(manager, currentReport);
try {
ConstellationLogger.getDefault().pluginStarted(plugin, parameters, GraphNode.getGraph(graph != null ? graph.getId() : null));
} catch (final Exception ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage());
}
try {
plugin.run(graph, interaction, parameters);
} catch (final InterruptedException ex) {
auditPluginError(plugin, ex);
reportException(plugin.getName(), interaction, currentReport, null, ex);
Thread.currentThread().interrupt();
throw ex;
} catch (final PluginException ex) {
auditPluginError(plugin, ex);
reportException(plugin.getName(), interaction, currentReport, ex.getNotificationLevel(), ex);
throw ex;
} catch (final Exception ex) {
auditPluginError(plugin, ex);
reportException(plugin.getName(), interaction, currentReport, PluginNotificationLevel.ERROR, ex);
throw ex;
} finally {
callingConstraints.setSilentCount(silentCount);
callingConstraints.setAlwaysSilent(alwaysSilent);
if (currentReport != null) {
currentReport.stop();
callingConstraints.setCurrentReport(parentReport);
currentReport.firePluginReportChangedEvent();
}
try {
ConstellationLogger.getDefault().pluginStopped(plugin, parameters);
} catch (final Exception ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage());
}
}
return null;
}
Aggregations