mirror of
https://github.com/usatiuk/dhfs.git
synced 2025-10-28 12:37:48 +01:00
Recordify tree metadata
This commit is contained in:
@@ -6,12 +6,7 @@ import com.usatiuk.objects.JObjectKey;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class JKleppmannTreeNodeMetaDirectory extends JKleppmannTreeNodeMeta {
|
||||
public JKleppmannTreeNodeMetaDirectory(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public record JKleppmannTreeNodeMetaDirectory(String name) implements JKleppmannTreeNodeMeta {
|
||||
public JKleppmannTreeNodeMeta withName(String name) {
|
||||
return new JKleppmannTreeNodeMetaDirectory(name);
|
||||
}
|
||||
|
||||
@@ -5,49 +5,15 @@ import com.usatiuk.objects.JObjectKey;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class JKleppmannTreeNodeMetaFile extends JKleppmannTreeNodeMeta {
|
||||
private final JObjectKey _fileIno;
|
||||
|
||||
public JKleppmannTreeNodeMetaFile(String name, JObjectKey fileIno) {
|
||||
super(name);
|
||||
_fileIno = fileIno;
|
||||
}
|
||||
|
||||
public JObjectKey getFileIno() {
|
||||
return _fileIno;
|
||||
}
|
||||
|
||||
public record JKleppmannTreeNodeMetaFile(String name, JObjectKey fileIno) implements JKleppmannTreeNodeMeta {
|
||||
@Override
|
||||
public JKleppmannTreeNodeMeta withName(String name) {
|
||||
return new JKleppmannTreeNodeMetaFile(name, _fileIno);
|
||||
}
|
||||
|
||||
@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;
|
||||
JKleppmannTreeNodeMetaFile that = (JKleppmannTreeNodeMetaFile) o;
|
||||
return Objects.equals(_fileIno, that._fileIno);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), _fileIno);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JKleppmannTreeNodeMetaFile{" +
|
||||
"_name=" + getName() + ", " +
|
||||
"_fileIno=" + _fileIno +
|
||||
'}';
|
||||
return new JKleppmannTreeNodeMetaFile(name, fileIno);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<JObjectKey> collectRefsTo() {
|
||||
return List.of(_fileIno);
|
||||
return List.of(fileIno);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ public class DhfsFileServiceImpl implements DhfsFileService {
|
||||
try {
|
||||
var ret = getDirEntryR(name);
|
||||
return switch (ret.meta()) {
|
||||
case JKleppmannTreeNodeMetaFile f -> Optional.of(f.getFileIno());
|
||||
case JKleppmannTreeNodeMetaFile f -> Optional.of(f.fileIno());
|
||||
case JKleppmannTreeNodeMetaDirectory f -> Optional.of(ret.key());
|
||||
default -> Optional.empty();
|
||||
};
|
||||
@@ -189,7 +189,7 @@ public class DhfsFileServiceImpl implements DhfsFileService {
|
||||
return jObjectTxManager.executeTx(() -> {
|
||||
return getTreeW().findParent(w -> {
|
||||
if (w.meta() instanceof JKleppmannTreeNodeMetaFile f)
|
||||
return f.getFileIno().equals(ino);
|
||||
return f.fileIno().equals(ino);
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -10,14 +10,14 @@ public record LogEffect<TimestampT extends Comparable<TimestampT>, PeerIdT exten
|
||||
NodeIdT childId) implements Serializable {
|
||||
public String oldName() {
|
||||
if (oldInfo.oldMeta() != null) {
|
||||
return oldInfo.oldMeta().getName();
|
||||
return oldInfo.oldMeta().name();
|
||||
}
|
||||
return childId.toString();
|
||||
}
|
||||
|
||||
public String newName() {
|
||||
if (newMeta != null) {
|
||||
return newMeta.getName();
|
||||
return newMeta.name();
|
||||
}
|
||||
return childId.toString();
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.usatiuk.kleppmanntree;
|
||||
import java.io.Serializable;
|
||||
|
||||
public interface NodeMeta extends Serializable {
|
||||
String getName();
|
||||
String name();
|
||||
|
||||
NodeMeta withName(String name);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ public record OpMove<TimestampT extends Comparable<TimestampT>, PeerIdT extends
|
||||
NodeIdT childId) implements Serializable {
|
||||
public String newName() {
|
||||
if (newMeta != null)
|
||||
return newMeta.getName();
|
||||
return newMeta.name();
|
||||
return childId.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public interface TreeNode<TimestampT extends Comparable<TimestampT>, PeerIdT ext
|
||||
|
||||
default String name() {
|
||||
var meta = meta();
|
||||
if (meta != null) return meta.getName();
|
||||
if (meta != null) return meta.name();
|
||||
return key().toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ public abstract class TestNodeMeta implements NodeMeta {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
public String name() {
|
||||
return _name;
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user