repo_name stringlengths 7 104 | file_path stringlengths 13 198 | context stringlengths 67 7.15k | import_statement stringlengths 16 4.43k | code stringlengths 40 6.98k | prompt stringlengths 227 8.27k | next_line stringlengths 8 795 |
|---|---|---|---|---|---|---|
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/event/VoteRequestHandler.java | // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/PersistentState.java
// public interface PersistentState {
//
// int NOT_VOTED_YET = -1;
//
// int currentTerm();
//
// int votedFor();
//
// int clearVotedForAndSetCurrentTerm(int term);
//
// int clearVotedForAndIncCurrentTerm();
//
// void votedFor(final int candidateId);
//
// CommandLog commandLog();
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.command.CommandLog;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.PersistentState;
import org.tools4j.hoverraft.state.Transition;
import java.util.Objects; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.event;
public final class VoteRequestHandler {
private final PersistentState persistentState;
public VoteRequestHandler(final PersistentState persistentState) {
this.persistentState = Objects.requireNonNull(persistentState);
}
| // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/PersistentState.java
// public interface PersistentState {
//
// int NOT_VOTED_YET = -1;
//
// int currentTerm();
//
// int votedFor();
//
// int clearVotedForAndSetCurrentTerm(int term);
//
// int clearVotedForAndIncCurrentTerm();
//
// void votedFor(final int candidateId);
//
// CommandLog commandLog();
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/event/VoteRequestHandler.java
import org.tools4j.hoverraft.command.CommandLog;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.PersistentState;
import org.tools4j.hoverraft.state.Transition;
import java.util.Objects;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.event;
public final class VoteRequestHandler {
private final PersistentState persistentState;
public VoteRequestHandler(final PersistentState persistentState) {
this.persistentState = Objects.requireNonNull(persistentState);
}
| public Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/event/VoteRequestHandler.java | // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/PersistentState.java
// public interface PersistentState {
//
// int NOT_VOTED_YET = -1;
//
// int currentTerm();
//
// int votedFor();
//
// int clearVotedForAndSetCurrentTerm(int term);
//
// int clearVotedForAndIncCurrentTerm();
//
// void votedFor(final int candidateId);
//
// CommandLog commandLog();
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.command.CommandLog;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.PersistentState;
import org.tools4j.hoverraft.state.Transition;
import java.util.Objects; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.event;
public final class VoteRequestHandler {
private final PersistentState persistentState;
public VoteRequestHandler(final PersistentState persistentState) {
this.persistentState = Objects.requireNonNull(persistentState);
}
public Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) { | // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/PersistentState.java
// public interface PersistentState {
//
// int NOT_VOTED_YET = -1;
//
// int currentTerm();
//
// int votedFor();
//
// int clearVotedForAndSetCurrentTerm(int term);
//
// int clearVotedForAndIncCurrentTerm();
//
// void votedFor(final int candidateId);
//
// CommandLog commandLog();
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/event/VoteRequestHandler.java
import org.tools4j.hoverraft.command.CommandLog;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.PersistentState;
import org.tools4j.hoverraft.state.Transition;
import java.util.Objects;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.event;
public final class VoteRequestHandler {
private final PersistentState persistentState;
public VoteRequestHandler(final PersistentState persistentState) {
this.persistentState = Objects.requireNonNull(persistentState);
}
public Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) { | final CommandLog commandLog = persistentState.commandLog(); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java | // Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.timer;
/**
* Events triggered by a timeout.
*/
public enum TimerEvent implements Event {
TIMEOUT;
@Override | // Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.timer;
/**
* Events triggered by a timeout.
*/
public enum TimerEvent implements Event {
TIMEOUT;
@Override | public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java | // Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.timer;
/**
* Events triggered by a timeout.
*/
public enum TimerEvent implements Event {
TIMEOUT;
@Override | // Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.timer;
/**
* Events triggered by a timeout.
*/
public enum TimerEvent implements Event {
TIMEOUT;
@Override | public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java | // Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.timer;
/**
* Events triggered by a timeout.
*/
public enum TimerEvent implements Event {
TIMEOUT;
@Override | // Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.timer;
/**
* Events triggered by a timeout.
*/
public enum TimerEvent implements Event {
TIMEOUT;
@Override | public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) { |
terzerm/hover-raft | src/test/java/org/tools4j/hoverraft/message/direct/DirectVoteResponseTest.java | // Path: src/main/java/org/tools4j/hoverraft/message/MessageType.java
// public enum MessageType {
// VOTE_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteRequest();
// }
// },
// VOTE_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteResponse();
// }
// },
// APPEND_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendRequest();
// }
// },
// APPEND_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendResponse();
// }
// },
// TIMEOUT_NOW {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.timeoutNow();
// }
// };
//
// private static final MessageType[] VALUES = values();
//
// public static final MessageType valueByOrdinal(final int ordinal) {
// return VALUES[ordinal];
// }
//
// public static final int maxOrdinal() {
// return VALUES.length - 1;
// }
//
// abstract public Message create(DirectFactory factory);
//
// public static MessageType readFrom(final DirectBuffer directBuffer, final int offset) {
// final int type = directBuffer.getInt(offset);
// if (type >= 0 & type <= MessageType.maxOrdinal()) {
// return MessageType.valueByOrdinal(type);
// }
// throw new IllegalArgumentException("Illegal message type: " + type);
// }
//
//
// }
| import org.agrona.ExpandableArrayBuffer;
import org.junit.Before;
import org.junit.Test;
import org.tools4j.hoverraft.message.MessageType;
import static org.assertj.core.api.Assertions.assertThat; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message.direct;
public class DirectVoteResponseTest {
private final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer(DirectVoteResponse.BYTE_LENGTH);
private final DirectVoteResponse directVoteResponse = new DirectVoteResponse();
@Before
public void init() {
directVoteResponse.wrap(buffer, 0);
}
@Test
public void should_get_the_data_that_has_been_set() throws Exception {
//given
final int term = 10;
final boolean voteGranted = true;
//when
directVoteResponse.term(term).voteGranted(voteGranted);
//then | // Path: src/main/java/org/tools4j/hoverraft/message/MessageType.java
// public enum MessageType {
// VOTE_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteRequest();
// }
// },
// VOTE_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteResponse();
// }
// },
// APPEND_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendRequest();
// }
// },
// APPEND_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendResponse();
// }
// },
// TIMEOUT_NOW {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.timeoutNow();
// }
// };
//
// private static final MessageType[] VALUES = values();
//
// public static final MessageType valueByOrdinal(final int ordinal) {
// return VALUES[ordinal];
// }
//
// public static final int maxOrdinal() {
// return VALUES.length - 1;
// }
//
// abstract public Message create(DirectFactory factory);
//
// public static MessageType readFrom(final DirectBuffer directBuffer, final int offset) {
// final int type = directBuffer.getInt(offset);
// if (type >= 0 & type <= MessageType.maxOrdinal()) {
// return MessageType.valueByOrdinal(type);
// }
// throw new IllegalArgumentException("Illegal message type: " + type);
// }
//
//
// }
// Path: src/test/java/org/tools4j/hoverraft/message/direct/DirectVoteResponseTest.java
import org.agrona.ExpandableArrayBuffer;
import org.junit.Before;
import org.junit.Test;
import org.tools4j.hoverraft.message.MessageType;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message.direct;
public class DirectVoteResponseTest {
private final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer(DirectVoteResponse.BYTE_LENGTH);
private final DirectVoteResponse directVoteResponse = new DirectVoteResponse();
@Before
public void init() {
directVoteResponse.wrap(buffer, 0);
}
@Test
public void should_get_the_data_that_has_been_set() throws Exception {
//given
final int term = 10;
final boolean voteGranted = true;
//when
directVoteResponse.term(term).voteGranted(voteGranted);
//then | assertThat(directVoteResponse.type()).isEqualTo(MessageType.VOTE_RESPONSE); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/transport/DefaultConnections.java | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/direct/DirectPayload.java
// public interface DirectPayload {
//
// int byteLength();
//
// int offset();
//
// DirectBuffer readBufferOrNull();
//
// MutableDirectBuffer writeBufferOrNull();
//
// void wrap(DirectBuffer buffer, int offset);
//
// void wrap(MutableDirectBuffer buffer, int offset);
//
// void unwrap();
//
// default boolean isWrapped() {
// return readBufferOrNull() != null || writeBufferOrNull() != null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/Message.java
// public interface Message extends DirectPayload, Event {
//
// MessageType type();
//
// default void sendTo(final Sender<? super Message> sender, final ResendStrategy resendStrategy) {
// final long res = sender.offer(this);
// if (res < 0) {
// resendStrategy.onRejectedOffer(sender, this, res);
// }
// }
//
//
// }
| import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.direct.DirectPayload;
import org.tools4j.hoverraft.message.Message;
import java.util.List;
import java.util.Objects; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.transport;
public class DefaultConnections<M extends Message> implements Connections<M> {
private final Receiver<Command>[] sourceReceivers;
private final Receiver<M>[] serverReceivers;
private final Sender<M> serverMulticastSender;
public DefaultConnections(final List<Receiver<? extends Command>> sourceReceivers,
final List<Receiver<? extends M>> serverReceivers,
final Sender<? super M> serverMulticastSender) {
Objects.requireNonNull(serverMulticastSender);
this.sourceReceivers = receivers(sourceReceivers);
this.serverReceivers = receivers(serverReceivers);
this.serverMulticastSender = (m) -> serverMulticastSender.offer(m);
}
//safely wraps Receiver<? super M> to Receiver<M> and converts List to array | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/direct/DirectPayload.java
// public interface DirectPayload {
//
// int byteLength();
//
// int offset();
//
// DirectBuffer readBufferOrNull();
//
// MutableDirectBuffer writeBufferOrNull();
//
// void wrap(DirectBuffer buffer, int offset);
//
// void wrap(MutableDirectBuffer buffer, int offset);
//
// void unwrap();
//
// default boolean isWrapped() {
// return readBufferOrNull() != null || writeBufferOrNull() != null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/Message.java
// public interface Message extends DirectPayload, Event {
//
// MessageType type();
//
// default void sendTo(final Sender<? super Message> sender, final ResendStrategy resendStrategy) {
// final long res = sender.offer(this);
// if (res < 0) {
// resendStrategy.onRejectedOffer(sender, this, res);
// }
// }
//
//
// }
// Path: src/main/java/org/tools4j/hoverraft/transport/DefaultConnections.java
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.direct.DirectPayload;
import org.tools4j.hoverraft.message.Message;
import java.util.List;
import java.util.Objects;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.transport;
public class DefaultConnections<M extends Message> implements Connections<M> {
private final Receiver<Command>[] sourceReceivers;
private final Receiver<M>[] serverReceivers;
private final Sender<M> serverMulticastSender;
public DefaultConnections(final List<Receiver<? extends Command>> sourceReceivers,
final List<Receiver<? extends M>> serverReceivers,
final Sender<? super M> serverMulticastSender) {
Objects.requireNonNull(serverMulticastSender);
this.sourceReceivers = receivers(sourceReceivers);
this.serverReceivers = receivers(serverReceivers);
this.serverMulticastSender = (m) -> serverMulticastSender.offer(m);
}
//safely wraps Receiver<? super M> to Receiver<M> and converts List to array | private static <M extends DirectPayload> Receiver<M>[] receivers(final List<Receiver<? extends M>> receivers) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/AppendResponse.java | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface AppendResponse extends Message {
int term();
AppendResponse term(int term);
boolean successful();
AppendResponse successful(boolean successful);
AppendResponse serverId(int serverId);
int serverId();
AppendResponse matchLogIndex(long matchLogIndex);
long matchLogIndex();
@Override | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/message/AppendResponse.java
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface AppendResponse extends Message {
int term();
AppendResponse term(int term);
boolean successful();
AppendResponse successful(boolean successful);
AppendResponse serverId(int serverId);
int serverId();
AppendResponse matchLogIndex(long matchLogIndex);
long matchLogIndex();
@Override | default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/AppendResponse.java | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface AppendResponse extends Message {
int term();
AppendResponse term(int term);
boolean successful();
AppendResponse successful(boolean successful);
AppendResponse serverId(int serverId);
int serverId();
AppendResponse matchLogIndex(long matchLogIndex);
long matchLogIndex();
@Override | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/message/AppendResponse.java
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface AppendResponse extends Message {
int term();
AppendResponse term(int term);
boolean successful();
AppendResponse successful(boolean successful);
AppendResponse serverId(int serverId);
int serverId();
AppendResponse matchLogIndex(long matchLogIndex);
long matchLogIndex();
@Override | default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/AppendResponse.java | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface AppendResponse extends Message {
int term();
AppendResponse term(int term);
boolean successful();
AppendResponse successful(boolean successful);
AppendResponse serverId(int serverId);
int serverId();
AppendResponse matchLogIndex(long matchLogIndex);
long matchLogIndex();
@Override | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/message/AppendResponse.java
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface AppendResponse extends Message {
int term();
AppendResponse term(int term);
boolean successful();
AppendResponse successful(boolean successful);
AppendResponse serverId(int serverId);
int serverId();
AppendResponse matchLogIndex(long matchLogIndex);
long matchLogIndex();
@Override | default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/State.java | // Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
| import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.server.ServerContext; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public interface State {
Role role(); | // Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/State.java
import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.server.ServerContext;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public interface State {
Role role(); | Transition onEvent(ServerContext serverContext, Event event); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/State.java | // Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
| import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.server.ServerContext; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public interface State {
Role role(); | // Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/State.java
import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.server.ServerContext;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public interface State {
Role role(); | Transition onEvent(ServerContext serverContext, Event event); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/AppendRequest.java | // Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogKey.java
// public interface LogKey extends Comparable<LogKey> {
// Comparator<LogKey> COMPARATOR = (k1, k2) -> {
// final int termCompare = Integer.compare(k1.term(), k2.term());
// return termCompare == 0 ? Long.compare(k1.index(), k2.index()) : termCompare;
// };
//
// int term();
// LogKey term(int term);
//
// long index();
// LogKey index(long index);
//
// @Override
// default int compareTo(final LogKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default LogContainment containedIn(final CommandLog commandLog) {
// return LogContainment.containmentFor(this, commandLog);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.command.LogKey;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface AppendRequest extends Message {
int term();
AppendRequest term(int term);
int leaderId();
AppendRequest leaderId(int leaderId);
| // Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogKey.java
// public interface LogKey extends Comparable<LogKey> {
// Comparator<LogKey> COMPARATOR = (k1, k2) -> {
// final int termCompare = Integer.compare(k1.term(), k2.term());
// return termCompare == 0 ? Long.compare(k1.index(), k2.index()) : termCompare;
// };
//
// int term();
// LogKey term(int term);
//
// long index();
// LogKey index(long index);
//
// @Override
// default int compareTo(final LogKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default LogContainment containedIn(final CommandLog commandLog) {
// return LogContainment.containmentFor(this, commandLog);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.command.LogKey;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface AppendRequest extends Message {
int term();
AppendRequest term(int term);
int leaderId();
AppendRequest leaderId(int leaderId);
| LogKey prevLogKey(); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/AppendRequest.java | // Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogKey.java
// public interface LogKey extends Comparable<LogKey> {
// Comparator<LogKey> COMPARATOR = (k1, k2) -> {
// final int termCompare = Integer.compare(k1.term(), k2.term());
// return termCompare == 0 ? Long.compare(k1.index(), k2.index()) : termCompare;
// };
//
// int term();
// LogKey term(int term);
//
// long index();
// LogKey index(long index);
//
// @Override
// default int compareTo(final LogKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default LogContainment containedIn(final CommandLog commandLog) {
// return LogContainment.containmentFor(this, commandLog);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.command.LogKey;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface AppendRequest extends Message {
int term();
AppendRequest term(int term);
int leaderId();
AppendRequest leaderId(int leaderId);
LogKey prevLogKey();
long leaderCommit();
AppendRequest leaderCommit(long leaderCommit);
| // Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogKey.java
// public interface LogKey extends Comparable<LogKey> {
// Comparator<LogKey> COMPARATOR = (k1, k2) -> {
// final int termCompare = Integer.compare(k1.term(), k2.term());
// return termCompare == 0 ? Long.compare(k1.index(), k2.index()) : termCompare;
// };
//
// int term();
// LogKey term(int term);
//
// long index();
// LogKey index(long index);
//
// @Override
// default int compareTo(final LogKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default LogContainment containedIn(final CommandLog commandLog) {
// return LogContainment.containmentFor(this, commandLog);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.command.LogKey;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface AppendRequest extends Message {
int term();
AppendRequest term(int term);
int leaderId();
AppendRequest leaderId(int leaderId);
LogKey prevLogKey();
long leaderCommit();
AppendRequest leaderCommit(long leaderCommit);
| Sequence<LogEntry> logEntries(); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/AppendRequest.java | // Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogKey.java
// public interface LogKey extends Comparable<LogKey> {
// Comparator<LogKey> COMPARATOR = (k1, k2) -> {
// final int termCompare = Integer.compare(k1.term(), k2.term());
// return termCompare == 0 ? Long.compare(k1.index(), k2.index()) : termCompare;
// };
//
// int term();
// LogKey term(int term);
//
// long index();
// LogKey index(long index);
//
// @Override
// default int compareTo(final LogKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default LogContainment containedIn(final CommandLog commandLog) {
// return LogContainment.containmentFor(this, commandLog);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.command.LogKey;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface AppendRequest extends Message {
int term();
AppendRequest term(int term);
int leaderId();
AppendRequest leaderId(int leaderId);
LogKey prevLogKey();
long leaderCommit();
AppendRequest leaderCommit(long leaderCommit);
Sequence<LogEntry> logEntries();
default AppendRequest appendLogEntry(final LogEntry logEntry) {
logEntries().append(logEntry);
return this;
}
@Override | // Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogKey.java
// public interface LogKey extends Comparable<LogKey> {
// Comparator<LogKey> COMPARATOR = (k1, k2) -> {
// final int termCompare = Integer.compare(k1.term(), k2.term());
// return termCompare == 0 ? Long.compare(k1.index(), k2.index()) : termCompare;
// };
//
// int term();
// LogKey term(int term);
//
// long index();
// LogKey index(long index);
//
// @Override
// default int compareTo(final LogKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default LogContainment containedIn(final CommandLog commandLog) {
// return LogContainment.containmentFor(this, commandLog);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.command.LogKey;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface AppendRequest extends Message {
int term();
AppendRequest term(int term);
int leaderId();
AppendRequest leaderId(int leaderId);
LogKey prevLogKey();
long leaderCommit();
AppendRequest leaderCommit(long leaderCommit);
Sequence<LogEntry> logEntries();
default AppendRequest appendLogEntry(final LogEntry logEntry) {
logEntries().append(logEntry);
return this;
}
@Override | default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/AppendRequest.java | // Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogKey.java
// public interface LogKey extends Comparable<LogKey> {
// Comparator<LogKey> COMPARATOR = (k1, k2) -> {
// final int termCompare = Integer.compare(k1.term(), k2.term());
// return termCompare == 0 ? Long.compare(k1.index(), k2.index()) : termCompare;
// };
//
// int term();
// LogKey term(int term);
//
// long index();
// LogKey index(long index);
//
// @Override
// default int compareTo(final LogKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default LogContainment containedIn(final CommandLog commandLog) {
// return LogContainment.containmentFor(this, commandLog);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.command.LogKey;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface AppendRequest extends Message {
int term();
AppendRequest term(int term);
int leaderId();
AppendRequest leaderId(int leaderId);
LogKey prevLogKey();
long leaderCommit();
AppendRequest leaderCommit(long leaderCommit);
Sequence<LogEntry> logEntries();
default AppendRequest appendLogEntry(final LogEntry logEntry) {
logEntries().append(logEntry);
return this;
}
@Override | // Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogKey.java
// public interface LogKey extends Comparable<LogKey> {
// Comparator<LogKey> COMPARATOR = (k1, k2) -> {
// final int termCompare = Integer.compare(k1.term(), k2.term());
// return termCompare == 0 ? Long.compare(k1.index(), k2.index()) : termCompare;
// };
//
// int term();
// LogKey term(int term);
//
// long index();
// LogKey index(long index);
//
// @Override
// default int compareTo(final LogKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default LogContainment containedIn(final CommandLog commandLog) {
// return LogContainment.containmentFor(this, commandLog);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.command.LogKey;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface AppendRequest extends Message {
int term();
AppendRequest term(int term);
int leaderId();
AppendRequest leaderId(int leaderId);
LogKey prevLogKey();
long leaderCommit();
AppendRequest leaderCommit(long leaderCommit);
Sequence<LogEntry> logEntries();
default AppendRequest appendLogEntry(final LogEntry logEntry) {
logEntries().append(logEntry);
return this;
}
@Override | default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/AppendRequest.java | // Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogKey.java
// public interface LogKey extends Comparable<LogKey> {
// Comparator<LogKey> COMPARATOR = (k1, k2) -> {
// final int termCompare = Integer.compare(k1.term(), k2.term());
// return termCompare == 0 ? Long.compare(k1.index(), k2.index()) : termCompare;
// };
//
// int term();
// LogKey term(int term);
//
// long index();
// LogKey index(long index);
//
// @Override
// default int compareTo(final LogKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default LogContainment containedIn(final CommandLog commandLog) {
// return LogContainment.containmentFor(this, commandLog);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.command.LogKey;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface AppendRequest extends Message {
int term();
AppendRequest term(int term);
int leaderId();
AppendRequest leaderId(int leaderId);
LogKey prevLogKey();
long leaderCommit();
AppendRequest leaderCommit(long leaderCommit);
Sequence<LogEntry> logEntries();
default AppendRequest appendLogEntry(final LogEntry logEntry) {
logEntries().append(logEntry);
return this;
}
@Override | // Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogKey.java
// public interface LogKey extends Comparable<LogKey> {
// Comparator<LogKey> COMPARATOR = (k1, k2) -> {
// final int termCompare = Integer.compare(k1.term(), k2.term());
// return termCompare == 0 ? Long.compare(k1.index(), k2.index()) : termCompare;
// };
//
// int term();
// LogKey term(int term);
//
// long index();
// LogKey index(long index);
//
// @Override
// default int compareTo(final LogKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default LogContainment containedIn(final CommandLog commandLog) {
// return LogContainment.containmentFor(this, commandLog);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.command.LogKey;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface AppendRequest extends Message {
int term();
AppendRequest term(int term);
int leaderId();
AppendRequest leaderId(int leaderId);
LogKey prevLogKey();
long leaderCommit();
AppendRequest leaderCommit(long leaderCommit);
Sequence<LogEntry> logEntries();
default AppendRequest appendLogEntry(final LogEntry logEntry) {
logEntries().append(logEntry);
return this;
}
@Override | default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/event/EventHandler.java | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
// public enum TimerEvent implements Event {
// TIMEOUT;
//
// @Override
// public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimerEvent(serverContext, this);
// }
// }
| import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.message.*;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
import org.tools4j.hoverraft.timer.TimerEvent; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.event;
/**
* Event handler for all event types. Acts as visitor called back in
* {@link Event#accept(ServerContext, EventHandler)}.
*/
public interface EventHandler {
default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;} | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
// public enum TimerEvent implements Event {
// TIMEOUT;
//
// @Override
// public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimerEvent(serverContext, this);
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.message.*;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
import org.tools4j.hoverraft.timer.TimerEvent;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.event;
/**
* Event handler for all event types. Acts as visitor called back in
* {@link Event#accept(ServerContext, EventHandler)}.
*/
public interface EventHandler {
default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;} | default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;} |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/event/EventHandler.java | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
// public enum TimerEvent implements Event {
// TIMEOUT;
//
// @Override
// public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimerEvent(serverContext, this);
// }
// }
| import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.message.*;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
import org.tools4j.hoverraft.timer.TimerEvent; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.event;
/**
* Event handler for all event types. Acts as visitor called back in
* {@link Event#accept(ServerContext, EventHandler)}.
*/
public interface EventHandler {
default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;} | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
// public enum TimerEvent implements Event {
// TIMEOUT;
//
// @Override
// public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimerEvent(serverContext, this);
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.message.*;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
import org.tools4j.hoverraft.timer.TimerEvent;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.event;
/**
* Event handler for all event types. Acts as visitor called back in
* {@link Event#accept(ServerContext, EventHandler)}.
*/
public interface EventHandler {
default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;} | default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;}; |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/direct/DirectCommand.java | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandPayload.java
// public interface CommandPayload {
// int commandByteLength();
// void bytesFrom(byte[] bytes, int offset, int length);
// void bytesFrom(ByteBuffer bytes, int offset, int length);
// void bytesFrom(DirectBuffer bytes, int offset, int length);
// void bytesTo(byte[] bytes, int offset);
// void bytesTo(ByteBuffer bytes, int offset);
// void bytesTo(MutableDirectBuffer bytes, int offset);
// void copyFrom(CommandPayload commandPayload);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/direct/AbstractDirectPayload.java
// abstract public class AbstractDirectPayload implements DirectPayload {
//
// protected DirectBuffer readBuffer;
// protected MutableDirectBuffer writeBuffer;
// protected int offset;
//
// @Override
// public int offset() {
// return offset;
// }
//
// @Override
// public DirectBuffer readBufferOrNull() {
// return readBuffer;
// }
//
// @Override
// public MutableDirectBuffer writeBufferOrNull() {
// return writeBuffer;
// }
//
// public void wrap(final DirectBuffer buffer, final int offset) {
// this.readBuffer = Objects.requireNonNull(buffer);
// this.writeBuffer = null;
// this.offset = offset;
// }
//
// public void wrap(final MutableDirectBuffer buffer, final int offset) {
// this.readBuffer = Objects.requireNonNull(buffer);
// this.writeBuffer = buffer;
// this.offset = offset;
// }
//
// public void unwrap() {
// this.readBuffer = null;
// this.writeBuffer = null;
// this.offset = 0;
// }
//
// protected void copyFrom(final DirectPayload directPayload) {
// this.writeBuffer.putBytes(offset, directPayload.readBufferOrNull(), directPayload.offset(), directPayload.byteLength());
// }
// }
| import org.agrona.DirectBuffer;
import org.agrona.MutableDirectBuffer;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.CommandPayload;
import org.tools4j.hoverraft.direct.AbstractDirectPayload; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message.direct;
public final class DirectCommand extends AbstractDirectPayload implements Command {
private static final int COMMAND_KEY_OFF = 0;
private static final int COMMAND_KEY_LEN = DirectCommandKey.BYTE_LENGTH;
private static final int COMMAND_PAYLOAD_OFF = COMMAND_KEY_OFF + COMMAND_KEY_LEN;
public static final int EMPTY_COMMAND_BYTE_LENGTH = COMMAND_KEY_LEN + DirectCommandPayload.EMPTY_PAYLOAD_BYTE_LENGTH;
private final DirectCommandKey commandKey = new DirectCommandKey();
private final DirectCommandPayload commandPayload = new DirectCommandPayload();
@Override
public int byteLength() {
return COMMAND_KEY_LEN + commandPayload.byteLength();
}
@Override | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandPayload.java
// public interface CommandPayload {
// int commandByteLength();
// void bytesFrom(byte[] bytes, int offset, int length);
// void bytesFrom(ByteBuffer bytes, int offset, int length);
// void bytesFrom(DirectBuffer bytes, int offset, int length);
// void bytesTo(byte[] bytes, int offset);
// void bytesTo(ByteBuffer bytes, int offset);
// void bytesTo(MutableDirectBuffer bytes, int offset);
// void copyFrom(CommandPayload commandPayload);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/direct/AbstractDirectPayload.java
// abstract public class AbstractDirectPayload implements DirectPayload {
//
// protected DirectBuffer readBuffer;
// protected MutableDirectBuffer writeBuffer;
// protected int offset;
//
// @Override
// public int offset() {
// return offset;
// }
//
// @Override
// public DirectBuffer readBufferOrNull() {
// return readBuffer;
// }
//
// @Override
// public MutableDirectBuffer writeBufferOrNull() {
// return writeBuffer;
// }
//
// public void wrap(final DirectBuffer buffer, final int offset) {
// this.readBuffer = Objects.requireNonNull(buffer);
// this.writeBuffer = null;
// this.offset = offset;
// }
//
// public void wrap(final MutableDirectBuffer buffer, final int offset) {
// this.readBuffer = Objects.requireNonNull(buffer);
// this.writeBuffer = buffer;
// this.offset = offset;
// }
//
// public void unwrap() {
// this.readBuffer = null;
// this.writeBuffer = null;
// this.offset = 0;
// }
//
// protected void copyFrom(final DirectPayload directPayload) {
// this.writeBuffer.putBytes(offset, directPayload.readBufferOrNull(), directPayload.offset(), directPayload.byteLength());
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/message/direct/DirectCommand.java
import org.agrona.DirectBuffer;
import org.agrona.MutableDirectBuffer;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.CommandPayload;
import org.tools4j.hoverraft.direct.AbstractDirectPayload;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message.direct;
public final class DirectCommand extends AbstractDirectPayload implements Command {
private static final int COMMAND_KEY_OFF = 0;
private static final int COMMAND_KEY_LEN = DirectCommandKey.BYTE_LENGTH;
private static final int COMMAND_PAYLOAD_OFF = COMMAND_KEY_OFF + COMMAND_KEY_LEN;
public static final int EMPTY_COMMAND_BYTE_LENGTH = COMMAND_KEY_LEN + DirectCommandPayload.EMPTY_PAYLOAD_BYTE_LENGTH;
private final DirectCommandKey commandKey = new DirectCommandKey();
private final DirectCommandPayload commandPayload = new DirectCommandPayload();
@Override
public int byteLength() {
return COMMAND_KEY_LEN + commandPayload.byteLength();
}
@Override | public CommandKey commandKey() { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/direct/DirectCommand.java | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandPayload.java
// public interface CommandPayload {
// int commandByteLength();
// void bytesFrom(byte[] bytes, int offset, int length);
// void bytesFrom(ByteBuffer bytes, int offset, int length);
// void bytesFrom(DirectBuffer bytes, int offset, int length);
// void bytesTo(byte[] bytes, int offset);
// void bytesTo(ByteBuffer bytes, int offset);
// void bytesTo(MutableDirectBuffer bytes, int offset);
// void copyFrom(CommandPayload commandPayload);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/direct/AbstractDirectPayload.java
// abstract public class AbstractDirectPayload implements DirectPayload {
//
// protected DirectBuffer readBuffer;
// protected MutableDirectBuffer writeBuffer;
// protected int offset;
//
// @Override
// public int offset() {
// return offset;
// }
//
// @Override
// public DirectBuffer readBufferOrNull() {
// return readBuffer;
// }
//
// @Override
// public MutableDirectBuffer writeBufferOrNull() {
// return writeBuffer;
// }
//
// public void wrap(final DirectBuffer buffer, final int offset) {
// this.readBuffer = Objects.requireNonNull(buffer);
// this.writeBuffer = null;
// this.offset = offset;
// }
//
// public void wrap(final MutableDirectBuffer buffer, final int offset) {
// this.readBuffer = Objects.requireNonNull(buffer);
// this.writeBuffer = buffer;
// this.offset = offset;
// }
//
// public void unwrap() {
// this.readBuffer = null;
// this.writeBuffer = null;
// this.offset = 0;
// }
//
// protected void copyFrom(final DirectPayload directPayload) {
// this.writeBuffer.putBytes(offset, directPayload.readBufferOrNull(), directPayload.offset(), directPayload.byteLength());
// }
// }
| import org.agrona.DirectBuffer;
import org.agrona.MutableDirectBuffer;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.CommandPayload;
import org.tools4j.hoverraft.direct.AbstractDirectPayload; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message.direct;
public final class DirectCommand extends AbstractDirectPayload implements Command {
private static final int COMMAND_KEY_OFF = 0;
private static final int COMMAND_KEY_LEN = DirectCommandKey.BYTE_LENGTH;
private static final int COMMAND_PAYLOAD_OFF = COMMAND_KEY_OFF + COMMAND_KEY_LEN;
public static final int EMPTY_COMMAND_BYTE_LENGTH = COMMAND_KEY_LEN + DirectCommandPayload.EMPTY_PAYLOAD_BYTE_LENGTH;
private final DirectCommandKey commandKey = new DirectCommandKey();
private final DirectCommandPayload commandPayload = new DirectCommandPayload();
@Override
public int byteLength() {
return COMMAND_KEY_LEN + commandPayload.byteLength();
}
@Override
public CommandKey commandKey() {
return commandKey;
}
@Override | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandPayload.java
// public interface CommandPayload {
// int commandByteLength();
// void bytesFrom(byte[] bytes, int offset, int length);
// void bytesFrom(ByteBuffer bytes, int offset, int length);
// void bytesFrom(DirectBuffer bytes, int offset, int length);
// void bytesTo(byte[] bytes, int offset);
// void bytesTo(ByteBuffer bytes, int offset);
// void bytesTo(MutableDirectBuffer bytes, int offset);
// void copyFrom(CommandPayload commandPayload);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/direct/AbstractDirectPayload.java
// abstract public class AbstractDirectPayload implements DirectPayload {
//
// protected DirectBuffer readBuffer;
// protected MutableDirectBuffer writeBuffer;
// protected int offset;
//
// @Override
// public int offset() {
// return offset;
// }
//
// @Override
// public DirectBuffer readBufferOrNull() {
// return readBuffer;
// }
//
// @Override
// public MutableDirectBuffer writeBufferOrNull() {
// return writeBuffer;
// }
//
// public void wrap(final DirectBuffer buffer, final int offset) {
// this.readBuffer = Objects.requireNonNull(buffer);
// this.writeBuffer = null;
// this.offset = offset;
// }
//
// public void wrap(final MutableDirectBuffer buffer, final int offset) {
// this.readBuffer = Objects.requireNonNull(buffer);
// this.writeBuffer = buffer;
// this.offset = offset;
// }
//
// public void unwrap() {
// this.readBuffer = null;
// this.writeBuffer = null;
// this.offset = 0;
// }
//
// protected void copyFrom(final DirectPayload directPayload) {
// this.writeBuffer.putBytes(offset, directPayload.readBufferOrNull(), directPayload.offset(), directPayload.byteLength());
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/message/direct/DirectCommand.java
import org.agrona.DirectBuffer;
import org.agrona.MutableDirectBuffer;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.CommandPayload;
import org.tools4j.hoverraft.direct.AbstractDirectPayload;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message.direct;
public final class DirectCommand extends AbstractDirectPayload implements Command {
private static final int COMMAND_KEY_OFF = 0;
private static final int COMMAND_KEY_LEN = DirectCommandKey.BYTE_LENGTH;
private static final int COMMAND_PAYLOAD_OFF = COMMAND_KEY_OFF + COMMAND_KEY_LEN;
public static final int EMPTY_COMMAND_BYTE_LENGTH = COMMAND_KEY_LEN + DirectCommandPayload.EMPTY_PAYLOAD_BYTE_LENGTH;
private final DirectCommandKey commandKey = new DirectCommandKey();
private final DirectCommandPayload commandPayload = new DirectCommandPayload();
@Override
public int byteLength() {
return COMMAND_KEY_LEN + commandPayload.byteLength();
}
@Override
public CommandKey commandKey() {
return commandKey;
}
@Override | public CommandPayload commandPayload() { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/PersistentState.java | // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
| import org.tools4j.hoverraft.command.CommandLog; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public interface PersistentState {
int NOT_VOTED_YET = -1;
int currentTerm();
int votedFor();
int clearVotedForAndSetCurrentTerm(int term);
int clearVotedForAndIncCurrentTerm();
void votedFor(final int candidateId);
| // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
// Path: src/main/java/org/tools4j/hoverraft/state/PersistentState.java
import org.tools4j.hoverraft.command.CommandLog;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public interface PersistentState {
int NOT_VOTED_YET = -1;
int currentTerm();
int votedFor();
int clearVotedForAndSetCurrentTerm(int term);
int clearVotedForAndIncCurrentTerm();
void votedFor(final int candidateId);
| CommandLog commandLog(); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/VolatileState.java | // Path: src/main/java/org/tools4j/hoverraft/config/ConsensusConfig.java
// public interface ConsensusConfig {
// long minElectionTimeoutMillis();
// long maxElectionTimeoutMillis();
// long heartbeatTimeoutMillis();
// Optional<String> ipcMulticastChannel();
// int serverCount();
// ServerConfig serverConfig(int index);
// int sourceCount();
// SourceConfig sourceConfig(int index);
// ThreadingMode threadingMode();
//
// default ServerConfig serverConfigByIdOrNull(int id) {
// for (int i = 0; i < serverCount(); i++) {
// final ServerConfig config = serverConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
//
// default SourceConfig sourceConfigByIdOrNull(int id) {
// for (int i = 0; i < sourceCount(); i++) {
// final SourceConfig config = sourceConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
// }
| import org.tools4j.hoverraft.config.ConsensusConfig; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public final class VolatileState {
private final TrackedFollowerState[] trackedFollowerStates;
@Deprecated //REMOVE this is now storted as State in HoverRaftMachine
private Role role = Role.FOLLOWER;
private long commitIndex = -1;
private long lastApplied = -1;
| // Path: src/main/java/org/tools4j/hoverraft/config/ConsensusConfig.java
// public interface ConsensusConfig {
// long minElectionTimeoutMillis();
// long maxElectionTimeoutMillis();
// long heartbeatTimeoutMillis();
// Optional<String> ipcMulticastChannel();
// int serverCount();
// ServerConfig serverConfig(int index);
// int sourceCount();
// SourceConfig sourceConfig(int index);
// ThreadingMode threadingMode();
//
// default ServerConfig serverConfigByIdOrNull(int id) {
// for (int i = 0; i < serverCount(); i++) {
// final ServerConfig config = serverConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
//
// default SourceConfig sourceConfigByIdOrNull(int id) {
// for (int i = 0; i < sourceCount(); i++) {
// final SourceConfig config = sourceConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/VolatileState.java
import org.tools4j.hoverraft.config.ConsensusConfig;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public final class VolatileState {
private final TrackedFollowerState[] trackedFollowerStates;
@Deprecated //REMOVE this is now storted as State in HoverRaftMachine
private Role role = Role.FOLLOWER;
private long commitIndex = -1;
private long lastApplied = -1;
| public VolatileState(final int serverId, final ConsensusConfig consensusConfig) { |
terzerm/hover-raft | src/test/java/org/tools4j/hoverraft/message/direct/DirectAppendResponseTest.java | // Path: src/main/java/org/tools4j/hoverraft/message/MessageType.java
// public enum MessageType {
// VOTE_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteRequest();
// }
// },
// VOTE_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteResponse();
// }
// },
// APPEND_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendRequest();
// }
// },
// APPEND_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendResponse();
// }
// },
// TIMEOUT_NOW {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.timeoutNow();
// }
// };
//
// private static final MessageType[] VALUES = values();
//
// public static final MessageType valueByOrdinal(final int ordinal) {
// return VALUES[ordinal];
// }
//
// public static final int maxOrdinal() {
// return VALUES.length - 1;
// }
//
// abstract public Message create(DirectFactory factory);
//
// public static MessageType readFrom(final DirectBuffer directBuffer, final int offset) {
// final int type = directBuffer.getInt(offset);
// if (type >= 0 & type <= MessageType.maxOrdinal()) {
// return MessageType.valueByOrdinal(type);
// }
// throw new IllegalArgumentException("Illegal message type: " + type);
// }
//
//
// }
| import org.agrona.ExpandableArrayBuffer;
import org.junit.Before;
import org.junit.Test;
import org.tools4j.hoverraft.message.MessageType;
import static org.assertj.core.api.Assertions.assertThat; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message.direct;
public class DirectAppendResponseTest {
private final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer(DirectAppendResponse.BYTE_LENGTH);
private final DirectAppendResponse directAppendResponse = new DirectAppendResponse();
@Before
public void init() {
directAppendResponse.wrap(buffer, 0);
}
@Test
public void should_get_the_data_that_has_been_set() throws Exception {
//given
final int term = 10;
final boolean sucessful = true;
final int serverId = 5;
final long matchLogIndex = 564564;
//when
directAppendResponse
.term(term)
.successful(sucessful)
.serverId(serverId)
.matchLogIndex(matchLogIndex);
//then | // Path: src/main/java/org/tools4j/hoverraft/message/MessageType.java
// public enum MessageType {
// VOTE_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteRequest();
// }
// },
// VOTE_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteResponse();
// }
// },
// APPEND_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendRequest();
// }
// },
// APPEND_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendResponse();
// }
// },
// TIMEOUT_NOW {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.timeoutNow();
// }
// };
//
// private static final MessageType[] VALUES = values();
//
// public static final MessageType valueByOrdinal(final int ordinal) {
// return VALUES[ordinal];
// }
//
// public static final int maxOrdinal() {
// return VALUES.length - 1;
// }
//
// abstract public Message create(DirectFactory factory);
//
// public static MessageType readFrom(final DirectBuffer directBuffer, final int offset) {
// final int type = directBuffer.getInt(offset);
// if (type >= 0 & type <= MessageType.maxOrdinal()) {
// return MessageType.valueByOrdinal(type);
// }
// throw new IllegalArgumentException("Illegal message type: " + type);
// }
//
//
// }
// Path: src/test/java/org/tools4j/hoverraft/message/direct/DirectAppendResponseTest.java
import org.agrona.ExpandableArrayBuffer;
import org.junit.Before;
import org.junit.Test;
import org.tools4j.hoverraft.message.MessageType;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message.direct;
public class DirectAppendResponseTest {
private final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer(DirectAppendResponse.BYTE_LENGTH);
private final DirectAppendResponse directAppendResponse = new DirectAppendResponse();
@Before
public void init() {
directAppendResponse.wrap(buffer, 0);
}
@Test
public void should_get_the_data_that_has_been_set() throws Exception {
//given
final int term = 10;
final boolean sucessful = true;
final int serverId = 5;
final long matchLogIndex = 564564;
//when
directAppendResponse
.term(term)
.successful(sucessful)
.serverId(serverId)
.matchLogIndex(matchLogIndex);
//then | assertThat(directAppendResponse.type()).isEqualTo(MessageType.APPEND_RESPONSE); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/direct/DirectAppendResponse.java | // Path: src/main/java/org/tools4j/hoverraft/message/AppendResponse.java
// public interface AppendResponse extends Message {
//
// int term();
//
// AppendResponse term(int term);
//
// boolean successful();
//
// AppendResponse successful(boolean successful);
//
// AppendResponse serverId(int serverId);
//
// int serverId();
//
// AppendResponse matchLogIndex(long matchLogIndex);
//
// long matchLogIndex();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendResponse(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/MessageType.java
// public enum MessageType {
// VOTE_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteRequest();
// }
// },
// VOTE_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteResponse();
// }
// },
// APPEND_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendRequest();
// }
// },
// APPEND_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendResponse();
// }
// },
// TIMEOUT_NOW {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.timeoutNow();
// }
// };
//
// private static final MessageType[] VALUES = values();
//
// public static final MessageType valueByOrdinal(final int ordinal) {
// return VALUES[ordinal];
// }
//
// public static final int maxOrdinal() {
// return VALUES.length - 1;
// }
//
// abstract public Message create(DirectFactory factory);
//
// public static MessageType readFrom(final DirectBuffer directBuffer, final int offset) {
// final int type = directBuffer.getInt(offset);
// if (type >= 0 & type <= MessageType.maxOrdinal()) {
// return MessageType.valueByOrdinal(type);
// }
// throw new IllegalArgumentException("Illegal message type: " + type);
// }
//
//
// }
| import org.tools4j.hoverraft.message.AppendResponse;
import org.tools4j.hoverraft.message.MessageType; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message.direct;
public final class DirectAppendResponse extends AbstractDirectMessage implements AppendResponse {
private static final byte SUCCESSFUL = 1;
private static final byte UNSUCCESSFUL = 0;
private static final int TERM_OFF = TYPE_OFF + TYPE_LEN;
private static final int TERM_LEN = 4;
private static final int SUCCESSFUL_OFF = TERM_OFF + TERM_LEN;
private static final int SUCCESSFUL_LEN = 1;
private static final int SERVER_ID_OFF = SUCCESSFUL_OFF + SUCCESSFUL_LEN;
private static final int SERVER_ID_LEN = 4;
private static final int MATCH_LOG_INDEX_OFF = SERVER_ID_OFF + SERVER_ID_LEN;
private static final int MATCH_LOG_INDEX__LEN = 8;
public static final int BYTE_LENGTH = MATCH_LOG_INDEX_OFF + MATCH_LOG_INDEX__LEN;
@Override | // Path: src/main/java/org/tools4j/hoverraft/message/AppendResponse.java
// public interface AppendResponse extends Message {
//
// int term();
//
// AppendResponse term(int term);
//
// boolean successful();
//
// AppendResponse successful(boolean successful);
//
// AppendResponse serverId(int serverId);
//
// int serverId();
//
// AppendResponse matchLogIndex(long matchLogIndex);
//
// long matchLogIndex();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendResponse(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/MessageType.java
// public enum MessageType {
// VOTE_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteRequest();
// }
// },
// VOTE_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteResponse();
// }
// },
// APPEND_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendRequest();
// }
// },
// APPEND_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendResponse();
// }
// },
// TIMEOUT_NOW {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.timeoutNow();
// }
// };
//
// private static final MessageType[] VALUES = values();
//
// public static final MessageType valueByOrdinal(final int ordinal) {
// return VALUES[ordinal];
// }
//
// public static final int maxOrdinal() {
// return VALUES.length - 1;
// }
//
// abstract public Message create(DirectFactory factory);
//
// public static MessageType readFrom(final DirectBuffer directBuffer, final int offset) {
// final int type = directBuffer.getInt(offset);
// if (type >= 0 & type <= MessageType.maxOrdinal()) {
// return MessageType.valueByOrdinal(type);
// }
// throw new IllegalArgumentException("Illegal message type: " + type);
// }
//
//
// }
// Path: src/main/java/org/tools4j/hoverraft/message/direct/DirectAppendResponse.java
import org.tools4j.hoverraft.message.AppendResponse;
import org.tools4j.hoverraft.message.MessageType;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message.direct;
public final class DirectAppendResponse extends AbstractDirectMessage implements AppendResponse {
private static final byte SUCCESSFUL = 1;
private static final byte UNSUCCESSFUL = 0;
private static final int TERM_OFF = TYPE_OFF + TYPE_LEN;
private static final int TERM_LEN = 4;
private static final int SUCCESSFUL_OFF = TERM_OFF + TERM_LEN;
private static final int SUCCESSFUL_LEN = 1;
private static final int SERVER_ID_OFF = SUCCESSFUL_OFF + SUCCESSFUL_LEN;
private static final int SERVER_ID_LEN = 4;
private static final int MATCH_LOG_INDEX_OFF = SERVER_ID_OFF + SERVER_ID_LEN;
private static final int MATCH_LOG_INDEX__LEN = 8;
public static final int BYTE_LENGTH = MATCH_LOG_INDEX_OFF + MATCH_LOG_INDEX__LEN;
@Override | public MessageType type() { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/DirectPersistentState.java | // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/config/ConsensusConfig.java
// public interface ConsensusConfig {
// long minElectionTimeoutMillis();
// long maxElectionTimeoutMillis();
// long heartbeatTimeoutMillis();
// Optional<String> ipcMulticastChannel();
// int serverCount();
// ServerConfig serverConfig(int index);
// int sourceCount();
// SourceConfig sourceConfig(int index);
// ThreadingMode threadingMode();
//
// default ServerConfig serverConfigByIdOrNull(int id) {
// for (int i = 0; i < serverCount(); i++) {
// final ServerConfig config = serverConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
//
// default SourceConfig sourceConfigByIdOrNull(int id) {
// for (int i = 0; i < sourceCount(); i++) {
// final SourceConfig config = sourceConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/config/ServerConfig.java
// public interface ServerConfig {
// int id();
// String channel();
// }
//
// Path: src/main/java/org/tools4j/hoverraft/util/Files.java
// public class Files {
//
// private static final int INITIAL_BUFFER_SIZE = 1024;
//
// public static final String SYS_PROP_FILE_DIR = "org.tools4j.hoverraft.FileDir";
//
// public static final String defaultFileDirectory() {
// return System.getProperty("java.util.tmpdir");
// }
//
// public static final String fileDirectory() {
// return System.getProperty(SYS_PROP_FILE_DIR, defaultFileDirectory());
// }
//
// public static final String fileName(final int serverId, final String name) {
// return "hover-raft_" + serverId + "_" + name;
// }
//
// public static final CommandLog commandLog(final int serverId, final String name) throws IOException {
// final String path = Files.fileDirectory();
// final String child = Files.fileName(serverId, name);
// final Chronicle chronicle = ChronicleQueueBuilder.vanilla(path, child).build();
// return new ChronicleCommandLog((VanillaChronicle)chronicle, new ExpandableArrayBuffer(INITIAL_BUFFER_SIZE));
// }
// }
| import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import org.agrona.MutableDirectBuffer;
import org.agrona.concurrent.UnsafeBuffer;
import org.tools4j.hoverraft.command.CommandLog;
import org.tools4j.hoverraft.config.ConsensusConfig;
import org.tools4j.hoverraft.config.ServerConfig;
import org.tools4j.hoverraft.util.Files; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public final class DirectPersistentState implements PersistentState {
private static final int STATE_SIZE = 4 + 4;
private final MutableDirectBuffer state; | // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/config/ConsensusConfig.java
// public interface ConsensusConfig {
// long minElectionTimeoutMillis();
// long maxElectionTimeoutMillis();
// long heartbeatTimeoutMillis();
// Optional<String> ipcMulticastChannel();
// int serverCount();
// ServerConfig serverConfig(int index);
// int sourceCount();
// SourceConfig sourceConfig(int index);
// ThreadingMode threadingMode();
//
// default ServerConfig serverConfigByIdOrNull(int id) {
// for (int i = 0; i < serverCount(); i++) {
// final ServerConfig config = serverConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
//
// default SourceConfig sourceConfigByIdOrNull(int id) {
// for (int i = 0; i < sourceCount(); i++) {
// final SourceConfig config = sourceConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/config/ServerConfig.java
// public interface ServerConfig {
// int id();
// String channel();
// }
//
// Path: src/main/java/org/tools4j/hoverraft/util/Files.java
// public class Files {
//
// private static final int INITIAL_BUFFER_SIZE = 1024;
//
// public static final String SYS_PROP_FILE_DIR = "org.tools4j.hoverraft.FileDir";
//
// public static final String defaultFileDirectory() {
// return System.getProperty("java.util.tmpdir");
// }
//
// public static final String fileDirectory() {
// return System.getProperty(SYS_PROP_FILE_DIR, defaultFileDirectory());
// }
//
// public static final String fileName(final int serverId, final String name) {
// return "hover-raft_" + serverId + "_" + name;
// }
//
// public static final CommandLog commandLog(final int serverId, final String name) throws IOException {
// final String path = Files.fileDirectory();
// final String child = Files.fileName(serverId, name);
// final Chronicle chronicle = ChronicleQueueBuilder.vanilla(path, child).build();
// return new ChronicleCommandLog((VanillaChronicle)chronicle, new ExpandableArrayBuffer(INITIAL_BUFFER_SIZE));
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/DirectPersistentState.java
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import org.agrona.MutableDirectBuffer;
import org.agrona.concurrent.UnsafeBuffer;
import org.tools4j.hoverraft.command.CommandLog;
import org.tools4j.hoverraft.config.ConsensusConfig;
import org.tools4j.hoverraft.config.ServerConfig;
import org.tools4j.hoverraft.util.Files;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public final class DirectPersistentState implements PersistentState {
private static final int STATE_SIZE = 4 + 4;
private final MutableDirectBuffer state; | private final CommandLog commandLog; |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/DirectPersistentState.java | // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/config/ConsensusConfig.java
// public interface ConsensusConfig {
// long minElectionTimeoutMillis();
// long maxElectionTimeoutMillis();
// long heartbeatTimeoutMillis();
// Optional<String> ipcMulticastChannel();
// int serverCount();
// ServerConfig serverConfig(int index);
// int sourceCount();
// SourceConfig sourceConfig(int index);
// ThreadingMode threadingMode();
//
// default ServerConfig serverConfigByIdOrNull(int id) {
// for (int i = 0; i < serverCount(); i++) {
// final ServerConfig config = serverConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
//
// default SourceConfig sourceConfigByIdOrNull(int id) {
// for (int i = 0; i < sourceCount(); i++) {
// final SourceConfig config = sourceConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/config/ServerConfig.java
// public interface ServerConfig {
// int id();
// String channel();
// }
//
// Path: src/main/java/org/tools4j/hoverraft/util/Files.java
// public class Files {
//
// private static final int INITIAL_BUFFER_SIZE = 1024;
//
// public static final String SYS_PROP_FILE_DIR = "org.tools4j.hoverraft.FileDir";
//
// public static final String defaultFileDirectory() {
// return System.getProperty("java.util.tmpdir");
// }
//
// public static final String fileDirectory() {
// return System.getProperty(SYS_PROP_FILE_DIR, defaultFileDirectory());
// }
//
// public static final String fileName(final int serverId, final String name) {
// return "hover-raft_" + serverId + "_" + name;
// }
//
// public static final CommandLog commandLog(final int serverId, final String name) throws IOException {
// final String path = Files.fileDirectory();
// final String child = Files.fileName(serverId, name);
// final Chronicle chronicle = ChronicleQueueBuilder.vanilla(path, child).build();
// return new ChronicleCommandLog((VanillaChronicle)chronicle, new ExpandableArrayBuffer(INITIAL_BUFFER_SIZE));
// }
// }
| import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import org.agrona.MutableDirectBuffer;
import org.agrona.concurrent.UnsafeBuffer;
import org.tools4j.hoverraft.command.CommandLog;
import org.tools4j.hoverraft.config.ConsensusConfig;
import org.tools4j.hoverraft.config.ServerConfig;
import org.tools4j.hoverraft.util.Files; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public final class DirectPersistentState implements PersistentState {
private static final int STATE_SIZE = 4 + 4;
private final MutableDirectBuffer state;
private final CommandLog commandLog;
| // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/config/ConsensusConfig.java
// public interface ConsensusConfig {
// long minElectionTimeoutMillis();
// long maxElectionTimeoutMillis();
// long heartbeatTimeoutMillis();
// Optional<String> ipcMulticastChannel();
// int serverCount();
// ServerConfig serverConfig(int index);
// int sourceCount();
// SourceConfig sourceConfig(int index);
// ThreadingMode threadingMode();
//
// default ServerConfig serverConfigByIdOrNull(int id) {
// for (int i = 0; i < serverCount(); i++) {
// final ServerConfig config = serverConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
//
// default SourceConfig sourceConfigByIdOrNull(int id) {
// for (int i = 0; i < sourceCount(); i++) {
// final SourceConfig config = sourceConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/config/ServerConfig.java
// public interface ServerConfig {
// int id();
// String channel();
// }
//
// Path: src/main/java/org/tools4j/hoverraft/util/Files.java
// public class Files {
//
// private static final int INITIAL_BUFFER_SIZE = 1024;
//
// public static final String SYS_PROP_FILE_DIR = "org.tools4j.hoverraft.FileDir";
//
// public static final String defaultFileDirectory() {
// return System.getProperty("java.util.tmpdir");
// }
//
// public static final String fileDirectory() {
// return System.getProperty(SYS_PROP_FILE_DIR, defaultFileDirectory());
// }
//
// public static final String fileName(final int serverId, final String name) {
// return "hover-raft_" + serverId + "_" + name;
// }
//
// public static final CommandLog commandLog(final int serverId, final String name) throws IOException {
// final String path = Files.fileDirectory();
// final String child = Files.fileName(serverId, name);
// final Chronicle chronicle = ChronicleQueueBuilder.vanilla(path, child).build();
// return new ChronicleCommandLog((VanillaChronicle)chronicle, new ExpandableArrayBuffer(INITIAL_BUFFER_SIZE));
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/DirectPersistentState.java
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import org.agrona.MutableDirectBuffer;
import org.agrona.concurrent.UnsafeBuffer;
import org.tools4j.hoverraft.command.CommandLog;
import org.tools4j.hoverraft.config.ConsensusConfig;
import org.tools4j.hoverraft.config.ServerConfig;
import org.tools4j.hoverraft.util.Files;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public final class DirectPersistentState implements PersistentState {
private static final int STATE_SIZE = 4 + 4;
private final MutableDirectBuffer state;
private final CommandLog commandLog;
| public DirectPersistentState(final ServerConfig serverConfig, final ConsensusConfig consensusConfig) throws IOException { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/DirectPersistentState.java | // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/config/ConsensusConfig.java
// public interface ConsensusConfig {
// long minElectionTimeoutMillis();
// long maxElectionTimeoutMillis();
// long heartbeatTimeoutMillis();
// Optional<String> ipcMulticastChannel();
// int serverCount();
// ServerConfig serverConfig(int index);
// int sourceCount();
// SourceConfig sourceConfig(int index);
// ThreadingMode threadingMode();
//
// default ServerConfig serverConfigByIdOrNull(int id) {
// for (int i = 0; i < serverCount(); i++) {
// final ServerConfig config = serverConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
//
// default SourceConfig sourceConfigByIdOrNull(int id) {
// for (int i = 0; i < sourceCount(); i++) {
// final SourceConfig config = sourceConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/config/ServerConfig.java
// public interface ServerConfig {
// int id();
// String channel();
// }
//
// Path: src/main/java/org/tools4j/hoverraft/util/Files.java
// public class Files {
//
// private static final int INITIAL_BUFFER_SIZE = 1024;
//
// public static final String SYS_PROP_FILE_DIR = "org.tools4j.hoverraft.FileDir";
//
// public static final String defaultFileDirectory() {
// return System.getProperty("java.util.tmpdir");
// }
//
// public static final String fileDirectory() {
// return System.getProperty(SYS_PROP_FILE_DIR, defaultFileDirectory());
// }
//
// public static final String fileName(final int serverId, final String name) {
// return "hover-raft_" + serverId + "_" + name;
// }
//
// public static final CommandLog commandLog(final int serverId, final String name) throws IOException {
// final String path = Files.fileDirectory();
// final String child = Files.fileName(serverId, name);
// final Chronicle chronicle = ChronicleQueueBuilder.vanilla(path, child).build();
// return new ChronicleCommandLog((VanillaChronicle)chronicle, new ExpandableArrayBuffer(INITIAL_BUFFER_SIZE));
// }
// }
| import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import org.agrona.MutableDirectBuffer;
import org.agrona.concurrent.UnsafeBuffer;
import org.tools4j.hoverraft.command.CommandLog;
import org.tools4j.hoverraft.config.ConsensusConfig;
import org.tools4j.hoverraft.config.ServerConfig;
import org.tools4j.hoverraft.util.Files; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public final class DirectPersistentState implements PersistentState {
private static final int STATE_SIZE = 4 + 4;
private final MutableDirectBuffer state;
private final CommandLog commandLog;
| // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/config/ConsensusConfig.java
// public interface ConsensusConfig {
// long minElectionTimeoutMillis();
// long maxElectionTimeoutMillis();
// long heartbeatTimeoutMillis();
// Optional<String> ipcMulticastChannel();
// int serverCount();
// ServerConfig serverConfig(int index);
// int sourceCount();
// SourceConfig sourceConfig(int index);
// ThreadingMode threadingMode();
//
// default ServerConfig serverConfigByIdOrNull(int id) {
// for (int i = 0; i < serverCount(); i++) {
// final ServerConfig config = serverConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
//
// default SourceConfig sourceConfigByIdOrNull(int id) {
// for (int i = 0; i < sourceCount(); i++) {
// final SourceConfig config = sourceConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/config/ServerConfig.java
// public interface ServerConfig {
// int id();
// String channel();
// }
//
// Path: src/main/java/org/tools4j/hoverraft/util/Files.java
// public class Files {
//
// private static final int INITIAL_BUFFER_SIZE = 1024;
//
// public static final String SYS_PROP_FILE_DIR = "org.tools4j.hoverraft.FileDir";
//
// public static final String defaultFileDirectory() {
// return System.getProperty("java.util.tmpdir");
// }
//
// public static final String fileDirectory() {
// return System.getProperty(SYS_PROP_FILE_DIR, defaultFileDirectory());
// }
//
// public static final String fileName(final int serverId, final String name) {
// return "hover-raft_" + serverId + "_" + name;
// }
//
// public static final CommandLog commandLog(final int serverId, final String name) throws IOException {
// final String path = Files.fileDirectory();
// final String child = Files.fileName(serverId, name);
// final Chronicle chronicle = ChronicleQueueBuilder.vanilla(path, child).build();
// return new ChronicleCommandLog((VanillaChronicle)chronicle, new ExpandableArrayBuffer(INITIAL_BUFFER_SIZE));
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/DirectPersistentState.java
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import org.agrona.MutableDirectBuffer;
import org.agrona.concurrent.UnsafeBuffer;
import org.tools4j.hoverraft.command.CommandLog;
import org.tools4j.hoverraft.config.ConsensusConfig;
import org.tools4j.hoverraft.config.ServerConfig;
import org.tools4j.hoverraft.util.Files;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public final class DirectPersistentState implements PersistentState {
private static final int STATE_SIZE = 4 + 4;
private final MutableDirectBuffer state;
private final CommandLog commandLog;
| public DirectPersistentState(final ServerConfig serverConfig, final ConsensusConfig consensusConfig) throws IOException { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/DirectPersistentState.java | // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/config/ConsensusConfig.java
// public interface ConsensusConfig {
// long minElectionTimeoutMillis();
// long maxElectionTimeoutMillis();
// long heartbeatTimeoutMillis();
// Optional<String> ipcMulticastChannel();
// int serverCount();
// ServerConfig serverConfig(int index);
// int sourceCount();
// SourceConfig sourceConfig(int index);
// ThreadingMode threadingMode();
//
// default ServerConfig serverConfigByIdOrNull(int id) {
// for (int i = 0; i < serverCount(); i++) {
// final ServerConfig config = serverConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
//
// default SourceConfig sourceConfigByIdOrNull(int id) {
// for (int i = 0; i < sourceCount(); i++) {
// final SourceConfig config = sourceConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/config/ServerConfig.java
// public interface ServerConfig {
// int id();
// String channel();
// }
//
// Path: src/main/java/org/tools4j/hoverraft/util/Files.java
// public class Files {
//
// private static final int INITIAL_BUFFER_SIZE = 1024;
//
// public static final String SYS_PROP_FILE_DIR = "org.tools4j.hoverraft.FileDir";
//
// public static final String defaultFileDirectory() {
// return System.getProperty("java.util.tmpdir");
// }
//
// public static final String fileDirectory() {
// return System.getProperty(SYS_PROP_FILE_DIR, defaultFileDirectory());
// }
//
// public static final String fileName(final int serverId, final String name) {
// return "hover-raft_" + serverId + "_" + name;
// }
//
// public static final CommandLog commandLog(final int serverId, final String name) throws IOException {
// final String path = Files.fileDirectory();
// final String child = Files.fileName(serverId, name);
// final Chronicle chronicle = ChronicleQueueBuilder.vanilla(path, child).build();
// return new ChronicleCommandLog((VanillaChronicle)chronicle, new ExpandableArrayBuffer(INITIAL_BUFFER_SIZE));
// }
// }
| import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import org.agrona.MutableDirectBuffer;
import org.agrona.concurrent.UnsafeBuffer;
import org.tools4j.hoverraft.command.CommandLog;
import org.tools4j.hoverraft.config.ConsensusConfig;
import org.tools4j.hoverraft.config.ServerConfig;
import org.tools4j.hoverraft.util.Files; | }
public int votedFor() {
return state.getInt(4);
}
@Override
public CommandLog commandLog() {
return commandLog;
}
public int clearVotedForAndSetCurrentTerm(int term) {
state.putInt(0, term);
state.putInt(4, NOT_VOTED_YET);
return term;
}
public int clearVotedForAndIncCurrentTerm() {
final int term = currentTerm() + 1;
state.putInt(0, term);
state.putInt(4, NOT_VOTED_YET);
return term;
}
public void votedFor(final int candidateId) {
state.putInt(4, candidateId);
}
private static MutableDirectBuffer initState(final ServerConfig serverConfig, final ConsensusConfig consensusConfig) throws IOException { | // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/config/ConsensusConfig.java
// public interface ConsensusConfig {
// long minElectionTimeoutMillis();
// long maxElectionTimeoutMillis();
// long heartbeatTimeoutMillis();
// Optional<String> ipcMulticastChannel();
// int serverCount();
// ServerConfig serverConfig(int index);
// int sourceCount();
// SourceConfig sourceConfig(int index);
// ThreadingMode threadingMode();
//
// default ServerConfig serverConfigByIdOrNull(int id) {
// for (int i = 0; i < serverCount(); i++) {
// final ServerConfig config = serverConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
//
// default SourceConfig sourceConfigByIdOrNull(int id) {
// for (int i = 0; i < sourceCount(); i++) {
// final SourceConfig config = sourceConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/config/ServerConfig.java
// public interface ServerConfig {
// int id();
// String channel();
// }
//
// Path: src/main/java/org/tools4j/hoverraft/util/Files.java
// public class Files {
//
// private static final int INITIAL_BUFFER_SIZE = 1024;
//
// public static final String SYS_PROP_FILE_DIR = "org.tools4j.hoverraft.FileDir";
//
// public static final String defaultFileDirectory() {
// return System.getProperty("java.util.tmpdir");
// }
//
// public static final String fileDirectory() {
// return System.getProperty(SYS_PROP_FILE_DIR, defaultFileDirectory());
// }
//
// public static final String fileName(final int serverId, final String name) {
// return "hover-raft_" + serverId + "_" + name;
// }
//
// public static final CommandLog commandLog(final int serverId, final String name) throws IOException {
// final String path = Files.fileDirectory();
// final String child = Files.fileName(serverId, name);
// final Chronicle chronicle = ChronicleQueueBuilder.vanilla(path, child).build();
// return new ChronicleCommandLog((VanillaChronicle)chronicle, new ExpandableArrayBuffer(INITIAL_BUFFER_SIZE));
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/DirectPersistentState.java
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import org.agrona.MutableDirectBuffer;
import org.agrona.concurrent.UnsafeBuffer;
import org.tools4j.hoverraft.command.CommandLog;
import org.tools4j.hoverraft.config.ConsensusConfig;
import org.tools4j.hoverraft.config.ServerConfig;
import org.tools4j.hoverraft.util.Files;
}
public int votedFor() {
return state.getInt(4);
}
@Override
public CommandLog commandLog() {
return commandLog;
}
public int clearVotedForAndSetCurrentTerm(int term) {
state.putInt(0, term);
state.putInt(4, NOT_VOTED_YET);
return term;
}
public int clearVotedForAndIncCurrentTerm() {
final int term = currentTerm() + 1;
state.putInt(0, term);
state.putInt(4, NOT_VOTED_YET);
return term;
}
public void votedFor(final int candidateId) {
state.putInt(4, candidateId);
}
private static MutableDirectBuffer initState(final ServerConfig serverConfig, final ConsensusConfig consensusConfig) throws IOException { | final String path = Files.fileDirectory(); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/direct/AllocatingDirectFactory.java | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/DirectLogEntry.java
// public class DirectLogEntry extends AbstractDirectPayload implements LogEntry {
// public static final int EMPTY_COMMAND_BYTE_LENGTH = DirectLogKey.BYTE_LENGTH + DirectCommand.EMPTY_COMMAND_BYTE_LENGTH;
// private static final int LOG_KEY_OFF = 0;
// private static final int LOG_KEY_LEN = DirectLogKey.BYTE_LENGTH;
//
// private static final int COMMAND_OFF = LOG_KEY_OFF + LOG_KEY_LEN;
//
// private DirectLogKey directLogKey = new DirectLogKey();
// private DirectCommand directCommand = new DirectCommand();
//
// @Override
// public void wrap(final DirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void wrap(final MutableDirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void unwrap() {
// directLogKey.unwrap();
// directCommand.unwrap();
// super.unwrap();
// }
//
//
// @Override
// public Command command() {
// return directCommand;
// }
//
// @Override
// public LogKey logKey() {
// return directLogKey;
// }
//
// @Override
// public int byteLength() {
// return COMMAND_OFF + directCommand.byteLength();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
| import org.tools4j.hoverraft.message.direct.*;
import org.agrona.ExpandableArrayBuffer;
import org.agrona.MutableDirectBuffer;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.DirectLogEntry;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.message.*; |
@Override
public AppendResponse appendResponse() {
final DirectAppendResponse directAppendResponse = new DirectAppendResponse();
directAppendResponse.wrap(newBuffer(DirectAppendResponse.BYTE_LENGTH), 0);
return directAppendResponse;
}
@Override
public VoteRequest voteRequest() {
final DirectVoteRequest directVoteRequest = new DirectVoteRequest();
directVoteRequest.wrap(newBuffer(DirectVoteRequest.BYTE_LENGTH), 0);
return directVoteRequest;
}
@Override
public VoteResponse voteResponse() {
final DirectVoteResponse directVoteResponse = new DirectVoteResponse();
directVoteResponse.wrap(newBuffer(DirectVoteResponse.BYTE_LENGTH), 0);
return directVoteResponse;
}
@Override
public TimeoutNow timeoutNow() {
final DirectTimeoutNow directTimeoutNow = new DirectTimeoutNow();
directTimeoutNow.wrap(newBuffer(DirectTimeoutNow.BYTE_LENGTH), 0);
return null;
}
@Override | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/DirectLogEntry.java
// public class DirectLogEntry extends AbstractDirectPayload implements LogEntry {
// public static final int EMPTY_COMMAND_BYTE_LENGTH = DirectLogKey.BYTE_LENGTH + DirectCommand.EMPTY_COMMAND_BYTE_LENGTH;
// private static final int LOG_KEY_OFF = 0;
// private static final int LOG_KEY_LEN = DirectLogKey.BYTE_LENGTH;
//
// private static final int COMMAND_OFF = LOG_KEY_OFF + LOG_KEY_LEN;
//
// private DirectLogKey directLogKey = new DirectLogKey();
// private DirectCommand directCommand = new DirectCommand();
//
// @Override
// public void wrap(final DirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void wrap(final MutableDirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void unwrap() {
// directLogKey.unwrap();
// directCommand.unwrap();
// super.unwrap();
// }
//
//
// @Override
// public Command command() {
// return directCommand;
// }
//
// @Override
// public LogKey logKey() {
// return directLogKey;
// }
//
// @Override
// public int byteLength() {
// return COMMAND_OFF + directCommand.byteLength();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/direct/AllocatingDirectFactory.java
import org.tools4j.hoverraft.message.direct.*;
import org.agrona.ExpandableArrayBuffer;
import org.agrona.MutableDirectBuffer;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.DirectLogEntry;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.message.*;
@Override
public AppendResponse appendResponse() {
final DirectAppendResponse directAppendResponse = new DirectAppendResponse();
directAppendResponse.wrap(newBuffer(DirectAppendResponse.BYTE_LENGTH), 0);
return directAppendResponse;
}
@Override
public VoteRequest voteRequest() {
final DirectVoteRequest directVoteRequest = new DirectVoteRequest();
directVoteRequest.wrap(newBuffer(DirectVoteRequest.BYTE_LENGTH), 0);
return directVoteRequest;
}
@Override
public VoteResponse voteResponse() {
final DirectVoteResponse directVoteResponse = new DirectVoteResponse();
directVoteResponse.wrap(newBuffer(DirectVoteResponse.BYTE_LENGTH), 0);
return directVoteResponse;
}
@Override
public TimeoutNow timeoutNow() {
final DirectTimeoutNow directTimeoutNow = new DirectTimeoutNow();
directTimeoutNow.wrap(newBuffer(DirectTimeoutNow.BYTE_LENGTH), 0);
return null;
}
@Override | public CommandKey commandKey() { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/direct/AllocatingDirectFactory.java | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/DirectLogEntry.java
// public class DirectLogEntry extends AbstractDirectPayload implements LogEntry {
// public static final int EMPTY_COMMAND_BYTE_LENGTH = DirectLogKey.BYTE_LENGTH + DirectCommand.EMPTY_COMMAND_BYTE_LENGTH;
// private static final int LOG_KEY_OFF = 0;
// private static final int LOG_KEY_LEN = DirectLogKey.BYTE_LENGTH;
//
// private static final int COMMAND_OFF = LOG_KEY_OFF + LOG_KEY_LEN;
//
// private DirectLogKey directLogKey = new DirectLogKey();
// private DirectCommand directCommand = new DirectCommand();
//
// @Override
// public void wrap(final DirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void wrap(final MutableDirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void unwrap() {
// directLogKey.unwrap();
// directCommand.unwrap();
// super.unwrap();
// }
//
//
// @Override
// public Command command() {
// return directCommand;
// }
//
// @Override
// public LogKey logKey() {
// return directLogKey;
// }
//
// @Override
// public int byteLength() {
// return COMMAND_OFF + directCommand.byteLength();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
| import org.tools4j.hoverraft.message.direct.*;
import org.agrona.ExpandableArrayBuffer;
import org.agrona.MutableDirectBuffer;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.DirectLogEntry;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.message.*; |
@Override
public VoteRequest voteRequest() {
final DirectVoteRequest directVoteRequest = new DirectVoteRequest();
directVoteRequest.wrap(newBuffer(DirectVoteRequest.BYTE_LENGTH), 0);
return directVoteRequest;
}
@Override
public VoteResponse voteResponse() {
final DirectVoteResponse directVoteResponse = new DirectVoteResponse();
directVoteResponse.wrap(newBuffer(DirectVoteResponse.BYTE_LENGTH), 0);
return directVoteResponse;
}
@Override
public TimeoutNow timeoutNow() {
final DirectTimeoutNow directTimeoutNow = new DirectTimeoutNow();
directTimeoutNow.wrap(newBuffer(DirectTimeoutNow.BYTE_LENGTH), 0);
return null;
}
@Override
public CommandKey commandKey() {
final DirectCommandKey directCommandKey = new DirectCommandKey();
directCommandKey.wrap(newBuffer(DirectCommandKey.BYTE_LENGTH), 0);
return directCommandKey;
}
@Override | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/DirectLogEntry.java
// public class DirectLogEntry extends AbstractDirectPayload implements LogEntry {
// public static final int EMPTY_COMMAND_BYTE_LENGTH = DirectLogKey.BYTE_LENGTH + DirectCommand.EMPTY_COMMAND_BYTE_LENGTH;
// private static final int LOG_KEY_OFF = 0;
// private static final int LOG_KEY_LEN = DirectLogKey.BYTE_LENGTH;
//
// private static final int COMMAND_OFF = LOG_KEY_OFF + LOG_KEY_LEN;
//
// private DirectLogKey directLogKey = new DirectLogKey();
// private DirectCommand directCommand = new DirectCommand();
//
// @Override
// public void wrap(final DirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void wrap(final MutableDirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void unwrap() {
// directLogKey.unwrap();
// directCommand.unwrap();
// super.unwrap();
// }
//
//
// @Override
// public Command command() {
// return directCommand;
// }
//
// @Override
// public LogKey logKey() {
// return directLogKey;
// }
//
// @Override
// public int byteLength() {
// return COMMAND_OFF + directCommand.byteLength();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/direct/AllocatingDirectFactory.java
import org.tools4j.hoverraft.message.direct.*;
import org.agrona.ExpandableArrayBuffer;
import org.agrona.MutableDirectBuffer;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.DirectLogEntry;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.message.*;
@Override
public VoteRequest voteRequest() {
final DirectVoteRequest directVoteRequest = new DirectVoteRequest();
directVoteRequest.wrap(newBuffer(DirectVoteRequest.BYTE_LENGTH), 0);
return directVoteRequest;
}
@Override
public VoteResponse voteResponse() {
final DirectVoteResponse directVoteResponse = new DirectVoteResponse();
directVoteResponse.wrap(newBuffer(DirectVoteResponse.BYTE_LENGTH), 0);
return directVoteResponse;
}
@Override
public TimeoutNow timeoutNow() {
final DirectTimeoutNow directTimeoutNow = new DirectTimeoutNow();
directTimeoutNow.wrap(newBuffer(DirectTimeoutNow.BYTE_LENGTH), 0);
return null;
}
@Override
public CommandKey commandKey() {
final DirectCommandKey directCommandKey = new DirectCommandKey();
directCommandKey.wrap(newBuffer(DirectCommandKey.BYTE_LENGTH), 0);
return directCommandKey;
}
@Override | public Command command() { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/direct/AllocatingDirectFactory.java | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/DirectLogEntry.java
// public class DirectLogEntry extends AbstractDirectPayload implements LogEntry {
// public static final int EMPTY_COMMAND_BYTE_LENGTH = DirectLogKey.BYTE_LENGTH + DirectCommand.EMPTY_COMMAND_BYTE_LENGTH;
// private static final int LOG_KEY_OFF = 0;
// private static final int LOG_KEY_LEN = DirectLogKey.BYTE_LENGTH;
//
// private static final int COMMAND_OFF = LOG_KEY_OFF + LOG_KEY_LEN;
//
// private DirectLogKey directLogKey = new DirectLogKey();
// private DirectCommand directCommand = new DirectCommand();
//
// @Override
// public void wrap(final DirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void wrap(final MutableDirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void unwrap() {
// directLogKey.unwrap();
// directCommand.unwrap();
// super.unwrap();
// }
//
//
// @Override
// public Command command() {
// return directCommand;
// }
//
// @Override
// public LogKey logKey() {
// return directLogKey;
// }
//
// @Override
// public int byteLength() {
// return COMMAND_OFF + directCommand.byteLength();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
| import org.tools4j.hoverraft.message.direct.*;
import org.agrona.ExpandableArrayBuffer;
import org.agrona.MutableDirectBuffer;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.DirectLogEntry;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.message.*; |
@Override
public VoteResponse voteResponse() {
final DirectVoteResponse directVoteResponse = new DirectVoteResponse();
directVoteResponse.wrap(newBuffer(DirectVoteResponse.BYTE_LENGTH), 0);
return directVoteResponse;
}
@Override
public TimeoutNow timeoutNow() {
final DirectTimeoutNow directTimeoutNow = new DirectTimeoutNow();
directTimeoutNow.wrap(newBuffer(DirectTimeoutNow.BYTE_LENGTH), 0);
return null;
}
@Override
public CommandKey commandKey() {
final DirectCommandKey directCommandKey = new DirectCommandKey();
directCommandKey.wrap(newBuffer(DirectCommandKey.BYTE_LENGTH), 0);
return directCommandKey;
}
@Override
public Command command() {
final DirectCommand directCommand = new DirectCommand();
directCommand.wrap(newBuffer(DirectCommand.EMPTY_COMMAND_BYTE_LENGTH), 0);
return directCommand;
}
@Override | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/DirectLogEntry.java
// public class DirectLogEntry extends AbstractDirectPayload implements LogEntry {
// public static final int EMPTY_COMMAND_BYTE_LENGTH = DirectLogKey.BYTE_LENGTH + DirectCommand.EMPTY_COMMAND_BYTE_LENGTH;
// private static final int LOG_KEY_OFF = 0;
// private static final int LOG_KEY_LEN = DirectLogKey.BYTE_LENGTH;
//
// private static final int COMMAND_OFF = LOG_KEY_OFF + LOG_KEY_LEN;
//
// private DirectLogKey directLogKey = new DirectLogKey();
// private DirectCommand directCommand = new DirectCommand();
//
// @Override
// public void wrap(final DirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void wrap(final MutableDirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void unwrap() {
// directLogKey.unwrap();
// directCommand.unwrap();
// super.unwrap();
// }
//
//
// @Override
// public Command command() {
// return directCommand;
// }
//
// @Override
// public LogKey logKey() {
// return directLogKey;
// }
//
// @Override
// public int byteLength() {
// return COMMAND_OFF + directCommand.byteLength();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/direct/AllocatingDirectFactory.java
import org.tools4j.hoverraft.message.direct.*;
import org.agrona.ExpandableArrayBuffer;
import org.agrona.MutableDirectBuffer;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.DirectLogEntry;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.message.*;
@Override
public VoteResponse voteResponse() {
final DirectVoteResponse directVoteResponse = new DirectVoteResponse();
directVoteResponse.wrap(newBuffer(DirectVoteResponse.BYTE_LENGTH), 0);
return directVoteResponse;
}
@Override
public TimeoutNow timeoutNow() {
final DirectTimeoutNow directTimeoutNow = new DirectTimeoutNow();
directTimeoutNow.wrap(newBuffer(DirectTimeoutNow.BYTE_LENGTH), 0);
return null;
}
@Override
public CommandKey commandKey() {
final DirectCommandKey directCommandKey = new DirectCommandKey();
directCommandKey.wrap(newBuffer(DirectCommandKey.BYTE_LENGTH), 0);
return directCommandKey;
}
@Override
public Command command() {
final DirectCommand directCommand = new DirectCommand();
directCommand.wrap(newBuffer(DirectCommand.EMPTY_COMMAND_BYTE_LENGTH), 0);
return directCommand;
}
@Override | public LogEntry logEntry() { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/direct/AllocatingDirectFactory.java | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/DirectLogEntry.java
// public class DirectLogEntry extends AbstractDirectPayload implements LogEntry {
// public static final int EMPTY_COMMAND_BYTE_LENGTH = DirectLogKey.BYTE_LENGTH + DirectCommand.EMPTY_COMMAND_BYTE_LENGTH;
// private static final int LOG_KEY_OFF = 0;
// private static final int LOG_KEY_LEN = DirectLogKey.BYTE_LENGTH;
//
// private static final int COMMAND_OFF = LOG_KEY_OFF + LOG_KEY_LEN;
//
// private DirectLogKey directLogKey = new DirectLogKey();
// private DirectCommand directCommand = new DirectCommand();
//
// @Override
// public void wrap(final DirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void wrap(final MutableDirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void unwrap() {
// directLogKey.unwrap();
// directCommand.unwrap();
// super.unwrap();
// }
//
//
// @Override
// public Command command() {
// return directCommand;
// }
//
// @Override
// public LogKey logKey() {
// return directLogKey;
// }
//
// @Override
// public int byteLength() {
// return COMMAND_OFF + directCommand.byteLength();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
| import org.tools4j.hoverraft.message.direct.*;
import org.agrona.ExpandableArrayBuffer;
import org.agrona.MutableDirectBuffer;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.DirectLogEntry;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.message.*; | @Override
public VoteResponse voteResponse() {
final DirectVoteResponse directVoteResponse = new DirectVoteResponse();
directVoteResponse.wrap(newBuffer(DirectVoteResponse.BYTE_LENGTH), 0);
return directVoteResponse;
}
@Override
public TimeoutNow timeoutNow() {
final DirectTimeoutNow directTimeoutNow = new DirectTimeoutNow();
directTimeoutNow.wrap(newBuffer(DirectTimeoutNow.BYTE_LENGTH), 0);
return null;
}
@Override
public CommandKey commandKey() {
final DirectCommandKey directCommandKey = new DirectCommandKey();
directCommandKey.wrap(newBuffer(DirectCommandKey.BYTE_LENGTH), 0);
return directCommandKey;
}
@Override
public Command command() {
final DirectCommand directCommand = new DirectCommand();
directCommand.wrap(newBuffer(DirectCommand.EMPTY_COMMAND_BYTE_LENGTH), 0);
return directCommand;
}
@Override
public LogEntry logEntry() { | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/DirectLogEntry.java
// public class DirectLogEntry extends AbstractDirectPayload implements LogEntry {
// public static final int EMPTY_COMMAND_BYTE_LENGTH = DirectLogKey.BYTE_LENGTH + DirectCommand.EMPTY_COMMAND_BYTE_LENGTH;
// private static final int LOG_KEY_OFF = 0;
// private static final int LOG_KEY_LEN = DirectLogKey.BYTE_LENGTH;
//
// private static final int COMMAND_OFF = LOG_KEY_OFF + LOG_KEY_LEN;
//
// private DirectLogKey directLogKey = new DirectLogKey();
// private DirectCommand directCommand = new DirectCommand();
//
// @Override
// public void wrap(final DirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void wrap(final MutableDirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void unwrap() {
// directLogKey.unwrap();
// directCommand.unwrap();
// super.unwrap();
// }
//
//
// @Override
// public Command command() {
// return directCommand;
// }
//
// @Override
// public LogKey logKey() {
// return directLogKey;
// }
//
// @Override
// public int byteLength() {
// return COMMAND_OFF + directCommand.byteLength();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/direct/AllocatingDirectFactory.java
import org.tools4j.hoverraft.message.direct.*;
import org.agrona.ExpandableArrayBuffer;
import org.agrona.MutableDirectBuffer;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.DirectLogEntry;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.message.*;
@Override
public VoteResponse voteResponse() {
final DirectVoteResponse directVoteResponse = new DirectVoteResponse();
directVoteResponse.wrap(newBuffer(DirectVoteResponse.BYTE_LENGTH), 0);
return directVoteResponse;
}
@Override
public TimeoutNow timeoutNow() {
final DirectTimeoutNow directTimeoutNow = new DirectTimeoutNow();
directTimeoutNow.wrap(newBuffer(DirectTimeoutNow.BYTE_LENGTH), 0);
return null;
}
@Override
public CommandKey commandKey() {
final DirectCommandKey directCommandKey = new DirectCommandKey();
directCommandKey.wrap(newBuffer(DirectCommandKey.BYTE_LENGTH), 0);
return directCommandKey;
}
@Override
public Command command() {
final DirectCommand directCommand = new DirectCommand();
directCommand.wrap(newBuffer(DirectCommand.EMPTY_COMMAND_BYTE_LENGTH), 0);
return directCommand;
}
@Override
public LogEntry logEntry() { | final DirectLogEntry directCommandLogEntry = new DirectLogEntry(); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/VoteResponse.java | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface VoteResponse extends Message {
int term();
VoteResponse term(int term);
boolean voteGranted();
VoteResponse voteGranted(boolean granted);
@Override | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/message/VoteResponse.java
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface VoteResponse extends Message {
int term();
VoteResponse term(int term);
boolean voteGranted();
VoteResponse voteGranted(boolean granted);
@Override | default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/VoteResponse.java | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface VoteResponse extends Message {
int term();
VoteResponse term(int term);
boolean voteGranted();
VoteResponse voteGranted(boolean granted);
@Override | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/message/VoteResponse.java
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface VoteResponse extends Message {
int term();
VoteResponse term(int term);
boolean voteGranted();
VoteResponse voteGranted(boolean granted);
@Override | default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/VoteResponse.java | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface VoteResponse extends Message {
int term();
VoteResponse term(int term);
boolean voteGranted();
VoteResponse voteGranted(boolean granted);
@Override | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/message/VoteResponse.java
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface VoteResponse extends Message {
int term();
VoteResponse term(int term);
boolean voteGranted();
VoteResponse voteGranted(boolean granted);
@Override | default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/TimeoutNow.java | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
/**
* Timeout request to initiate leadership transfer.
*/
public interface TimeoutNow extends Message {
int term();
TimeoutNow term(int term);
int candidateId();
TimeoutNow candidateId(int candidateId);
@Override | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/message/TimeoutNow.java
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
/**
* Timeout request to initiate leadership transfer.
*/
public interface TimeoutNow extends Message {
int term();
TimeoutNow term(int term);
int candidateId();
TimeoutNow candidateId(int candidateId);
@Override | default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/TimeoutNow.java | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
/**
* Timeout request to initiate leadership transfer.
*/
public interface TimeoutNow extends Message {
int term();
TimeoutNow term(int term);
int candidateId();
TimeoutNow candidateId(int candidateId);
@Override | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/message/TimeoutNow.java
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
/**
* Timeout request to initiate leadership transfer.
*/
public interface TimeoutNow extends Message {
int term();
TimeoutNow term(int term);
int candidateId();
TimeoutNow candidateId(int candidateId);
@Override | default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/TimeoutNow.java | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
/**
* Timeout request to initiate leadership transfer.
*/
public interface TimeoutNow extends Message {
int term();
TimeoutNow term(int term);
int candidateId();
TimeoutNow candidateId(int candidateId);
@Override | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/message/TimeoutNow.java
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
/**
* Timeout request to initiate leadership transfer.
*/
public interface TimeoutNow extends Message {
int term();
TimeoutNow term(int term);
int candidateId();
TimeoutNow candidateId(int candidateId);
@Override | default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/AbstractState.java | // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/machine/StateMachine.java
// public interface StateMachine {
// void onMessage(Command message);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
| import java.util.Objects;
import org.tools4j.hoverraft.command.CommandLog;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.command.machine.StateMachine;
import org.tools4j.hoverraft.event.*;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
abstract public class AbstractState implements State {
private final Role role;
private final PersistentState persistentState;
private final VolatileState volatileState;
private final HigherTermHandler higherTermHandler;
private final VoteRequestHandler voteRequestHandler;
private final AppendRequestHandler appendRequestHandler;
public AbstractState(final Role role, final PersistentState persistentState, final VolatileState volatileState) {
this.role = Objects.requireNonNull(role);
this.persistentState = Objects.requireNonNull(persistentState);
this.volatileState = Objects.requireNonNull(volatileState);
this.higherTermHandler = new HigherTermHandler(persistentState);
this.voteRequestHandler = new VoteRequestHandler(persistentState);
this.appendRequestHandler = new AppendRequestHandler(persistentState, volatileState);
}
abstract protected EventHandler eventHandler();
@Override
public final Role role() {
return role;
}
@Override | // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/machine/StateMachine.java
// public interface StateMachine {
// void onMessage(Command message);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/AbstractState.java
import java.util.Objects;
import org.tools4j.hoverraft.command.CommandLog;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.command.machine.StateMachine;
import org.tools4j.hoverraft.event.*;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
abstract public class AbstractState implements State {
private final Role role;
private final PersistentState persistentState;
private final VolatileState volatileState;
private final HigherTermHandler higherTermHandler;
private final VoteRequestHandler voteRequestHandler;
private final AppendRequestHandler appendRequestHandler;
public AbstractState(final Role role, final PersistentState persistentState, final VolatileState volatileState) {
this.role = Objects.requireNonNull(role);
this.persistentState = Objects.requireNonNull(persistentState);
this.volatileState = Objects.requireNonNull(volatileState);
this.higherTermHandler = new HigherTermHandler(persistentState);
this.voteRequestHandler = new VoteRequestHandler(persistentState);
this.appendRequestHandler = new AppendRequestHandler(persistentState, volatileState);
}
abstract protected EventHandler eventHandler();
@Override
public final Role role() {
return role;
}
@Override | public final Transition onEvent(final ServerContext serverContext, final Event event) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/AbstractState.java | // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/machine/StateMachine.java
// public interface StateMachine {
// void onMessage(Command message);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
| import java.util.Objects;
import org.tools4j.hoverraft.command.CommandLog;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.command.machine.StateMachine;
import org.tools4j.hoverraft.event.*;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext; | this.voteRequestHandler = new VoteRequestHandler(persistentState);
this.appendRequestHandler = new AppendRequestHandler(persistentState, volatileState);
}
abstract protected EventHandler eventHandler();
@Override
public final Role role() {
return role;
}
@Override
public final Transition onEvent(final ServerContext serverContext, final Event event) {
return Transition
.startWith(serverContext, event, higherTermHandler)
.ifSteadyThen(serverContext, event, eventHandler());
}
public int currentTerm() {
return persistentState.currentTerm();
}
protected PersistentState persistentState() {
return persistentState;
}
protected VolatileState volatileState() {
return volatileState;
}
| // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/machine/StateMachine.java
// public interface StateMachine {
// void onMessage(Command message);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/AbstractState.java
import java.util.Objects;
import org.tools4j.hoverraft.command.CommandLog;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.command.machine.StateMachine;
import org.tools4j.hoverraft.event.*;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext;
this.voteRequestHandler = new VoteRequestHandler(persistentState);
this.appendRequestHandler = new AppendRequestHandler(persistentState, volatileState);
}
abstract protected EventHandler eventHandler();
@Override
public final Role role() {
return role;
}
@Override
public final Transition onEvent(final ServerContext serverContext, final Event event) {
return Transition
.startWith(serverContext, event, higherTermHandler)
.ifSteadyThen(serverContext, event, eventHandler());
}
public int currentTerm() {
return persistentState.currentTerm();
}
protected PersistentState persistentState() {
return persistentState;
}
protected VolatileState volatileState() {
return volatileState;
}
| protected Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/AbstractState.java | // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/machine/StateMachine.java
// public interface StateMachine {
// void onMessage(Command message);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
| import java.util.Objects;
import org.tools4j.hoverraft.command.CommandLog;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.command.machine.StateMachine;
import org.tools4j.hoverraft.event.*;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext; | abstract protected EventHandler eventHandler();
@Override
public final Role role() {
return role;
}
@Override
public final Transition onEvent(final ServerContext serverContext, final Event event) {
return Transition
.startWith(serverContext, event, higherTermHandler)
.ifSteadyThen(serverContext, event, eventHandler());
}
public int currentTerm() {
return persistentState.currentTerm();
}
protected PersistentState persistentState() {
return persistentState;
}
protected VolatileState volatileState() {
return volatileState;
}
protected Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) {
return voteRequestHandler.onVoteRequest(serverContext, voteRequest);
}
| // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/machine/StateMachine.java
// public interface StateMachine {
// void onMessage(Command message);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/AbstractState.java
import java.util.Objects;
import org.tools4j.hoverraft.command.CommandLog;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.command.machine.StateMachine;
import org.tools4j.hoverraft.event.*;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext;
abstract protected EventHandler eventHandler();
@Override
public final Role role() {
return role;
}
@Override
public final Transition onEvent(final ServerContext serverContext, final Event event) {
return Transition
.startWith(serverContext, event, higherTermHandler)
.ifSteadyThen(serverContext, event, eventHandler());
}
public int currentTerm() {
return persistentState.currentTerm();
}
protected PersistentState persistentState() {
return persistentState;
}
protected VolatileState volatileState() {
return volatileState;
}
protected Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) {
return voteRequestHandler.onVoteRequest(serverContext, voteRequest);
}
| protected Transition onAppendRequest(final ServerContext serverContext, final AppendRequest appendRequest) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/AbstractState.java | // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/machine/StateMachine.java
// public interface StateMachine {
// void onMessage(Command message);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
| import java.util.Objects;
import org.tools4j.hoverraft.command.CommandLog;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.command.machine.StateMachine;
import org.tools4j.hoverraft.event.*;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext; | }
@Override
public final Transition onEvent(final ServerContext serverContext, final Event event) {
return Transition
.startWith(serverContext, event, higherTermHandler)
.ifSteadyThen(serverContext, event, eventHandler());
}
public int currentTerm() {
return persistentState.currentTerm();
}
protected PersistentState persistentState() {
return persistentState;
}
protected VolatileState volatileState() {
return volatileState;
}
protected Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) {
return voteRequestHandler.onVoteRequest(serverContext, voteRequest);
}
protected Transition onAppendRequest(final ServerContext serverContext, final AppendRequest appendRequest) {
return appendRequestHandler.onAppendRequest(serverContext, appendRequest);
}
protected void invokeStateMachineWithCommittedLogEntries(final ServerContext serverContext) { | // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/machine/StateMachine.java
// public interface StateMachine {
// void onMessage(Command message);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/AbstractState.java
import java.util.Objects;
import org.tools4j.hoverraft.command.CommandLog;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.command.machine.StateMachine;
import org.tools4j.hoverraft.event.*;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext;
}
@Override
public final Transition onEvent(final ServerContext serverContext, final Event event) {
return Transition
.startWith(serverContext, event, higherTermHandler)
.ifSteadyThen(serverContext, event, eventHandler());
}
public int currentTerm() {
return persistentState.currentTerm();
}
protected PersistentState persistentState() {
return persistentState;
}
protected VolatileState volatileState() {
return volatileState;
}
protected Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) {
return voteRequestHandler.onVoteRequest(serverContext, voteRequest);
}
protected Transition onAppendRequest(final ServerContext serverContext, final AppendRequest appendRequest) {
return appendRequestHandler.onAppendRequest(serverContext, appendRequest);
}
protected void invokeStateMachineWithCommittedLogEntries(final ServerContext serverContext) { | final CommandLog commandLog = persistentState.commandLog(); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/AbstractState.java | // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/machine/StateMachine.java
// public interface StateMachine {
// void onMessage(Command message);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
| import java.util.Objects;
import org.tools4j.hoverraft.command.CommandLog;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.command.machine.StateMachine;
import org.tools4j.hoverraft.event.*;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext; |
@Override
public final Transition onEvent(final ServerContext serverContext, final Event event) {
return Transition
.startWith(serverContext, event, higherTermHandler)
.ifSteadyThen(serverContext, event, eventHandler());
}
public int currentTerm() {
return persistentState.currentTerm();
}
protected PersistentState persistentState() {
return persistentState;
}
protected VolatileState volatileState() {
return volatileState;
}
protected Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) {
return voteRequestHandler.onVoteRequest(serverContext, voteRequest);
}
protected Transition onAppendRequest(final ServerContext serverContext, final AppendRequest appendRequest) {
return appendRequestHandler.onAppendRequest(serverContext, appendRequest);
}
protected void invokeStateMachineWithCommittedLogEntries(final ServerContext serverContext) {
final CommandLog commandLog = persistentState.commandLog(); | // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/machine/StateMachine.java
// public interface StateMachine {
// void onMessage(Command message);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/AbstractState.java
import java.util.Objects;
import org.tools4j.hoverraft.command.CommandLog;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.command.machine.StateMachine;
import org.tools4j.hoverraft.event.*;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext;
@Override
public final Transition onEvent(final ServerContext serverContext, final Event event) {
return Transition
.startWith(serverContext, event, higherTermHandler)
.ifSteadyThen(serverContext, event, eventHandler());
}
public int currentTerm() {
return persistentState.currentTerm();
}
protected PersistentState persistentState() {
return persistentState;
}
protected VolatileState volatileState() {
return volatileState;
}
protected Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) {
return voteRequestHandler.onVoteRequest(serverContext, voteRequest);
}
protected Transition onAppendRequest(final ServerContext serverContext, final AppendRequest appendRequest) {
return appendRequestHandler.onAppendRequest(serverContext, appendRequest);
}
protected void invokeStateMachineWithCommittedLogEntries(final ServerContext serverContext) {
final CommandLog commandLog = persistentState.commandLog(); | final StateMachine stateMachine = serverContext.stateMachine(); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/AbstractState.java | // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/machine/StateMachine.java
// public interface StateMachine {
// void onMessage(Command message);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
| import java.util.Objects;
import org.tools4j.hoverraft.command.CommandLog;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.command.machine.StateMachine;
import org.tools4j.hoverraft.event.*;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext; | .startWith(serverContext, event, higherTermHandler)
.ifSteadyThen(serverContext, event, eventHandler());
}
public int currentTerm() {
return persistentState.currentTerm();
}
protected PersistentState persistentState() {
return persistentState;
}
protected VolatileState volatileState() {
return volatileState;
}
protected Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) {
return voteRequestHandler.onVoteRequest(serverContext, voteRequest);
}
protected Transition onAppendRequest(final ServerContext serverContext, final AppendRequest appendRequest) {
return appendRequestHandler.onAppendRequest(serverContext, appendRequest);
}
protected void invokeStateMachineWithCommittedLogEntries(final ServerContext serverContext) {
final CommandLog commandLog = persistentState.commandLog();
final StateMachine stateMachine = serverContext.stateMachine();
long lastApplied = volatileState.lastApplied();
while (volatileState.commitIndex() > lastApplied) {
lastApplied++; | // Path: src/main/java/org/tools4j/hoverraft/command/CommandLog.java
// public interface CommandLog {
// long size();
// default long lastIndex() {
// return size() - 1;
// }
// int readTerm(long index);
// void readTo(long index, LogKey target);
// void readTo(long index, CommandKey target);
// void readTo(long index, LogEntry target);
//
// void append(int term, Command command);
// void truncateIncluding(long index);
//
// default int lastTerm() {
// return readTerm(lastIndex());
// }
//
// default void lastKeyTo(final LogKey target) {
// readTo(lastIndex(), target);
// }
//
// default int lastKeyCompareTo(final LogKey logKey) {
// final int termCompare = Integer.compare(lastTerm(), logKey.term());
// return termCompare == 0 ? Long.compare(lastIndex(), logKey.index()) : termCompare;
// }
//
// boolean contains(CommandKey commandKey);
// default LogContainment contains(final LogKey logKey) {
// return LogContainment.containmentFor(logKey, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/machine/StateMachine.java
// public interface StateMachine {
// void onMessage(Command message);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/AbstractState.java
import java.util.Objects;
import org.tools4j.hoverraft.command.CommandLog;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.command.machine.StateMachine;
import org.tools4j.hoverraft.event.*;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext;
.startWith(serverContext, event, higherTermHandler)
.ifSteadyThen(serverContext, event, eventHandler());
}
public int currentTerm() {
return persistentState.currentTerm();
}
protected PersistentState persistentState() {
return persistentState;
}
protected VolatileState volatileState() {
return volatileState;
}
protected Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) {
return voteRequestHandler.onVoteRequest(serverContext, voteRequest);
}
protected Transition onAppendRequest(final ServerContext serverContext, final AppendRequest appendRequest) {
return appendRequestHandler.onAppendRequest(serverContext, appendRequest);
}
protected void invokeStateMachineWithCommittedLogEntries(final ServerContext serverContext) {
final CommandLog commandLog = persistentState.commandLog();
final StateMachine stateMachine = serverContext.stateMachine();
long lastApplied = volatileState.lastApplied();
while (volatileState.commitIndex() > lastApplied) {
lastApplied++; | final LogEntry logEntry = serverContext.directFactory().logEntry(); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/command/CommandKeyLookup.java | // Path: src/main/java/org/tools4j/hoverraft/direct/AllocatingDirectFactory.java
// public class AllocatingDirectFactory implements DirectFactory {
//
// private MutableDirectBuffer newBuffer(final int initialCapacity) {
// return new ExpandableArrayBuffer(initialCapacity);
// }
//
// @Override
// public AppendRequest appendRequest() {
// final DirectAppendRequest directAppendRequest = new DirectAppendRequest();
// directAppendRequest.wrap(newBuffer(DirectAppendRequest.EMPTY_LOG_BYTE_LENGTH), 0);
// return directAppendRequest;
// }
//
// @Override
// public AppendResponse appendResponse() {
// final DirectAppendResponse directAppendResponse = new DirectAppendResponse();
// directAppendResponse.wrap(newBuffer(DirectAppendResponse.BYTE_LENGTH), 0);
// return directAppendResponse;
// }
//
// @Override
// public VoteRequest voteRequest() {
// final DirectVoteRequest directVoteRequest = new DirectVoteRequest();
// directVoteRequest.wrap(newBuffer(DirectVoteRequest.BYTE_LENGTH), 0);
// return directVoteRequest;
// }
//
// @Override
// public VoteResponse voteResponse() {
// final DirectVoteResponse directVoteResponse = new DirectVoteResponse();
// directVoteResponse.wrap(newBuffer(DirectVoteResponse.BYTE_LENGTH), 0);
// return directVoteResponse;
// }
//
// @Override
// public TimeoutNow timeoutNow() {
// final DirectTimeoutNow directTimeoutNow = new DirectTimeoutNow();
// directTimeoutNow.wrap(newBuffer(DirectTimeoutNow.BYTE_LENGTH), 0);
// return null;
// }
//
// @Override
// public CommandKey commandKey() {
// final DirectCommandKey directCommandKey = new DirectCommandKey();
// directCommandKey.wrap(newBuffer(DirectCommandKey.BYTE_LENGTH), 0);
// return directCommandKey;
// }
//
// @Override
// public Command command() {
// final DirectCommand directCommand = new DirectCommand();
// directCommand.wrap(newBuffer(DirectCommand.EMPTY_COMMAND_BYTE_LENGTH), 0);
// return directCommand;
// }
//
// @Override
// public LogEntry logEntry() {
// final DirectLogEntry directCommandLogEntry = new DirectLogEntry();
// directCommandLogEntry.wrap(newBuffer(DirectLogEntry.EMPTY_COMMAND_BYTE_LENGTH), 0);
// return directCommandLogEntry;
// }
// }
| import org.agrona.collections.Long2LongHashMap;
import org.tools4j.hoverraft.direct.AllocatingDirectFactory;
import java.util.Objects; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.command;
/**
* Lookup to determine whether a {@link CommandKey} is contained in a {@link CommandLog}.
* Based on the observation that commands are appended with gap free strictly increasing indices per
* source ID.
*/
public final class CommandKeyLookup {
private final Long2LongHashMap maxCommandIndexBySourceId = new Long2LongHashMap(-1); | // Path: src/main/java/org/tools4j/hoverraft/direct/AllocatingDirectFactory.java
// public class AllocatingDirectFactory implements DirectFactory {
//
// private MutableDirectBuffer newBuffer(final int initialCapacity) {
// return new ExpandableArrayBuffer(initialCapacity);
// }
//
// @Override
// public AppendRequest appendRequest() {
// final DirectAppendRequest directAppendRequest = new DirectAppendRequest();
// directAppendRequest.wrap(newBuffer(DirectAppendRequest.EMPTY_LOG_BYTE_LENGTH), 0);
// return directAppendRequest;
// }
//
// @Override
// public AppendResponse appendResponse() {
// final DirectAppendResponse directAppendResponse = new DirectAppendResponse();
// directAppendResponse.wrap(newBuffer(DirectAppendResponse.BYTE_LENGTH), 0);
// return directAppendResponse;
// }
//
// @Override
// public VoteRequest voteRequest() {
// final DirectVoteRequest directVoteRequest = new DirectVoteRequest();
// directVoteRequest.wrap(newBuffer(DirectVoteRequest.BYTE_LENGTH), 0);
// return directVoteRequest;
// }
//
// @Override
// public VoteResponse voteResponse() {
// final DirectVoteResponse directVoteResponse = new DirectVoteResponse();
// directVoteResponse.wrap(newBuffer(DirectVoteResponse.BYTE_LENGTH), 0);
// return directVoteResponse;
// }
//
// @Override
// public TimeoutNow timeoutNow() {
// final DirectTimeoutNow directTimeoutNow = new DirectTimeoutNow();
// directTimeoutNow.wrap(newBuffer(DirectTimeoutNow.BYTE_LENGTH), 0);
// return null;
// }
//
// @Override
// public CommandKey commandKey() {
// final DirectCommandKey directCommandKey = new DirectCommandKey();
// directCommandKey.wrap(newBuffer(DirectCommandKey.BYTE_LENGTH), 0);
// return directCommandKey;
// }
//
// @Override
// public Command command() {
// final DirectCommand directCommand = new DirectCommand();
// directCommand.wrap(newBuffer(DirectCommand.EMPTY_COMMAND_BYTE_LENGTH), 0);
// return directCommand;
// }
//
// @Override
// public LogEntry logEntry() {
// final DirectLogEntry directCommandLogEntry = new DirectLogEntry();
// directCommandLogEntry.wrap(newBuffer(DirectLogEntry.EMPTY_COMMAND_BYTE_LENGTH), 0);
// return directCommandLogEntry;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKeyLookup.java
import org.agrona.collections.Long2LongHashMap;
import org.tools4j.hoverraft.direct.AllocatingDirectFactory;
import java.util.Objects;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.command;
/**
* Lookup to determine whether a {@link CommandKey} is contained in a {@link CommandLog}.
* Based on the observation that commands are appended with gap free strictly increasing indices per
* source ID.
*/
public final class CommandKeyLookup {
private final Long2LongHashMap maxCommandIndexBySourceId = new Long2LongHashMap(-1); | private final CommandKey tempKey = new AllocatingDirectFactory().commandKey(); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/command/Command.java | // Path: src/main/java/org/tools4j/hoverraft/direct/DirectPayload.java
// public interface DirectPayload {
//
// int byteLength();
//
// int offset();
//
// DirectBuffer readBufferOrNull();
//
// MutableDirectBuffer writeBufferOrNull();
//
// void wrap(DirectBuffer buffer, int offset);
//
// void wrap(MutableDirectBuffer buffer, int offset);
//
// void unwrap();
//
// default boolean isWrapped() {
// return readBufferOrNull() != null || writeBufferOrNull() != null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.direct.DirectPayload;
import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.command;
public interface Command extends DirectPayload, Event {
CommandKey commandKey();
CommandPayload commandPayload();
default Command sourceId(final int sourceId) {
commandKey().sourceId(sourceId);
return this;
}
default Command commandIndex(final long commandIndex) {
commandKey().commandIndex(commandIndex);
return this;
}
default void copyFrom(final Command command) {
writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
}
@Override | // Path: src/main/java/org/tools4j/hoverraft/direct/DirectPayload.java
// public interface DirectPayload {
//
// int byteLength();
//
// int offset();
//
// DirectBuffer readBufferOrNull();
//
// MutableDirectBuffer writeBufferOrNull();
//
// void wrap(DirectBuffer buffer, int offset);
//
// void wrap(MutableDirectBuffer buffer, int offset);
//
// void unwrap();
//
// default boolean isWrapped() {
// return readBufferOrNull() != null || writeBufferOrNull() != null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/command/Command.java
import org.tools4j.hoverraft.direct.DirectPayload;
import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.command;
public interface Command extends DirectPayload, Event {
CommandKey commandKey();
CommandPayload commandPayload();
default Command sourceId(final int sourceId) {
commandKey().sourceId(sourceId);
return this;
}
default Command commandIndex(final long commandIndex) {
commandKey().commandIndex(commandIndex);
return this;
}
default void copyFrom(final Command command) {
writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
}
@Override | default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/command/Command.java | // Path: src/main/java/org/tools4j/hoverraft/direct/DirectPayload.java
// public interface DirectPayload {
//
// int byteLength();
//
// int offset();
//
// DirectBuffer readBufferOrNull();
//
// MutableDirectBuffer writeBufferOrNull();
//
// void wrap(DirectBuffer buffer, int offset);
//
// void wrap(MutableDirectBuffer buffer, int offset);
//
// void unwrap();
//
// default boolean isWrapped() {
// return readBufferOrNull() != null || writeBufferOrNull() != null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.direct.DirectPayload;
import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.command;
public interface Command extends DirectPayload, Event {
CommandKey commandKey();
CommandPayload commandPayload();
default Command sourceId(final int sourceId) {
commandKey().sourceId(sourceId);
return this;
}
default Command commandIndex(final long commandIndex) {
commandKey().commandIndex(commandIndex);
return this;
}
default void copyFrom(final Command command) {
writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
}
@Override | // Path: src/main/java/org/tools4j/hoverraft/direct/DirectPayload.java
// public interface DirectPayload {
//
// int byteLength();
//
// int offset();
//
// DirectBuffer readBufferOrNull();
//
// MutableDirectBuffer writeBufferOrNull();
//
// void wrap(DirectBuffer buffer, int offset);
//
// void wrap(MutableDirectBuffer buffer, int offset);
//
// void unwrap();
//
// default boolean isWrapped() {
// return readBufferOrNull() != null || writeBufferOrNull() != null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/command/Command.java
import org.tools4j.hoverraft.direct.DirectPayload;
import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.command;
public interface Command extends DirectPayload, Event {
CommandKey commandKey();
CommandPayload commandPayload();
default Command sourceId(final int sourceId) {
commandKey().sourceId(sourceId);
return this;
}
default Command commandIndex(final long commandIndex) {
commandKey().commandIndex(commandIndex);
return this;
}
default void copyFrom(final Command command) {
writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
}
@Override | default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/command/Command.java | // Path: src/main/java/org/tools4j/hoverraft/direct/DirectPayload.java
// public interface DirectPayload {
//
// int byteLength();
//
// int offset();
//
// DirectBuffer readBufferOrNull();
//
// MutableDirectBuffer writeBufferOrNull();
//
// void wrap(DirectBuffer buffer, int offset);
//
// void wrap(MutableDirectBuffer buffer, int offset);
//
// void unwrap();
//
// default boolean isWrapped() {
// return readBufferOrNull() != null || writeBufferOrNull() != null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.direct.DirectPayload;
import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.command;
public interface Command extends DirectPayload, Event {
CommandKey commandKey();
CommandPayload commandPayload();
default Command sourceId(final int sourceId) {
commandKey().sourceId(sourceId);
return this;
}
default Command commandIndex(final long commandIndex) {
commandKey().commandIndex(commandIndex);
return this;
}
default void copyFrom(final Command command) {
writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
}
@Override | // Path: src/main/java/org/tools4j/hoverraft/direct/DirectPayload.java
// public interface DirectPayload {
//
// int byteLength();
//
// int offset();
//
// DirectBuffer readBufferOrNull();
//
// MutableDirectBuffer writeBufferOrNull();
//
// void wrap(DirectBuffer buffer, int offset);
//
// void wrap(MutableDirectBuffer buffer, int offset);
//
// void unwrap();
//
// default boolean isWrapped() {
// return readBufferOrNull() != null || writeBufferOrNull() != null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/command/Command.java
import org.tools4j.hoverraft.direct.DirectPayload;
import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.command;
public interface Command extends DirectPayload, Event {
CommandKey commandKey();
CommandPayload commandPayload();
default Command sourceId(final int sourceId) {
commandKey().sourceId(sourceId);
return this;
}
default Command commandIndex(final long commandIndex) {
commandKey().commandIndex(commandIndex);
return this;
}
default void copyFrom(final Command command) {
writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
}
@Override | default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) { |
terzerm/hover-raft | src/test/java/org/tools4j/hoverraft/message/direct/DirectVoteRequestTest.java | // Path: src/main/java/org/tools4j/hoverraft/message/MessageType.java
// public enum MessageType {
// VOTE_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteRequest();
// }
// },
// VOTE_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteResponse();
// }
// },
// APPEND_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendRequest();
// }
// },
// APPEND_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendResponse();
// }
// },
// TIMEOUT_NOW {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.timeoutNow();
// }
// };
//
// private static final MessageType[] VALUES = values();
//
// public static final MessageType valueByOrdinal(final int ordinal) {
// return VALUES[ordinal];
// }
//
// public static final int maxOrdinal() {
// return VALUES.length - 1;
// }
//
// abstract public Message create(DirectFactory factory);
//
// public static MessageType readFrom(final DirectBuffer directBuffer, final int offset) {
// final int type = directBuffer.getInt(offset);
// if (type >= 0 & type <= MessageType.maxOrdinal()) {
// return MessageType.valueByOrdinal(type);
// }
// throw new IllegalArgumentException("Illegal message type: " + type);
// }
//
//
// }
| import org.agrona.ExpandableArrayBuffer;
import org.junit.Before;
import org.junit.Test;
import org.tools4j.hoverraft.message.MessageType;
import static org.assertj.core.api.Assertions.assertThat; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message.direct;
public class DirectVoteRequestTest {
private final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer(DirectVoteRequest.BYTE_LENGTH);
private final DirectVoteRequest directVoteRequest = new DirectVoteRequest();
@Before
public void init() {
directVoteRequest.wrap(buffer, 0);
}
@Test
public void should_get_the_data_that_has_been_set() throws Exception {
//given
final int term = 9;
final int candidateId = 5;
final int lastLogTerm = 8;
final int lastLogIndex = 345244;
//when
directVoteRequest
.term(term)
.candidateId(candidateId)
.lastLogKey()
.term(lastLogTerm)
.index(lastLogIndex);
//then | // Path: src/main/java/org/tools4j/hoverraft/message/MessageType.java
// public enum MessageType {
// VOTE_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteRequest();
// }
// },
// VOTE_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteResponse();
// }
// },
// APPEND_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendRequest();
// }
// },
// APPEND_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendResponse();
// }
// },
// TIMEOUT_NOW {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.timeoutNow();
// }
// };
//
// private static final MessageType[] VALUES = values();
//
// public static final MessageType valueByOrdinal(final int ordinal) {
// return VALUES[ordinal];
// }
//
// public static final int maxOrdinal() {
// return VALUES.length - 1;
// }
//
// abstract public Message create(DirectFactory factory);
//
// public static MessageType readFrom(final DirectBuffer directBuffer, final int offset) {
// final int type = directBuffer.getInt(offset);
// if (type >= 0 & type <= MessageType.maxOrdinal()) {
// return MessageType.valueByOrdinal(type);
// }
// throw new IllegalArgumentException("Illegal message type: " + type);
// }
//
//
// }
// Path: src/test/java/org/tools4j/hoverraft/message/direct/DirectVoteRequestTest.java
import org.agrona.ExpandableArrayBuffer;
import org.junit.Before;
import org.junit.Test;
import org.tools4j.hoverraft.message.MessageType;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message.direct;
public class DirectVoteRequestTest {
private final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer(DirectVoteRequest.BYTE_LENGTH);
private final DirectVoteRequest directVoteRequest = new DirectVoteRequest();
@Before
public void init() {
directVoteRequest.wrap(buffer, 0);
}
@Test
public void should_get_the_data_that_has_been_set() throws Exception {
//given
final int term = 9;
final int candidateId = 5;
final int lastLogTerm = 8;
final int lastLogIndex = 345244;
//when
directVoteRequest
.term(term)
.candidateId(candidateId)
.lastLogKey()
.term(lastLogTerm)
.index(lastLogIndex);
//then | assertThat(directVoteRequest.type()).isEqualTo(MessageType.VOTE_REQUEST); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/HoverRaftMachine.java | // Path: src/main/java/org/tools4j/hoverraft/command/machine/StateMachine.java
// public interface StateMachine {
// void onMessage(Command message);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
| import org.tools4j.hoverraft.command.machine.StateMachine;
import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.server.ServerContext;
import java.util.EnumMap;
import java.util.Map;
import java.util.Objects; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
/**
* The Hover raft state machine. Not named state machine to avoid confusion with the application
* {@link StateMachine}.
*/
public class HoverRaftMachine {
private final Map<Role, State> stateMap;
private final PersistentState persistentState;
private final VolatileState volatileState;
private State currentState;
public HoverRaftMachine(final PersistentState persistentState, final VolatileState volatileState) {
this.persistentState = Objects.requireNonNull(persistentState);
this.volatileState = Objects.requireNonNull(volatileState);
this.stateMap = initStateMap();
currentState = initialState();
}
private Map<Role, State> initStateMap() {
final Map<Role, State> map = new EnumMap<>(Role.class);
for (final Role role : Role.values()) {
map.put(role, role.createState(persistentState, volatileState));
}
return map;
}
private State initialState() {
return transitionTo(Role.FOLLOWER);
}
private State transitionTo(final Role role) {
return stateMap.get(role);
}
| // Path: src/main/java/org/tools4j/hoverraft/command/machine/StateMachine.java
// public interface StateMachine {
// void onMessage(Command message);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/HoverRaftMachine.java
import org.tools4j.hoverraft.command.machine.StateMachine;
import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.server.ServerContext;
import java.util.EnumMap;
import java.util.Map;
import java.util.Objects;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
/**
* The Hover raft state machine. Not named state machine to avoid confusion with the application
* {@link StateMachine}.
*/
public class HoverRaftMachine {
private final Map<Role, State> stateMap;
private final PersistentState persistentState;
private final VolatileState volatileState;
private State currentState;
public HoverRaftMachine(final PersistentState persistentState, final VolatileState volatileState) {
this.persistentState = Objects.requireNonNull(persistentState);
this.volatileState = Objects.requireNonNull(volatileState);
this.stateMap = initStateMap();
currentState = initialState();
}
private Map<Role, State> initStateMap() {
final Map<Role, State> map = new EnumMap<>(Role.class);
for (final Role role : Role.values()) {
map.put(role, role.createState(persistentState, volatileState));
}
return map;
}
private State initialState() {
return transitionTo(Role.FOLLOWER);
}
private State transitionTo(final Role role) {
return stateMap.get(role);
}
| public void onEvent(final ServerContext serverContext, final Event event) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/HoverRaftMachine.java | // Path: src/main/java/org/tools4j/hoverraft/command/machine/StateMachine.java
// public interface StateMachine {
// void onMessage(Command message);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
| import org.tools4j.hoverraft.command.machine.StateMachine;
import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.server.ServerContext;
import java.util.EnumMap;
import java.util.Map;
import java.util.Objects; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
/**
* The Hover raft state machine. Not named state machine to avoid confusion with the application
* {@link StateMachine}.
*/
public class HoverRaftMachine {
private final Map<Role, State> stateMap;
private final PersistentState persistentState;
private final VolatileState volatileState;
private State currentState;
public HoverRaftMachine(final PersistentState persistentState, final VolatileState volatileState) {
this.persistentState = Objects.requireNonNull(persistentState);
this.volatileState = Objects.requireNonNull(volatileState);
this.stateMap = initStateMap();
currentState = initialState();
}
private Map<Role, State> initStateMap() {
final Map<Role, State> map = new EnumMap<>(Role.class);
for (final Role role : Role.values()) {
map.put(role, role.createState(persistentState, volatileState));
}
return map;
}
private State initialState() {
return transitionTo(Role.FOLLOWER);
}
private State transitionTo(final Role role) {
return stateMap.get(role);
}
| // Path: src/main/java/org/tools4j/hoverraft/command/machine/StateMachine.java
// public interface StateMachine {
// void onMessage(Command message);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/HoverRaftMachine.java
import org.tools4j.hoverraft.command.machine.StateMachine;
import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.server.ServerContext;
import java.util.EnumMap;
import java.util.Map;
import java.util.Objects;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
/**
* The Hover raft state machine. Not named state machine to avoid confusion with the application
* {@link StateMachine}.
*/
public class HoverRaftMachine {
private final Map<Role, State> stateMap;
private final PersistentState persistentState;
private final VolatileState volatileState;
private State currentState;
public HoverRaftMachine(final PersistentState persistentState, final VolatileState volatileState) {
this.persistentState = Objects.requireNonNull(persistentState);
this.volatileState = Objects.requireNonNull(volatileState);
this.stateMap = initStateMap();
currentState = initialState();
}
private Map<Role, State> initStateMap() {
final Map<Role, State> map = new EnumMap<>(Role.class);
for (final Role role : Role.values()) {
map.put(role, role.createState(persistentState, volatileState));
}
return map;
}
private State initialState() {
return transitionTo(Role.FOLLOWER);
}
private State transitionTo(final Role role) {
return stateMap.get(role);
}
| public void onEvent(final ServerContext serverContext, final Event event) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/direct/RecyclingDirectFactory.java | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/DirectLogEntry.java
// public class DirectLogEntry extends AbstractDirectPayload implements LogEntry {
// public static final int EMPTY_COMMAND_BYTE_LENGTH = DirectLogKey.BYTE_LENGTH + DirectCommand.EMPTY_COMMAND_BYTE_LENGTH;
// private static final int LOG_KEY_OFF = 0;
// private static final int LOG_KEY_LEN = DirectLogKey.BYTE_LENGTH;
//
// private static final int COMMAND_OFF = LOG_KEY_OFF + LOG_KEY_LEN;
//
// private DirectLogKey directLogKey = new DirectLogKey();
// private DirectCommand directCommand = new DirectCommand();
//
// @Override
// public void wrap(final DirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void wrap(final MutableDirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void unwrap() {
// directLogKey.unwrap();
// directCommand.unwrap();
// super.unwrap();
// }
//
//
// @Override
// public Command command() {
// return directCommand;
// }
//
// @Override
// public LogKey logKey() {
// return directLogKey;
// }
//
// @Override
// public int byteLength() {
// return COMMAND_OFF + directCommand.byteLength();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
| import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.DirectLogEntry;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.message.*;
import org.tools4j.hoverraft.message.direct.*; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.direct;
/**
* Not a true factory since messages are recycled accross multiple calls.
*/
public final class RecyclingDirectFactory implements DirectFactory {
private final AppendRequest appendRequest = new DirectAppendRequest();
private final AppendResponse appendResponse = new DirectAppendResponse();
private final VoteRequest voteRequest = new DirectVoteRequest();
private final VoteResponse voteResponse = new DirectVoteResponse();
private final TimeoutNow timeoutNow = new DirectTimeoutNow(); | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/DirectLogEntry.java
// public class DirectLogEntry extends AbstractDirectPayload implements LogEntry {
// public static final int EMPTY_COMMAND_BYTE_LENGTH = DirectLogKey.BYTE_LENGTH + DirectCommand.EMPTY_COMMAND_BYTE_LENGTH;
// private static final int LOG_KEY_OFF = 0;
// private static final int LOG_KEY_LEN = DirectLogKey.BYTE_LENGTH;
//
// private static final int COMMAND_OFF = LOG_KEY_OFF + LOG_KEY_LEN;
//
// private DirectLogKey directLogKey = new DirectLogKey();
// private DirectCommand directCommand = new DirectCommand();
//
// @Override
// public void wrap(final DirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void wrap(final MutableDirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void unwrap() {
// directLogKey.unwrap();
// directCommand.unwrap();
// super.unwrap();
// }
//
//
// @Override
// public Command command() {
// return directCommand;
// }
//
// @Override
// public LogKey logKey() {
// return directLogKey;
// }
//
// @Override
// public int byteLength() {
// return COMMAND_OFF + directCommand.byteLength();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/direct/RecyclingDirectFactory.java
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.DirectLogEntry;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.message.*;
import org.tools4j.hoverraft.message.direct.*;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.direct;
/**
* Not a true factory since messages are recycled accross multiple calls.
*/
public final class RecyclingDirectFactory implements DirectFactory {
private final AppendRequest appendRequest = new DirectAppendRequest();
private final AppendResponse appendResponse = new DirectAppendResponse();
private final VoteRequest voteRequest = new DirectVoteRequest();
private final VoteResponse voteResponse = new DirectVoteResponse();
private final TimeoutNow timeoutNow = new DirectTimeoutNow(); | private final CommandKey commandKey = new DirectCommandKey(); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/direct/RecyclingDirectFactory.java | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/DirectLogEntry.java
// public class DirectLogEntry extends AbstractDirectPayload implements LogEntry {
// public static final int EMPTY_COMMAND_BYTE_LENGTH = DirectLogKey.BYTE_LENGTH + DirectCommand.EMPTY_COMMAND_BYTE_LENGTH;
// private static final int LOG_KEY_OFF = 0;
// private static final int LOG_KEY_LEN = DirectLogKey.BYTE_LENGTH;
//
// private static final int COMMAND_OFF = LOG_KEY_OFF + LOG_KEY_LEN;
//
// private DirectLogKey directLogKey = new DirectLogKey();
// private DirectCommand directCommand = new DirectCommand();
//
// @Override
// public void wrap(final DirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void wrap(final MutableDirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void unwrap() {
// directLogKey.unwrap();
// directCommand.unwrap();
// super.unwrap();
// }
//
//
// @Override
// public Command command() {
// return directCommand;
// }
//
// @Override
// public LogKey logKey() {
// return directLogKey;
// }
//
// @Override
// public int byteLength() {
// return COMMAND_OFF + directCommand.byteLength();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
| import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.DirectLogEntry;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.message.*;
import org.tools4j.hoverraft.message.direct.*; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.direct;
/**
* Not a true factory since messages are recycled accross multiple calls.
*/
public final class RecyclingDirectFactory implements DirectFactory {
private final AppendRequest appendRequest = new DirectAppendRequest();
private final AppendResponse appendResponse = new DirectAppendResponse();
private final VoteRequest voteRequest = new DirectVoteRequest();
private final VoteResponse voteResponse = new DirectVoteResponse();
private final TimeoutNow timeoutNow = new DirectTimeoutNow();
private final CommandKey commandKey = new DirectCommandKey(); | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/DirectLogEntry.java
// public class DirectLogEntry extends AbstractDirectPayload implements LogEntry {
// public static final int EMPTY_COMMAND_BYTE_LENGTH = DirectLogKey.BYTE_LENGTH + DirectCommand.EMPTY_COMMAND_BYTE_LENGTH;
// private static final int LOG_KEY_OFF = 0;
// private static final int LOG_KEY_LEN = DirectLogKey.BYTE_LENGTH;
//
// private static final int COMMAND_OFF = LOG_KEY_OFF + LOG_KEY_LEN;
//
// private DirectLogKey directLogKey = new DirectLogKey();
// private DirectCommand directCommand = new DirectCommand();
//
// @Override
// public void wrap(final DirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void wrap(final MutableDirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void unwrap() {
// directLogKey.unwrap();
// directCommand.unwrap();
// super.unwrap();
// }
//
//
// @Override
// public Command command() {
// return directCommand;
// }
//
// @Override
// public LogKey logKey() {
// return directLogKey;
// }
//
// @Override
// public int byteLength() {
// return COMMAND_OFF + directCommand.byteLength();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/direct/RecyclingDirectFactory.java
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.DirectLogEntry;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.message.*;
import org.tools4j.hoverraft.message.direct.*;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.direct;
/**
* Not a true factory since messages are recycled accross multiple calls.
*/
public final class RecyclingDirectFactory implements DirectFactory {
private final AppendRequest appendRequest = new DirectAppendRequest();
private final AppendResponse appendResponse = new DirectAppendResponse();
private final VoteRequest voteRequest = new DirectVoteRequest();
private final VoteResponse voteResponse = new DirectVoteResponse();
private final TimeoutNow timeoutNow = new DirectTimeoutNow();
private final CommandKey commandKey = new DirectCommandKey(); | private final Command command = new DirectCommand(); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/direct/RecyclingDirectFactory.java | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/DirectLogEntry.java
// public class DirectLogEntry extends AbstractDirectPayload implements LogEntry {
// public static final int EMPTY_COMMAND_BYTE_LENGTH = DirectLogKey.BYTE_LENGTH + DirectCommand.EMPTY_COMMAND_BYTE_LENGTH;
// private static final int LOG_KEY_OFF = 0;
// private static final int LOG_KEY_LEN = DirectLogKey.BYTE_LENGTH;
//
// private static final int COMMAND_OFF = LOG_KEY_OFF + LOG_KEY_LEN;
//
// private DirectLogKey directLogKey = new DirectLogKey();
// private DirectCommand directCommand = new DirectCommand();
//
// @Override
// public void wrap(final DirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void wrap(final MutableDirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void unwrap() {
// directLogKey.unwrap();
// directCommand.unwrap();
// super.unwrap();
// }
//
//
// @Override
// public Command command() {
// return directCommand;
// }
//
// @Override
// public LogKey logKey() {
// return directLogKey;
// }
//
// @Override
// public int byteLength() {
// return COMMAND_OFF + directCommand.byteLength();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
| import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.DirectLogEntry;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.message.*;
import org.tools4j.hoverraft.message.direct.*; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.direct;
/**
* Not a true factory since messages are recycled accross multiple calls.
*/
public final class RecyclingDirectFactory implements DirectFactory {
private final AppendRequest appendRequest = new DirectAppendRequest();
private final AppendResponse appendResponse = new DirectAppendResponse();
private final VoteRequest voteRequest = new DirectVoteRequest();
private final VoteResponse voteResponse = new DirectVoteResponse();
private final TimeoutNow timeoutNow = new DirectTimeoutNow();
private final CommandKey commandKey = new DirectCommandKey();
private final Command command = new DirectCommand(); | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/DirectLogEntry.java
// public class DirectLogEntry extends AbstractDirectPayload implements LogEntry {
// public static final int EMPTY_COMMAND_BYTE_LENGTH = DirectLogKey.BYTE_LENGTH + DirectCommand.EMPTY_COMMAND_BYTE_LENGTH;
// private static final int LOG_KEY_OFF = 0;
// private static final int LOG_KEY_LEN = DirectLogKey.BYTE_LENGTH;
//
// private static final int COMMAND_OFF = LOG_KEY_OFF + LOG_KEY_LEN;
//
// private DirectLogKey directLogKey = new DirectLogKey();
// private DirectCommand directCommand = new DirectCommand();
//
// @Override
// public void wrap(final DirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void wrap(final MutableDirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void unwrap() {
// directLogKey.unwrap();
// directCommand.unwrap();
// super.unwrap();
// }
//
//
// @Override
// public Command command() {
// return directCommand;
// }
//
// @Override
// public LogKey logKey() {
// return directLogKey;
// }
//
// @Override
// public int byteLength() {
// return COMMAND_OFF + directCommand.byteLength();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/direct/RecyclingDirectFactory.java
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.DirectLogEntry;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.message.*;
import org.tools4j.hoverraft.message.direct.*;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.direct;
/**
* Not a true factory since messages are recycled accross multiple calls.
*/
public final class RecyclingDirectFactory implements DirectFactory {
private final AppendRequest appendRequest = new DirectAppendRequest();
private final AppendResponse appendResponse = new DirectAppendResponse();
private final VoteRequest voteRequest = new DirectVoteRequest();
private final VoteResponse voteResponse = new DirectVoteResponse();
private final TimeoutNow timeoutNow = new DirectTimeoutNow();
private final CommandKey commandKey = new DirectCommandKey();
private final Command command = new DirectCommand(); | private final LogEntry logEntry = new DirectLogEntry(); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/direct/RecyclingDirectFactory.java | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/DirectLogEntry.java
// public class DirectLogEntry extends AbstractDirectPayload implements LogEntry {
// public static final int EMPTY_COMMAND_BYTE_LENGTH = DirectLogKey.BYTE_LENGTH + DirectCommand.EMPTY_COMMAND_BYTE_LENGTH;
// private static final int LOG_KEY_OFF = 0;
// private static final int LOG_KEY_LEN = DirectLogKey.BYTE_LENGTH;
//
// private static final int COMMAND_OFF = LOG_KEY_OFF + LOG_KEY_LEN;
//
// private DirectLogKey directLogKey = new DirectLogKey();
// private DirectCommand directCommand = new DirectCommand();
//
// @Override
// public void wrap(final DirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void wrap(final MutableDirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void unwrap() {
// directLogKey.unwrap();
// directCommand.unwrap();
// super.unwrap();
// }
//
//
// @Override
// public Command command() {
// return directCommand;
// }
//
// @Override
// public LogKey logKey() {
// return directLogKey;
// }
//
// @Override
// public int byteLength() {
// return COMMAND_OFF + directCommand.byteLength();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
| import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.DirectLogEntry;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.message.*;
import org.tools4j.hoverraft.message.direct.*; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.direct;
/**
* Not a true factory since messages are recycled accross multiple calls.
*/
public final class RecyclingDirectFactory implements DirectFactory {
private final AppendRequest appendRequest = new DirectAppendRequest();
private final AppendResponse appendResponse = new DirectAppendResponse();
private final VoteRequest voteRequest = new DirectVoteRequest();
private final VoteResponse voteResponse = new DirectVoteResponse();
private final TimeoutNow timeoutNow = new DirectTimeoutNow();
private final CommandKey commandKey = new DirectCommandKey();
private final Command command = new DirectCommand(); | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/DirectLogEntry.java
// public class DirectLogEntry extends AbstractDirectPayload implements LogEntry {
// public static final int EMPTY_COMMAND_BYTE_LENGTH = DirectLogKey.BYTE_LENGTH + DirectCommand.EMPTY_COMMAND_BYTE_LENGTH;
// private static final int LOG_KEY_OFF = 0;
// private static final int LOG_KEY_LEN = DirectLogKey.BYTE_LENGTH;
//
// private static final int COMMAND_OFF = LOG_KEY_OFF + LOG_KEY_LEN;
//
// private DirectLogKey directLogKey = new DirectLogKey();
// private DirectCommand directCommand = new DirectCommand();
//
// @Override
// public void wrap(final DirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void wrap(final MutableDirectBuffer buffer, final int offset) {
// super.wrap(buffer, offset);
// directLogKey.wrap(buffer, offset + LOG_KEY_OFF);
// directCommand.wrap(buffer, offset + COMMAND_OFF);
// }
//
// @Override
// public void unwrap() {
// directLogKey.unwrap();
// directCommand.unwrap();
// super.unwrap();
// }
//
//
// @Override
// public Command command() {
// return directCommand;
// }
//
// @Override
// public LogKey logKey() {
// return directLogKey;
// }
//
// @Override
// public int byteLength() {
// return COMMAND_OFF + directCommand.byteLength();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/direct/RecyclingDirectFactory.java
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.DirectLogEntry;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.message.*;
import org.tools4j.hoverraft.message.direct.*;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.direct;
/**
* Not a true factory since messages are recycled accross multiple calls.
*/
public final class RecyclingDirectFactory implements DirectFactory {
private final AppendRequest appendRequest = new DirectAppendRequest();
private final AppendResponse appendResponse = new DirectAppendResponse();
private final VoteRequest voteRequest = new DirectVoteRequest();
private final VoteResponse voteResponse = new DirectVoteResponse();
private final TimeoutNow timeoutNow = new DirectTimeoutNow();
private final CommandKey commandKey = new DirectCommandKey();
private final Command command = new DirectCommand(); | private final LogEntry logEntry = new DirectLogEntry(); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/direct/DirectVoteRequest.java | // Path: src/main/java/org/tools4j/hoverraft/command/LogKey.java
// public interface LogKey extends Comparable<LogKey> {
// Comparator<LogKey> COMPARATOR = (k1, k2) -> {
// final int termCompare = Integer.compare(k1.term(), k2.term());
// return termCompare == 0 ? Long.compare(k1.index(), k2.index()) : termCompare;
// };
//
// int term();
// LogKey term(int term);
//
// long index();
// LogKey index(long index);
//
// @Override
// default int compareTo(final LogKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default LogContainment containedIn(final CommandLog commandLog) {
// return LogContainment.containmentFor(this, commandLog);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/MessageType.java
// public enum MessageType {
// VOTE_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteRequest();
// }
// },
// VOTE_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteResponse();
// }
// },
// APPEND_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendRequest();
// }
// },
// APPEND_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendResponse();
// }
// },
// TIMEOUT_NOW {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.timeoutNow();
// }
// };
//
// private static final MessageType[] VALUES = values();
//
// public static final MessageType valueByOrdinal(final int ordinal) {
// return VALUES[ordinal];
// }
//
// public static final int maxOrdinal() {
// return VALUES.length - 1;
// }
//
// abstract public Message create(DirectFactory factory);
//
// public static MessageType readFrom(final DirectBuffer directBuffer, final int offset) {
// final int type = directBuffer.getInt(offset);
// if (type >= 0 & type <= MessageType.maxOrdinal()) {
// return MessageType.valueByOrdinal(type);
// }
// throw new IllegalArgumentException("Illegal message type: " + type);
// }
//
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
| import org.agrona.DirectBuffer;
import org.agrona.MutableDirectBuffer;
import org.tools4j.hoverraft.command.LogKey;
import org.tools4j.hoverraft.message.MessageType;
import org.tools4j.hoverraft.message.VoteRequest; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message.direct;
public final class DirectVoteRequest extends AbstractDirectMessage implements VoteRequest {
private static final int TERM_OFF = TYPE_OFF + TYPE_LEN;
private static final int TERM_LEN = 4;
private static final int CANDIDATE_ID_OFF = TERM_OFF + TERM_LEN;
private static final int CANDIDATE_ID_LEN = 4;
private static final int LAST_LOG_KEY_OFF = CANDIDATE_ID_OFF + CANDIDATE_ID_LEN;
private static final int LAST_LOG_KEY_LEN = DirectLogKey.BYTE_LENGTH;
public static final int BYTE_LENGTH = LAST_LOG_KEY_OFF + LAST_LOG_KEY_LEN;
private final DirectLogKey lastLogKey = new DirectLogKey() ;
@Override | // Path: src/main/java/org/tools4j/hoverraft/command/LogKey.java
// public interface LogKey extends Comparable<LogKey> {
// Comparator<LogKey> COMPARATOR = (k1, k2) -> {
// final int termCompare = Integer.compare(k1.term(), k2.term());
// return termCompare == 0 ? Long.compare(k1.index(), k2.index()) : termCompare;
// };
//
// int term();
// LogKey term(int term);
//
// long index();
// LogKey index(long index);
//
// @Override
// default int compareTo(final LogKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default LogContainment containedIn(final CommandLog commandLog) {
// return LogContainment.containmentFor(this, commandLog);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/MessageType.java
// public enum MessageType {
// VOTE_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteRequest();
// }
// },
// VOTE_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteResponse();
// }
// },
// APPEND_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendRequest();
// }
// },
// APPEND_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendResponse();
// }
// },
// TIMEOUT_NOW {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.timeoutNow();
// }
// };
//
// private static final MessageType[] VALUES = values();
//
// public static final MessageType valueByOrdinal(final int ordinal) {
// return VALUES[ordinal];
// }
//
// public static final int maxOrdinal() {
// return VALUES.length - 1;
// }
//
// abstract public Message create(DirectFactory factory);
//
// public static MessageType readFrom(final DirectBuffer directBuffer, final int offset) {
// final int type = directBuffer.getInt(offset);
// if (type >= 0 & type <= MessageType.maxOrdinal()) {
// return MessageType.valueByOrdinal(type);
// }
// throw new IllegalArgumentException("Illegal message type: " + type);
// }
//
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/message/direct/DirectVoteRequest.java
import org.agrona.DirectBuffer;
import org.agrona.MutableDirectBuffer;
import org.tools4j.hoverraft.command.LogKey;
import org.tools4j.hoverraft.message.MessageType;
import org.tools4j.hoverraft.message.VoteRequest;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message.direct;
public final class DirectVoteRequest extends AbstractDirectMessage implements VoteRequest {
private static final int TERM_OFF = TYPE_OFF + TYPE_LEN;
private static final int TERM_LEN = 4;
private static final int CANDIDATE_ID_OFF = TERM_OFF + TERM_LEN;
private static final int CANDIDATE_ID_LEN = 4;
private static final int LAST_LOG_KEY_OFF = CANDIDATE_ID_OFF + CANDIDATE_ID_LEN;
private static final int LAST_LOG_KEY_LEN = DirectLogKey.BYTE_LENGTH;
public static final int BYTE_LENGTH = LAST_LOG_KEY_OFF + LAST_LOG_KEY_LEN;
private final DirectLogKey lastLogKey = new DirectLogKey() ;
@Override | public MessageType type() { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/direct/DirectVoteRequest.java | // Path: src/main/java/org/tools4j/hoverraft/command/LogKey.java
// public interface LogKey extends Comparable<LogKey> {
// Comparator<LogKey> COMPARATOR = (k1, k2) -> {
// final int termCompare = Integer.compare(k1.term(), k2.term());
// return termCompare == 0 ? Long.compare(k1.index(), k2.index()) : termCompare;
// };
//
// int term();
// LogKey term(int term);
//
// long index();
// LogKey index(long index);
//
// @Override
// default int compareTo(final LogKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default LogContainment containedIn(final CommandLog commandLog) {
// return LogContainment.containmentFor(this, commandLog);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/MessageType.java
// public enum MessageType {
// VOTE_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteRequest();
// }
// },
// VOTE_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteResponse();
// }
// },
// APPEND_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendRequest();
// }
// },
// APPEND_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendResponse();
// }
// },
// TIMEOUT_NOW {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.timeoutNow();
// }
// };
//
// private static final MessageType[] VALUES = values();
//
// public static final MessageType valueByOrdinal(final int ordinal) {
// return VALUES[ordinal];
// }
//
// public static final int maxOrdinal() {
// return VALUES.length - 1;
// }
//
// abstract public Message create(DirectFactory factory);
//
// public static MessageType readFrom(final DirectBuffer directBuffer, final int offset) {
// final int type = directBuffer.getInt(offset);
// if (type >= 0 & type <= MessageType.maxOrdinal()) {
// return MessageType.valueByOrdinal(type);
// }
// throw new IllegalArgumentException("Illegal message type: " + type);
// }
//
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
| import org.agrona.DirectBuffer;
import org.agrona.MutableDirectBuffer;
import org.tools4j.hoverraft.command.LogKey;
import org.tools4j.hoverraft.message.MessageType;
import org.tools4j.hoverraft.message.VoteRequest; | }
@Override
public int byteLength() {
return BYTE_LENGTH;
}
@Override
public int term() {
return readBuffer.getInt(offset + TERM_OFF);
}
@Override
public DirectVoteRequest term(final int term) {
writeBuffer.putInt(offset + TERM_OFF, term);
return this;
}
@Override
public int candidateId() {
return readBuffer.getInt(offset + CANDIDATE_ID_OFF);
}
@Override
public DirectVoteRequest candidateId(final int candidateId) {
writeBuffer.putInt(offset + CANDIDATE_ID_OFF, candidateId);
return this;
}
@Override | // Path: src/main/java/org/tools4j/hoverraft/command/LogKey.java
// public interface LogKey extends Comparable<LogKey> {
// Comparator<LogKey> COMPARATOR = (k1, k2) -> {
// final int termCompare = Integer.compare(k1.term(), k2.term());
// return termCompare == 0 ? Long.compare(k1.index(), k2.index()) : termCompare;
// };
//
// int term();
// LogKey term(int term);
//
// long index();
// LogKey index(long index);
//
// @Override
// default int compareTo(final LogKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default LogContainment containedIn(final CommandLog commandLog) {
// return LogContainment.containmentFor(this, commandLog);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/MessageType.java
// public enum MessageType {
// VOTE_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteRequest();
// }
// },
// VOTE_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteResponse();
// }
// },
// APPEND_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendRequest();
// }
// },
// APPEND_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendResponse();
// }
// },
// TIMEOUT_NOW {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.timeoutNow();
// }
// };
//
// private static final MessageType[] VALUES = values();
//
// public static final MessageType valueByOrdinal(final int ordinal) {
// return VALUES[ordinal];
// }
//
// public static final int maxOrdinal() {
// return VALUES.length - 1;
// }
//
// abstract public Message create(DirectFactory factory);
//
// public static MessageType readFrom(final DirectBuffer directBuffer, final int offset) {
// final int type = directBuffer.getInt(offset);
// if (type >= 0 & type <= MessageType.maxOrdinal()) {
// return MessageType.valueByOrdinal(type);
// }
// throw new IllegalArgumentException("Illegal message type: " + type);
// }
//
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/message/direct/DirectVoteRequest.java
import org.agrona.DirectBuffer;
import org.agrona.MutableDirectBuffer;
import org.tools4j.hoverraft.command.LogKey;
import org.tools4j.hoverraft.message.MessageType;
import org.tools4j.hoverraft.message.VoteRequest;
}
@Override
public int byteLength() {
return BYTE_LENGTH;
}
@Override
public int term() {
return readBuffer.getInt(offset + TERM_OFF);
}
@Override
public DirectVoteRequest term(final int term) {
writeBuffer.putInt(offset + TERM_OFF, term);
return this;
}
@Override
public int candidateId() {
return readBuffer.getInt(offset + CANDIDATE_ID_OFF);
}
@Override
public DirectVoteRequest candidateId(final int candidateId) {
writeBuffer.putInt(offset + CANDIDATE_ID_OFF, candidateId);
return this;
}
@Override | public LogKey lastLogKey() { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/direct/DirectFactory.java | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
| import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.message.*; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.direct;
/**
* Factory for {@link DirectPayload} objects.
*/
public interface DirectFactory {
AppendRequest appendRequest();
AppendResponse appendResponse();
VoteRequest voteRequest();
VoteResponse voteResponse();
TimeoutNow timeoutNow();
| // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/direct/DirectFactory.java
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.message.*;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.direct;
/**
* Factory for {@link DirectPayload} objects.
*/
public interface DirectFactory {
AppendRequest appendRequest();
AppendResponse appendResponse();
VoteRequest voteRequest();
VoteResponse voteResponse();
TimeoutNow timeoutNow();
| CommandKey commandKey(); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/direct/DirectFactory.java | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
| import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.message.*; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.direct;
/**
* Factory for {@link DirectPayload} objects.
*/
public interface DirectFactory {
AppendRequest appendRequest();
AppendResponse appendResponse();
VoteRequest voteRequest();
VoteResponse voteResponse();
TimeoutNow timeoutNow();
CommandKey commandKey();
| // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/direct/DirectFactory.java
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.message.*;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.direct;
/**
* Factory for {@link DirectPayload} objects.
*/
public interface DirectFactory {
AppendRequest appendRequest();
AppendResponse appendResponse();
VoteRequest voteRequest();
VoteResponse voteResponse();
TimeoutNow timeoutNow();
CommandKey commandKey();
| Command command(); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/direct/DirectFactory.java | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
| import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.message.*; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.direct;
/**
* Factory for {@link DirectPayload} objects.
*/
public interface DirectFactory {
AppendRequest appendRequest();
AppendResponse appendResponse();
VoteRequest voteRequest();
VoteResponse voteResponse();
TimeoutNow timeoutNow();
CommandKey commandKey();
Command command();
| // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/CommandKey.java
// public interface CommandKey extends Comparable<CommandKey> {
// Comparator<CommandKey> COMPARATOR = (k1, k2) -> {
// final int sourceCompare = Integer.compare(k1.sourceId(), k2.sourceId());
// return sourceCompare == 0 ? Long.compare(k1.commandIndex(), k2.commandIndex()) : sourceCompare;
// };
//
// int sourceId();
// CommandKey sourceId(int sourceId);
//
// long commandIndex();
// CommandKey commandIndex(long commandIndex);
//
// @Override
// default int compareTo(final CommandKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default boolean containedIn(final CommandLog commandLog) {
// return commandLog.contains(this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/command/LogEntry.java
// public interface LogEntry extends DirectPayload {
// LogKey logKey();
//
// default LogEntry term(final int term) {
// logKey().term(term);
// return this;
// }
// default LogEntry index(final long index) {
// logKey().index(index);
// return this;
// }
//
// Command command();
//
// default void copyFrom(final LogEntry logEntry) {
// writeBufferOrNull().putBytes(offset(), logEntry.readBufferOrNull(), logEntry.offset(), logEntry.byteLength());
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/direct/DirectFactory.java
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.command.CommandKey;
import org.tools4j.hoverraft.command.LogEntry;
import org.tools4j.hoverraft.message.*;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.direct;
/**
* Factory for {@link DirectPayload} objects.
*/
public interface DirectFactory {
AppendRequest appendRequest();
AppendResponse appendResponse();
VoteRequest voteRequest();
VoteResponse voteResponse();
TimeoutNow timeoutNow();
CommandKey commandKey();
Command command();
| LogEntry logEntry(); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/VoteRequest.java | // Path: src/main/java/org/tools4j/hoverraft/command/LogKey.java
// public interface LogKey extends Comparable<LogKey> {
// Comparator<LogKey> COMPARATOR = (k1, k2) -> {
// final int termCompare = Integer.compare(k1.term(), k2.term());
// return termCompare == 0 ? Long.compare(k1.index(), k2.index()) : termCompare;
// };
//
// int term();
// LogKey term(int term);
//
// long index();
// LogKey index(long index);
//
// @Override
// default int compareTo(final LogKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default LogContainment containedIn(final CommandLog commandLog) {
// return LogContainment.containmentFor(this, commandLog);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.command.LogKey;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface VoteRequest extends Message {
int term();
VoteRequest term(int term);
int candidateId();
VoteRequest candidateId(int candidateId);
| // Path: src/main/java/org/tools4j/hoverraft/command/LogKey.java
// public interface LogKey extends Comparable<LogKey> {
// Comparator<LogKey> COMPARATOR = (k1, k2) -> {
// final int termCompare = Integer.compare(k1.term(), k2.term());
// return termCompare == 0 ? Long.compare(k1.index(), k2.index()) : termCompare;
// };
//
// int term();
// LogKey term(int term);
//
// long index();
// LogKey index(long index);
//
// @Override
// default int compareTo(final LogKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default LogContainment containedIn(final CommandLog commandLog) {
// return LogContainment.containmentFor(this, commandLog);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
import org.tools4j.hoverraft.command.LogKey;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface VoteRequest extends Message {
int term();
VoteRequest term(int term);
int candidateId();
VoteRequest candidateId(int candidateId);
| LogKey lastLogKey(); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/VoteRequest.java | // Path: src/main/java/org/tools4j/hoverraft/command/LogKey.java
// public interface LogKey extends Comparable<LogKey> {
// Comparator<LogKey> COMPARATOR = (k1, k2) -> {
// final int termCompare = Integer.compare(k1.term(), k2.term());
// return termCompare == 0 ? Long.compare(k1.index(), k2.index()) : termCompare;
// };
//
// int term();
// LogKey term(int term);
//
// long index();
// LogKey index(long index);
//
// @Override
// default int compareTo(final LogKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default LogContainment containedIn(final CommandLog commandLog) {
// return LogContainment.containmentFor(this, commandLog);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.command.LogKey;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface VoteRequest extends Message {
int term();
VoteRequest term(int term);
int candidateId();
VoteRequest candidateId(int candidateId);
LogKey lastLogKey();
@Override | // Path: src/main/java/org/tools4j/hoverraft/command/LogKey.java
// public interface LogKey extends Comparable<LogKey> {
// Comparator<LogKey> COMPARATOR = (k1, k2) -> {
// final int termCompare = Integer.compare(k1.term(), k2.term());
// return termCompare == 0 ? Long.compare(k1.index(), k2.index()) : termCompare;
// };
//
// int term();
// LogKey term(int term);
//
// long index();
// LogKey index(long index);
//
// @Override
// default int compareTo(final LogKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default LogContainment containedIn(final CommandLog commandLog) {
// return LogContainment.containmentFor(this, commandLog);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
import org.tools4j.hoverraft.command.LogKey;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface VoteRequest extends Message {
int term();
VoteRequest term(int term);
int candidateId();
VoteRequest candidateId(int candidateId);
LogKey lastLogKey();
@Override | default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/VoteRequest.java | // Path: src/main/java/org/tools4j/hoverraft/command/LogKey.java
// public interface LogKey extends Comparable<LogKey> {
// Comparator<LogKey> COMPARATOR = (k1, k2) -> {
// final int termCompare = Integer.compare(k1.term(), k2.term());
// return termCompare == 0 ? Long.compare(k1.index(), k2.index()) : termCompare;
// };
//
// int term();
// LogKey term(int term);
//
// long index();
// LogKey index(long index);
//
// @Override
// default int compareTo(final LogKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default LogContainment containedIn(final CommandLog commandLog) {
// return LogContainment.containmentFor(this, commandLog);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.command.LogKey;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface VoteRequest extends Message {
int term();
VoteRequest term(int term);
int candidateId();
VoteRequest candidateId(int candidateId);
LogKey lastLogKey();
@Override | // Path: src/main/java/org/tools4j/hoverraft/command/LogKey.java
// public interface LogKey extends Comparable<LogKey> {
// Comparator<LogKey> COMPARATOR = (k1, k2) -> {
// final int termCompare = Integer.compare(k1.term(), k2.term());
// return termCompare == 0 ? Long.compare(k1.index(), k2.index()) : termCompare;
// };
//
// int term();
// LogKey term(int term);
//
// long index();
// LogKey index(long index);
//
// @Override
// default int compareTo(final LogKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default LogContainment containedIn(final CommandLog commandLog) {
// return LogContainment.containmentFor(this, commandLog);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
import org.tools4j.hoverraft.command.LogKey;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface VoteRequest extends Message {
int term();
VoteRequest term(int term);
int candidateId();
VoteRequest candidateId(int candidateId);
LogKey lastLogKey();
@Override | default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/VoteRequest.java | // Path: src/main/java/org/tools4j/hoverraft/command/LogKey.java
// public interface LogKey extends Comparable<LogKey> {
// Comparator<LogKey> COMPARATOR = (k1, k2) -> {
// final int termCompare = Integer.compare(k1.term(), k2.term());
// return termCompare == 0 ? Long.compare(k1.index(), k2.index()) : termCompare;
// };
//
// int term();
// LogKey term(int term);
//
// long index();
// LogKey index(long index);
//
// @Override
// default int compareTo(final LogKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default LogContainment containedIn(final CommandLog commandLog) {
// return LogContainment.containmentFor(this, commandLog);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.command.LogKey;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface VoteRequest extends Message {
int term();
VoteRequest term(int term);
int candidateId();
VoteRequest candidateId(int candidateId);
LogKey lastLogKey();
@Override | // Path: src/main/java/org/tools4j/hoverraft/command/LogKey.java
// public interface LogKey extends Comparable<LogKey> {
// Comparator<LogKey> COMPARATOR = (k1, k2) -> {
// final int termCompare = Integer.compare(k1.term(), k2.term());
// return termCompare == 0 ? Long.compare(k1.index(), k2.index()) : termCompare;
// };
//
// int term();
// LogKey term(int term);
//
// long index();
// LogKey index(long index);
//
// @Override
// default int compareTo(final LogKey other) {
// return COMPARATOR.compare(this, other);
// }
//
// default LogContainment containedIn(final CommandLog commandLog) {
// return LogContainment.containmentFor(this, commandLog);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
import org.tools4j.hoverraft.command.LogKey;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.Transition;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
public interface VoteRequest extends Message {
int term();
VoteRequest term(int term);
int candidateId();
VoteRequest candidateId(int candidateId);
LogKey lastLogKey();
@Override | default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/Transition.java | // Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
| import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
/**
* Transition from current state, either STEADY (no change) or into a new {@link Role}.
*/
public enum Transition implements Event {
STEADY(null, false),
TO_FOLLOWER(Role.FOLLOWER, true),
TO_CANDIDATE(Role.CANDIDATE, false),
TO_LEADER(Role.LEADER, false);
private final Role targetRole;
private final boolean replayEvent;
Transition(final Role targetRole, final boolean replayEvent) {
this.targetRole = targetRole;//nullable
this.replayEvent = replayEvent;
}
public final Role targetRole(final Role currentRole) {
return this == STEADY ? currentRole : targetRole;
}
public final boolean replayEvent() {
return replayEvent;
}
@Override | // Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
/**
* Transition from current state, either STEADY (no change) or into a new {@link Role}.
*/
public enum Transition implements Event {
STEADY(null, false),
TO_FOLLOWER(Role.FOLLOWER, true),
TO_CANDIDATE(Role.CANDIDATE, false),
TO_LEADER(Role.LEADER, false);
private final Role targetRole;
private final boolean replayEvent;
Transition(final Role targetRole, final boolean replayEvent) {
this.targetRole = targetRole;//nullable
this.replayEvent = replayEvent;
}
public final Role targetRole(final Role currentRole) {
return this == STEADY ? currentRole : targetRole;
}
public final boolean replayEvent() {
return replayEvent;
}
@Override | public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/Transition.java | // Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
| import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
/**
* Transition from current state, either STEADY (no change) or into a new {@link Role}.
*/
public enum Transition implements Event {
STEADY(null, false),
TO_FOLLOWER(Role.FOLLOWER, true),
TO_CANDIDATE(Role.CANDIDATE, false),
TO_LEADER(Role.LEADER, false);
private final Role targetRole;
private final boolean replayEvent;
Transition(final Role targetRole, final boolean replayEvent) {
this.targetRole = targetRole;//nullable
this.replayEvent = replayEvent;
}
public final Role targetRole(final Role currentRole) {
return this == STEADY ? currentRole : targetRole;
}
public final boolean replayEvent() {
return replayEvent;
}
@Override | // Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.server.ServerContext;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
/**
* Transition from current state, either STEADY (no change) or into a new {@link Role}.
*/
public enum Transition implements Event {
STEADY(null, false),
TO_FOLLOWER(Role.FOLLOWER, true),
TO_CANDIDATE(Role.CANDIDATE, false),
TO_LEADER(Role.LEADER, false);
private final Role targetRole;
private final boolean replayEvent;
Transition(final Role targetRole, final boolean replayEvent) {
this.targetRole = targetRole;//nullable
this.replayEvent = replayEvent;
}
public final Role targetRole(final Role currentRole) {
return this == STEADY ? currentRole : targetRole;
}
public final boolean replayEvent() {
return replayEvent;
}
@Override | public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/CandidateState.java | // Path: src/main/java/org/tools4j/hoverraft/config/ConsensusConfig.java
// public interface ConsensusConfig {
// long minElectionTimeoutMillis();
// long maxElectionTimeoutMillis();
// long heartbeatTimeoutMillis();
// Optional<String> ipcMulticastChannel();
// int serverCount();
// ServerConfig serverConfig(int index);
// int sourceCount();
// SourceConfig sourceConfig(int index);
// ThreadingMode threadingMode();
//
// default ServerConfig serverConfigByIdOrNull(int id) {
// for (int i = 0; i < serverCount(); i++) {
// final ServerConfig config = serverConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
//
// default SourceConfig sourceConfigByIdOrNull(int id) {
// for (int i = 0; i < sourceCount(); i++) {
// final SourceConfig config = sourceConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteResponse.java
// public interface VoteResponse extends Message {
//
// int term();
//
// VoteResponse term(int term);
//
// boolean voteGranted();
//
// VoteResponse voteGranted(boolean granted);
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteResponse(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
// public enum TimerEvent implements Event {
// TIMEOUT;
//
// @Override
// public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimerEvent(serverContext, this);
// }
// }
| import org.tools4j.hoverraft.config.ConsensusConfig;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.message.VoteResponse;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.timer.TimerEvent; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public final class CandidateState extends AbstractState {
private int voteCount;
public CandidateState(final PersistentState persistentState, final VolatileState volatileState) {
super(Role.CANDIDATE, persistentState, volatileState);
}
@Override | // Path: src/main/java/org/tools4j/hoverraft/config/ConsensusConfig.java
// public interface ConsensusConfig {
// long minElectionTimeoutMillis();
// long maxElectionTimeoutMillis();
// long heartbeatTimeoutMillis();
// Optional<String> ipcMulticastChannel();
// int serverCount();
// ServerConfig serverConfig(int index);
// int sourceCount();
// SourceConfig sourceConfig(int index);
// ThreadingMode threadingMode();
//
// default ServerConfig serverConfigByIdOrNull(int id) {
// for (int i = 0; i < serverCount(); i++) {
// final ServerConfig config = serverConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
//
// default SourceConfig sourceConfigByIdOrNull(int id) {
// for (int i = 0; i < sourceCount(); i++) {
// final SourceConfig config = sourceConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteResponse.java
// public interface VoteResponse extends Message {
//
// int term();
//
// VoteResponse term(int term);
//
// boolean voteGranted();
//
// VoteResponse voteGranted(boolean granted);
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteResponse(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
// public enum TimerEvent implements Event {
// TIMEOUT;
//
// @Override
// public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimerEvent(serverContext, this);
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/CandidateState.java
import org.tools4j.hoverraft.config.ConsensusConfig;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.message.VoteResponse;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.timer.TimerEvent;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public final class CandidateState extends AbstractState {
private int voteCount;
public CandidateState(final PersistentState persistentState, final VolatileState volatileState) {
super(Role.CANDIDATE, persistentState, volatileState);
}
@Override | protected EventHandler eventHandler() { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/CandidateState.java | // Path: src/main/java/org/tools4j/hoverraft/config/ConsensusConfig.java
// public interface ConsensusConfig {
// long minElectionTimeoutMillis();
// long maxElectionTimeoutMillis();
// long heartbeatTimeoutMillis();
// Optional<String> ipcMulticastChannel();
// int serverCount();
// ServerConfig serverConfig(int index);
// int sourceCount();
// SourceConfig sourceConfig(int index);
// ThreadingMode threadingMode();
//
// default ServerConfig serverConfigByIdOrNull(int id) {
// for (int i = 0; i < serverCount(); i++) {
// final ServerConfig config = serverConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
//
// default SourceConfig sourceConfigByIdOrNull(int id) {
// for (int i = 0; i < sourceCount(); i++) {
// final SourceConfig config = sourceConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteResponse.java
// public interface VoteResponse extends Message {
//
// int term();
//
// VoteResponse term(int term);
//
// boolean voteGranted();
//
// VoteResponse voteGranted(boolean granted);
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteResponse(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
// public enum TimerEvent implements Event {
// TIMEOUT;
//
// @Override
// public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimerEvent(serverContext, this);
// }
// }
| import org.tools4j.hoverraft.config.ConsensusConfig;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.message.VoteResponse;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.timer.TimerEvent; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public final class CandidateState extends AbstractState {
private int voteCount;
public CandidateState(final PersistentState persistentState, final VolatileState volatileState) {
super(Role.CANDIDATE, persistentState, volatileState);
}
@Override
protected EventHandler eventHandler() {
return new EventHandler() {
@Override | // Path: src/main/java/org/tools4j/hoverraft/config/ConsensusConfig.java
// public interface ConsensusConfig {
// long minElectionTimeoutMillis();
// long maxElectionTimeoutMillis();
// long heartbeatTimeoutMillis();
// Optional<String> ipcMulticastChannel();
// int serverCount();
// ServerConfig serverConfig(int index);
// int sourceCount();
// SourceConfig sourceConfig(int index);
// ThreadingMode threadingMode();
//
// default ServerConfig serverConfigByIdOrNull(int id) {
// for (int i = 0; i < serverCount(); i++) {
// final ServerConfig config = serverConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
//
// default SourceConfig sourceConfigByIdOrNull(int id) {
// for (int i = 0; i < sourceCount(); i++) {
// final SourceConfig config = sourceConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteResponse.java
// public interface VoteResponse extends Message {
//
// int term();
//
// VoteResponse term(int term);
//
// boolean voteGranted();
//
// VoteResponse voteGranted(boolean granted);
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteResponse(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
// public enum TimerEvent implements Event {
// TIMEOUT;
//
// @Override
// public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimerEvent(serverContext, this);
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/CandidateState.java
import org.tools4j.hoverraft.config.ConsensusConfig;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.message.VoteResponse;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.timer.TimerEvent;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public final class CandidateState extends AbstractState {
private int voteCount;
public CandidateState(final PersistentState persistentState, final VolatileState volatileState) {
super(Role.CANDIDATE, persistentState, volatileState);
}
@Override
protected EventHandler eventHandler() {
return new EventHandler() {
@Override | public Transition onTransition(final ServerContext serverContext, final Transition transition) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/CandidateState.java | // Path: src/main/java/org/tools4j/hoverraft/config/ConsensusConfig.java
// public interface ConsensusConfig {
// long minElectionTimeoutMillis();
// long maxElectionTimeoutMillis();
// long heartbeatTimeoutMillis();
// Optional<String> ipcMulticastChannel();
// int serverCount();
// ServerConfig serverConfig(int index);
// int sourceCount();
// SourceConfig sourceConfig(int index);
// ThreadingMode threadingMode();
//
// default ServerConfig serverConfigByIdOrNull(int id) {
// for (int i = 0; i < serverCount(); i++) {
// final ServerConfig config = serverConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
//
// default SourceConfig sourceConfigByIdOrNull(int id) {
// for (int i = 0; i < sourceCount(); i++) {
// final SourceConfig config = sourceConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteResponse.java
// public interface VoteResponse extends Message {
//
// int term();
//
// VoteResponse term(int term);
//
// boolean voteGranted();
//
// VoteResponse voteGranted(boolean granted);
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteResponse(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
// public enum TimerEvent implements Event {
// TIMEOUT;
//
// @Override
// public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimerEvent(serverContext, this);
// }
// }
| import org.tools4j.hoverraft.config.ConsensusConfig;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.message.VoteResponse;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.timer.TimerEvent; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public final class CandidateState extends AbstractState {
private int voteCount;
public CandidateState(final PersistentState persistentState, final VolatileState volatileState) {
super(Role.CANDIDATE, persistentState, volatileState);
}
@Override
protected EventHandler eventHandler() {
return new EventHandler() {
@Override
public Transition onTransition(final ServerContext serverContext, final Transition transition) {
return CandidateState.this.onTransition(serverContext, transition);
}
@Override | // Path: src/main/java/org/tools4j/hoverraft/config/ConsensusConfig.java
// public interface ConsensusConfig {
// long minElectionTimeoutMillis();
// long maxElectionTimeoutMillis();
// long heartbeatTimeoutMillis();
// Optional<String> ipcMulticastChannel();
// int serverCount();
// ServerConfig serverConfig(int index);
// int sourceCount();
// SourceConfig sourceConfig(int index);
// ThreadingMode threadingMode();
//
// default ServerConfig serverConfigByIdOrNull(int id) {
// for (int i = 0; i < serverCount(); i++) {
// final ServerConfig config = serverConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
//
// default SourceConfig sourceConfigByIdOrNull(int id) {
// for (int i = 0; i < sourceCount(); i++) {
// final SourceConfig config = sourceConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteResponse.java
// public interface VoteResponse extends Message {
//
// int term();
//
// VoteResponse term(int term);
//
// boolean voteGranted();
//
// VoteResponse voteGranted(boolean granted);
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteResponse(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
// public enum TimerEvent implements Event {
// TIMEOUT;
//
// @Override
// public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimerEvent(serverContext, this);
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/CandidateState.java
import org.tools4j.hoverraft.config.ConsensusConfig;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.message.VoteResponse;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.timer.TimerEvent;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public final class CandidateState extends AbstractState {
private int voteCount;
public CandidateState(final PersistentState persistentState, final VolatileState volatileState) {
super(Role.CANDIDATE, persistentState, volatileState);
}
@Override
protected EventHandler eventHandler() {
return new EventHandler() {
@Override
public Transition onTransition(final ServerContext serverContext, final Transition transition) {
return CandidateState.this.onTransition(serverContext, transition);
}
@Override | public Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/CandidateState.java | // Path: src/main/java/org/tools4j/hoverraft/config/ConsensusConfig.java
// public interface ConsensusConfig {
// long minElectionTimeoutMillis();
// long maxElectionTimeoutMillis();
// long heartbeatTimeoutMillis();
// Optional<String> ipcMulticastChannel();
// int serverCount();
// ServerConfig serverConfig(int index);
// int sourceCount();
// SourceConfig sourceConfig(int index);
// ThreadingMode threadingMode();
//
// default ServerConfig serverConfigByIdOrNull(int id) {
// for (int i = 0; i < serverCount(); i++) {
// final ServerConfig config = serverConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
//
// default SourceConfig sourceConfigByIdOrNull(int id) {
// for (int i = 0; i < sourceCount(); i++) {
// final SourceConfig config = sourceConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteResponse.java
// public interface VoteResponse extends Message {
//
// int term();
//
// VoteResponse term(int term);
//
// boolean voteGranted();
//
// VoteResponse voteGranted(boolean granted);
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteResponse(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
// public enum TimerEvent implements Event {
// TIMEOUT;
//
// @Override
// public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimerEvent(serverContext, this);
// }
// }
| import org.tools4j.hoverraft.config.ConsensusConfig;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.message.VoteResponse;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.timer.TimerEvent; | startNewElection(serverContext);
return Transition.STEADY;
}
private Transition onVoteResponse(final ServerContext serverContext, final VoteResponse voteResponse) {
if (voteResponse.term() == currentTerm() && voteResponse.voteGranted()) {
return incVoteCount(serverContext);
}
return Transition.STEADY;
}
protected Transition onAppendRequest(final ServerContext serverContext, final AppendRequest appendRequest) {
final int appendRequestTerm = appendRequest.term();
final int currentTerm = currentTerm();
if (appendRequestTerm >= currentTerm) {
serverContext.timer().reset();
return Transition.TO_FOLLOWER;
} else {
return super.onAppendRequest(serverContext, appendRequest);
}
}
private Transition onTimerEvent(final ServerContext serverContext, final TimerEvent timerEvent) {
startNewElection(serverContext);
return Transition.STEADY;
}
private void startNewElection(final ServerContext serverContext) { | // Path: src/main/java/org/tools4j/hoverraft/config/ConsensusConfig.java
// public interface ConsensusConfig {
// long minElectionTimeoutMillis();
// long maxElectionTimeoutMillis();
// long heartbeatTimeoutMillis();
// Optional<String> ipcMulticastChannel();
// int serverCount();
// ServerConfig serverConfig(int index);
// int sourceCount();
// SourceConfig sourceConfig(int index);
// ThreadingMode threadingMode();
//
// default ServerConfig serverConfigByIdOrNull(int id) {
// for (int i = 0; i < serverCount(); i++) {
// final ServerConfig config = serverConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
//
// default SourceConfig sourceConfigByIdOrNull(int id) {
// for (int i = 0; i < sourceCount(); i++) {
// final SourceConfig config = sourceConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteResponse.java
// public interface VoteResponse extends Message {
//
// int term();
//
// VoteResponse term(int term);
//
// boolean voteGranted();
//
// VoteResponse voteGranted(boolean granted);
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteResponse(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
// public enum TimerEvent implements Event {
// TIMEOUT;
//
// @Override
// public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimerEvent(serverContext, this);
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/CandidateState.java
import org.tools4j.hoverraft.config.ConsensusConfig;
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.message.VoteResponse;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.timer.TimerEvent;
startNewElection(serverContext);
return Transition.STEADY;
}
private Transition onVoteResponse(final ServerContext serverContext, final VoteResponse voteResponse) {
if (voteResponse.term() == currentTerm() && voteResponse.voteGranted()) {
return incVoteCount(serverContext);
}
return Transition.STEADY;
}
protected Transition onAppendRequest(final ServerContext serverContext, final AppendRequest appendRequest) {
final int appendRequestTerm = appendRequest.term();
final int currentTerm = currentTerm();
if (appendRequestTerm >= currentTerm) {
serverContext.timer().reset();
return Transition.TO_FOLLOWER;
} else {
return super.onAppendRequest(serverContext, appendRequest);
}
}
private Transition onTimerEvent(final ServerContext serverContext, final TimerEvent timerEvent) {
startNewElection(serverContext);
return Transition.STEADY;
}
private void startNewElection(final ServerContext serverContext) { | final ConsensusConfig config = serverContext.consensusConfig(); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/server/RoundRobinMessagePoller.java | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/config/ConsensusConfig.java
// public interface ConsensusConfig {
// long minElectionTimeoutMillis();
// long maxElectionTimeoutMillis();
// long heartbeatTimeoutMillis();
// Optional<String> ipcMulticastChannel();
// int serverCount();
// ServerConfig serverConfig(int index);
// int sourceCount();
// SourceConfig sourceConfig(int index);
// ThreadingMode threadingMode();
//
// default ServerConfig serverConfigByIdOrNull(int id) {
// for (int i = 0; i < serverCount(); i++) {
// final ServerConfig config = serverConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
//
// default SourceConfig sourceConfigByIdOrNull(int id) {
// for (int i = 0; i < sourceCount(); i++) {
// final SourceConfig config = sourceConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/direct/DirectPayload.java
// public interface DirectPayload {
//
// int byteLength();
//
// int offset();
//
// DirectBuffer readBufferOrNull();
//
// MutableDirectBuffer writeBufferOrNull();
//
// void wrap(DirectBuffer buffer, int offset);
//
// void wrap(MutableDirectBuffer buffer, int offset);
//
// void unwrap();
//
// default boolean isWrapped() {
// return readBufferOrNull() != null || writeBufferOrNull() != null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/Message.java
// public interface Message extends DirectPayload, Event {
//
// MessageType type();
//
// default void sendTo(final Sender<? super Message> sender, final ResendStrategy resendStrategy) {
// final long res = sender.offer(this);
// if (res < 0) {
// resendStrategy.onRejectedOffer(sender, this, res);
// }
// }
//
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/transport/Receiver.java
// public interface Receiver<M extends DirectPayload> {
// /**
// * Polls messages in non-blocking mode. Messages are passed to the specified
// * message event.
// *
// * @param messageMandler the event invoked for each message
// * @param limit maximum number of messages to receive
// * @return number of messages received, zero to at most {@code limit} messages
// */
// int poll(Consumer<? super M> messageMandler, int limit);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/transport/Receivers.java
// public final class Receivers {
//
// public static <M extends DirectPayload> Receiver<M> roundRobinReceiver(final Receiver<? extends M>... receivers) {
// return new Receiver<M>() {
// private int index = -1;
//
// @Override
// public int poll(final Consumer<? super M> messageMandler, final int limit) {
// final Receiver<? extends M>[] r = receivers;
// final int len = r.length;
// int cnt = 0;
// for (int i = 0; i < len && cnt < limit; i++) {
// index++;
// if (index >= len) {
// index -= len;
// }
// cnt += r[index].poll(messageMandler, limit - cnt);
// }
// return cnt;
// }
// };
// }
//
// }
| import java.util.Objects;
import java.util.function.Consumer;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.config.ConsensusConfig;
import org.tools4j.hoverraft.direct.DirectPayload;
import org.tools4j.hoverraft.message.Message;
import org.tools4j.hoverraft.transport.Receiver;
import org.tools4j.hoverraft.transport.Receivers; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.server;
public class RoundRobinMessagePoller<M extends DirectPayload> {
private final Receiver<M> roundRobinReceiver;
private final Consumer<? super M> messageHandler;
private RoundRobinMessagePoller(final Receiver<M> roundRobinReceiver,
final Consumer<? super M> messageHandler) {
this.roundRobinReceiver = Objects.requireNonNull(roundRobinReceiver);
this.messageHandler = Objects.requireNonNull(messageHandler);
}
| // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/config/ConsensusConfig.java
// public interface ConsensusConfig {
// long minElectionTimeoutMillis();
// long maxElectionTimeoutMillis();
// long heartbeatTimeoutMillis();
// Optional<String> ipcMulticastChannel();
// int serverCount();
// ServerConfig serverConfig(int index);
// int sourceCount();
// SourceConfig sourceConfig(int index);
// ThreadingMode threadingMode();
//
// default ServerConfig serverConfigByIdOrNull(int id) {
// for (int i = 0; i < serverCount(); i++) {
// final ServerConfig config = serverConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
//
// default SourceConfig sourceConfigByIdOrNull(int id) {
// for (int i = 0; i < sourceCount(); i++) {
// final SourceConfig config = sourceConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/direct/DirectPayload.java
// public interface DirectPayload {
//
// int byteLength();
//
// int offset();
//
// DirectBuffer readBufferOrNull();
//
// MutableDirectBuffer writeBufferOrNull();
//
// void wrap(DirectBuffer buffer, int offset);
//
// void wrap(MutableDirectBuffer buffer, int offset);
//
// void unwrap();
//
// default boolean isWrapped() {
// return readBufferOrNull() != null || writeBufferOrNull() != null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/Message.java
// public interface Message extends DirectPayload, Event {
//
// MessageType type();
//
// default void sendTo(final Sender<? super Message> sender, final ResendStrategy resendStrategy) {
// final long res = sender.offer(this);
// if (res < 0) {
// resendStrategy.onRejectedOffer(sender, this, res);
// }
// }
//
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/transport/Receiver.java
// public interface Receiver<M extends DirectPayload> {
// /**
// * Polls messages in non-blocking mode. Messages are passed to the specified
// * message event.
// *
// * @param messageMandler the event invoked for each message
// * @param limit maximum number of messages to receive
// * @return number of messages received, zero to at most {@code limit} messages
// */
// int poll(Consumer<? super M> messageMandler, int limit);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/transport/Receivers.java
// public final class Receivers {
//
// public static <M extends DirectPayload> Receiver<M> roundRobinReceiver(final Receiver<? extends M>... receivers) {
// return new Receiver<M>() {
// private int index = -1;
//
// @Override
// public int poll(final Consumer<? super M> messageMandler, final int limit) {
// final Receiver<? extends M>[] r = receivers;
// final int len = r.length;
// int cnt = 0;
// for (int i = 0; i < len && cnt < limit; i++) {
// index++;
// if (index >= len) {
// index -= len;
// }
// cnt += r[index].poll(messageMandler, limit - cnt);
// }
// return cnt;
// }
// };
// }
//
// }
// Path: src/main/java/org/tools4j/hoverraft/server/RoundRobinMessagePoller.java
import java.util.Objects;
import java.util.function.Consumer;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.config.ConsensusConfig;
import org.tools4j.hoverraft.direct.DirectPayload;
import org.tools4j.hoverraft.message.Message;
import org.tools4j.hoverraft.transport.Receiver;
import org.tools4j.hoverraft.transport.Receivers;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.server;
public class RoundRobinMessagePoller<M extends DirectPayload> {
private final Receiver<M> roundRobinReceiver;
private final Consumer<? super M> messageHandler;
private RoundRobinMessagePoller(final Receiver<M> roundRobinReceiver,
final Consumer<? super M> messageHandler) {
this.roundRobinReceiver = Objects.requireNonNull(roundRobinReceiver);
this.messageHandler = Objects.requireNonNull(messageHandler);
}
| public static RoundRobinMessagePoller<Message> forServerMessages(final ServerContext serverContext, |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/server/RoundRobinMessagePoller.java | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/config/ConsensusConfig.java
// public interface ConsensusConfig {
// long minElectionTimeoutMillis();
// long maxElectionTimeoutMillis();
// long heartbeatTimeoutMillis();
// Optional<String> ipcMulticastChannel();
// int serverCount();
// ServerConfig serverConfig(int index);
// int sourceCount();
// SourceConfig sourceConfig(int index);
// ThreadingMode threadingMode();
//
// default ServerConfig serverConfigByIdOrNull(int id) {
// for (int i = 0; i < serverCount(); i++) {
// final ServerConfig config = serverConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
//
// default SourceConfig sourceConfigByIdOrNull(int id) {
// for (int i = 0; i < sourceCount(); i++) {
// final SourceConfig config = sourceConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/direct/DirectPayload.java
// public interface DirectPayload {
//
// int byteLength();
//
// int offset();
//
// DirectBuffer readBufferOrNull();
//
// MutableDirectBuffer writeBufferOrNull();
//
// void wrap(DirectBuffer buffer, int offset);
//
// void wrap(MutableDirectBuffer buffer, int offset);
//
// void unwrap();
//
// default boolean isWrapped() {
// return readBufferOrNull() != null || writeBufferOrNull() != null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/Message.java
// public interface Message extends DirectPayload, Event {
//
// MessageType type();
//
// default void sendTo(final Sender<? super Message> sender, final ResendStrategy resendStrategy) {
// final long res = sender.offer(this);
// if (res < 0) {
// resendStrategy.onRejectedOffer(sender, this, res);
// }
// }
//
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/transport/Receiver.java
// public interface Receiver<M extends DirectPayload> {
// /**
// * Polls messages in non-blocking mode. Messages are passed to the specified
// * message event.
// *
// * @param messageMandler the event invoked for each message
// * @param limit maximum number of messages to receive
// * @return number of messages received, zero to at most {@code limit} messages
// */
// int poll(Consumer<? super M> messageMandler, int limit);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/transport/Receivers.java
// public final class Receivers {
//
// public static <M extends DirectPayload> Receiver<M> roundRobinReceiver(final Receiver<? extends M>... receivers) {
// return new Receiver<M>() {
// private int index = -1;
//
// @Override
// public int poll(final Consumer<? super M> messageMandler, final int limit) {
// final Receiver<? extends M>[] r = receivers;
// final int len = r.length;
// int cnt = 0;
// for (int i = 0; i < len && cnt < limit; i++) {
// index++;
// if (index >= len) {
// index -= len;
// }
// cnt += r[index].poll(messageMandler, limit - cnt);
// }
// return cnt;
// }
// };
// }
//
// }
| import java.util.Objects;
import java.util.function.Consumer;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.config.ConsensusConfig;
import org.tools4j.hoverraft.direct.DirectPayload;
import org.tools4j.hoverraft.message.Message;
import org.tools4j.hoverraft.transport.Receiver;
import org.tools4j.hoverraft.transport.Receivers; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.server;
public class RoundRobinMessagePoller<M extends DirectPayload> {
private final Receiver<M> roundRobinReceiver;
private final Consumer<? super M> messageHandler;
private RoundRobinMessagePoller(final Receiver<M> roundRobinReceiver,
final Consumer<? super M> messageHandler) {
this.roundRobinReceiver = Objects.requireNonNull(roundRobinReceiver);
this.messageHandler = Objects.requireNonNull(messageHandler);
}
public static RoundRobinMessagePoller<Message> forServerMessages(final ServerContext serverContext,
final Consumer<? super Message> messageHandler) { | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/config/ConsensusConfig.java
// public interface ConsensusConfig {
// long minElectionTimeoutMillis();
// long maxElectionTimeoutMillis();
// long heartbeatTimeoutMillis();
// Optional<String> ipcMulticastChannel();
// int serverCount();
// ServerConfig serverConfig(int index);
// int sourceCount();
// SourceConfig sourceConfig(int index);
// ThreadingMode threadingMode();
//
// default ServerConfig serverConfigByIdOrNull(int id) {
// for (int i = 0; i < serverCount(); i++) {
// final ServerConfig config = serverConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
//
// default SourceConfig sourceConfigByIdOrNull(int id) {
// for (int i = 0; i < sourceCount(); i++) {
// final SourceConfig config = sourceConfig(i);
// if (config.id() == id) {
// return config;
// }
// }
// return null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/direct/DirectPayload.java
// public interface DirectPayload {
//
// int byteLength();
//
// int offset();
//
// DirectBuffer readBufferOrNull();
//
// MutableDirectBuffer writeBufferOrNull();
//
// void wrap(DirectBuffer buffer, int offset);
//
// void wrap(MutableDirectBuffer buffer, int offset);
//
// void unwrap();
//
// default boolean isWrapped() {
// return readBufferOrNull() != null || writeBufferOrNull() != null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/Message.java
// public interface Message extends DirectPayload, Event {
//
// MessageType type();
//
// default void sendTo(final Sender<? super Message> sender, final ResendStrategy resendStrategy) {
// final long res = sender.offer(this);
// if (res < 0) {
// resendStrategy.onRejectedOffer(sender, this, res);
// }
// }
//
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/transport/Receiver.java
// public interface Receiver<M extends DirectPayload> {
// /**
// * Polls messages in non-blocking mode. Messages are passed to the specified
// * message event.
// *
// * @param messageMandler the event invoked for each message
// * @param limit maximum number of messages to receive
// * @return number of messages received, zero to at most {@code limit} messages
// */
// int poll(Consumer<? super M> messageMandler, int limit);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/transport/Receivers.java
// public final class Receivers {
//
// public static <M extends DirectPayload> Receiver<M> roundRobinReceiver(final Receiver<? extends M>... receivers) {
// return new Receiver<M>() {
// private int index = -1;
//
// @Override
// public int poll(final Consumer<? super M> messageMandler, final int limit) {
// final Receiver<? extends M>[] r = receivers;
// final int len = r.length;
// int cnt = 0;
// for (int i = 0; i < len && cnt < limit; i++) {
// index++;
// if (index >= len) {
// index -= len;
// }
// cnt += r[index].poll(messageMandler, limit - cnt);
// }
// return cnt;
// }
// };
// }
//
// }
// Path: src/main/java/org/tools4j/hoverraft/server/RoundRobinMessagePoller.java
import java.util.Objects;
import java.util.function.Consumer;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.config.ConsensusConfig;
import org.tools4j.hoverraft.direct.DirectPayload;
import org.tools4j.hoverraft.message.Message;
import org.tools4j.hoverraft.transport.Receiver;
import org.tools4j.hoverraft.transport.Receivers;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.server;
public class RoundRobinMessagePoller<M extends DirectPayload> {
private final Receiver<M> roundRobinReceiver;
private final Consumer<? super M> messageHandler;
private RoundRobinMessagePoller(final Receiver<M> roundRobinReceiver,
final Consumer<? super M> messageHandler) {
this.roundRobinReceiver = Objects.requireNonNull(roundRobinReceiver);
this.messageHandler = Objects.requireNonNull(messageHandler);
}
public static RoundRobinMessagePoller<Message> forServerMessages(final ServerContext serverContext,
final Consumer<? super Message> messageHandler) { | final ConsensusConfig config = serverContext.consensusConfig(); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/direct/DirectTimeoutNow.java | // Path: src/main/java/org/tools4j/hoverraft/message/MessageType.java
// public enum MessageType {
// VOTE_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteRequest();
// }
// },
// VOTE_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteResponse();
// }
// },
// APPEND_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendRequest();
// }
// },
// APPEND_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendResponse();
// }
// },
// TIMEOUT_NOW {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.timeoutNow();
// }
// };
//
// private static final MessageType[] VALUES = values();
//
// public static final MessageType valueByOrdinal(final int ordinal) {
// return VALUES[ordinal];
// }
//
// public static final int maxOrdinal() {
// return VALUES.length - 1;
// }
//
// abstract public Message create(DirectFactory factory);
//
// public static MessageType readFrom(final DirectBuffer directBuffer, final int offset) {
// final int type = directBuffer.getInt(offset);
// if (type >= 0 & type <= MessageType.maxOrdinal()) {
// return MessageType.valueByOrdinal(type);
// }
// throw new IllegalArgumentException("Illegal message type: " + type);
// }
//
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/TimeoutNow.java
// public interface TimeoutNow extends Message {
//
// int term();
//
// TimeoutNow term(int term);
//
// int candidateId();
//
// TimeoutNow candidateId(int candidateId);
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimeoutNow(serverContext, this);
// }
// }
| import org.tools4j.hoverraft.message.MessageType;
import org.tools4j.hoverraft.message.TimeoutNow; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message.direct;
/**
* Timeout request to initiate leadership transfer.
*/
public final class DirectTimeoutNow extends AbstractDirectMessage implements TimeoutNow {
private static final int TERM_OFF = TYPE_OFF + TYPE_LEN;
private static final int TERM_LEN = 4;
private static final int CANDIDATE_ID_OFF = TERM_OFF + TERM_LEN;
private static final int CANDIDATE_ID_LEN = 4;
public static final int BYTE_LENGTH = CANDIDATE_ID_OFF + CANDIDATE_ID_LEN;
@Override | // Path: src/main/java/org/tools4j/hoverraft/message/MessageType.java
// public enum MessageType {
// VOTE_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteRequest();
// }
// },
// VOTE_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteResponse();
// }
// },
// APPEND_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendRequest();
// }
// },
// APPEND_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendResponse();
// }
// },
// TIMEOUT_NOW {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.timeoutNow();
// }
// };
//
// private static final MessageType[] VALUES = values();
//
// public static final MessageType valueByOrdinal(final int ordinal) {
// return VALUES[ordinal];
// }
//
// public static final int maxOrdinal() {
// return VALUES.length - 1;
// }
//
// abstract public Message create(DirectFactory factory);
//
// public static MessageType readFrom(final DirectBuffer directBuffer, final int offset) {
// final int type = directBuffer.getInt(offset);
// if (type >= 0 & type <= MessageType.maxOrdinal()) {
// return MessageType.valueByOrdinal(type);
// }
// throw new IllegalArgumentException("Illegal message type: " + type);
// }
//
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/TimeoutNow.java
// public interface TimeoutNow extends Message {
//
// int term();
//
// TimeoutNow term(int term);
//
// int candidateId();
//
// TimeoutNow candidateId(int candidateId);
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimeoutNow(serverContext, this);
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/message/direct/DirectTimeoutNow.java
import org.tools4j.hoverraft.message.MessageType;
import org.tools4j.hoverraft.message.TimeoutNow;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message.direct;
/**
* Timeout request to initiate leadership transfer.
*/
public final class DirectTimeoutNow extends AbstractDirectMessage implements TimeoutNow {
private static final int TERM_OFF = TYPE_OFF + TYPE_LEN;
private static final int TERM_LEN = 4;
private static final int CANDIDATE_ID_OFF = TERM_OFF + TERM_LEN;
private static final int CANDIDATE_ID_LEN = 4;
public static final int BYTE_LENGTH = CANDIDATE_ID_OFF + CANDIDATE_ID_LEN;
@Override | public MessageType type() { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/FollowerState.java | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/TimeoutNow.java
// public interface TimeoutNow extends Message {
//
// int term();
//
// TimeoutNow term(int term);
//
// int candidateId();
//
// TimeoutNow candidateId(int candidateId);
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimeoutNow(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
// public enum TimerEvent implements Event {
// TIMEOUT;
//
// @Override
// public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimerEvent(serverContext, this);
// }
// }
| import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.TimeoutNow;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.timer.TimerEvent; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public class FollowerState extends AbstractState {
public FollowerState(final PersistentState persistentState, final VolatileState volatileState) {
super(Role.FOLLOWER, persistentState, volatileState);
}
@Override | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/TimeoutNow.java
// public interface TimeoutNow extends Message {
//
// int term();
//
// TimeoutNow term(int term);
//
// int candidateId();
//
// TimeoutNow candidateId(int candidateId);
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimeoutNow(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
// public enum TimerEvent implements Event {
// TIMEOUT;
//
// @Override
// public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimerEvent(serverContext, this);
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/FollowerState.java
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.TimeoutNow;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.timer.TimerEvent;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public class FollowerState extends AbstractState {
public FollowerState(final PersistentState persistentState, final VolatileState volatileState) {
super(Role.FOLLOWER, persistentState, volatileState);
}
@Override | protected EventHandler eventHandler() { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/FollowerState.java | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/TimeoutNow.java
// public interface TimeoutNow extends Message {
//
// int term();
//
// TimeoutNow term(int term);
//
// int candidateId();
//
// TimeoutNow candidateId(int candidateId);
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimeoutNow(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
// public enum TimerEvent implements Event {
// TIMEOUT;
//
// @Override
// public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimerEvent(serverContext, this);
// }
// }
| import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.TimeoutNow;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.timer.TimerEvent; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public class FollowerState extends AbstractState {
public FollowerState(final PersistentState persistentState, final VolatileState volatileState) {
super(Role.FOLLOWER, persistentState, volatileState);
}
@Override
protected EventHandler eventHandler() {
return new EventHandler() {
@Override | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/TimeoutNow.java
// public interface TimeoutNow extends Message {
//
// int term();
//
// TimeoutNow term(int term);
//
// int candidateId();
//
// TimeoutNow candidateId(int candidateId);
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimeoutNow(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
// public enum TimerEvent implements Event {
// TIMEOUT;
//
// @Override
// public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimerEvent(serverContext, this);
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/FollowerState.java
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.TimeoutNow;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.timer.TimerEvent;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public class FollowerState extends AbstractState {
public FollowerState(final PersistentState persistentState, final VolatileState volatileState) {
super(Role.FOLLOWER, persistentState, volatileState);
}
@Override
protected EventHandler eventHandler() {
return new EventHandler() {
@Override | public Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/FollowerState.java | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/TimeoutNow.java
// public interface TimeoutNow extends Message {
//
// int term();
//
// TimeoutNow term(int term);
//
// int candidateId();
//
// TimeoutNow candidateId(int candidateId);
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimeoutNow(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
// public enum TimerEvent implements Event {
// TIMEOUT;
//
// @Override
// public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimerEvent(serverContext, this);
// }
// }
| import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.TimeoutNow;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.timer.TimerEvent; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public class FollowerState extends AbstractState {
public FollowerState(final PersistentState persistentState, final VolatileState volatileState) {
super(Role.FOLLOWER, persistentState, volatileState);
}
@Override
protected EventHandler eventHandler() {
return new EventHandler() {
@Override | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/TimeoutNow.java
// public interface TimeoutNow extends Message {
//
// int term();
//
// TimeoutNow term(int term);
//
// int candidateId();
//
// TimeoutNow candidateId(int candidateId);
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimeoutNow(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
// public enum TimerEvent implements Event {
// TIMEOUT;
//
// @Override
// public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimerEvent(serverContext, this);
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/FollowerState.java
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.TimeoutNow;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.timer.TimerEvent;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public class FollowerState extends AbstractState {
public FollowerState(final PersistentState persistentState, final VolatileState volatileState) {
super(Role.FOLLOWER, persistentState, volatileState);
}
@Override
protected EventHandler eventHandler() {
return new EventHandler() {
@Override | public Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/FollowerState.java | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/TimeoutNow.java
// public interface TimeoutNow extends Message {
//
// int term();
//
// TimeoutNow term(int term);
//
// int candidateId();
//
// TimeoutNow candidateId(int candidateId);
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimeoutNow(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
// public enum TimerEvent implements Event {
// TIMEOUT;
//
// @Override
// public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimerEvent(serverContext, this);
// }
// }
| import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.TimeoutNow;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.timer.TimerEvent; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public class FollowerState extends AbstractState {
public FollowerState(final PersistentState persistentState, final VolatileState volatileState) {
super(Role.FOLLOWER, persistentState, volatileState);
}
@Override
protected EventHandler eventHandler() {
return new EventHandler() {
@Override
public Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) {
return FollowerState.this.onVoteRequest(serverContext, voteRequest);
}
@Override | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/TimeoutNow.java
// public interface TimeoutNow extends Message {
//
// int term();
//
// TimeoutNow term(int term);
//
// int candidateId();
//
// TimeoutNow candidateId(int candidateId);
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimeoutNow(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
// public enum TimerEvent implements Event {
// TIMEOUT;
//
// @Override
// public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimerEvent(serverContext, this);
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/FollowerState.java
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.TimeoutNow;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.timer.TimerEvent;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public class FollowerState extends AbstractState {
public FollowerState(final PersistentState persistentState, final VolatileState volatileState) {
super(Role.FOLLOWER, persistentState, volatileState);
}
@Override
protected EventHandler eventHandler() {
return new EventHandler() {
@Override
public Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) {
return FollowerState.this.onVoteRequest(serverContext, voteRequest);
}
@Override | public Transition onAppendRequest(final ServerContext serverContext, final AppendRequest appendRequest) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/FollowerState.java | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/TimeoutNow.java
// public interface TimeoutNow extends Message {
//
// int term();
//
// TimeoutNow term(int term);
//
// int candidateId();
//
// TimeoutNow candidateId(int candidateId);
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimeoutNow(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
// public enum TimerEvent implements Event {
// TIMEOUT;
//
// @Override
// public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimerEvent(serverContext, this);
// }
// }
| import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.TimeoutNow;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.timer.TimerEvent; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public class FollowerState extends AbstractState {
public FollowerState(final PersistentState persistentState, final VolatileState volatileState) {
super(Role.FOLLOWER, persistentState, volatileState);
}
@Override
protected EventHandler eventHandler() {
return new EventHandler() {
@Override
public Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) {
return FollowerState.this.onVoteRequest(serverContext, voteRequest);
}
@Override
public Transition onAppendRequest(final ServerContext serverContext, final AppendRequest appendRequest) {
return FollowerState.this.onAppendRequest(serverContext, appendRequest);
}
@Override | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/TimeoutNow.java
// public interface TimeoutNow extends Message {
//
// int term();
//
// TimeoutNow term(int term);
//
// int candidateId();
//
// TimeoutNow candidateId(int candidateId);
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimeoutNow(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
// public enum TimerEvent implements Event {
// TIMEOUT;
//
// @Override
// public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimerEvent(serverContext, this);
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/FollowerState.java
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.TimeoutNow;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.timer.TimerEvent;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public class FollowerState extends AbstractState {
public FollowerState(final PersistentState persistentState, final VolatileState volatileState) {
super(Role.FOLLOWER, persistentState, volatileState);
}
@Override
protected EventHandler eventHandler() {
return new EventHandler() {
@Override
public Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) {
return FollowerState.this.onVoteRequest(serverContext, voteRequest);
}
@Override
public Transition onAppendRequest(final ServerContext serverContext, final AppendRequest appendRequest) {
return FollowerState.this.onAppendRequest(serverContext, appendRequest);
}
@Override | public Transition onTimerEvent(final ServerContext serverContext, final TimerEvent timerEvent) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/state/FollowerState.java | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/TimeoutNow.java
// public interface TimeoutNow extends Message {
//
// int term();
//
// TimeoutNow term(int term);
//
// int candidateId();
//
// TimeoutNow candidateId(int candidateId);
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimeoutNow(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
// public enum TimerEvent implements Event {
// TIMEOUT;
//
// @Override
// public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimerEvent(serverContext, this);
// }
// }
| import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.TimeoutNow;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.timer.TimerEvent; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public class FollowerState extends AbstractState {
public FollowerState(final PersistentState persistentState, final VolatileState volatileState) {
super(Role.FOLLOWER, persistentState, volatileState);
}
@Override
protected EventHandler eventHandler() {
return new EventHandler() {
@Override
public Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) {
return FollowerState.this.onVoteRequest(serverContext, voteRequest);
}
@Override
public Transition onAppendRequest(final ServerContext serverContext, final AppendRequest appendRequest) {
return FollowerState.this.onAppendRequest(serverContext, appendRequest);
}
@Override
public Transition onTimerEvent(final ServerContext serverContext, final TimerEvent timerEvent) {
return FollowerState.this.onTimerEvent(serverContext, timerEvent);
}
@Override | // Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/AppendRequest.java
// public interface AppendRequest extends Message {
//
// int term();
//
// AppendRequest term(int term);
//
// int leaderId();
//
// AppendRequest leaderId(int leaderId);
//
// LogKey prevLogKey();
//
// long leaderCommit();
//
// AppendRequest leaderCommit(long leaderCommit);
//
// Sequence<LogEntry> logEntries();
//
// default AppendRequest appendLogEntry(final LogEntry logEntry) {
// logEntries().append(logEntry);
// return this;
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onAppendRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/TimeoutNow.java
// public interface TimeoutNow extends Message {
//
// int term();
//
// TimeoutNow term(int term);
//
// int candidateId();
//
// TimeoutNow candidateId(int candidateId);
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimeoutNow(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/VoteRequest.java
// public interface VoteRequest extends Message {
//
// int term();
//
// VoteRequest term(int term);
//
// int candidateId();
//
// VoteRequest candidateId(int candidateId);
//
// LogKey lastLogKey();
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onVoteRequest(serverContext, this);
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/timer/TimerEvent.java
// public enum TimerEvent implements Event {
// TIMEOUT;
//
// @Override
// public final Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTimerEvent(serverContext, this);
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/state/FollowerState.java
import org.tools4j.hoverraft.event.EventHandler;
import org.tools4j.hoverraft.message.AppendRequest;
import org.tools4j.hoverraft.message.TimeoutNow;
import org.tools4j.hoverraft.message.VoteRequest;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.timer.TimerEvent;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.state;
public class FollowerState extends AbstractState {
public FollowerState(final PersistentState persistentState, final VolatileState volatileState) {
super(Role.FOLLOWER, persistentState, volatileState);
}
@Override
protected EventHandler eventHandler() {
return new EventHandler() {
@Override
public Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) {
return FollowerState.this.onVoteRequest(serverContext, voteRequest);
}
@Override
public Transition onAppendRequest(final ServerContext serverContext, final AppendRequest appendRequest) {
return FollowerState.this.onAppendRequest(serverContext, appendRequest);
}
@Override
public Transition onTimerEvent(final ServerContext serverContext, final TimerEvent timerEvent) {
return FollowerState.this.onTimerEvent(serverContext, timerEvent);
}
@Override | public Transition onTimeoutNow(final ServerContext serverContext, final TimeoutNow timeoutNow) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/event/HigherTermHandler.java | // Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/PersistentState.java
// public interface PersistentState {
//
// int NOT_VOTED_YET = -1;
//
// int currentTerm();
//
// int votedFor();
//
// int clearVotedForAndSetCurrentTerm(int term);
//
// int clearVotedForAndIncCurrentTerm();
//
// void votedFor(final int candidateId);
//
// CommandLog commandLog();
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.message.*;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.PersistentState;
import org.tools4j.hoverraft.state.Transition;
import java.util.Objects; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.event;
public final class HigherTermHandler implements EventHandler {
private final PersistentState persistentState;
public HigherTermHandler(final PersistentState persistentState) {
this.persistentState = Objects.requireNonNull(persistentState);
}
@Override | // Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/PersistentState.java
// public interface PersistentState {
//
// int NOT_VOTED_YET = -1;
//
// int currentTerm();
//
// int votedFor();
//
// int clearVotedForAndSetCurrentTerm(int term);
//
// int clearVotedForAndIncCurrentTerm();
//
// void votedFor(final int candidateId);
//
// CommandLog commandLog();
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/event/HigherTermHandler.java
import org.tools4j.hoverraft.message.*;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.PersistentState;
import org.tools4j.hoverraft.state.Transition;
import java.util.Objects;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.event;
public final class HigherTermHandler implements EventHandler {
private final PersistentState persistentState;
public HigherTermHandler(final PersistentState persistentState) {
this.persistentState = Objects.requireNonNull(persistentState);
}
@Override | public Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/event/HigherTermHandler.java | // Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/PersistentState.java
// public interface PersistentState {
//
// int NOT_VOTED_YET = -1;
//
// int currentTerm();
//
// int votedFor();
//
// int clearVotedForAndSetCurrentTerm(int term);
//
// int clearVotedForAndIncCurrentTerm();
//
// void votedFor(final int candidateId);
//
// CommandLog commandLog();
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
| import org.tools4j.hoverraft.message.*;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.PersistentState;
import org.tools4j.hoverraft.state.Transition;
import java.util.Objects; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.event;
public final class HigherTermHandler implements EventHandler {
private final PersistentState persistentState;
public HigherTermHandler(final PersistentState persistentState) {
this.persistentState = Objects.requireNonNull(persistentState);
}
@Override | // Path: src/main/java/org/tools4j/hoverraft/server/ServerContext.java
// public interface ServerContext {
//
// ServerConfig serverConfig();
//
// ConsensusConfig consensusConfig();
//
// Connections<Message> connections();
//
// DirectFactory directFactory();
//
// StateMachine stateMachine();
//
// Timer timer();
//
// ResendStrategy resendStrategy();
//
// void perform();
//
// default int id() {
// return serverConfig().id();
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/PersistentState.java
// public interface PersistentState {
//
// int NOT_VOTED_YET = -1;
//
// int currentTerm();
//
// int votedFor();
//
// int clearVotedForAndSetCurrentTerm(int term);
//
// int clearVotedForAndIncCurrentTerm();
//
// void votedFor(final int candidateId);
//
// CommandLog commandLog();
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/Transition.java
// public enum Transition implements Event {
// STEADY(null, false),
// TO_FOLLOWER(Role.FOLLOWER, true),
// TO_CANDIDATE(Role.CANDIDATE, false),
// TO_LEADER(Role.LEADER, false);
//
// private final Role targetRole;
// private final boolean replayEvent;
//
// Transition(final Role targetRole, final boolean replayEvent) {
// this.targetRole = targetRole;//nullable
// this.replayEvent = replayEvent;
// }
//
// public final Role targetRole(final Role currentRole) {
// return this == STEADY ? currentRole : targetRole;
// }
//
// public final boolean replayEvent() {
// return replayEvent;
// }
//
// @Override
// public Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onTransition(serverContext, this);
// }
//
// public static Transition startWith(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// return event.accept(serverContext, eventHandler);
// }
// public final Transition ifSteadyThen(final ServerContext serverContext, final Event event, final EventHandler eventHandler) {
// if (this == STEADY) {
// return event.accept(serverContext, eventHandler);
// }
// return this;
// }
// }
// Path: src/main/java/org/tools4j/hoverraft/event/HigherTermHandler.java
import org.tools4j.hoverraft.message.*;
import org.tools4j.hoverraft.server.ServerContext;
import org.tools4j.hoverraft.state.PersistentState;
import org.tools4j.hoverraft.state.Transition;
import java.util.Objects;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.event;
public final class HigherTermHandler implements EventHandler {
private final PersistentState persistentState;
public HigherTermHandler(final PersistentState persistentState) {
this.persistentState = Objects.requireNonNull(persistentState);
}
@Override | public Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/transport/aeron/AeronReceiver.java | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/direct/DirectFactory.java
// public interface DirectFactory {
//
// AppendRequest appendRequest();
//
// AppendResponse appendResponse();
//
// VoteRequest voteRequest();
//
// VoteResponse voteResponse();
//
// TimeoutNow timeoutNow();
//
// CommandKey commandKey();
//
// Command command();
//
// LogEntry logEntry();
// }
//
// Path: src/main/java/org/tools4j/hoverraft/direct/DirectPayload.java
// public interface DirectPayload {
//
// int byteLength();
//
// int offset();
//
// DirectBuffer readBufferOrNull();
//
// MutableDirectBuffer writeBufferOrNull();
//
// void wrap(DirectBuffer buffer, int offset);
//
// void wrap(MutableDirectBuffer buffer, int offset);
//
// void unwrap();
//
// default boolean isWrapped() {
// return readBufferOrNull() != null || writeBufferOrNull() != null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/Message.java
// public interface Message extends DirectPayload, Event {
//
// MessageType type();
//
// default void sendTo(final Sender<? super Message> sender, final ResendStrategy resendStrategy) {
// final long res = sender.offer(this);
// if (res < 0) {
// resendStrategy.onRejectedOffer(sender, this, res);
// }
// }
//
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/MessageType.java
// public enum MessageType {
// VOTE_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteRequest();
// }
// },
// VOTE_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteResponse();
// }
// },
// APPEND_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendRequest();
// }
// },
// APPEND_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendResponse();
// }
// },
// TIMEOUT_NOW {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.timeoutNow();
// }
// };
//
// private static final MessageType[] VALUES = values();
//
// public static final MessageType valueByOrdinal(final int ordinal) {
// return VALUES[ordinal];
// }
//
// public static final int maxOrdinal() {
// return VALUES.length - 1;
// }
//
// abstract public Message create(DirectFactory factory);
//
// public static MessageType readFrom(final DirectBuffer directBuffer, final int offset) {
// final int type = directBuffer.getInt(offset);
// if (type >= 0 & type <= MessageType.maxOrdinal()) {
// return MessageType.valueByOrdinal(type);
// }
// throw new IllegalArgumentException("Illegal message type: " + type);
// }
//
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/transport/Receiver.java
// public interface Receiver<M extends DirectPayload> {
// /**
// * Polls messages in non-blocking mode. Messages are passed to the specified
// * message event.
// *
// * @param messageMandler the event invoked for each message
// * @param limit maximum number of messages to receive
// * @return number of messages received, zero to at most {@code limit} messages
// */
// int poll(Consumer<? super M> messageMandler, int limit);
// }
| import org.tools4j.hoverraft.message.Message;
import org.tools4j.hoverraft.message.MessageType;
import org.tools4j.hoverraft.transport.Receiver;
import java.util.Objects;
import java.util.function.Consumer;
import io.aeron.Subscription;
import io.aeron.logbuffer.FragmentHandler;
import io.aeron.logbuffer.Header;
import org.agrona.DirectBuffer;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.direct.DirectFactory;
import org.tools4j.hoverraft.direct.DirectPayload; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.transport.aeron;
public class AeronReceiver<M extends DirectPayload> implements Receiver<M> {
private final Subscription subscription;
private final AeronHandler<M> aeronHandler;
private AeronReceiver(final Subscription subscription,
final AeronHandler<M> aeronHandler) {
this.subscription = Objects.requireNonNull(subscription);
this.aeronHandler= Objects.requireNonNull(aeronHandler);
}
| // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/direct/DirectFactory.java
// public interface DirectFactory {
//
// AppendRequest appendRequest();
//
// AppendResponse appendResponse();
//
// VoteRequest voteRequest();
//
// VoteResponse voteResponse();
//
// TimeoutNow timeoutNow();
//
// CommandKey commandKey();
//
// Command command();
//
// LogEntry logEntry();
// }
//
// Path: src/main/java/org/tools4j/hoverraft/direct/DirectPayload.java
// public interface DirectPayload {
//
// int byteLength();
//
// int offset();
//
// DirectBuffer readBufferOrNull();
//
// MutableDirectBuffer writeBufferOrNull();
//
// void wrap(DirectBuffer buffer, int offset);
//
// void wrap(MutableDirectBuffer buffer, int offset);
//
// void unwrap();
//
// default boolean isWrapped() {
// return readBufferOrNull() != null || writeBufferOrNull() != null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/Message.java
// public interface Message extends DirectPayload, Event {
//
// MessageType type();
//
// default void sendTo(final Sender<? super Message> sender, final ResendStrategy resendStrategy) {
// final long res = sender.offer(this);
// if (res < 0) {
// resendStrategy.onRejectedOffer(sender, this, res);
// }
// }
//
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/MessageType.java
// public enum MessageType {
// VOTE_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteRequest();
// }
// },
// VOTE_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteResponse();
// }
// },
// APPEND_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendRequest();
// }
// },
// APPEND_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendResponse();
// }
// },
// TIMEOUT_NOW {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.timeoutNow();
// }
// };
//
// private static final MessageType[] VALUES = values();
//
// public static final MessageType valueByOrdinal(final int ordinal) {
// return VALUES[ordinal];
// }
//
// public static final int maxOrdinal() {
// return VALUES.length - 1;
// }
//
// abstract public Message create(DirectFactory factory);
//
// public static MessageType readFrom(final DirectBuffer directBuffer, final int offset) {
// final int type = directBuffer.getInt(offset);
// if (type >= 0 & type <= MessageType.maxOrdinal()) {
// return MessageType.valueByOrdinal(type);
// }
// throw new IllegalArgumentException("Illegal message type: " + type);
// }
//
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/transport/Receiver.java
// public interface Receiver<M extends DirectPayload> {
// /**
// * Polls messages in non-blocking mode. Messages are passed to the specified
// * message event.
// *
// * @param messageMandler the event invoked for each message
// * @param limit maximum number of messages to receive
// * @return number of messages received, zero to at most {@code limit} messages
// */
// int poll(Consumer<? super M> messageMandler, int limit);
// }
// Path: src/main/java/org/tools4j/hoverraft/transport/aeron/AeronReceiver.java
import org.tools4j.hoverraft.message.Message;
import org.tools4j.hoverraft.message.MessageType;
import org.tools4j.hoverraft.transport.Receiver;
import java.util.Objects;
import java.util.function.Consumer;
import io.aeron.Subscription;
import io.aeron.logbuffer.FragmentHandler;
import io.aeron.logbuffer.Header;
import org.agrona.DirectBuffer;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.direct.DirectFactory;
import org.tools4j.hoverraft.direct.DirectPayload;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.transport.aeron;
public class AeronReceiver<M extends DirectPayload> implements Receiver<M> {
private final Subscription subscription;
private final AeronHandler<M> aeronHandler;
private AeronReceiver(final Subscription subscription,
final AeronHandler<M> aeronHandler) {
this.subscription = Objects.requireNonNull(subscription);
this.aeronHandler= Objects.requireNonNull(aeronHandler);
}
| public static AeronReceiver<Command> commandReceiver(final DirectFactory directFactory, |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/transport/aeron/AeronReceiver.java | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/direct/DirectFactory.java
// public interface DirectFactory {
//
// AppendRequest appendRequest();
//
// AppendResponse appendResponse();
//
// VoteRequest voteRequest();
//
// VoteResponse voteResponse();
//
// TimeoutNow timeoutNow();
//
// CommandKey commandKey();
//
// Command command();
//
// LogEntry logEntry();
// }
//
// Path: src/main/java/org/tools4j/hoverraft/direct/DirectPayload.java
// public interface DirectPayload {
//
// int byteLength();
//
// int offset();
//
// DirectBuffer readBufferOrNull();
//
// MutableDirectBuffer writeBufferOrNull();
//
// void wrap(DirectBuffer buffer, int offset);
//
// void wrap(MutableDirectBuffer buffer, int offset);
//
// void unwrap();
//
// default boolean isWrapped() {
// return readBufferOrNull() != null || writeBufferOrNull() != null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/Message.java
// public interface Message extends DirectPayload, Event {
//
// MessageType type();
//
// default void sendTo(final Sender<? super Message> sender, final ResendStrategy resendStrategy) {
// final long res = sender.offer(this);
// if (res < 0) {
// resendStrategy.onRejectedOffer(sender, this, res);
// }
// }
//
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/MessageType.java
// public enum MessageType {
// VOTE_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteRequest();
// }
// },
// VOTE_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteResponse();
// }
// },
// APPEND_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendRequest();
// }
// },
// APPEND_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendResponse();
// }
// },
// TIMEOUT_NOW {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.timeoutNow();
// }
// };
//
// private static final MessageType[] VALUES = values();
//
// public static final MessageType valueByOrdinal(final int ordinal) {
// return VALUES[ordinal];
// }
//
// public static final int maxOrdinal() {
// return VALUES.length - 1;
// }
//
// abstract public Message create(DirectFactory factory);
//
// public static MessageType readFrom(final DirectBuffer directBuffer, final int offset) {
// final int type = directBuffer.getInt(offset);
// if (type >= 0 & type <= MessageType.maxOrdinal()) {
// return MessageType.valueByOrdinal(type);
// }
// throw new IllegalArgumentException("Illegal message type: " + type);
// }
//
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/transport/Receiver.java
// public interface Receiver<M extends DirectPayload> {
// /**
// * Polls messages in non-blocking mode. Messages are passed to the specified
// * message event.
// *
// * @param messageMandler the event invoked for each message
// * @param limit maximum number of messages to receive
// * @return number of messages received, zero to at most {@code limit} messages
// */
// int poll(Consumer<? super M> messageMandler, int limit);
// }
| import org.tools4j.hoverraft.message.Message;
import org.tools4j.hoverraft.message.MessageType;
import org.tools4j.hoverraft.transport.Receiver;
import java.util.Objects;
import java.util.function.Consumer;
import io.aeron.Subscription;
import io.aeron.logbuffer.FragmentHandler;
import io.aeron.logbuffer.Header;
import org.agrona.DirectBuffer;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.direct.DirectFactory;
import org.tools4j.hoverraft.direct.DirectPayload; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.transport.aeron;
public class AeronReceiver<M extends DirectPayload> implements Receiver<M> {
private final Subscription subscription;
private final AeronHandler<M> aeronHandler;
private AeronReceiver(final Subscription subscription,
final AeronHandler<M> aeronHandler) {
this.subscription = Objects.requireNonNull(subscription);
this.aeronHandler= Objects.requireNonNull(aeronHandler);
}
| // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/direct/DirectFactory.java
// public interface DirectFactory {
//
// AppendRequest appendRequest();
//
// AppendResponse appendResponse();
//
// VoteRequest voteRequest();
//
// VoteResponse voteResponse();
//
// TimeoutNow timeoutNow();
//
// CommandKey commandKey();
//
// Command command();
//
// LogEntry logEntry();
// }
//
// Path: src/main/java/org/tools4j/hoverraft/direct/DirectPayload.java
// public interface DirectPayload {
//
// int byteLength();
//
// int offset();
//
// DirectBuffer readBufferOrNull();
//
// MutableDirectBuffer writeBufferOrNull();
//
// void wrap(DirectBuffer buffer, int offset);
//
// void wrap(MutableDirectBuffer buffer, int offset);
//
// void unwrap();
//
// default boolean isWrapped() {
// return readBufferOrNull() != null || writeBufferOrNull() != null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/Message.java
// public interface Message extends DirectPayload, Event {
//
// MessageType type();
//
// default void sendTo(final Sender<? super Message> sender, final ResendStrategy resendStrategy) {
// final long res = sender.offer(this);
// if (res < 0) {
// resendStrategy.onRejectedOffer(sender, this, res);
// }
// }
//
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/message/MessageType.java
// public enum MessageType {
// VOTE_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteRequest();
// }
// },
// VOTE_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.voteResponse();
// }
// },
// APPEND_REQUEST {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendRequest();
// }
// },
// APPEND_RESPONSE {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.appendResponse();
// }
// },
// TIMEOUT_NOW {
// @Override
// public Message create(final DirectFactory factory) {
// return factory.timeoutNow();
// }
// };
//
// private static final MessageType[] VALUES = values();
//
// public static final MessageType valueByOrdinal(final int ordinal) {
// return VALUES[ordinal];
// }
//
// public static final int maxOrdinal() {
// return VALUES.length - 1;
// }
//
// abstract public Message create(DirectFactory factory);
//
// public static MessageType readFrom(final DirectBuffer directBuffer, final int offset) {
// final int type = directBuffer.getInt(offset);
// if (type >= 0 & type <= MessageType.maxOrdinal()) {
// return MessageType.valueByOrdinal(type);
// }
// throw new IllegalArgumentException("Illegal message type: " + type);
// }
//
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/transport/Receiver.java
// public interface Receiver<M extends DirectPayload> {
// /**
// * Polls messages in non-blocking mode. Messages are passed to the specified
// * message event.
// *
// * @param messageMandler the event invoked for each message
// * @param limit maximum number of messages to receive
// * @return number of messages received, zero to at most {@code limit} messages
// */
// int poll(Consumer<? super M> messageMandler, int limit);
// }
// Path: src/main/java/org/tools4j/hoverraft/transport/aeron/AeronReceiver.java
import org.tools4j.hoverraft.message.Message;
import org.tools4j.hoverraft.message.MessageType;
import org.tools4j.hoverraft.transport.Receiver;
import java.util.Objects;
import java.util.function.Consumer;
import io.aeron.Subscription;
import io.aeron.logbuffer.FragmentHandler;
import io.aeron.logbuffer.Header;
import org.agrona.DirectBuffer;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.direct.DirectFactory;
import org.tools4j.hoverraft.direct.DirectPayload;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.transport.aeron;
public class AeronReceiver<M extends DirectPayload> implements Receiver<M> {
private final Subscription subscription;
private final AeronHandler<M> aeronHandler;
private AeronReceiver(final Subscription subscription,
final AeronHandler<M> aeronHandler) {
this.subscription = Objects.requireNonNull(subscription);
this.aeronHandler= Objects.requireNonNull(aeronHandler);
}
| public static AeronReceiver<Command> commandReceiver(final DirectFactory directFactory, |
terzerm/hover-raft | src/test/java/org/tools4j/hoverraft/server/HigherTermHandlerTest.java | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/HigherTermHandler.java
// public final class HigherTermHandler implements EventHandler {
//
// private final PersistentState persistentState;
//
// public HigherTermHandler(final PersistentState persistentState) {
// this.persistentState = Objects.requireNonNull(persistentState);
// }
//
// @Override
// public Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) {
// return onTerm(voteRequest.term());
// }
//
// @Override
// public Transition onVoteResponse(final ServerContext serverContext, final VoteResponse voteResponse) {
// return onTerm(voteResponse.term());
// }
//
// @Override
// public Transition onAppendRequest(final ServerContext serverContext, final AppendRequest appendRequest) {
// return onTerm(appendRequest.term());
// }
//
// @Override
// public Transition onAppendResponse(final ServerContext serverContext, final AppendResponse appendResponse) {
// return onTerm(appendResponse.term());
// }
//
// @Override
// public Transition onTimeoutNow(final ServerContext serverContext, final TimeoutNow timeoutRequest) {
// return onTerm(timeoutRequest.term());
// }
//
// private Transition onTerm(final int term) {
// if (term > persistentState.currentTerm()) {
// persistentState.clearVotedForAndSetCurrentTerm(term);
// return Transition.TO_FOLLOWER;
// }
// return Transition.STEADY;
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/PersistentState.java
// public interface PersistentState {
//
// int NOT_VOTED_YET = -1;
//
// int currentTerm();
//
// int votedFor();
//
// int clearVotedForAndSetCurrentTerm(int term);
//
// int clearVotedForAndIncCurrentTerm();
//
// void votedFor(final int candidateId);
//
// CommandLog commandLog();
// }
| import org.tools4j.hoverraft.event.HigherTermHandler;
import org.tools4j.hoverraft.message.*;
import org.tools4j.hoverraft.state.PersistentState;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.event.EventHandler; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.server;
@RunWith(MockitoJUnitRunner.class)
public class HigherTermHandlerTest {
//under test | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/HigherTermHandler.java
// public final class HigherTermHandler implements EventHandler {
//
// private final PersistentState persistentState;
//
// public HigherTermHandler(final PersistentState persistentState) {
// this.persistentState = Objects.requireNonNull(persistentState);
// }
//
// @Override
// public Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) {
// return onTerm(voteRequest.term());
// }
//
// @Override
// public Transition onVoteResponse(final ServerContext serverContext, final VoteResponse voteResponse) {
// return onTerm(voteResponse.term());
// }
//
// @Override
// public Transition onAppendRequest(final ServerContext serverContext, final AppendRequest appendRequest) {
// return onTerm(appendRequest.term());
// }
//
// @Override
// public Transition onAppendResponse(final ServerContext serverContext, final AppendResponse appendResponse) {
// return onTerm(appendResponse.term());
// }
//
// @Override
// public Transition onTimeoutNow(final ServerContext serverContext, final TimeoutNow timeoutRequest) {
// return onTerm(timeoutRequest.term());
// }
//
// private Transition onTerm(final int term) {
// if (term > persistentState.currentTerm()) {
// persistentState.clearVotedForAndSetCurrentTerm(term);
// return Transition.TO_FOLLOWER;
// }
// return Transition.STEADY;
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/PersistentState.java
// public interface PersistentState {
//
// int NOT_VOTED_YET = -1;
//
// int currentTerm();
//
// int votedFor();
//
// int clearVotedForAndSetCurrentTerm(int term);
//
// int clearVotedForAndIncCurrentTerm();
//
// void votedFor(final int candidateId);
//
// CommandLog commandLog();
// }
// Path: src/test/java/org/tools4j/hoverraft/server/HigherTermHandlerTest.java
import org.tools4j.hoverraft.event.HigherTermHandler;
import org.tools4j.hoverraft.message.*;
import org.tools4j.hoverraft.state.PersistentState;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.event.EventHandler;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.server;
@RunWith(MockitoJUnitRunner.class)
public class HigherTermHandlerTest {
//under test | private EventHandler handler; |
terzerm/hover-raft | src/test/java/org/tools4j/hoverraft/server/HigherTermHandlerTest.java | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/HigherTermHandler.java
// public final class HigherTermHandler implements EventHandler {
//
// private final PersistentState persistentState;
//
// public HigherTermHandler(final PersistentState persistentState) {
// this.persistentState = Objects.requireNonNull(persistentState);
// }
//
// @Override
// public Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) {
// return onTerm(voteRequest.term());
// }
//
// @Override
// public Transition onVoteResponse(final ServerContext serverContext, final VoteResponse voteResponse) {
// return onTerm(voteResponse.term());
// }
//
// @Override
// public Transition onAppendRequest(final ServerContext serverContext, final AppendRequest appendRequest) {
// return onTerm(appendRequest.term());
// }
//
// @Override
// public Transition onAppendResponse(final ServerContext serverContext, final AppendResponse appendResponse) {
// return onTerm(appendResponse.term());
// }
//
// @Override
// public Transition onTimeoutNow(final ServerContext serverContext, final TimeoutNow timeoutRequest) {
// return onTerm(timeoutRequest.term());
// }
//
// private Transition onTerm(final int term) {
// if (term > persistentState.currentTerm()) {
// persistentState.clearVotedForAndSetCurrentTerm(term);
// return Transition.TO_FOLLOWER;
// }
// return Transition.STEADY;
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/PersistentState.java
// public interface PersistentState {
//
// int NOT_VOTED_YET = -1;
//
// int currentTerm();
//
// int votedFor();
//
// int clearVotedForAndSetCurrentTerm(int term);
//
// int clearVotedForAndIncCurrentTerm();
//
// void votedFor(final int candidateId);
//
// CommandLog commandLog();
// }
| import org.tools4j.hoverraft.event.HigherTermHandler;
import org.tools4j.hoverraft.message.*;
import org.tools4j.hoverraft.state.PersistentState;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.event.EventHandler; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.server;
@RunWith(MockitoJUnitRunner.class)
public class HigherTermHandlerTest {
//under test
private EventHandler handler;
private ServerContext serverContext; | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/HigherTermHandler.java
// public final class HigherTermHandler implements EventHandler {
//
// private final PersistentState persistentState;
//
// public HigherTermHandler(final PersistentState persistentState) {
// this.persistentState = Objects.requireNonNull(persistentState);
// }
//
// @Override
// public Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) {
// return onTerm(voteRequest.term());
// }
//
// @Override
// public Transition onVoteResponse(final ServerContext serverContext, final VoteResponse voteResponse) {
// return onTerm(voteResponse.term());
// }
//
// @Override
// public Transition onAppendRequest(final ServerContext serverContext, final AppendRequest appendRequest) {
// return onTerm(appendRequest.term());
// }
//
// @Override
// public Transition onAppendResponse(final ServerContext serverContext, final AppendResponse appendResponse) {
// return onTerm(appendResponse.term());
// }
//
// @Override
// public Transition onTimeoutNow(final ServerContext serverContext, final TimeoutNow timeoutRequest) {
// return onTerm(timeoutRequest.term());
// }
//
// private Transition onTerm(final int term) {
// if (term > persistentState.currentTerm()) {
// persistentState.clearVotedForAndSetCurrentTerm(term);
// return Transition.TO_FOLLOWER;
// }
// return Transition.STEADY;
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/PersistentState.java
// public interface PersistentState {
//
// int NOT_VOTED_YET = -1;
//
// int currentTerm();
//
// int votedFor();
//
// int clearVotedForAndSetCurrentTerm(int term);
//
// int clearVotedForAndIncCurrentTerm();
//
// void votedFor(final int candidateId);
//
// CommandLog commandLog();
// }
// Path: src/test/java/org/tools4j/hoverraft/server/HigherTermHandlerTest.java
import org.tools4j.hoverraft.event.HigherTermHandler;
import org.tools4j.hoverraft.message.*;
import org.tools4j.hoverraft.state.PersistentState;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.event.EventHandler;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.server;
@RunWith(MockitoJUnitRunner.class)
public class HigherTermHandlerTest {
//under test
private EventHandler handler;
private ServerContext serverContext; | private PersistentState persistentState; |
terzerm/hover-raft | src/test/java/org/tools4j/hoverraft/server/HigherTermHandlerTest.java | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/HigherTermHandler.java
// public final class HigherTermHandler implements EventHandler {
//
// private final PersistentState persistentState;
//
// public HigherTermHandler(final PersistentState persistentState) {
// this.persistentState = Objects.requireNonNull(persistentState);
// }
//
// @Override
// public Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) {
// return onTerm(voteRequest.term());
// }
//
// @Override
// public Transition onVoteResponse(final ServerContext serverContext, final VoteResponse voteResponse) {
// return onTerm(voteResponse.term());
// }
//
// @Override
// public Transition onAppendRequest(final ServerContext serverContext, final AppendRequest appendRequest) {
// return onTerm(appendRequest.term());
// }
//
// @Override
// public Transition onAppendResponse(final ServerContext serverContext, final AppendResponse appendResponse) {
// return onTerm(appendResponse.term());
// }
//
// @Override
// public Transition onTimeoutNow(final ServerContext serverContext, final TimeoutNow timeoutRequest) {
// return onTerm(timeoutRequest.term());
// }
//
// private Transition onTerm(final int term) {
// if (term > persistentState.currentTerm()) {
// persistentState.clearVotedForAndSetCurrentTerm(term);
// return Transition.TO_FOLLOWER;
// }
// return Transition.STEADY;
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/PersistentState.java
// public interface PersistentState {
//
// int NOT_VOTED_YET = -1;
//
// int currentTerm();
//
// int votedFor();
//
// int clearVotedForAndSetCurrentTerm(int term);
//
// int clearVotedForAndIncCurrentTerm();
//
// void votedFor(final int candidateId);
//
// CommandLog commandLog();
// }
| import org.tools4j.hoverraft.event.HigherTermHandler;
import org.tools4j.hoverraft.message.*;
import org.tools4j.hoverraft.state.PersistentState;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.event.EventHandler; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.server;
@RunWith(MockitoJUnitRunner.class)
public class HigherTermHandlerTest {
//under test
private EventHandler handler;
private ServerContext serverContext;
private PersistentState persistentState;
@Mock
private VoteRequest voteRequest;
@Mock
private VoteResponse voteResponse;
@Mock
private AppendRequest appendRequest;
@Mock
private AppendResponse appendResponse;
@Mock
private TimeoutNow timeoutNow;
@Mock | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/HigherTermHandler.java
// public final class HigherTermHandler implements EventHandler {
//
// private final PersistentState persistentState;
//
// public HigherTermHandler(final PersistentState persistentState) {
// this.persistentState = Objects.requireNonNull(persistentState);
// }
//
// @Override
// public Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) {
// return onTerm(voteRequest.term());
// }
//
// @Override
// public Transition onVoteResponse(final ServerContext serverContext, final VoteResponse voteResponse) {
// return onTerm(voteResponse.term());
// }
//
// @Override
// public Transition onAppendRequest(final ServerContext serverContext, final AppendRequest appendRequest) {
// return onTerm(appendRequest.term());
// }
//
// @Override
// public Transition onAppendResponse(final ServerContext serverContext, final AppendResponse appendResponse) {
// return onTerm(appendResponse.term());
// }
//
// @Override
// public Transition onTimeoutNow(final ServerContext serverContext, final TimeoutNow timeoutRequest) {
// return onTerm(timeoutRequest.term());
// }
//
// private Transition onTerm(final int term) {
// if (term > persistentState.currentTerm()) {
// persistentState.clearVotedForAndSetCurrentTerm(term);
// return Transition.TO_FOLLOWER;
// }
// return Transition.STEADY;
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/PersistentState.java
// public interface PersistentState {
//
// int NOT_VOTED_YET = -1;
//
// int currentTerm();
//
// int votedFor();
//
// int clearVotedForAndSetCurrentTerm(int term);
//
// int clearVotedForAndIncCurrentTerm();
//
// void votedFor(final int candidateId);
//
// CommandLog commandLog();
// }
// Path: src/test/java/org/tools4j/hoverraft/server/HigherTermHandlerTest.java
import org.tools4j.hoverraft.event.HigherTermHandler;
import org.tools4j.hoverraft.message.*;
import org.tools4j.hoverraft.state.PersistentState;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.event.EventHandler;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.server;
@RunWith(MockitoJUnitRunner.class)
public class HigherTermHandlerTest {
//under test
private EventHandler handler;
private ServerContext serverContext;
private PersistentState persistentState;
@Mock
private VoteRequest voteRequest;
@Mock
private VoteResponse voteResponse;
@Mock
private AppendRequest appendRequest;
@Mock
private AppendResponse appendResponse;
@Mock
private TimeoutNow timeoutNow;
@Mock | private Command command; |
terzerm/hover-raft | src/test/java/org/tools4j/hoverraft/server/HigherTermHandlerTest.java | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/HigherTermHandler.java
// public final class HigherTermHandler implements EventHandler {
//
// private final PersistentState persistentState;
//
// public HigherTermHandler(final PersistentState persistentState) {
// this.persistentState = Objects.requireNonNull(persistentState);
// }
//
// @Override
// public Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) {
// return onTerm(voteRequest.term());
// }
//
// @Override
// public Transition onVoteResponse(final ServerContext serverContext, final VoteResponse voteResponse) {
// return onTerm(voteResponse.term());
// }
//
// @Override
// public Transition onAppendRequest(final ServerContext serverContext, final AppendRequest appendRequest) {
// return onTerm(appendRequest.term());
// }
//
// @Override
// public Transition onAppendResponse(final ServerContext serverContext, final AppendResponse appendResponse) {
// return onTerm(appendResponse.term());
// }
//
// @Override
// public Transition onTimeoutNow(final ServerContext serverContext, final TimeoutNow timeoutRequest) {
// return onTerm(timeoutRequest.term());
// }
//
// private Transition onTerm(final int term) {
// if (term > persistentState.currentTerm()) {
// persistentState.clearVotedForAndSetCurrentTerm(term);
// return Transition.TO_FOLLOWER;
// }
// return Transition.STEADY;
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/PersistentState.java
// public interface PersistentState {
//
// int NOT_VOTED_YET = -1;
//
// int currentTerm();
//
// int votedFor();
//
// int clearVotedForAndSetCurrentTerm(int term);
//
// int clearVotedForAndIncCurrentTerm();
//
// void votedFor(final int candidateId);
//
// CommandLog commandLog();
// }
| import org.tools4j.hoverraft.event.HigherTermHandler;
import org.tools4j.hoverraft.message.*;
import org.tools4j.hoverraft.state.PersistentState;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.event.EventHandler; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.server;
@RunWith(MockitoJUnitRunner.class)
public class HigherTermHandlerTest {
//under test
private EventHandler handler;
private ServerContext serverContext;
private PersistentState persistentState;
@Mock
private VoteRequest voteRequest;
@Mock
private VoteResponse voteResponse;
@Mock
private AppendRequest appendRequest;
@Mock
private AppendResponse appendResponse;
@Mock
private TimeoutNow timeoutNow;
@Mock
private Command command;
@Before
public void init() {
serverContext = Mockery.simple(1);
persistentState = Mockery.persistentState();
//under test | // Path: src/main/java/org/tools4j/hoverraft/command/Command.java
// public interface Command extends DirectPayload, Event {
//
// CommandKey commandKey();
//
// CommandPayload commandPayload();
//
// default Command sourceId(final int sourceId) {
// commandKey().sourceId(sourceId);
// return this;
// }
//
// default Command commandIndex(final long commandIndex) {
// commandKey().commandIndex(commandIndex);
// return this;
// }
//
// default void copyFrom(final Command command) {
// writeBufferOrNull().putBytes(offset(), command.readBufferOrNull(), command.offset(), command.byteLength());
// }
//
// @Override
// default Transition accept(final ServerContext serverContext, final EventHandler eventHandler) {
// return eventHandler.onCommand(serverContext, this);
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/EventHandler.java
// public interface EventHandler {
// default Transition onTransition(ServerContext serverContext, Transition transition) {return Transition.STEADY;}
// default Transition onCommand(ServerContext serverContext, Command command) {return Transition.STEADY;}
// default Transition onVoteRequest(ServerContext serverContext, VoteRequest voteRequest) {return Transition.STEADY;}
// default Transition onVoteResponse(ServerContext serverContext, VoteResponse voteResponse) {return Transition.STEADY;}
// default Transition onAppendRequest(ServerContext serverContext, AppendRequest appendRequest) {return Transition.STEADY;}
// default Transition onAppendResponse(ServerContext serverContext, AppendResponse appendResponse) {return Transition.STEADY;}
// default Transition onTimeoutNow(ServerContext serverContext, TimeoutNow timeoutNow) {return Transition.STEADY;}
// default Transition onTimerEvent(ServerContext serverContext, TimerEvent timerEvent) {return Transition.STEADY;};
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/HigherTermHandler.java
// public final class HigherTermHandler implements EventHandler {
//
// private final PersistentState persistentState;
//
// public HigherTermHandler(final PersistentState persistentState) {
// this.persistentState = Objects.requireNonNull(persistentState);
// }
//
// @Override
// public Transition onVoteRequest(final ServerContext serverContext, final VoteRequest voteRequest) {
// return onTerm(voteRequest.term());
// }
//
// @Override
// public Transition onVoteResponse(final ServerContext serverContext, final VoteResponse voteResponse) {
// return onTerm(voteResponse.term());
// }
//
// @Override
// public Transition onAppendRequest(final ServerContext serverContext, final AppendRequest appendRequest) {
// return onTerm(appendRequest.term());
// }
//
// @Override
// public Transition onAppendResponse(final ServerContext serverContext, final AppendResponse appendResponse) {
// return onTerm(appendResponse.term());
// }
//
// @Override
// public Transition onTimeoutNow(final ServerContext serverContext, final TimeoutNow timeoutRequest) {
// return onTerm(timeoutRequest.term());
// }
//
// private Transition onTerm(final int term) {
// if (term > persistentState.currentTerm()) {
// persistentState.clearVotedForAndSetCurrentTerm(term);
// return Transition.TO_FOLLOWER;
// }
// return Transition.STEADY;
// }
//
// }
//
// Path: src/main/java/org/tools4j/hoverraft/state/PersistentState.java
// public interface PersistentState {
//
// int NOT_VOTED_YET = -1;
//
// int currentTerm();
//
// int votedFor();
//
// int clearVotedForAndSetCurrentTerm(int term);
//
// int clearVotedForAndIncCurrentTerm();
//
// void votedFor(final int candidateId);
//
// CommandLog commandLog();
// }
// Path: src/test/java/org/tools4j/hoverraft/server/HigherTermHandlerTest.java
import org.tools4j.hoverraft.event.HigherTermHandler;
import org.tools4j.hoverraft.message.*;
import org.tools4j.hoverraft.state.PersistentState;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.tools4j.hoverraft.command.Command;
import org.tools4j.hoverraft.event.EventHandler;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.server;
@RunWith(MockitoJUnitRunner.class)
public class HigherTermHandlerTest {
//under test
private EventHandler handler;
private ServerContext serverContext;
private PersistentState persistentState;
@Mock
private VoteRequest voteRequest;
@Mock
private VoteResponse voteResponse;
@Mock
private AppendRequest appendRequest;
@Mock
private AppendResponse appendResponse;
@Mock
private TimeoutNow timeoutNow;
@Mock
private Command command;
@Before
public void init() {
serverContext = Mockery.simple(1);
persistentState = Mockery.persistentState();
//under test | handler = new HigherTermHandler(persistentState); |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/Message.java | // Path: src/main/java/org/tools4j/hoverraft/direct/DirectPayload.java
// public interface DirectPayload {
//
// int byteLength();
//
// int offset();
//
// DirectBuffer readBufferOrNull();
//
// MutableDirectBuffer writeBufferOrNull();
//
// void wrap(DirectBuffer buffer, int offset);
//
// void wrap(MutableDirectBuffer buffer, int offset);
//
// void unwrap();
//
// default boolean isWrapped() {
// return readBufferOrNull() != null || writeBufferOrNull() != null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/transport/ResendStrategy.java
// public interface ResendStrategy {
// <M extends Message> void onRejectedOffer(Sender<? super M> sender, M message, long rejectReason);
//
// ResendStrategy NOOP = new ResendStrategy() {
// @Override
// public <M extends Message> void onRejectedOffer(Sender<? super M> sender, M message, long rejectReason) {
// //no op
// }
// };
// }
//
// Path: src/main/java/org/tools4j/hoverraft/transport/Sender.java
// public interface Sender<M extends DirectPayload> {
// /**
// * Terminates composing and offsers the message to the transport in
// * non-blocking mode. Can be called multiple times for same message if sending
// * failed which is indicated through a negative return value.
// *
// * @param message the message to send
// * @return Non-negative transpport state such as position, otherwise zero if
// * not applicable and successful or a negative error value
// * {@link RejectReason#NOT_CONNECTED}, {@link RejectReason#BACK_PRESSURED},
// * {@link RejectReason#ADMIN_ACTION} or {@link RejectReason#CLOSED}.
// */
// long offer(M message);
// }
| import org.tools4j.hoverraft.direct.DirectPayload;
import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.transport.ResendStrategy;
import org.tools4j.hoverraft.transport.Sender; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
/**
* Base interface for all messages.
*/
public interface Message extends DirectPayload, Event {
MessageType type();
| // Path: src/main/java/org/tools4j/hoverraft/direct/DirectPayload.java
// public interface DirectPayload {
//
// int byteLength();
//
// int offset();
//
// DirectBuffer readBufferOrNull();
//
// MutableDirectBuffer writeBufferOrNull();
//
// void wrap(DirectBuffer buffer, int offset);
//
// void wrap(MutableDirectBuffer buffer, int offset);
//
// void unwrap();
//
// default boolean isWrapped() {
// return readBufferOrNull() != null || writeBufferOrNull() != null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/transport/ResendStrategy.java
// public interface ResendStrategy {
// <M extends Message> void onRejectedOffer(Sender<? super M> sender, M message, long rejectReason);
//
// ResendStrategy NOOP = new ResendStrategy() {
// @Override
// public <M extends Message> void onRejectedOffer(Sender<? super M> sender, M message, long rejectReason) {
// //no op
// }
// };
// }
//
// Path: src/main/java/org/tools4j/hoverraft/transport/Sender.java
// public interface Sender<M extends DirectPayload> {
// /**
// * Terminates composing and offsers the message to the transport in
// * non-blocking mode. Can be called multiple times for same message if sending
// * failed which is indicated through a negative return value.
// *
// * @param message the message to send
// * @return Non-negative transpport state such as position, otherwise zero if
// * not applicable and successful or a negative error value
// * {@link RejectReason#NOT_CONNECTED}, {@link RejectReason#BACK_PRESSURED},
// * {@link RejectReason#ADMIN_ACTION} or {@link RejectReason#CLOSED}.
// */
// long offer(M message);
// }
// Path: src/main/java/org/tools4j/hoverraft/message/Message.java
import org.tools4j.hoverraft.direct.DirectPayload;
import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.transport.ResendStrategy;
import org.tools4j.hoverraft.transport.Sender;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
/**
* Base interface for all messages.
*/
public interface Message extends DirectPayload, Event {
MessageType type();
| default void sendTo(final Sender<? super Message> sender, final ResendStrategy resendStrategy) { |
terzerm/hover-raft | src/main/java/org/tools4j/hoverraft/message/Message.java | // Path: src/main/java/org/tools4j/hoverraft/direct/DirectPayload.java
// public interface DirectPayload {
//
// int byteLength();
//
// int offset();
//
// DirectBuffer readBufferOrNull();
//
// MutableDirectBuffer writeBufferOrNull();
//
// void wrap(DirectBuffer buffer, int offset);
//
// void wrap(MutableDirectBuffer buffer, int offset);
//
// void unwrap();
//
// default boolean isWrapped() {
// return readBufferOrNull() != null || writeBufferOrNull() != null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/transport/ResendStrategy.java
// public interface ResendStrategy {
// <M extends Message> void onRejectedOffer(Sender<? super M> sender, M message, long rejectReason);
//
// ResendStrategy NOOP = new ResendStrategy() {
// @Override
// public <M extends Message> void onRejectedOffer(Sender<? super M> sender, M message, long rejectReason) {
// //no op
// }
// };
// }
//
// Path: src/main/java/org/tools4j/hoverraft/transport/Sender.java
// public interface Sender<M extends DirectPayload> {
// /**
// * Terminates composing and offsers the message to the transport in
// * non-blocking mode. Can be called multiple times for same message if sending
// * failed which is indicated through a negative return value.
// *
// * @param message the message to send
// * @return Non-negative transpport state such as position, otherwise zero if
// * not applicable and successful or a negative error value
// * {@link RejectReason#NOT_CONNECTED}, {@link RejectReason#BACK_PRESSURED},
// * {@link RejectReason#ADMIN_ACTION} or {@link RejectReason#CLOSED}.
// */
// long offer(M message);
// }
| import org.tools4j.hoverraft.direct.DirectPayload;
import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.transport.ResendStrategy;
import org.tools4j.hoverraft.transport.Sender; | /**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
/**
* Base interface for all messages.
*/
public interface Message extends DirectPayload, Event {
MessageType type();
| // Path: src/main/java/org/tools4j/hoverraft/direct/DirectPayload.java
// public interface DirectPayload {
//
// int byteLength();
//
// int offset();
//
// DirectBuffer readBufferOrNull();
//
// MutableDirectBuffer writeBufferOrNull();
//
// void wrap(DirectBuffer buffer, int offset);
//
// void wrap(MutableDirectBuffer buffer, int offset);
//
// void unwrap();
//
// default boolean isWrapped() {
// return readBufferOrNull() != null || writeBufferOrNull() != null;
// }
// }
//
// Path: src/main/java/org/tools4j/hoverraft/event/Event.java
// public interface Event {
// Transition accept(ServerContext serverContext, EventHandler eventHandler);
// }
//
// Path: src/main/java/org/tools4j/hoverraft/transport/ResendStrategy.java
// public interface ResendStrategy {
// <M extends Message> void onRejectedOffer(Sender<? super M> sender, M message, long rejectReason);
//
// ResendStrategy NOOP = new ResendStrategy() {
// @Override
// public <M extends Message> void onRejectedOffer(Sender<? super M> sender, M message, long rejectReason) {
// //no op
// }
// };
// }
//
// Path: src/main/java/org/tools4j/hoverraft/transport/Sender.java
// public interface Sender<M extends DirectPayload> {
// /**
// * Terminates composing and offsers the message to the transport in
// * non-blocking mode. Can be called multiple times for same message if sending
// * failed which is indicated through a negative return value.
// *
// * @param message the message to send
// * @return Non-negative transpport state such as position, otherwise zero if
// * not applicable and successful or a negative error value
// * {@link RejectReason#NOT_CONNECTED}, {@link RejectReason#BACK_PRESSURED},
// * {@link RejectReason#ADMIN_ACTION} or {@link RejectReason#CLOSED}.
// */
// long offer(M message);
// }
// Path: src/main/java/org/tools4j/hoverraft/message/Message.java
import org.tools4j.hoverraft.direct.DirectPayload;
import org.tools4j.hoverraft.event.Event;
import org.tools4j.hoverraft.transport.ResendStrategy;
import org.tools4j.hoverraft.transport.Sender;
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 hover-raft (tools4j), Marco Terzer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.tools4j.hoverraft.message;
/**
* Base interface for all messages.
*/
public interface Message extends DirectPayload, Event {
MessageType type();
| default void sendTo(final Sender<? super Message> sender, final ResendStrategy resendStrategy) { |
wdiestel/arbaro | test/net/sourceforge/arbaro/tree/impl/treeTest.java | // Path: src/net/sourceforge/arbaro/tree/Tree.java
// public interface Tree {
//
// /**
// * used with the TreeTraversal interface
// *
// * @param traversal
// * @return when false stop travers the tree
// */
// abstract boolean traverseTree(TreeTraversal traversal);
//
// /**
// *
// * @return the number of all stems of all levels of the tree
// */
// public abstract long getStemCount();
//
// /**
// *
// * @return the number of leaves of the tree
// */
// public abstract long getLeafCount();
//
// /**
// *
// * @return a vector with the highest coordinates of the tree.
// * (Considering all stems of all levels)
// */
// public abstract Vector getMaxPoint();
//
// /**
// *
// * @return a vector with the lowest coordinates of the tree.
// * (Considering all stems of all levels)
// */
// public abstract Vector getMinPoint();
//
// /**
// *
// * @return the seed of the tree. It is used for randomnization.
// */
// public int getSeed();
//
// /**
// *
// * @return the height of the tree (highest z-coordinate)
// */
// public double getHeight();
//
// /**
// *
// * @return the widht of the tree (highest value of sqrt(x*x+y*y))
// */
// public double getWidth();
//
// /**
// * Writes the trees parameters to a stream
// * @param w
// */
// public void paramsToXML(PrintWriter w);
//
// /**
// *
// * @return the tree species name
// */
// public String getSpecies();
//
// /**
// *
// * @return the tree scale
// */
// public double getScale();
//
// /**
// *
// * @return the tree stem levels
// */
// public int getLevels();
//
// /**
// *
// * @return the leaf shape name
// */
// public String getLeafShape();
//
// /**
// *
// * @return the leaf width
// */
// public double getLeafWidth();
//
// /**
// *
// * @return the leaf length
// */
// public double getLeafLength();
//
// /**
// *
// * @return the virtual leaf stem length, i.e. the distance of
// * the leaf from the stem center line
// */
// public double getLeafStemLength();
//
// /**
// * Use this for verbose output when generating a mesh or
// * exporting a tree
// *
// * @param level
// * @return an information string with the number of section
// * points for this stem level and if smoothing should be used
// */
// public String getVertexInfo(int level);
//
// }
//
// Path: src/net/sourceforge/arbaro/tree/TreeGeneratorFactory.java
// public class TreeGeneratorFactory {
// static public TreeGenerator createTreeGenerator() {
// return new TreeGeneratorImpl();
// }
//
// static public TreeGenerator createTreeGenerator(Params params) {
// return new TreeGeneratorImpl(params);
// }
//
// static public TreeGenerator createShieldedTreeGenerator() {
// return new ShieldedTreeGenerator(new TreeGeneratorImpl());
// }
//
// static public TreeGenerator createShieldedTreeGenerator(Params params) {
// return new ShieldedTreeGenerator(new TreeGeneratorImpl(params));
// }
//
//
// }
| import junit.framework.TestCase;
import net.sourceforge.arbaro.tree.Tree;
import net.sourceforge.arbaro.tree.TreeGenerator;
import net.sourceforge.arbaro.tree.TreeGeneratorFactory;
import net.sourceforge.arbaro.params.*;
import net.sourceforge.arbaro.feedback.Progress;
import java.util.*;
import java.io.*; | String val = (String)sassafrasParams.get(key);
if (par.getType() == ParamTypes.INT_PARAM)
assertEquals(new Integer(val).intValue(),par.getIntValue());
else if (par.getType() == ParamTypes.DBL_PARAM)
assertEquals(new Double(val).doubleValue(),new Double(par.getValue()).doubleValue(),prec);
else
assertEquals(val,par.getValue());
// if (! val.equals(par.getValue()))
// throw new ParamException("Param "+key+": expected value "+
// val+" but found "+par.getValue());
}
private void checkParams(Params params) {
// compare with SassafrasParams
Enumeration keys = sassafrasParams.keys();
while (keys.hasMoreElements()) {
String key = (String)keys.nextElement();
if (key.equals("species"))
checkParam(key,params.param("Species"));
else
checkParam(key,params.param(key));
}
}
public void testTreeGenerator () {
ParamManager params = new ParamManager();
// get params from String SassafrasCfg
InputStream is = new ByteArrayInputStream(sassafrasCfg.getBytes());
params.getParamReader().readFromCfg(is);
| // Path: src/net/sourceforge/arbaro/tree/Tree.java
// public interface Tree {
//
// /**
// * used with the TreeTraversal interface
// *
// * @param traversal
// * @return when false stop travers the tree
// */
// abstract boolean traverseTree(TreeTraversal traversal);
//
// /**
// *
// * @return the number of all stems of all levels of the tree
// */
// public abstract long getStemCount();
//
// /**
// *
// * @return the number of leaves of the tree
// */
// public abstract long getLeafCount();
//
// /**
// *
// * @return a vector with the highest coordinates of the tree.
// * (Considering all stems of all levels)
// */
// public abstract Vector getMaxPoint();
//
// /**
// *
// * @return a vector with the lowest coordinates of the tree.
// * (Considering all stems of all levels)
// */
// public abstract Vector getMinPoint();
//
// /**
// *
// * @return the seed of the tree. It is used for randomnization.
// */
// public int getSeed();
//
// /**
// *
// * @return the height of the tree (highest z-coordinate)
// */
// public double getHeight();
//
// /**
// *
// * @return the widht of the tree (highest value of sqrt(x*x+y*y))
// */
// public double getWidth();
//
// /**
// * Writes the trees parameters to a stream
// * @param w
// */
// public void paramsToXML(PrintWriter w);
//
// /**
// *
// * @return the tree species name
// */
// public String getSpecies();
//
// /**
// *
// * @return the tree scale
// */
// public double getScale();
//
// /**
// *
// * @return the tree stem levels
// */
// public int getLevels();
//
// /**
// *
// * @return the leaf shape name
// */
// public String getLeafShape();
//
// /**
// *
// * @return the leaf width
// */
// public double getLeafWidth();
//
// /**
// *
// * @return the leaf length
// */
// public double getLeafLength();
//
// /**
// *
// * @return the virtual leaf stem length, i.e. the distance of
// * the leaf from the stem center line
// */
// public double getLeafStemLength();
//
// /**
// * Use this for verbose output when generating a mesh or
// * exporting a tree
// *
// * @param level
// * @return an information string with the number of section
// * points for this stem level and if smoothing should be used
// */
// public String getVertexInfo(int level);
//
// }
//
// Path: src/net/sourceforge/arbaro/tree/TreeGeneratorFactory.java
// public class TreeGeneratorFactory {
// static public TreeGenerator createTreeGenerator() {
// return new TreeGeneratorImpl();
// }
//
// static public TreeGenerator createTreeGenerator(Params params) {
// return new TreeGeneratorImpl(params);
// }
//
// static public TreeGenerator createShieldedTreeGenerator() {
// return new ShieldedTreeGenerator(new TreeGeneratorImpl());
// }
//
// static public TreeGenerator createShieldedTreeGenerator(Params params) {
// return new ShieldedTreeGenerator(new TreeGeneratorImpl(params));
// }
//
//
// }
// Path: test/net/sourceforge/arbaro/tree/impl/treeTest.java
import junit.framework.TestCase;
import net.sourceforge.arbaro.tree.Tree;
import net.sourceforge.arbaro.tree.TreeGenerator;
import net.sourceforge.arbaro.tree.TreeGeneratorFactory;
import net.sourceforge.arbaro.params.*;
import net.sourceforge.arbaro.feedback.Progress;
import java.util.*;
import java.io.*;
String val = (String)sassafrasParams.get(key);
if (par.getType() == ParamTypes.INT_PARAM)
assertEquals(new Integer(val).intValue(),par.getIntValue());
else if (par.getType() == ParamTypes.DBL_PARAM)
assertEquals(new Double(val).doubleValue(),new Double(par.getValue()).doubleValue(),prec);
else
assertEquals(val,par.getValue());
// if (! val.equals(par.getValue()))
// throw new ParamException("Param "+key+": expected value "+
// val+" but found "+par.getValue());
}
private void checkParams(Params params) {
// compare with SassafrasParams
Enumeration keys = sassafrasParams.keys();
while (keys.hasMoreElements()) {
String key = (String)keys.nextElement();
if (key.equals("species"))
checkParam(key,params.param("Species"));
else
checkParam(key,params.param(key));
}
}
public void testTreeGenerator () {
ParamManager params = new ParamManager();
// get params from String SassafrasCfg
InputStream is = new ByteArrayInputStream(sassafrasCfg.getBytes());
params.getParamReader().readFromCfg(is);
| TreeGenerator generator = TreeGeneratorFactory.createTreeGenerator(params); |
wdiestel/arbaro | test/net/sourceforge/arbaro/tree/impl/treeTest.java | // Path: src/net/sourceforge/arbaro/tree/Tree.java
// public interface Tree {
//
// /**
// * used with the TreeTraversal interface
// *
// * @param traversal
// * @return when false stop travers the tree
// */
// abstract boolean traverseTree(TreeTraversal traversal);
//
// /**
// *
// * @return the number of all stems of all levels of the tree
// */
// public abstract long getStemCount();
//
// /**
// *
// * @return the number of leaves of the tree
// */
// public abstract long getLeafCount();
//
// /**
// *
// * @return a vector with the highest coordinates of the tree.
// * (Considering all stems of all levels)
// */
// public abstract Vector getMaxPoint();
//
// /**
// *
// * @return a vector with the lowest coordinates of the tree.
// * (Considering all stems of all levels)
// */
// public abstract Vector getMinPoint();
//
// /**
// *
// * @return the seed of the tree. It is used for randomnization.
// */
// public int getSeed();
//
// /**
// *
// * @return the height of the tree (highest z-coordinate)
// */
// public double getHeight();
//
// /**
// *
// * @return the widht of the tree (highest value of sqrt(x*x+y*y))
// */
// public double getWidth();
//
// /**
// * Writes the trees parameters to a stream
// * @param w
// */
// public void paramsToXML(PrintWriter w);
//
// /**
// *
// * @return the tree species name
// */
// public String getSpecies();
//
// /**
// *
// * @return the tree scale
// */
// public double getScale();
//
// /**
// *
// * @return the tree stem levels
// */
// public int getLevels();
//
// /**
// *
// * @return the leaf shape name
// */
// public String getLeafShape();
//
// /**
// *
// * @return the leaf width
// */
// public double getLeafWidth();
//
// /**
// *
// * @return the leaf length
// */
// public double getLeafLength();
//
// /**
// *
// * @return the virtual leaf stem length, i.e. the distance of
// * the leaf from the stem center line
// */
// public double getLeafStemLength();
//
// /**
// * Use this for verbose output when generating a mesh or
// * exporting a tree
// *
// * @param level
// * @return an information string with the number of section
// * points for this stem level and if smoothing should be used
// */
// public String getVertexInfo(int level);
//
// }
//
// Path: src/net/sourceforge/arbaro/tree/TreeGeneratorFactory.java
// public class TreeGeneratorFactory {
// static public TreeGenerator createTreeGenerator() {
// return new TreeGeneratorImpl();
// }
//
// static public TreeGenerator createTreeGenerator(Params params) {
// return new TreeGeneratorImpl(params);
// }
//
// static public TreeGenerator createShieldedTreeGenerator() {
// return new ShieldedTreeGenerator(new TreeGeneratorImpl());
// }
//
// static public TreeGenerator createShieldedTreeGenerator(Params params) {
// return new ShieldedTreeGenerator(new TreeGeneratorImpl(params));
// }
//
//
// }
| import junit.framework.TestCase;
import net.sourceforge.arbaro.tree.Tree;
import net.sourceforge.arbaro.tree.TreeGenerator;
import net.sourceforge.arbaro.tree.TreeGeneratorFactory;
import net.sourceforge.arbaro.params.*;
import net.sourceforge.arbaro.feedback.Progress;
import java.util.*;
import java.io.*; |
public void testTreeGenerator () {
ParamManager params = new ParamManager();
// get params from String SassafrasCfg
InputStream is = new ByteArrayInputStream(sassafrasCfg.getBytes());
params.getParamReader().readFromCfg(is);
TreeGenerator generator = TreeGeneratorFactory.createTreeGenerator(params);
checkParams(generator.getParamManager().getTreeParams());
// write Params as XML to a StringBuffer
StringWriter xsw = new StringWriter();
PrintWriter pw = new PrintWriter(xsw);
params.getParamWriter().toXML(pw);
// clear params
params = new ParamManager();
// generator.clearParams();
assertEquals(params.getParamEditing().getSpecies(),"default");
// read params again from there
InputStream xis = new ByteArrayInputStream(xsw.toString().getBytes());
params.getParamReader().readFromXML(xis);
generator = TreeGeneratorFactory.createTreeGenerator(params);
checkParams(generator.getParamManager().getTreeParams());
// make Tree with this params | // Path: src/net/sourceforge/arbaro/tree/Tree.java
// public interface Tree {
//
// /**
// * used with the TreeTraversal interface
// *
// * @param traversal
// * @return when false stop travers the tree
// */
// abstract boolean traverseTree(TreeTraversal traversal);
//
// /**
// *
// * @return the number of all stems of all levels of the tree
// */
// public abstract long getStemCount();
//
// /**
// *
// * @return the number of leaves of the tree
// */
// public abstract long getLeafCount();
//
// /**
// *
// * @return a vector with the highest coordinates of the tree.
// * (Considering all stems of all levels)
// */
// public abstract Vector getMaxPoint();
//
// /**
// *
// * @return a vector with the lowest coordinates of the tree.
// * (Considering all stems of all levels)
// */
// public abstract Vector getMinPoint();
//
// /**
// *
// * @return the seed of the tree. It is used for randomnization.
// */
// public int getSeed();
//
// /**
// *
// * @return the height of the tree (highest z-coordinate)
// */
// public double getHeight();
//
// /**
// *
// * @return the widht of the tree (highest value of sqrt(x*x+y*y))
// */
// public double getWidth();
//
// /**
// * Writes the trees parameters to a stream
// * @param w
// */
// public void paramsToXML(PrintWriter w);
//
// /**
// *
// * @return the tree species name
// */
// public String getSpecies();
//
// /**
// *
// * @return the tree scale
// */
// public double getScale();
//
// /**
// *
// * @return the tree stem levels
// */
// public int getLevels();
//
// /**
// *
// * @return the leaf shape name
// */
// public String getLeafShape();
//
// /**
// *
// * @return the leaf width
// */
// public double getLeafWidth();
//
// /**
// *
// * @return the leaf length
// */
// public double getLeafLength();
//
// /**
// *
// * @return the virtual leaf stem length, i.e. the distance of
// * the leaf from the stem center line
// */
// public double getLeafStemLength();
//
// /**
// * Use this for verbose output when generating a mesh or
// * exporting a tree
// *
// * @param level
// * @return an information string with the number of section
// * points for this stem level and if smoothing should be used
// */
// public String getVertexInfo(int level);
//
// }
//
// Path: src/net/sourceforge/arbaro/tree/TreeGeneratorFactory.java
// public class TreeGeneratorFactory {
// static public TreeGenerator createTreeGenerator() {
// return new TreeGeneratorImpl();
// }
//
// static public TreeGenerator createTreeGenerator(Params params) {
// return new TreeGeneratorImpl(params);
// }
//
// static public TreeGenerator createShieldedTreeGenerator() {
// return new ShieldedTreeGenerator(new TreeGeneratorImpl());
// }
//
// static public TreeGenerator createShieldedTreeGenerator(Params params) {
// return new ShieldedTreeGenerator(new TreeGeneratorImpl(params));
// }
//
//
// }
// Path: test/net/sourceforge/arbaro/tree/impl/treeTest.java
import junit.framework.TestCase;
import net.sourceforge.arbaro.tree.Tree;
import net.sourceforge.arbaro.tree.TreeGenerator;
import net.sourceforge.arbaro.tree.TreeGeneratorFactory;
import net.sourceforge.arbaro.params.*;
import net.sourceforge.arbaro.feedback.Progress;
import java.util.*;
import java.io.*;
public void testTreeGenerator () {
ParamManager params = new ParamManager();
// get params from String SassafrasCfg
InputStream is = new ByteArrayInputStream(sassafrasCfg.getBytes());
params.getParamReader().readFromCfg(is);
TreeGenerator generator = TreeGeneratorFactory.createTreeGenerator(params);
checkParams(generator.getParamManager().getTreeParams());
// write Params as XML to a StringBuffer
StringWriter xsw = new StringWriter();
PrintWriter pw = new PrintWriter(xsw);
params.getParamWriter().toXML(pw);
// clear params
params = new ParamManager();
// generator.clearParams();
assertEquals(params.getParamEditing().getSpecies(),"default");
// read params again from there
InputStream xis = new ByteArrayInputStream(xsw.toString().getBytes());
params.getParamReader().readFromXML(xis);
generator = TreeGeneratorFactory.createTreeGenerator(params);
checkParams(generator.getParamManager().getTreeParams());
// make Tree with this params | Tree tree = generator.makeTree(new Progress()); |
wdiestel/arbaro | test/net/sourceforge/arbaro/tree/impl/StemTest.java | // Path: src/net/sourceforge/arbaro/tree/Tree.java
// public interface Tree {
//
// /**
// * used with the TreeTraversal interface
// *
// * @param traversal
// * @return when false stop travers the tree
// */
// abstract boolean traverseTree(TreeTraversal traversal);
//
// /**
// *
// * @return the number of all stems of all levels of the tree
// */
// public abstract long getStemCount();
//
// /**
// *
// * @return the number of leaves of the tree
// */
// public abstract long getLeafCount();
//
// /**
// *
// * @return a vector with the highest coordinates of the tree.
// * (Considering all stems of all levels)
// */
// public abstract Vector getMaxPoint();
//
// /**
// *
// * @return a vector with the lowest coordinates of the tree.
// * (Considering all stems of all levels)
// */
// public abstract Vector getMinPoint();
//
// /**
// *
// * @return the seed of the tree. It is used for randomnization.
// */
// public int getSeed();
//
// /**
// *
// * @return the height of the tree (highest z-coordinate)
// */
// public double getHeight();
//
// /**
// *
// * @return the widht of the tree (highest value of sqrt(x*x+y*y))
// */
// public double getWidth();
//
// /**
// * Writes the trees parameters to a stream
// * @param w
// */
// public void paramsToXML(PrintWriter w);
//
// /**
// *
// * @return the tree species name
// */
// public String getSpecies();
//
// /**
// *
// * @return the tree scale
// */
// public double getScale();
//
// /**
// *
// * @return the tree stem levels
// */
// public int getLevels();
//
// /**
// *
// * @return the leaf shape name
// */
// public String getLeafShape();
//
// /**
// *
// * @return the leaf width
// */
// public double getLeafWidth();
//
// /**
// *
// * @return the leaf length
// */
// public double getLeafLength();
//
// /**
// *
// * @return the virtual leaf stem length, i.e. the distance of
// * the leaf from the stem center line
// */
// public double getLeafStemLength();
//
// /**
// * Use this for verbose output when generating a mesh or
// * exporting a tree
// *
// * @param level
// * @return an information string with the number of section
// * points for this stem level and if smoothing should be used
// */
// public String getVertexInfo(int level);
//
// }
//
// Path: src/net/sourceforge/arbaro/tree/TreeGeneratorFactory.java
// public class TreeGeneratorFactory {
// static public TreeGenerator createTreeGenerator() {
// return new TreeGeneratorImpl();
// }
//
// static public TreeGenerator createTreeGenerator(Params params) {
// return new TreeGeneratorImpl(params);
// }
//
// static public TreeGenerator createShieldedTreeGenerator() {
// return new ShieldedTreeGenerator(new TreeGeneratorImpl());
// }
//
// static public TreeGenerator createShieldedTreeGenerator(Params params) {
// return new ShieldedTreeGenerator(new TreeGeneratorImpl(params));
// }
//
//
// }
| import junit.framework.TestCase;
import java.util.Enumeration;
import net.sourceforge.arbaro.transformation.Transformation;
import net.sourceforge.arbaro.tree.Stem;
import net.sourceforge.arbaro.tree.Tree;
import net.sourceforge.arbaro.tree.TreeGenerator;
import net.sourceforge.arbaro.tree.TreeGeneratorFactory;
import net.sourceforge.arbaro.tree.impl.StemImpl;
import net.sourceforge.arbaro.tree.impl.TreeImpl;
import net.sourceforge.arbaro.params.*;
| /*
* Created on 12.11.2004
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package net.sourceforge.arbaro.tree.impl;
/**
* @author wdiestel
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class StemTest extends TestCase {
static Tree aTestTree = makeTestTree();
static StemImpl aTestStem = makeTestStem();
static StemImpl makeTestStem() {
StemImpl stem=new StemImpl((TreeImpl)aTestTree,null,0,new Transformation(),0);
stem.make();
return stem;
}
static Tree makeTestTree() {
try {
ParamManager params = new ParamManager();
| // Path: src/net/sourceforge/arbaro/tree/Tree.java
// public interface Tree {
//
// /**
// * used with the TreeTraversal interface
// *
// * @param traversal
// * @return when false stop travers the tree
// */
// abstract boolean traverseTree(TreeTraversal traversal);
//
// /**
// *
// * @return the number of all stems of all levels of the tree
// */
// public abstract long getStemCount();
//
// /**
// *
// * @return the number of leaves of the tree
// */
// public abstract long getLeafCount();
//
// /**
// *
// * @return a vector with the highest coordinates of the tree.
// * (Considering all stems of all levels)
// */
// public abstract Vector getMaxPoint();
//
// /**
// *
// * @return a vector with the lowest coordinates of the tree.
// * (Considering all stems of all levels)
// */
// public abstract Vector getMinPoint();
//
// /**
// *
// * @return the seed of the tree. It is used for randomnization.
// */
// public int getSeed();
//
// /**
// *
// * @return the height of the tree (highest z-coordinate)
// */
// public double getHeight();
//
// /**
// *
// * @return the widht of the tree (highest value of sqrt(x*x+y*y))
// */
// public double getWidth();
//
// /**
// * Writes the trees parameters to a stream
// * @param w
// */
// public void paramsToXML(PrintWriter w);
//
// /**
// *
// * @return the tree species name
// */
// public String getSpecies();
//
// /**
// *
// * @return the tree scale
// */
// public double getScale();
//
// /**
// *
// * @return the tree stem levels
// */
// public int getLevels();
//
// /**
// *
// * @return the leaf shape name
// */
// public String getLeafShape();
//
// /**
// *
// * @return the leaf width
// */
// public double getLeafWidth();
//
// /**
// *
// * @return the leaf length
// */
// public double getLeafLength();
//
// /**
// *
// * @return the virtual leaf stem length, i.e. the distance of
// * the leaf from the stem center line
// */
// public double getLeafStemLength();
//
// /**
// * Use this for verbose output when generating a mesh or
// * exporting a tree
// *
// * @param level
// * @return an information string with the number of section
// * points for this stem level and if smoothing should be used
// */
// public String getVertexInfo(int level);
//
// }
//
// Path: src/net/sourceforge/arbaro/tree/TreeGeneratorFactory.java
// public class TreeGeneratorFactory {
// static public TreeGenerator createTreeGenerator() {
// return new TreeGeneratorImpl();
// }
//
// static public TreeGenerator createTreeGenerator(Params params) {
// return new TreeGeneratorImpl(params);
// }
//
// static public TreeGenerator createShieldedTreeGenerator() {
// return new ShieldedTreeGenerator(new TreeGeneratorImpl());
// }
//
// static public TreeGenerator createShieldedTreeGenerator(Params params) {
// return new ShieldedTreeGenerator(new TreeGeneratorImpl(params));
// }
//
//
// }
// Path: test/net/sourceforge/arbaro/tree/impl/StemTest.java
import junit.framework.TestCase;
import java.util.Enumeration;
import net.sourceforge.arbaro.transformation.Transformation;
import net.sourceforge.arbaro.tree.Stem;
import net.sourceforge.arbaro.tree.Tree;
import net.sourceforge.arbaro.tree.TreeGenerator;
import net.sourceforge.arbaro.tree.TreeGeneratorFactory;
import net.sourceforge.arbaro.tree.impl.StemImpl;
import net.sourceforge.arbaro.tree.impl.TreeImpl;
import net.sourceforge.arbaro.params.*;
/*
* Created on 12.11.2004
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package net.sourceforge.arbaro.tree.impl;
/**
* @author wdiestel
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class StemTest extends TestCase {
static Tree aTestTree = makeTestTree();
static StemImpl aTestStem = makeTestStem();
static StemImpl makeTestStem() {
StemImpl stem=new StemImpl((TreeImpl)aTestTree,null,0,new Transformation(),0);
stem.make();
return stem;
}
static Tree makeTestTree() {
try {
ParamManager params = new ParamManager();
| TreeGenerator treeGenerator = TreeGeneratorFactory.createTreeGenerator(params); //,null,false,false);
|
wdiestel/arbaro | src/net/sourceforge/arbaro/params/AbstractParam.java | // Path: src/net/sourceforge/arbaro/export/Console.java
// final public class Console {
// static final public int REALLY_QUIET=0;
// static final public int QUIET=1;
// static final public int VERBOSE=2;
// static final public int DEBUG=3;
//
// static public char progrChr=' '; // show progress on Console
//
// static public int outputLevel;
//
// static public void setOutputLevel(int level) {
// outputLevel = level;
// if (outputLevel>= VERBOSE)
// progrChr = '.';
// else
// progrChr = ' ';
// }
//
// static synchronized public boolean debug() {
// return outputLevel>=DEBUG;
// }
//
// static synchronized public void progressChar() {
// if (outputLevel>=VERBOSE) {
// System.err.print(progrChr);
// }
// }
//
// static synchronized public void verboseOutput(String msg) {
// if (outputLevel>=VERBOSE) {
// System.err.println(msg);
// }
// }
//
// static synchronized public void debugOutput(String msg) {
// if (outputLevel>=DEBUG) {
// System.err.println(msg);
// }
// }
//
// static synchronized public void errorOutput(String msg) {
// if (outputLevel>REALLY_QUIET) {
// System.err.println(msg);
// }
// }
//
// static synchronized public void printException(Exception e) {
// if (outputLevel>REALLY_QUIET) {
// System.err.println(e);
// e.printStackTrace(System.err);
// }
// }
//
// static synchronized public void progressChar(char c) {
// if (outputLevel>=VERBOSE) {
// System.err.print(c);
// }
// }
//
// static public void setProgressChar(char consoleChar) {
// Console.progrChr= consoleChar;
// }
//
// }
| import javax.swing.event.*;
import net.sourceforge.arbaro.export.Console;
| // #**************************************************************************
// #
// # Copyright (C) 2003-2006 Wolfram Diestel
// #
// # This program is free software; you can redistribute it and/or modify
// # it under the terms of the GNU General Public License as published by
// # the Free Software Foundation; either version 2 of the License, or
// # (at your option) any later version.
// #
// # This program is distributed in the hope that it will be useful,
// # but WITHOUT ANY WARRANTY; without even the implied warranty of
// # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// # GNU General Public License for more details.
// #
// # You should have received a copy of the GNU General Public License
// # along with this program; if not, write to the Free Software
// # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// #
// # Send comments and bug fixes to diestel@steloj.de
// #
// #**************************************************************************/
package net.sourceforge.arbaro.params;
public abstract class AbstractParam {
public static final int GENERAL = -999; // no level - general params
String name;
String group;
int level;
int order;
String shortDesc;
String longDesc;
boolean enabled;
protected ChangeEvent changeEvent = null;
protected EventListenerList listenerList = new EventListenerList();
public AbstractParam(String nam, String grp, int lev, int ord,
String sh, String lng) {
name = nam;
group = grp;
level = lev;
order = ord;
shortDesc = sh;
longDesc = lng;
enabled=true;
}
public abstract void setValue(String val) throws ParamException;
public abstract String getValue();
public abstract String getDefaultValue();
public abstract void clear();
public abstract boolean empty();
public static boolean loading=false;
protected void warn(String warning) {
| // Path: src/net/sourceforge/arbaro/export/Console.java
// final public class Console {
// static final public int REALLY_QUIET=0;
// static final public int QUIET=1;
// static final public int VERBOSE=2;
// static final public int DEBUG=3;
//
// static public char progrChr=' '; // show progress on Console
//
// static public int outputLevel;
//
// static public void setOutputLevel(int level) {
// outputLevel = level;
// if (outputLevel>= VERBOSE)
// progrChr = '.';
// else
// progrChr = ' ';
// }
//
// static synchronized public boolean debug() {
// return outputLevel>=DEBUG;
// }
//
// static synchronized public void progressChar() {
// if (outputLevel>=VERBOSE) {
// System.err.print(progrChr);
// }
// }
//
// static synchronized public void verboseOutput(String msg) {
// if (outputLevel>=VERBOSE) {
// System.err.println(msg);
// }
// }
//
// static synchronized public void debugOutput(String msg) {
// if (outputLevel>=DEBUG) {
// System.err.println(msg);
// }
// }
//
// static synchronized public void errorOutput(String msg) {
// if (outputLevel>REALLY_QUIET) {
// System.err.println(msg);
// }
// }
//
// static synchronized public void printException(Exception e) {
// if (outputLevel>REALLY_QUIET) {
// System.err.println(e);
// e.printStackTrace(System.err);
// }
// }
//
// static synchronized public void progressChar(char c) {
// if (outputLevel>=VERBOSE) {
// System.err.print(c);
// }
// }
//
// static public void setProgressChar(char consoleChar) {
// Console.progrChr= consoleChar;
// }
//
// }
// Path: src/net/sourceforge/arbaro/params/AbstractParam.java
import javax.swing.event.*;
import net.sourceforge.arbaro.export.Console;
// #**************************************************************************
// #
// # Copyright (C) 2003-2006 Wolfram Diestel
// #
// # This program is free software; you can redistribute it and/or modify
// # it under the terms of the GNU General Public License as published by
// # the Free Software Foundation; either version 2 of the License, or
// # (at your option) any later version.
// #
// # This program is distributed in the hope that it will be useful,
// # but WITHOUT ANY WARRANTY; without even the implied warranty of
// # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// # GNU General Public License for more details.
// #
// # You should have received a copy of the GNU General Public License
// # along with this program; if not, write to the Free Software
// # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// #
// # Send comments and bug fixes to diestel@steloj.de
// #
// #**************************************************************************/
package net.sourceforge.arbaro.params;
public abstract class AbstractParam {
public static final int GENERAL = -999; // no level - general params
String name;
String group;
int level;
int order;
String shortDesc;
String longDesc;
boolean enabled;
protected ChangeEvent changeEvent = null;
protected EventListenerList listenerList = new EventListenerList();
public AbstractParam(String nam, String grp, int lev, int ord,
String sh, String lng) {
name = nam;
group = grp;
level = lev;
order = ord;
shortDesc = sh;
longDesc = lng;
enabled=true;
}
public abstract void setValue(String val) throws ParamException;
public abstract String getValue();
public abstract String getDefaultValue();
public abstract void clear();
public abstract boolean empty();
public static boolean loading=false;
protected void warn(String warning) {
| if (! loading) Console.errorOutput("WARNING: "+warning);
|
wdiestel/arbaro | src/net/sourceforge/arbaro/mesh/MeshPart.java | // Path: src/net/sourceforge/arbaro/export/Console.java
// final public class Console {
// static final public int REALLY_QUIET=0;
// static final public int QUIET=1;
// static final public int VERBOSE=2;
// static final public int DEBUG=3;
//
// static public char progrChr=' '; // show progress on Console
//
// static public int outputLevel;
//
// static public void setOutputLevel(int level) {
// outputLevel = level;
// if (outputLevel>= VERBOSE)
// progrChr = '.';
// else
// progrChr = ' ';
// }
//
// static synchronized public boolean debug() {
// return outputLevel>=DEBUG;
// }
//
// static synchronized public void progressChar() {
// if (outputLevel>=VERBOSE) {
// System.err.print(progrChr);
// }
// }
//
// static synchronized public void verboseOutput(String msg) {
// if (outputLevel>=VERBOSE) {
// System.err.println(msg);
// }
// }
//
// static synchronized public void debugOutput(String msg) {
// if (outputLevel>=DEBUG) {
// System.err.println(msg);
// }
// }
//
// static synchronized public void errorOutput(String msg) {
// if (outputLevel>REALLY_QUIET) {
// System.err.println(msg);
// }
// }
//
// static synchronized public void printException(Exception e) {
// if (outputLevel>REALLY_QUIET) {
// System.err.println(e);
// e.printStackTrace(System.err);
// }
// }
//
// static synchronized public void progressChar(char c) {
// if (outputLevel>=VERBOSE) {
// System.err.print(c);
// }
// }
//
// static public void setProgressChar(char consoleChar) {
// Console.progrChr= consoleChar;
// }
//
// }
| import java.lang.Math;
import java.util.Enumeration;
import net.sourceforge.arbaro.tree.Stem;
import net.sourceforge.arbaro.export.Console; | private class FaceEnumerator implements Enumeration {
private Enumeration sections;
private Enumeration sectionFaces;
private MeshSection section;
private boolean UVFaces;
private boolean useQuads;
private int startIndex;
// private int sectionSize;
public FaceEnumerator(Mesh mesh, int startInx, boolean uv, boolean quads) {
UVFaces = uv;
startIndex = startInx;
useQuads = quads;
sections = elements();
// ignore root point
MeshSection sec =
(MeshSection)sections.nextElement();
// if it's a clone calculate a vertex offset
// finding the corresponding segment in the parent stem's mesh
int uvVertexOffset=0;
if (uv && stem.isClone()) {
MeshPart mp = ((MeshPart)mesh.elementAt(mesh.firstMeshPart[stem.getLevel()]));
MeshSection ms = ((MeshSection)mp.elementAt(1)); // ignore root vertex
// if (Console.debug()) Console.debugOutput("cloneOff: "+stem.getCloneSectionOffset());
for (int i=0; i<stem.getCloneSectionOffset(); i++) {
uvVertexOffset += ms.size()==1? 1 : ms.size()+1; | // Path: src/net/sourceforge/arbaro/export/Console.java
// final public class Console {
// static final public int REALLY_QUIET=0;
// static final public int QUIET=1;
// static final public int VERBOSE=2;
// static final public int DEBUG=3;
//
// static public char progrChr=' '; // show progress on Console
//
// static public int outputLevel;
//
// static public void setOutputLevel(int level) {
// outputLevel = level;
// if (outputLevel>= VERBOSE)
// progrChr = '.';
// else
// progrChr = ' ';
// }
//
// static synchronized public boolean debug() {
// return outputLevel>=DEBUG;
// }
//
// static synchronized public void progressChar() {
// if (outputLevel>=VERBOSE) {
// System.err.print(progrChr);
// }
// }
//
// static synchronized public void verboseOutput(String msg) {
// if (outputLevel>=VERBOSE) {
// System.err.println(msg);
// }
// }
//
// static synchronized public void debugOutput(String msg) {
// if (outputLevel>=DEBUG) {
// System.err.println(msg);
// }
// }
//
// static synchronized public void errorOutput(String msg) {
// if (outputLevel>REALLY_QUIET) {
// System.err.println(msg);
// }
// }
//
// static synchronized public void printException(Exception e) {
// if (outputLevel>REALLY_QUIET) {
// System.err.println(e);
// e.printStackTrace(System.err);
// }
// }
//
// static synchronized public void progressChar(char c) {
// if (outputLevel>=VERBOSE) {
// System.err.print(c);
// }
// }
//
// static public void setProgressChar(char consoleChar) {
// Console.progrChr= consoleChar;
// }
//
// }
// Path: src/net/sourceforge/arbaro/mesh/MeshPart.java
import java.lang.Math;
import java.util.Enumeration;
import net.sourceforge.arbaro.tree.Stem;
import net.sourceforge.arbaro.export.Console;
private class FaceEnumerator implements Enumeration {
private Enumeration sections;
private Enumeration sectionFaces;
private MeshSection section;
private boolean UVFaces;
private boolean useQuads;
private int startIndex;
// private int sectionSize;
public FaceEnumerator(Mesh mesh, int startInx, boolean uv, boolean quads) {
UVFaces = uv;
startIndex = startInx;
useQuads = quads;
sections = elements();
// ignore root point
MeshSection sec =
(MeshSection)sections.nextElement();
// if it's a clone calculate a vertex offset
// finding the corresponding segment in the parent stem's mesh
int uvVertexOffset=0;
if (uv && stem.isClone()) {
MeshPart mp = ((MeshPart)mesh.elementAt(mesh.firstMeshPart[stem.getLevel()]));
MeshSection ms = ((MeshSection)mp.elementAt(1)); // ignore root vertex
// if (Console.debug()) Console.debugOutput("cloneOff: "+stem.getCloneSectionOffset());
for (int i=0; i<stem.getCloneSectionOffset(); i++) {
uvVertexOffset += ms.size()==1? 1 : ms.size()+1; | if (Console.debug()) Console.debugOutput("i: "+i+" vertexOff: "+uvVertexOffset); |
wdiestel/arbaro | src/net/sourceforge/arbaro/gui/ShieldedGUIMeshGenerator.java | // Path: src/net/sourceforge/arbaro/mesh/MeshGenerator.java
// public interface MeshGenerator {
//
// public abstract Mesh createStemMesh(Tree tree, Progress progress);
//
// public abstract Mesh createStemMeshByLevel(Tree tree, Progress progress);
//
// public abstract LeafMesh createLeafMesh(Tree tree, boolean useQuads);
//
// public boolean getUseQuads();
//
// }
//
// Path: src/net/sourceforge/arbaro/mesh/ShieldedMeshGenerator.java
// public class ShieldedMeshGenerator implements MeshGenerator {
// private MeshGenerator meshGenerator;
//
// public boolean getUseQuads() {
// return meshGenerator.getUseQuads();
// }
//
// /**
// *
// */
// public ShieldedMeshGenerator(MeshGenerator meshGenerator) {
// this.meshGenerator = meshGenerator;
// }
//
// protected void showException(Exception e) {
// Console.errorOutput("Error in mesh generator:");
// Console.printException(e);
// }
//
// /* (non-Javadoc)
// * @see net.sourceforge.arbaro.mesh.MeshGenerator#createLeafMesh(net.sourceforge.arbaro.tree.Tree, boolean)
// */
// public LeafMesh createLeafMesh(Tree tree, boolean useQuads) {
// try {
// return meshGenerator.createLeafMesh(tree, useQuads);
// } catch (Exception e) {
// showException(e);
// return null;
// }
// }
//
// /* (non-Javadoc)
// * @see net.sourceforge.arbaro.mesh.MeshGenerator#createStemMesh(net.sourceforge.arbaro.tree.Tree, net.sourceforge.arbaro.export.Progress)
// */
// public Mesh createStemMesh(Tree tree, Progress progress) {
// try {
// return meshGenerator.createStemMesh(tree, progress);
// } catch (Exception e) {
// showException(e);
// return null;
// }
// }
//
// /* (non-Javadoc)
// * @see net.sourceforge.arbaro.mesh.MeshGenerator#createStemMeshByLevel(net.sourceforge.arbaro.tree.Tree, net.sourceforge.arbaro.export.Progress)
// */
// public Mesh createStemMeshByLevel(Tree tree, Progress progress) {
// try {
// return meshGenerator.createStemMeshByLevel(tree, progress);
// } catch (Exception e) {
// showException(e);
// return null;
// }
// }
//
// }
| import java.awt.Component;
import net.sourceforge.arbaro.mesh.MeshGenerator;
import net.sourceforge.arbaro.mesh.ShieldedMeshGenerator; | // #**************************************************************************
// #
// # Copyright (C) 2003-2006 Wolfram Diestel
// #
// # This program is free software; you can redistribute it and/or modify
// # it under the terms of the GNU General Public License as published by
// # the Free Software Foundation; either version 2 of the License, or
// # (at your option) any later version.
// #
// # This program is distributed in the hope that it will be useful,
// # but WITHOUT ANY WARRANTY; without even the implied warranty of
// # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// # GNU General Public License for more details.
// #
// # You should have received a copy of the GNU General Public License
// # along with this program; if not, write to the Free Software
// # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// #
// # Send comments and bug fixes to diestel@steloj.de
// #
// #**************************************************************************/
package net.sourceforge.arbaro.gui;
/**
* @author wolfram
*
*/
public class ShieldedGUIMeshGenerator extends ShieldedMeshGenerator {
Component parent;
/**
* @param meshGenerator
*/
public ShieldedGUIMeshGenerator(Component parent, | // Path: src/net/sourceforge/arbaro/mesh/MeshGenerator.java
// public interface MeshGenerator {
//
// public abstract Mesh createStemMesh(Tree tree, Progress progress);
//
// public abstract Mesh createStemMeshByLevel(Tree tree, Progress progress);
//
// public abstract LeafMesh createLeafMesh(Tree tree, boolean useQuads);
//
// public boolean getUseQuads();
//
// }
//
// Path: src/net/sourceforge/arbaro/mesh/ShieldedMeshGenerator.java
// public class ShieldedMeshGenerator implements MeshGenerator {
// private MeshGenerator meshGenerator;
//
// public boolean getUseQuads() {
// return meshGenerator.getUseQuads();
// }
//
// /**
// *
// */
// public ShieldedMeshGenerator(MeshGenerator meshGenerator) {
// this.meshGenerator = meshGenerator;
// }
//
// protected void showException(Exception e) {
// Console.errorOutput("Error in mesh generator:");
// Console.printException(e);
// }
//
// /* (non-Javadoc)
// * @see net.sourceforge.arbaro.mesh.MeshGenerator#createLeafMesh(net.sourceforge.arbaro.tree.Tree, boolean)
// */
// public LeafMesh createLeafMesh(Tree tree, boolean useQuads) {
// try {
// return meshGenerator.createLeafMesh(tree, useQuads);
// } catch (Exception e) {
// showException(e);
// return null;
// }
// }
//
// /* (non-Javadoc)
// * @see net.sourceforge.arbaro.mesh.MeshGenerator#createStemMesh(net.sourceforge.arbaro.tree.Tree, net.sourceforge.arbaro.export.Progress)
// */
// public Mesh createStemMesh(Tree tree, Progress progress) {
// try {
// return meshGenerator.createStemMesh(tree, progress);
// } catch (Exception e) {
// showException(e);
// return null;
// }
// }
//
// /* (non-Javadoc)
// * @see net.sourceforge.arbaro.mesh.MeshGenerator#createStemMeshByLevel(net.sourceforge.arbaro.tree.Tree, net.sourceforge.arbaro.export.Progress)
// */
// public Mesh createStemMeshByLevel(Tree tree, Progress progress) {
// try {
// return meshGenerator.createStemMeshByLevel(tree, progress);
// } catch (Exception e) {
// showException(e);
// return null;
// }
// }
//
// }
// Path: src/net/sourceforge/arbaro/gui/ShieldedGUIMeshGenerator.java
import java.awt.Component;
import net.sourceforge.arbaro.mesh.MeshGenerator;
import net.sourceforge.arbaro.mesh.ShieldedMeshGenerator;
// #**************************************************************************
// #
// # Copyright (C) 2003-2006 Wolfram Diestel
// #
// # This program is free software; you can redistribute it and/or modify
// # it under the terms of the GNU General Public License as published by
// # the Free Software Foundation; either version 2 of the License, or
// # (at your option) any later version.
// #
// # This program is distributed in the hope that it will be useful,
// # but WITHOUT ANY WARRANTY; without even the implied warranty of
// # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// # GNU General Public License for more details.
// #
// # You should have received a copy of the GNU General Public License
// # along with this program; if not, write to the Free Software
// # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// #
// # Send comments and bug fixes to diestel@steloj.de
// #
// #**************************************************************************/
package net.sourceforge.arbaro.gui;
/**
* @author wolfram
*
*/
public class ShieldedGUIMeshGenerator extends ShieldedMeshGenerator {
Component parent;
/**
* @param meshGenerator
*/
public ShieldedGUIMeshGenerator(Component parent, | MeshGenerator meshGenerator) { |
wdiestel/arbaro | src/net/sourceforge/arbaro/transformation/Vector.java | // Path: src/net/sourceforge/arbaro/params/FloatFormat.java
// public class FloatFormat {
//
// public static NumberFormat getInstance() {
// NumberFormat form = NumberFormat.getNumberInstance(Locale.US);
// form.setMaximumFractionDigits(5);
// form.setMinimumFractionDigits(0);
// return form;
// }
// }
| import java.lang.String;
import java.lang.Math;
import java.text.NumberFormat;
import net.sourceforge.arbaro.params.FloatFormat;
|
public Vector(Vector v) {
coord = new double[Z+1];
coord[X] = v.coord[X];
coord[Y] = v.coord[Y];
coord[Z] = v.coord[Z];
}
public Vector(double value) {
coord = new double[Z+1];
coord[X] = coord[Y] = coord[Z] = value;
}
public Vector(double x, double y, double z) {
coord = new double[Z+1];
coord[X] = x;
coord[Y] = y;
coord[Z] = z;
}
public boolean equals(Vector v) {
return this.sub(v).abs() < 0.0000001;
}
public double abs() {
//returns the length of the vector
return Math.sqrt(coord[X]*coord[X] + coord[Y]*coord[Y] + coord[Z]*coord[Z]);
}
public String toString() {
| // Path: src/net/sourceforge/arbaro/params/FloatFormat.java
// public class FloatFormat {
//
// public static NumberFormat getInstance() {
// NumberFormat form = NumberFormat.getNumberInstance(Locale.US);
// form.setMaximumFractionDigits(5);
// form.setMinimumFractionDigits(0);
// return form;
// }
// }
// Path: src/net/sourceforge/arbaro/transformation/Vector.java
import java.lang.String;
import java.lang.Math;
import java.text.NumberFormat;
import net.sourceforge.arbaro.params.FloatFormat;
public Vector(Vector v) {
coord = new double[Z+1];
coord[X] = v.coord[X];
coord[Y] = v.coord[Y];
coord[Z] = v.coord[Z];
}
public Vector(double value) {
coord = new double[Z+1];
coord[X] = coord[Y] = coord[Z] = value;
}
public Vector(double x, double y, double z) {
coord = new double[Z+1];
coord[X] = x;
coord[Y] = y;
coord[Z] = z;
}
public boolean equals(Vector v) {
return this.sub(v).abs() < 0.0000001;
}
public double abs() {
//returns the length of the vector
return Math.sqrt(coord[X]*coord[X] + coord[Y]*coord[Y] + coord[Z]*coord[Z]);
}
public String toString() {
| NumberFormat fmt = FloatFormat.getInstance();
|
wdiestel/arbaro | src/net/sourceforge/arbaro/params/Params.java | // Path: src/net/sourceforge/arbaro/export/Console.java
// final public class Console {
// static final public int REALLY_QUIET=0;
// static final public int QUIET=1;
// static final public int VERBOSE=2;
// static final public int DEBUG=3;
//
// static public char progrChr=' '; // show progress on Console
//
// static public int outputLevel;
//
// static public void setOutputLevel(int level) {
// outputLevel = level;
// if (outputLevel>= VERBOSE)
// progrChr = '.';
// else
// progrChr = ' ';
// }
//
// static synchronized public boolean debug() {
// return outputLevel>=DEBUG;
// }
//
// static synchronized public void progressChar() {
// if (outputLevel>=VERBOSE) {
// System.err.print(progrChr);
// }
// }
//
// static synchronized public void verboseOutput(String msg) {
// if (outputLevel>=VERBOSE) {
// System.err.println(msg);
// }
// }
//
// static synchronized public void debugOutput(String msg) {
// if (outputLevel>=DEBUG) {
// System.err.println(msg);
// }
// }
//
// static synchronized public void errorOutput(String msg) {
// if (outputLevel>REALLY_QUIET) {
// System.err.println(msg);
// }
// }
//
// static synchronized public void printException(Exception e) {
// if (outputLevel>REALLY_QUIET) {
// System.err.println(e);
// e.printStackTrace(System.err);
// }
// }
//
// static synchronized public void progressChar(char c) {
// if (outputLevel>=VERBOSE) {
// System.err.print(c);
// }
// }
//
// static public void setProgressChar(char consoleChar) {
// Console.progrChr= consoleChar;
// }
//
// }
| import net.sourceforge.arbaro.export.Console;
import java.io.PrintWriter;
import java.io.InputStream;
import java.io.IOException;
import java.io.LineNumberReader;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileReader;
import java.util.Hashtable;
import java.util.Enumeration;
import java.util.TreeMap;
import javax.swing.event.*;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
| };
public Params(Params other) {
// copy values from other
//debug = other.debug;
//verbose = other.verbose;
ignoreVParams = other.ignoreVParams;
stopLevel = other.stopLevel;
Species = other.Species;
// Seed = other.Seed;
Smooth = other.Smooth;
// create paramDB
paramDB = new Hashtable();
levelParams = new LevelParams[4];
for (int l=0; l<4; l++) {
levelParams[l] = new LevelParams(l,paramDB);
}
registerParams();
// copy param values
for (Enumeration e = paramDB.elements(); e.hasMoreElements();) {
AbstractParam p = ((AbstractParam)e.nextElement());
try {
AbstractParam otherParam = other.getParam(p.name);
if (! otherParam.empty()) {
p.setValue(otherParam.getValue());
} // else use default value
} catch (ParamException err) {
| // Path: src/net/sourceforge/arbaro/export/Console.java
// final public class Console {
// static final public int REALLY_QUIET=0;
// static final public int QUIET=1;
// static final public int VERBOSE=2;
// static final public int DEBUG=3;
//
// static public char progrChr=' '; // show progress on Console
//
// static public int outputLevel;
//
// static public void setOutputLevel(int level) {
// outputLevel = level;
// if (outputLevel>= VERBOSE)
// progrChr = '.';
// else
// progrChr = ' ';
// }
//
// static synchronized public boolean debug() {
// return outputLevel>=DEBUG;
// }
//
// static synchronized public void progressChar() {
// if (outputLevel>=VERBOSE) {
// System.err.print(progrChr);
// }
// }
//
// static synchronized public void verboseOutput(String msg) {
// if (outputLevel>=VERBOSE) {
// System.err.println(msg);
// }
// }
//
// static synchronized public void debugOutput(String msg) {
// if (outputLevel>=DEBUG) {
// System.err.println(msg);
// }
// }
//
// static synchronized public void errorOutput(String msg) {
// if (outputLevel>REALLY_QUIET) {
// System.err.println(msg);
// }
// }
//
// static synchronized public void printException(Exception e) {
// if (outputLevel>REALLY_QUIET) {
// System.err.println(e);
// e.printStackTrace(System.err);
// }
// }
//
// static synchronized public void progressChar(char c) {
// if (outputLevel>=VERBOSE) {
// System.err.print(c);
// }
// }
//
// static public void setProgressChar(char consoleChar) {
// Console.progrChr= consoleChar;
// }
//
// }
// Path: src/net/sourceforge/arbaro/params/Params.java
import net.sourceforge.arbaro.export.Console;
import java.io.PrintWriter;
import java.io.InputStream;
import java.io.IOException;
import java.io.LineNumberReader;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileReader;
import java.util.Hashtable;
import java.util.Enumeration;
import java.util.TreeMap;
import javax.swing.event.*;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
};
public Params(Params other) {
// copy values from other
//debug = other.debug;
//verbose = other.verbose;
ignoreVParams = other.ignoreVParams;
stopLevel = other.stopLevel;
Species = other.Species;
// Seed = other.Seed;
Smooth = other.Smooth;
// create paramDB
paramDB = new Hashtable();
levelParams = new LevelParams[4];
for (int l=0; l<4; l++) {
levelParams[l] = new LevelParams(l,paramDB);
}
registerParams();
// copy param values
for (Enumeration e = paramDB.elements(); e.hasMoreElements();) {
AbstractParam p = ((AbstractParam)e.nextElement());
try {
AbstractParam otherParam = other.getParam(p.name);
if (! otherParam.empty()) {
p.setValue(otherParam.getValue());
} // else use default value
} catch (ParamException err) {
| Console.errorOutput("Error copying params: "+err.getMessage());
|
wdiestel/arbaro | src/net/sourceforge/arbaro/tree/StemImpl.java | // Path: src/net/sourceforge/arbaro/export/Console.java
// final public class Console {
// static final public int REALLY_QUIET=0;
// static final public int QUIET=1;
// static final public int VERBOSE=2;
// static final public int DEBUG=3;
//
// static public char progrChr=' '; // show progress on Console
//
// static public int outputLevel;
//
// static public void setOutputLevel(int level) {
// outputLevel = level;
// if (outputLevel>= VERBOSE)
// progrChr = '.';
// else
// progrChr = ' ';
// }
//
// static synchronized public boolean debug() {
// return outputLevel>=DEBUG;
// }
//
// static synchronized public void progressChar() {
// if (outputLevel>=VERBOSE) {
// System.err.print(progrChr);
// }
// }
//
// static synchronized public void verboseOutput(String msg) {
// if (outputLevel>=VERBOSE) {
// System.err.println(msg);
// }
// }
//
// static synchronized public void debugOutput(String msg) {
// if (outputLevel>=DEBUG) {
// System.err.println(msg);
// }
// }
//
// static synchronized public void errorOutput(String msg) {
// if (outputLevel>REALLY_QUIET) {
// System.err.println(msg);
// }
// }
//
// static synchronized public void printException(Exception e) {
// if (outputLevel>REALLY_QUIET) {
// System.err.println(e);
// e.printStackTrace(System.err);
// }
// }
//
// static synchronized public void progressChar(char c) {
// if (outputLevel>=VERBOSE) {
// System.err.print(c);
// }
// }
//
// static public void setProgressChar(char consoleChar) {
// Console.progrChr= consoleChar;
// }
//
// }
| import java.util.Enumeration;
import java.util.NoSuchElementException;
import net.sourceforge.arbaro.transformation.*;
import net.sourceforge.arbaro.params.*;
import net.sourceforge.arbaro.export.Console;
| pruneTest = false; // flag used for pruning
//...
maxPoint = new Vector(-Double.MAX_VALUE,-Double.MAX_VALUE,-Double.MAX_VALUE);
minPoint = new Vector(Double.MAX_VALUE,Double.MAX_VALUE,Double.MAX_VALUE);
}
/**
* For debugging:
* Prints out the transformation to stderr nicely
* (only if debugging is enabled)
*
* @param where The position in the tree, i.e. wich stem
* has this transformation
* @param trf The transformation
*/
void TRF(String where, Transformation trf) {
DBG(where + ": " + trf.toString());
}
/**
* Output debug string, when debugging ist enabled
*
* @param dbgstr The output string
*/
public void DBG(String dbgstr) {
// print debug string to stderr if debugging is enabled
| // Path: src/net/sourceforge/arbaro/export/Console.java
// final public class Console {
// static final public int REALLY_QUIET=0;
// static final public int QUIET=1;
// static final public int VERBOSE=2;
// static final public int DEBUG=3;
//
// static public char progrChr=' '; // show progress on Console
//
// static public int outputLevel;
//
// static public void setOutputLevel(int level) {
// outputLevel = level;
// if (outputLevel>= VERBOSE)
// progrChr = '.';
// else
// progrChr = ' ';
// }
//
// static synchronized public boolean debug() {
// return outputLevel>=DEBUG;
// }
//
// static synchronized public void progressChar() {
// if (outputLevel>=VERBOSE) {
// System.err.print(progrChr);
// }
// }
//
// static synchronized public void verboseOutput(String msg) {
// if (outputLevel>=VERBOSE) {
// System.err.println(msg);
// }
// }
//
// static synchronized public void debugOutput(String msg) {
// if (outputLevel>=DEBUG) {
// System.err.println(msg);
// }
// }
//
// static synchronized public void errorOutput(String msg) {
// if (outputLevel>REALLY_QUIET) {
// System.err.println(msg);
// }
// }
//
// static synchronized public void printException(Exception e) {
// if (outputLevel>REALLY_QUIET) {
// System.err.println(e);
// e.printStackTrace(System.err);
// }
// }
//
// static synchronized public void progressChar(char c) {
// if (outputLevel>=VERBOSE) {
// System.err.print(c);
// }
// }
//
// static public void setProgressChar(char consoleChar) {
// Console.progrChr= consoleChar;
// }
//
// }
// Path: src/net/sourceforge/arbaro/tree/StemImpl.java
import java.util.Enumeration;
import java.util.NoSuchElementException;
import net.sourceforge.arbaro.transformation.*;
import net.sourceforge.arbaro.params.*;
import net.sourceforge.arbaro.export.Console;
pruneTest = false; // flag used for pruning
//...
maxPoint = new Vector(-Double.MAX_VALUE,-Double.MAX_VALUE,-Double.MAX_VALUE);
minPoint = new Vector(Double.MAX_VALUE,Double.MAX_VALUE,Double.MAX_VALUE);
}
/**
* For debugging:
* Prints out the transformation to stderr nicely
* (only if debugging is enabled)
*
* @param where The position in the tree, i.e. wich stem
* has this transformation
* @param trf The transformation
*/
void TRF(String where, Transformation trf) {
DBG(where + ": " + trf.toString());
}
/**
* Output debug string, when debugging ist enabled
*
* @param dbgstr The output string
*/
public void DBG(String dbgstr) {
// print debug string to stderr if debugging is enabled
| Console.debugOutput(getTreePosition() + ":" + dbgstr);
|
wdiestel/arbaro | src/net/sourceforge/arbaro/gui/ParamGroupsView.java | // Path: src/net/sourceforge/arbaro/params/AbstractParam.java
// public abstract class AbstractParam {
// public static final int GENERAL = -999; // no level - general params
// String name;
// String group;
// int level;
// int order;
// String shortDesc;
// String longDesc;
// boolean enabled;
//
// protected ChangeEvent changeEvent = null;
// protected EventListenerList listenerList = new EventListenerList();
//
// public AbstractParam(String nam, String grp, int lev, int ord,
// String sh, String lng) {
// name = nam;
// group = grp;
// level = lev;
// order = ord;
// shortDesc = sh;
// longDesc = lng;
// enabled=true;
// }
//
// public abstract void setValue(String val) throws ParamException;
// public abstract String getValue();
// public abstract String getDefaultValue();
// public abstract void clear();
// public abstract boolean empty();
//
// public static boolean loading=false;
//
// protected void warn(String warning) {
// if (! loading) Console.errorOutput("WARNING: "+warning);
// }
//
// public String getNiceName() {
//
// String result = "";
// // remove leading number
// int i = ('0'<=name.charAt(0))&&(name.charAt(0)<='9') ? 1 : 0;
// for (; i < name.length(); i++) {
// char c = name.charAt(i);
// if(('A'<=c) && (c<='Z')) {
// result += " " + c;
// } else {
// result += c;
// }
// }
// // replace 'V' at end with 'Variation'
// if('V'==result.charAt(result.length()-1)) {
// result = result.substring(0,result.length()-1)+"Variation";
// }
// // replace 'Res' at end with 'Resolution'
// if(result.substring(result.length()-3).equals("Res")) {
// result = result.substring(0,result.length()-3)+"Resolution";
// }
// // replace 'Res' at end with 'Resolution'
// if(result.substring(result.length()-4).equals("Dist")) {
// result = result.substring(0,result.length()-4)+"Distribution";
// }
//
// return result;
// }
//
// public void setEnabled(boolean en) {
// enabled = en;
// fireStateChanged();
// }
//
// public boolean getEnabled() {
// return enabled;
// }
//
// public String getName() {
// return name;
// }
//
// public static String replaceCharAt(String s, int pos, char c) {
// return s.substring(0,pos) + c + s.substring(pos+1);
// }
//
// public String getGroup() {
// return group;
// }
//
// public int getLevel() {
// return level;
// }
//
// public int getOrder() {
// return order;
// }
//
// public String getShortDesc() {
// return shortDesc;
// }
//
// public String toString() {
// if (! empty()) {
// return getValue();
// }
// // else
// return getDefaultValue();
// }
//
// public String getLongDesc() {
// return longDesc;
// }
//
// public void addChangeListener(ChangeListener l) {
// listenerList.add(ChangeListener.class, l);
// }
//
// public void removeChangeListener(ChangeListener l) {
// listenerList.remove(ChangeListener.class, l);
// }
//
// protected void fireStateChanged() {
// Object [] listeners = listenerList.getListenerList();
// for (int i = listeners.length -2; i>=0; i-=2) {
// if (listeners[i] == ChangeListener.class) {
// if (changeEvent == null) {
// changeEvent = new ChangeEvent(this);
// }
// ((ChangeListener)listeners[i+1]).stateChanged(changeEvent);
// }
// }
// }
// }
| import net.sourceforge.arbaro.params.AbstractParam;
import java.awt.Color;
import javax.swing.JTree;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.*;
| }
);
}
public String getGroupName() throws Exception {
DefaultMutableTreeNode node =
(DefaultMutableTreeNode)
getLastSelectedPathComponent();
if (!node.isRoot()) {
return ((GroupNode)node).getGroupName();
}
// no group selected
throw new Exception("no group selected");
}
public int getGroupLevel() throws Exception {
// FIXME: higher nodes could return the level too
DefaultMutableTreeNode node =
(DefaultMutableTreeNode)
getLastSelectedPathComponent();
if (!node.isRoot()) {
return ((GroupNode)node).getGroupLevel();
}
// no group selected
throw new Exception("no group selected");
}
private void createNodes() {
| // Path: src/net/sourceforge/arbaro/params/AbstractParam.java
// public abstract class AbstractParam {
// public static final int GENERAL = -999; // no level - general params
// String name;
// String group;
// int level;
// int order;
// String shortDesc;
// String longDesc;
// boolean enabled;
//
// protected ChangeEvent changeEvent = null;
// protected EventListenerList listenerList = new EventListenerList();
//
// public AbstractParam(String nam, String grp, int lev, int ord,
// String sh, String lng) {
// name = nam;
// group = grp;
// level = lev;
// order = ord;
// shortDesc = sh;
// longDesc = lng;
// enabled=true;
// }
//
// public abstract void setValue(String val) throws ParamException;
// public abstract String getValue();
// public abstract String getDefaultValue();
// public abstract void clear();
// public abstract boolean empty();
//
// public static boolean loading=false;
//
// protected void warn(String warning) {
// if (! loading) Console.errorOutput("WARNING: "+warning);
// }
//
// public String getNiceName() {
//
// String result = "";
// // remove leading number
// int i = ('0'<=name.charAt(0))&&(name.charAt(0)<='9') ? 1 : 0;
// for (; i < name.length(); i++) {
// char c = name.charAt(i);
// if(('A'<=c) && (c<='Z')) {
// result += " " + c;
// } else {
// result += c;
// }
// }
// // replace 'V' at end with 'Variation'
// if('V'==result.charAt(result.length()-1)) {
// result = result.substring(0,result.length()-1)+"Variation";
// }
// // replace 'Res' at end with 'Resolution'
// if(result.substring(result.length()-3).equals("Res")) {
// result = result.substring(0,result.length()-3)+"Resolution";
// }
// // replace 'Res' at end with 'Resolution'
// if(result.substring(result.length()-4).equals("Dist")) {
// result = result.substring(0,result.length()-4)+"Distribution";
// }
//
// return result;
// }
//
// public void setEnabled(boolean en) {
// enabled = en;
// fireStateChanged();
// }
//
// public boolean getEnabled() {
// return enabled;
// }
//
// public String getName() {
// return name;
// }
//
// public static String replaceCharAt(String s, int pos, char c) {
// return s.substring(0,pos) + c + s.substring(pos+1);
// }
//
// public String getGroup() {
// return group;
// }
//
// public int getLevel() {
// return level;
// }
//
// public int getOrder() {
// return order;
// }
//
// public String getShortDesc() {
// return shortDesc;
// }
//
// public String toString() {
// if (! empty()) {
// return getValue();
// }
// // else
// return getDefaultValue();
// }
//
// public String getLongDesc() {
// return longDesc;
// }
//
// public void addChangeListener(ChangeListener l) {
// listenerList.add(ChangeListener.class, l);
// }
//
// public void removeChangeListener(ChangeListener l) {
// listenerList.remove(ChangeListener.class, l);
// }
//
// protected void fireStateChanged() {
// Object [] listeners = listenerList.getListenerList();
// for (int i = listeners.length -2; i>=0; i-=2) {
// if (listeners[i] == ChangeListener.class) {
// if (changeEvent == null) {
// changeEvent = new ChangeEvent(this);
// }
// ((ChangeListener)listeners[i+1]).stateChanged(changeEvent);
// }
// }
// }
// }
// Path: src/net/sourceforge/arbaro/gui/ParamGroupsView.java
import net.sourceforge.arbaro.params.AbstractParam;
import java.awt.Color;
import javax.swing.JTree;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.*;
}
);
}
public String getGroupName() throws Exception {
DefaultMutableTreeNode node =
(DefaultMutableTreeNode)
getLastSelectedPathComponent();
if (!node.isRoot()) {
return ((GroupNode)node).getGroupName();
}
// no group selected
throw new Exception("no group selected");
}
public int getGroupLevel() throws Exception {
// FIXME: higher nodes could return the level too
DefaultMutableTreeNode node =
(DefaultMutableTreeNode)
getLastSelectedPathComponent();
if (!node.isRoot()) {
return ((GroupNode)node).getGroupLevel();
}
// no group selected
throw new Exception("no group selected");
}
private void createNodes() {
| GroupNode general = new GroupNode("","General",AbstractParam.GENERAL);
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.