Search in sources :

Example 1 with GraphChangeEvent

use of au.gov.asd.tac.constellation.graph.monitor.GraphChangeEvent in project constellation by constellation-app.

the class DualGraph method createLockingManager.

private LockingManager<LockingStoreGraph> createLockingManager() {
    return new LockingManager<LockingStoreGraph>() {

        @Override
        protected void update(final Object description, final Object editor) {
            final GraphChangeEvent event = new GraphChangeEvent(previousEvent, DualGraph.this, editor, description);
            previousEvent = event;
            SwingUtilities.invokeLater(() -> {
                synchronized (graphChangeListeners) {
                    for (final GraphChangeListener listener : graphChangeListeners) {
                        listener.graphChanged(event);
                    }
                }
            });
        }
    };
}
Also used : GraphChangeListener(au.gov.asd.tac.constellation.graph.monitor.GraphChangeListener) GraphChangeEvent(au.gov.asd.tac.constellation.graph.monitor.GraphChangeEvent)

Example 2 with GraphChangeEvent

use of au.gov.asd.tac.constellation.graph.monitor.GraphChangeEvent in project constellation by constellation-app.

the class DualGraphFlushTester method main.

public static void main(String[] args) throws InterruptedException {
    StoreGraph g = new StoreGraph();
    Graph dg = new DualGraph(g, true);
    dg.setUndoManager(new UndoRedo.Manager());
    WritableGraph wg = dg.getWritableGraph("sdfgsdfg", true);
    final int x = VisualConcept.VertexAttribute.X.ensure(wg);
    final int y = VisualConcept.VertexAttribute.Y.ensure(wg);
    final int z = VisualConcept.VertexAttribute.Z.ensure(wg);
    final int id = VisualConcept.VertexAttribute.IDENTIFIER.ensure(wg);
    for (int i = 0; i < 1000; i++) {
        final int vxId = wg.addVertex();
        wg.setFloatValue(x, vxId, i);
        wg.setFloatValue(y, vxId, i);
        wg.setFloatValue(z, vxId, i);
        wg.setStringValue(id, vxId, String.valueOf(i));
    }
    wg.commit();
    final float[] coordSums = new float[1000];
    GraphChangeListener gcl = (GraphChangeEvent event) -> {
        ReadableGraph rg = dg.getReadableGraph();
        try {
            for (int i = 0; i < 1000; i++) {
                final int vxId = rg.getVertex(i);
                coordSums[i] = rg.getFloatValue(x, vxId) + rg.getFloatValue(y, vxId) + rg.getFloatValue(z, vxId);
            }
        } finally {
            rg.release();
        }
    };
    dg.addGraphChangeListener(gcl);
    long time = System.currentTimeMillis();
    wg = dg.getWritableGraph("test", false);
    for (int i = 0; i < 100000; i++) {
        for (int j = 0; j < 1000; j++) {
            final int vxId = wg.getVertex(j);
            wg.setFloatValue(x, vxId, wg.getFloatValue(x, vxId) + 1);
            wg.setFloatValue(y, vxId, wg.getFloatValue(y, vxId) + 2);
            wg.setFloatValue(z, vxId, wg.getFloatValue(z, vxId) + 3);
        }
        wg = wg.flush(false);
    }
    wg.commit();
    LOGGER.log(Level.INFO, "took: {0}", (System.currentTimeMillis() - time));
    Thread.sleep(3000);
    LOGGER.log(Level.INFO, "{0}", Arrays.toString(coordSums));
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) GraphChangeListener(au.gov.asd.tac.constellation.graph.monitor.GraphChangeListener) UndoRedo(org.openide.awt.UndoRedo) GraphChangeEvent(au.gov.asd.tac.constellation.graph.monitor.GraphChangeEvent) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph)

Aggregations

GraphChangeEvent (au.gov.asd.tac.constellation.graph.monitor.GraphChangeEvent)2 GraphChangeListener (au.gov.asd.tac.constellation.graph.monitor.GraphChangeListener)2 Graph (au.gov.asd.tac.constellation.graph.Graph)1 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)1 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)1 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)1 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)1 UndoRedo (org.openide.awt.UndoRedo)1