1 package org.simantics.acorn.lru;
3 import org.simantics.acorn.ClusterManager;
4 import org.simantics.acorn.cluster.ClusterImpl;
5 import org.simantics.acorn.internal.ClusterChange;
6 import org.simantics.acorn.internal.ClusterChange2;
7 import org.simantics.acorn.internal.ClusterUpdateProcessor;
8 import org.simantics.acorn.internal.ClusterUpdateProcessor2;
9 import org.simantics.db.service.Bytes;
10 import org.simantics.db.service.ClusterUID;
12 final public class ClusterUpdateOperation {
14 final public ClusterUID uid;
15 final protected ClusterManager manager;
16 final protected ClusterInfo info;
20 public ClusterStreamChunk chunk;
21 public ClusterChangeSet ccs;
22 boolean finished = false;
24 public ClusterUpdateOperation(ClusterManager manager, byte[] data) {
26 long cuid1 = Bytes.readLE8(data, 8);
27 long cuid2 = Bytes.readLE8(data, 16);
29 this.manager = manager;
30 this.uid = ClusterUID.make(cuid1, cuid2);
32 this.info = manager.clusterLRU.getOrCreate(uid, true);
36 public void finish() {
40 public void scheduled(String ccsInfoId) {
41 ccs = new ClusterChangeSet(ccsInfoId, uid);
42 chunk = ccs.getChunk(manager);
43 manager.addIntoCurrentChangeSet(ccsInfoId);
47 ClusterUpdateOperation op = null;
52 op = chunk.operations.get(ccs.chunkOffset);
54 } catch (Throwable t) {
55 throw new IllegalStateException(t);
62 public void runWithData(byte[] data) {
65 int version = Bytes.readLE4(data, 4);
66 if(version == ClusterChange.VERSION) {
67 ClusterUpdateProcessor processor = new ClusterUpdateProcessor(manager, manager.support, data, this);
68 ClusterImpl cluster = info.getForUpdate();
69 cluster = processor.process(cluster);
70 manager.update(uid, cluster);
71 } else if (version == ClusterChange2.VERSION) {
72 ClusterUpdateProcessor2 processor = new ClusterUpdateProcessor2(manager.support, data, this);
73 ClusterImpl cluster = info.getForUpdate();
74 processor.process(cluster);
75 manager.update(uid, cluster);
77 throw new IllegalStateException();
79 } catch (Throwable 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("]");