Search in sources :

Example 1 with MonitorTransitionFilter

use of au.gov.asd.tac.constellation.graph.monitor.MonitorTransitionFilter 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);
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) AttributeCountMonitor(au.gov.asd.tac.constellation.graph.monitor.AttributeCountMonitor) AttributeValueMonitor(au.gov.asd.tac.constellation.graph.monitor.AttributeValueMonitor) GlobalMonitor(au.gov.asd.tac.constellation.graph.monitor.GlobalMonitor) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) MonitorTransitionFilter(au.gov.asd.tac.constellation.graph.monitor.MonitorTransitionFilter) Consumer(java.util.function.Consumer) StructureMonitor(au.gov.asd.tac.constellation.graph.monitor.StructureMonitor) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple)

Aggregations

Graph (au.gov.asd.tac.constellation.graph.Graph)1 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)1 AttributeCountMonitor (au.gov.asd.tac.constellation.graph.monitor.AttributeCountMonitor)1 AttributeValueMonitor (au.gov.asd.tac.constellation.graph.monitor.AttributeValueMonitor)1 GlobalMonitor (au.gov.asd.tac.constellation.graph.monitor.GlobalMonitor)1 MonitorTransitionFilter (au.gov.asd.tac.constellation.graph.monitor.MonitorTransitionFilter)1 StructureMonitor (au.gov.asd.tac.constellation.graph.monitor.StructureMonitor)1 Tuple (au.gov.asd.tac.constellation.utilities.datastructure.Tuple)1 Consumer (java.util.function.Consumer)1