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);
}
}
});
}
};
}
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));
}
Aggregations