use of au.gov.asd.tac.constellation.graph.monitor.GlobalMonitor in project constellation by constellation-app.
the class ListeningTopComponent method newActiveGraph.
@Override
public final void newActiveGraph(final Graph graph) {
LOGGER.finer("NewActiveGraph");
if (currentGraph != graph) {
if (currentGraph != null) {
currentGraph.removeGraphChangeListener(this);
currentGraph = null;
}
if (graph != null) {
currentGraph = graph;
currentGraph.addGraphChangeListener(this);
ReadableGraph readableGraph = currentGraph.getReadableGraph();
try {
final Map<GlobalMonitor, Consumer<Graph>> globalMonitorsCopy;
synchronized (globalMonitors) {
globalMonitorsCopy = new HashMap<>(globalMonitors);
}
globalMonitorsCopy.forEach((monitor, handler) -> monitor.update(readableGraph));
final Map<StructureMonitor, Consumer<Graph>> structureMonitorsCopy;
synchronized (globalMonitors) {
structureMonitorsCopy = new HashMap<>(structureMonitors);
}
structureMonitorsCopy.forEach((monitor, handler) -> monitor.update(readableGraph));
final Map<AttributeCountMonitor, Consumer<Graph>> attributeCountMonitorsCopy;
synchronized (globalMonitors) {
attributeCountMonitorsCopy = new HashMap<>(attributeCountMonitors);
}
attributeCountMonitorsCopy.forEach((monitor, handler) -> monitor.update(readableGraph));
final Map<AttributeValueMonitor, Tuple<Consumer<Graph>, MonitorTransitionFilter>> attributeMonitorsCopy;
synchronized (globalMonitors) {
attributeMonitorsCopy = new HashMap<>(attributeValueMonitors);
}
attributeMonitorsCopy.forEach((monitor, handler) -> monitor.update(readableGraph));
} finally {
readableGraph.release();
}
graphChanged(null);
}
}
handleNewGraph(graph);
}
use of au.gov.asd.tac.constellation.graph.monitor.GlobalMonitor in project constellation by constellation-app.
the class ListeningTopComponent method addGlobalChangeHandler.
/**
* Define how your TopComponent handles any change to the graph.
*
* @param handler a {@link Consumer} of {@link Graph} objects which
* determines how this top component should respond to any change to the
* graph.
* @return the {@link GlobalMonitor} attached to your handler.
*/
protected GlobalMonitor addGlobalChangeHandler(final Consumer<Graph> handler) {
final GlobalMonitor globalMonitor = new GlobalMonitor();
initialiseMonitor(globalMonitor);
globalMonitors.put(globalMonitor, handler);
LOGGER.log(Level.FINE, "Added GlobalMonitor, count is {0}", globalMonitors.size());
return globalMonitor;
}
use of au.gov.asd.tac.constellation.graph.monitor.GlobalMonitor in project constellation by constellation-app.
the class ListeningTopComponent method graphChanged.
@Override
public final void graphChanged(final GraphChangeEvent event) {
LOGGER.finer("GraphChange");
if (event != null && ignoredEvents.contains(event.getDescription())) {
LOGGER.log(Level.FINER, "IgnoringEvent::{0}", event.getDescription());
return;
}
ReadableGraph readableGraph = currentGraph.getReadableGraph();
try {
final Map<GlobalMonitor, Consumer<Graph>> globalMonitorsCopy;
synchronized (globalMonitors) {
globalMonitorsCopy = new HashMap<>(globalMonitors);
}
globalMonitorsCopy.forEach((monitor, handler) -> {
LOGGER.finer("GraphChanged::CheckGlobal");
if (monitor.update(readableGraph) == MonitorTransition.CHANGED) {
LOGGER.finer("GraphChanged::UpdateGlobal");
if (handler != null) {
handler.accept(currentGraph);
}
}
});
final Map<StructureMonitor, Consumer<Graph>> structureMonitorsCopy;
synchronized (globalMonitors) {
structureMonitorsCopy = new HashMap<>(structureMonitors);
}
structureMonitorsCopy.forEach((monitor, handler) -> {
LOGGER.finer("GraphChanged::CheckStructure");
if (monitor.update(readableGraph) == MonitorTransition.CHANGED) {
LOGGER.finer("GraphChanged::UpdateStructure");
if (handler != null) {
handler.accept(currentGraph);
}
}
});
final Map<AttributeCountMonitor, Consumer<Graph>> attributeCountMonitorsCopy;
synchronized (globalMonitors) {
attributeCountMonitorsCopy = new HashMap<>(attributeCountMonitors);
}
attributeCountMonitorsCopy.forEach((monitor, handler) -> {
LOGGER.finer("GraphChanged::CheckAttributeCount");
if (monitor.update(readableGraph) == MonitorTransition.CHANGED) {
LOGGER.finer("GraphChanged::UpdateAttributeCount");
if (handler != null) {
handler.accept(currentGraph);
}
}
});
final Map<AttributeValueMonitor, Tuple<Consumer<Graph>, MonitorTransitionFilter>> attributeMonitorsCopy;
synchronized (globalMonitors) {
attributeMonitorsCopy = new HashMap<>(attributeValueMonitors);
}
attributeMonitorsCopy.forEach((monitor, handlerPair) -> {
LOGGER.finer("GraphChanged::CheckAttribute");
final Consumer<Graph> handler = handlerPair.getFirst();
final MonitorTransitionFilter transitionFilter = handlerPair.getSecond();
monitor.update(readableGraph);
if (transitionFilter.matchesTransitions(monitor)) {
LOGGER.log(Level.FINER, "GraphChanged::UpdateAttribute::{0}", monitor.getName());
if (handler != null) {
handler.accept(currentGraph);
}
}
});
} finally {
readableGraph.release();
}
handleGraphChange(event);
}
Aggregations