From 290369e244eaf5504f471c01812bc1f18eca981b Mon Sep 17 00:00:00 2001 From: Hugo Louro Date: Wed, 29 Mar 2017 22:54:44 -0700 Subject: [PATCH] RATIS-8: Avoid using Optional for data fields in TransactionContex --- .../statemachine/TransactionContext.java | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/ratis-server/src/main/java/org/apache/ratis/statemachine/TransactionContext.java b/ratis-server/src/main/java/org/apache/ratis/statemachine/TransactionContext.java index 81bea45d70..190b946200 100644 --- a/ratis-server/src/main/java/org/apache/ratis/statemachine/TransactionContext.java +++ b/ratis-server/src/main/java/org/apache/ratis/statemachine/TransactionContext.java @@ -49,13 +49,13 @@ public class TransactionContext { private final StateMachine stateMachine; /** Original request from the client */ - private Optional clientRequest = Optional.empty(); + private RaftClientRequest clientRequest; /** Exception from the {@link StateMachine} or from the log */ - private Optional exception = Optional.empty(); + private Exception exception; /** Data from the {@link StateMachine} */ - private Optional smLogEntryProto = Optional.empty(); + private SMLogEntryProto smLogEntryProto; /** * Context specific to the state machine. @@ -63,7 +63,7 @@ public class TransactionContext { * {@link StateMachine#startTransaction(RaftClientRequest)} and * {@link StateMachine#applyTransaction(TransactionContext)}. */ - private Optional stateMachineContext = Optional.empty(); + private Object stateMachineContext; /** * Whether to commit the transaction to the RAFT Log. @@ -73,7 +73,7 @@ public class TransactionContext { private boolean shouldCommit = true; /** Committed LogEntry. */ - private Optional logEntry = Optional.empty(); + private LogEntryProto logEntry; private TransactionContext(StateMachine stateMachine) { this.stateMachine = stateMachine; @@ -96,9 +96,9 @@ public TransactionContext( StateMachine stateMachine, RaftClientRequest clientRequest, SMLogEntryProto smLogEntryProto, Object stateMachineContext) { this(stateMachine); - this.clientRequest = Optional.of(clientRequest); - this.smLogEntryProto = Optional.ofNullable(smLogEntryProto); - this.stateMachineContext = Optional.ofNullable(stateMachineContext); + this.clientRequest = clientRequest; + this.smLogEntryProto = smLogEntryProto; + this.stateMachineContext = stateMachineContext; } /** The same as this(stateMachine, clientRequest, exception, null). */ @@ -117,9 +117,9 @@ public TransactionContext( StateMachine stateMachine, RaftClientRequest clientRequest, Exception exception, Object stateMachineContext) { this(stateMachine); - this.clientRequest = Optional.of(clientRequest); - this.exception = Optional.of(exception); - this.stateMachineContext = Optional.ofNullable(stateMachineContext); + this.clientRequest = clientRequest; + this.exception = exception; + this.stateMachineContext = stateMachineContext; } /** @@ -129,48 +129,48 @@ public TransactionContext( */ public TransactionContext(StateMachine stateMachine, LogEntryProto logEntry) { this(stateMachine); - this.smLogEntryProto = Optional.of(logEntry.getSmLogEntry()); - this.logEntry = Optional.of(logEntry); + this.smLogEntryProto = logEntry.getSmLogEntry(); + this.logEntry = logEntry; } public Optional getClientRequest() { - return this.clientRequest; + return Optional.ofNullable(clientRequest); } public Optional getSMLogEntry() { - return this.smLogEntryProto; + return Optional.ofNullable(smLogEntryProto); } public Optional getException() { - return this.exception; + return Optional.ofNullable(exception); } public TransactionContext setStateMachineContext(Object stateMachineContext) { - this.stateMachineContext = Optional.ofNullable(stateMachineContext); + this.stateMachineContext = stateMachineContext; return this; } public Optional getStateMachineContext() { - return stateMachineContext; + return Optional.ofNullable(stateMachineContext); } public TransactionContext setLogEntry(LogEntryProto logEntry) { - this.logEntry = Optional.of(logEntry); + this.logEntry = logEntry; return this; } public TransactionContext setSmLogEntryProto(SMLogEntryProto smLogEntryProto) { - this.smLogEntryProto = Optional.of(smLogEntryProto); + this.smLogEntryProto = smLogEntryProto; return this; } public Optional getLogEntry() { - return logEntry; + return Optional.ofNullable(logEntry); } private TransactionContext setException(IOException ioe) { - assert !this.exception.isPresent(); - this.exception = Optional.of(ioe); + assert exception != null; + this.exception = ioe; return this; }