1 package org.simantics.acorn.lru;
3 import org.simantics.acorn.ClusterManager;
4 import org.simantics.acorn.cluster.ClusterImpl;
5 import org.simantics.acorn.exception.AcornAccessVerificationException;
6 import org.simantics.acorn.exception.IllegalAcornStateException;
7 import org.simantics.acorn.internal.ClusterUpdateProcessor;
8 import org.simantics.db.service.Bytes;
9 import org.simantics.db.service.ClusterUID;
11 final public class ClusterUpdateOperation {
13 final public ClusterUID uid;
14 final protected ClusterManager manager;
15 final protected ClusterInfo info;
19 public ClusterStreamChunk chunk;
20 public ClusterChangeSet ccs;
21 boolean finished = false;
23 public ClusterUpdateOperation(ClusterManager manager, byte[] data) throws IllegalAcornStateException, AcornAccessVerificationException {
25 long cuid1 = Bytes.readLE8(data, 8);
26 long cuid2 = Bytes.readLE8(data, 16);
28 this.manager = manager;
29 this.uid = ClusterUID.make(cuid1, cuid2);
31 this.info = manager.clusterLRU.getOrCreate(uid, true);
34 public void finish() {
38 public void scheduled(String ccsInfoId) throws AcornAccessVerificationException, IllegalAcornStateException {
39 ccs = new ClusterChangeSet(ccsInfoId, uid);
40 chunk = ccs.getChunk(manager);
41 manager.addIntoCurrentChangeSet(ccsInfoId);
44 public void run() throws AcornAccessVerificationException, IllegalAcornStateException {
45 ClusterUpdateOperation op = null;
50 op = chunk.operations.get(ccs.chunkOffset);
58 public void runWithData(byte[] data) throws IllegalAcornStateException, AcornAccessVerificationException {
60 ClusterUpdateProcessor processor = new ClusterUpdateProcessor(manager, manager.support, data, this);
61 ClusterImpl cluster = info.getForUpdate();
62 cluster = processor.process(cluster);
63 manager.update(uid, cluster);
64 } catch (IllegalAcornStateException | AcornAccessVerificationException e) {
66 } catch (Throwable t) {
67 throw new IllegalAcornStateException(t);
72 public String toString() {
73 StringBuilder sb = new StringBuilder();
74 sb.append("ClusterUpdateOperation [uid=").append(uid).append("] [info=").append(info).append("] [ccs=").append(ccs).append("] [chunk=").append("]");