Recordify tree metadata

This commit is contained in:
2025-04-25 13:35:54 +02:00
parent e5be1e6164
commit 16ba692019
12 changed files with 23 additions and 116 deletions

View File

@@ -168,7 +168,7 @@ public class JKleppmannTreeManager {
// }
if (Log.isTraceEnabled())
Log.trace("Received op from " + from + ": " + jop.op().timestamp().timestamp() + " " + jop.op().childId() + "->" + jop.op().newParentId() + " as " + jop.op().newMeta().getName());
Log.trace("Received op from " + from + ": " + jop.op().timestamp().timestamp() + " " + jop.op().childId() + "->" + jop.op().newParentId() + " as " + jop.op().newMeta().name());
try {
_tree.applyExternalOp(from, jop.op());

View File

@@ -4,42 +4,10 @@ import com.usatiuk.kleppmanntree.NodeMeta;
import com.usatiuk.objects.JObjectKey;
import java.util.Collection;
import java.util.Objects;
//@ProtoMirror(JKleppmannTreeNodeMetaP.class)
public abstract class JKleppmannTreeNodeMeta implements NodeMeta {
private final String _name;
public interface JKleppmannTreeNodeMeta extends NodeMeta {
JKleppmannTreeNodeMeta withName(String name);
public JKleppmannTreeNodeMeta(String name) {
_name = name;
}
public String getName() {
return _name;
}
public abstract JKleppmannTreeNodeMeta withName(String name);
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
JKleppmannTreeNodeMeta that = (JKleppmannTreeNodeMeta) o;
return Objects.equals(_name, that._name);
}
@Override
public int hashCode() {
return Objects.hashCode(_name);
}
@Override
public String toString() {
return "JKleppmannTreeNodeMeta{" +
"class=" + this.getClass().getSimpleName() + " " +
"_name='" + _name + '\'' +
'}';
}
abstract public Collection<JObjectKey> collectRefsTo();
Collection<JObjectKey> collectRefsTo();
}

View File

@@ -41,7 +41,7 @@ public class PeerInfoService {
return jObjectTxManager.run(() -> {
return curTx.get(JKleppmannTreeNode.class, key).flatMap(node -> {
var meta = (JKleppmannTreeNodeMetaPeer) node.meta();
return remoteTx.getData(PeerInfo.class, meta.getPeerId());
return remoteTx.getData(PeerInfo.class, meta.peerId());
});
});
@@ -65,7 +65,7 @@ public class PeerInfoService {
}
return curTx.get(JKleppmannTreeNode.class, gotKey).flatMap(node -> {
var meta = (JKleppmannTreeNodeMetaPeer) node.meta();
return remoteTx.getData(PeerInfo.class, meta.getPeerId());
return remoteTx.getData(PeerInfo.class, meta.peerId());
});
});
}

View File

@@ -6,15 +6,11 @@ import com.usatiuk.objects.JObjectKey;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
//@ProtoMirror(JKleppmannTreeNodeMetaFileP.class)
public class JKleppmannTreeNodeMetaPeer extends JKleppmannTreeNodeMeta {
private final JObjectKey _peerId;
public record JKleppmannTreeNodeMetaPeer(String name, JObjectKey peerId) implements JKleppmannTreeNodeMeta {
public JKleppmannTreeNodeMetaPeer(PeerId id) {
super(peerIdToNodeId(id).value());
_peerId = id.toJObjectKey();
this(peerIdToNodeId(id).value(), id.id());
}
public static JObjectKey peerIdToNodeId(PeerId id) {
@@ -28,33 +24,15 @@ public class JKleppmannTreeNodeMetaPeer extends JKleppmannTreeNodeMeta {
return PeerId.of(id.value().substring(0, id.value().length() - "_tree_node".length()));
}
public JObjectKey getPeerId() {
return _peerId;
}
@Override
public JKleppmannTreeNodeMeta withName(String name) {
assert name.equals(peerIdToNodeId(PeerId.of(getPeerId().value())).toString());
assert getName().equals(name);
assert name.equals(peerIdToNodeId(PeerId.of(peerId().value())).toString());
assert name().equals(name);
return this;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
JKleppmannTreeNodeMetaPeer that = (JKleppmannTreeNodeMetaPeer) o;
return Objects.equals(_peerId, that._peerId);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), _peerId);
}
@Override
public Collection<JObjectKey> collectRefsTo() {
return List.of(_peerId);
return List.of(peerId);
}
}