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.ClusterChange;
8 import org.simantics.acorn.internal.ClusterChange2;
9 import org.simantics.acorn.internal.ClusterUpdateProcessor;
10 import org.simantics.acorn.internal.ClusterUpdateProcessor2;
11 import org.simantics.db.service.Bytes;
12 import org.simantics.db.service.ClusterUID;
14 final public class ClusterUpdateOperation {
16 final public ClusterUID uid;
17 final protected ClusterManager manager;
18 final protected ClusterInfo info;
22 public ClusterStreamChunk chunk;
23 public ClusterChangeSet ccs;
24 boolean finished = false;
26 public ClusterUpdateOperation(ClusterManager manager, byte[] data) throws IllegalAcornStateException, AcornAccessVerificationException {
28 long cuid1 = Bytes.readLE8(data, 8);
29 long cuid2 = Bytes.readLE8(data, 16);
31 this.manager = manager;
32 this.uid = ClusterUID.make(cuid1, cuid2);
34 this.info = manager.clusterLRU.getOrCreate(uid, true);
37 public void finish() {
41 public void scheduled(String ccsInfoId) throws AcornAccessVerificationException, IllegalAcornStateException {
42 ccs = new ClusterChangeSet(ccsInfoId, uid);
43 chunk = ccs.getChunk(manager);
44 manager.addIntoCurrentChangeSet(ccsInfoId);
47 public void run() throws AcornAccessVerificationException, IllegalAcornStateException {
48 ClusterUpdateOperation op = null;
53 op = chunk.operations.get(ccs.chunkOffset);
61 public void runWithData(byte[] data) throws IllegalAcornStateException, AcornAccessVerificationException {
64 int version = Bytes.readLE4(data, 4);
65 if(version == ClusterChange.VERSION) {
66 ClusterUpdateProcessor processor = new ClusterUpdateProcessor(manager, manager.support, data, this);
67 ClusterImpl cluster = info.getForUpdate();
68 cluster = processor.process(cluster);
69 manager.update(uid, cluster);
70 } else if (version == ClusterChange2.VERSION) {
71 ClusterUpdateProcessor2 processor = new ClusterUpdateProcessor2(manager.support, data, this);
72 ClusterImpl cluster = info.getForUpdate();
73 processor.process(cluster);
74 manager.update(uid, cluster);
76 throw new IllegalAcornStateException("unsupported clusterChange version " + version);
78 } catch (IllegalAcornStateException | AcornAccessVerificationException e) {
80 } catch (Throwable t) {
81 throw new IllegalAcornStateException(t);
86 public String toString() {
87 StringBuilder sb = new StringBuilder();
88 sb.append("ClusterUpdateOperation [uid=").append(uid).append("] [info=").append(info).append("] [ccs=").append(ccs).append("] [chunk=").append("]");