Skip to content

Commit

Permalink
#302 Prepare new protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
dvoraka committed Jan 7, 2018
1 parent 2af1a45 commit 2b5eb12
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public final class DefaultReplicationMessage implements ReplicationMessage, File
private final String fromId;
private final String toId;
private final long sequence;
private final boolean master;
private final MessageRouting routing;
private final ReplicationStatus replicationStatus;
private final Command command;
Expand All @@ -46,6 +47,7 @@ private DefaultReplicationMessage(Builder builder) {
this.fromId = builder.fromId;
this.toId = builder.toId;
this.sequence = builder.sequence;
this.master = builder.master;
this.routing = builder.routing;
this.replicationStatus = builder.replicationStatus;
this.command = builder.command;
Expand Down Expand Up @@ -96,6 +98,11 @@ public long getSequence() {
return sequence;
}

@Override
public boolean isMaster() {
return false;
}

@Override
public MessageRouting getRouting() {
return routing;
Expand Down Expand Up @@ -177,6 +184,7 @@ public static class Builder {
private String fromId;
private String toId;
private long sequence;
private boolean master;
private MessageRouting routing;
private ReplicationStatus replicationStatus;
private Command command;
Expand Down Expand Up @@ -232,6 +240,11 @@ public Builder sequence(long sequence) {
return this;
}

public Builder master(boolean master) {
this.master = master;
return this;
}

public Builder routing(MessageRouting routing) {
this.routing = routing;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ public interface ReplicationMessage extends FileMessage {
*/
long getSequence();

/**
* Returns a master flag.
*
* @return the master flag
*/
boolean isMaster();

/**
* Returns a message routing type.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class DefaultRemoteLock implements
private int maxResponseTime;
private volatile boolean running;

private boolean master;

private final String idString;


Expand Down Expand Up @@ -213,7 +215,12 @@ private void initializeSequence() {
.peek(message -> log.debug("Sequence {}: {}", idString, message))
.findFirst()
.map(ReplicationMessage::getSequence)
.orElse(1L);
.orElse((long) NOT_INITIALIZED);

if (actualSequence == NOT_INITIALIZED) {
setMaster(true);
actualSequence = 1;
}

setSequence(actualSequence);

Expand Down Expand Up @@ -362,4 +369,12 @@ private void setRunning(boolean running) {
public boolean isRunning() {
return running;
}

private boolean isMaster() {
return master;
}

private void setMaster(boolean master) {
this.master = master;
}
}

0 comments on commit 2b5eb12

Please sign in to comment.