Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions client/src/main/java/io/lionweb/client/DeltaErrors.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.lionweb.client;

public enum DeltaErrors {
invalidParticipation,
nodeAlreadyExists,
unknownNode,
unknownIndex,
indexNodeMismatch,
moveWithoutParent,
invalidMove,
undefinedReferenceTarget
}
41 changes: 41 additions & 0 deletions client/src/main/java/io/lionweb/client/delta/CommandSource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.lionweb.client.delta;

import java.util.Objects;
import org.jetbrains.annotations.NotNull;

public class CommandSource {
public final @NotNull String participationId;
public final @NotNull String commandId;

public CommandSource(@NotNull String participationId, @NotNull String commandId) {
Objects.requireNonNull(participationId, "participationId should not be null");
Objects.requireNonNull(commandId, "commandId should not be null");
this.participationId = participationId;
this.commandId = commandId;
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
CommandSource that = (CommandSource) o;
return Objects.equals(participationId, that.participationId)
&& Objects.equals(commandId, that.commandId);
}

@Override
public int hashCode() {
return Objects.hash(participationId, commandId);
}

@Override
public String toString() {
return "CommandSource{"
+ "participationId='"
+ participationId
+ '\''
+ ", commandId='"
+ commandId
+ '\''
+ '}';
}
}
33 changes: 33 additions & 0 deletions client/src/main/java/io/lionweb/client/delta/DeltaChannel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.lionweb.client.delta;

import io.lionweb.client.delta.messages.DeltaCommand;
import io.lionweb.client.delta.messages.DeltaCommandResponse;
import io.lionweb.client.delta.messages.DeltaQuery;
import io.lionweb.client.delta.messages.DeltaQueryResponse;

/**
* The DeltaChannel must be a specific link between a Client and the Server. Different clients
* should use different DeltaChannels because the clientId must be determined from the channel.
*/
public interface DeltaChannel {
/**
* Queries initiated/requested by the client, with synchronous response by the repository. A query
* requests some information from the repository without changing the repository’s contents. The
* repository gathers all information needed to answer the query, and sends the information back.
* The repository might reply invalid queries with a failure message. We also use queries for
* managing participations.
*/
DeltaQueryResponse sendQuery(DeltaQuery query);

/**
* Commands initiated/requested by the client, with synchronous response by the repository. A
* command requests some change to the repository. The repository quickly confirms having received
* the command, or rejects a failed command.[5] However, the repository processes the command
* asynchronously, and eventually broadcasts the effect(s) as event.
*/
DeltaCommandResponse sendCommand(DeltaCommand command);

void registerEventReceiver(DeltaEventReceiver deltaEventReceiver);

void unregisterEventReceiver(DeltaEventReceiver deltaEventReceiver);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.lionweb.client.delta;

import io.lionweb.client.delta.messages.CommonDeltaEvent;

public interface DeltaEventReceiver {

void receiveEvent(CommonDeltaEvent event);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.lionweb.client.delta;

public enum DeltaProtocolVersion {
v2025_1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.lionweb.client.delta.messages;

import io.lionweb.client.delta.CommandSource;
import java.util.LinkedList;
import java.util.List;

public class CommonDeltaEvent extends DeltaEvent {
public final int sequenceNumber;
public final List<CommandSource> originCommands = new LinkedList<>();

public CommonDeltaEvent(int sequenceNumber) {
this.sequenceNumber = sequenceNumber;
}

public void addSource(CommandSource source) {
originCommands.add(source);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.lionweb.client.delta.messages;

import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;

public class DeltaCommand {
public final @NotNull String commandId;
public final List<ProtocolMessage> protocolMessages = new LinkedList<>();

public DeltaCommand(@NotNull String commandId) {
Objects.requireNonNull(commandId, "commandId should not be null");
this.commandId = commandId;
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
DeltaCommand that = (DeltaCommand) o;
return Objects.equals(commandId, that.commandId);
}

@Override
public int hashCode() {
return Objects.hashCode(commandId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package io.lionweb.client.delta.messages;

public class DeltaCommandResponse {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.lionweb.client.delta.messages;

import java.util.LinkedList;
import java.util.List;

public abstract class DeltaEvent {
public final List<ProtocolMessage> protocolMessages = new LinkedList<>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.lionweb.client.delta.messages;

import java.util.LinkedList;
import java.util.List;
import org.jetbrains.annotations.NotNull;

public abstract class DeltaQuery {
public final @NotNull String queryId;
public final List<ProtocolMessage> protocolMessages = new LinkedList<>();

public DeltaQuery(@NotNull String queryId) {
this.queryId = queryId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.lionweb.client.delta.messages;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.jetbrains.annotations.NotNull;

public class DeltaQueryResponse {
public final @NotNull String queryId;
public final List<ProtocolMessage> protocolMessages = new LinkedList<>();
public final Map<String, Object> values = new HashMap<>();

public DeltaQueryResponse(@NotNull String queryId) {
this.queryId = queryId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package io.lionweb.client.delta.messages;

public abstract class ProtocolMessage {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.lionweb.client.delta.messages.commands;

import io.lionweb.client.delta.messages.DeltaCommand;
import io.lionweb.serialization.data.MetaPointer;
import org.jetbrains.annotations.NotNull;

/** Change classifier of node to newClassifier. */
public class ChangeClassifier extends DeltaCommand {

public final String node;
public final MetaPointer newClassifier;

public ChangeClassifier(@NotNull String commandId, String node, MetaPointer newClassifier) {
super(commandId);
this.node = node;
this.newClassifier = newClassifier;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.lionweb.client.delta.messages.commands;

import io.lionweb.client.delta.messages.DeltaCommand;
import java.util.List;
import org.jetbrains.annotations.NotNull;

/** Groups several commands into a logical group. The parts are ordered. */
public class CompositeCommand extends DeltaCommand {
public final List<DeltaCommand> parts;

public CompositeCommand(@NotNull String commandId, List<DeltaCommand> parts) {
super(commandId);
this.parts = parts;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.lionweb.client.delta.messages.commands.annotations;

import io.lionweb.client.delta.messages.DeltaCommand;
import io.lionweb.serialization.data.SerializationChunk;
import org.jetbrains.annotations.NotNull;

/**
* Add new node newAnnotation to parent's annotations at index. newAnnotation might be a single node
* or an arbitrary complex subtree. All nodes in that subtree MUST be new, i.e. their id MUST NOT
* exist in the repository. Nodes in that subtree MAY have references to already existing nodes, and
* already existing nodes MAY have references to nodes in that subtree.
*/
public final class AddAnnotation extends DeltaCommand {
public final String parent;
public final SerializationChunk newAnnotation;
public final int index;

public AddAnnotation(
@NotNull String commandId, String parent, SerializationChunk newAnnotation, int index) {
super(commandId);
this.parent = parent;
this.newAnnotation = newAnnotation;
this.index = index;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.lionweb.client.delta.messages.commands.annotations;

import io.lionweb.client.delta.messages.DeltaCommand;
import org.jetbrains.annotations.NotNull;

/**
* Delete existing node deletedAnnotation from parent's annotations at index, and all its
* descendants (including annotation instances). Does NOT change references to any of the deleted
* nodes.
*/
public final class DeleteAnnotation extends DeltaCommand {
public final String node;
public final int index;
public final String deletedAnnotation;

public DeleteAnnotation(
@NotNull String commandId, String node, int index, String deletedAnnotation) {
super(commandId);
this.node = node;
this.index = index;
this.deletedAnnotation = deletedAnnotation;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.lionweb.client.delta.messages.commands.annotations;

import io.lionweb.client.delta.messages.DeltaCommand;
import org.jetbrains.annotations.NotNull;

/**
* Move existing node movedAnnotation inside newParent's annotations at newIndex. Delete current
* node replacedAnnotation at newParent's annotations at newIndex, and all its descendants
* (including annotation instances). Does NOT change references to any of the deleted nodes
*/
public final class MoveAndReplaceAnnotationFromOtherParent extends DeltaCommand {
public final String newParent;
public final int newIndex;
public final String replacedAnnotation;
public final String movedAnnotation;

public MoveAndReplaceAnnotationFromOtherParent(
@NotNull String commandId,
String newParent,
int newIndex,
String replacedAnnotation,
String movedAnnotation) {
super(commandId);
this.newParent = newParent;
this.newIndex = newIndex;
this.replacedAnnotation = replacedAnnotation;
this.movedAnnotation = movedAnnotation;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.lionweb.client.delta.messages.commands.annotations;

import io.lionweb.client.delta.messages.DeltaCommand;
import org.jetbrains.annotations.NotNull;

/**
* Move existing node movedAnnotation within the same parent to newIndex. Delete current node
* replacedAnnotation at movedAnnotation's parent’s annotations at newIndex, and all its descendants
* (including annotation instances). Does NOT change references to any of the deleted nodes.
*/
public final class MoveAndReplaceAnnotationInSameParent extends DeltaCommand {
public final int newIndex;
public final String replacedAnnotation;
public final String movedAnnotation;

public MoveAndReplaceAnnotationInSameParent(
@NotNull String commandId, int newIndex, String replacedAnnotation, String movedAnnotation) {
super(commandId);
this.newIndex = newIndex;
this.replacedAnnotation = replacedAnnotation;
this.movedAnnotation = movedAnnotation;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.lionweb.client.delta.messages.commands.annotations;

import io.lionweb.client.delta.messages.DeltaCommand;
import org.jetbrains.annotations.NotNull;

/** Move existing node movedAnnotation inside newParent's annotations at newIndex. */
public final class MoveAnnotationFromOtherParent extends DeltaCommand {
public final String newParent;
public final int newIndex;
public final String movedAnnotation;

public MoveAnnotationFromOtherParent(
@NotNull String commandId, String newParent, int newIndex, String movedAnnotation) {
super(commandId);
this.newParent = newParent;
this.newIndex = newIndex;
this.movedAnnotation = movedAnnotation;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.lionweb.client.delta.messages.commands.annotations;

import io.lionweb.client.delta.messages.DeltaCommand;
import org.jetbrains.annotations.NotNull;

/** Move existing node movedAnnotation within the same parent to newIndex. */
public final class MoveAnnotationInSameParent extends DeltaCommand {
public final int newIndex;
public final String movedAnnotation;

public MoveAnnotationInSameParent(
@NotNull String commandId, int newIndex, String movedAnnotation) {
super(commandId);
this.newIndex = newIndex;
this.movedAnnotation = movedAnnotation;
}
}
Loading