Class DefaultApplicationState
- java.lang.Object
-
- bftsmart.tom.server.defaultservices.DefaultApplicationState
-
- All Implemented Interfaces:
ApplicationState,java.io.Serializable
public class DefaultApplicationState extends java.lang.Object implements ApplicationState
This class represents a state transfered from a replica to another. The state associated with the last checkpoint together with all the batches of messages received do far, comprises the sender's current state- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanhasStateprotected intlastCIDprotected java.util.TreeMap<java.lang.Integer,TOMMessage>lastRepliesprotected byte[]lastRepliesHashprotected byte[]stateprotected byte[]stateHash
-
Constructor Summary
Constructors Constructor Description DefaultApplicationState()Constructs a TansferableState This constructor should be used when there isn't a valid state to construct the object withDefaultApplicationState(CommandsInfo[] messageBatches, byte[] logHash, int lastCheckpointCID, int lastCID, byte[] state, byte[] stateHash, int pid)DefaultApplicationState(CommandsInfo[] messageBatches, int lastCheckpointCID, int lastCID, byte[] state, byte[] stateHash, int pid)Constructs a TansferableState This constructor should be used when there is a valid state to construct the object withDefaultApplicationState(CommandsInfo[] messageBatches, int lastCheckpointCID, int lastCID, byte[] state, byte[] stateHash, int pid, java.util.TreeMap<java.lang.Integer,TOMMessage> lastReplies, byte[] lastRepliesHash)Constructs a TansferableState This constructor should be used when there isn't a valid state to construct the object with
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object obj)This method MUST be implemented.CertifiedDecisiongetCertifiedDecision(ServerViewController controller)Retrieves the certified decision for the last consensus present in this objectintgetLastCheckpointCID()Retrieves the consensus ID for the last checkpointintgetLastCID()Retrieves the consensus ID for the last messages batch delivered to the applicationjava.util.TreeMap<java.lang.Integer,TOMMessage>getLastReplies()CommandsInfogetMessageBatch(int cid)Retrieves the specified batch of messagesCommandsInfo[]getMessageBatches()Retrieves all batches of messagesbyte[]getSerializedState()Byte array that must be a representation of the application statebyte[]getState()Retrieves the state associated with the last checkpointbyte[]getStateHash()Retrieves the hash of the state associated with the last checkpointinthashCode()This method MUST be implemented.booleanhasState()Indicates if the TransferableState object has a valid statevoidsetMessageBatches(CommandsInfo[] messageBatches)voidsetSerializedState(byte[] state)Sets a byte array that must be a representation of the application statevoidsetState(byte[] state)Sets the state associated with the last checkpoint
-
-
-
Field Detail
-
state
protected byte[] state
-
stateHash
protected byte[] stateHash
-
lastCID
protected int lastCID
-
hasState
protected boolean hasState
-
lastReplies
protected java.util.TreeMap<java.lang.Integer,TOMMessage> lastReplies
-
lastRepliesHash
protected byte[] lastRepliesHash
-
-
Constructor Detail
-
DefaultApplicationState
public DefaultApplicationState(CommandsInfo[] messageBatches, int lastCheckpointCID, int lastCID, byte[] state, byte[] stateHash, int pid)
Constructs a TansferableState This constructor should be used when there is a valid state to construct the object with- Parameters:
messageBatches- Batches received since the last checkpoint.state- State associated with the last checkpointstateHash- Hash of the state associated with the last checkpoint
-
DefaultApplicationState
public DefaultApplicationState(CommandsInfo[] messageBatches, byte[] logHash, int lastCheckpointCID, int lastCID, byte[] state, byte[] stateHash, int pid)
-
DefaultApplicationState
public DefaultApplicationState(CommandsInfo[] messageBatches, int lastCheckpointCID, int lastCID, byte[] state, byte[] stateHash, int pid, java.util.TreeMap<java.lang.Integer,TOMMessage> lastReplies, byte[] lastRepliesHash)
Constructs a TansferableState This constructor should be used when there isn't a valid state to construct the object with
-
DefaultApplicationState
public DefaultApplicationState()
Constructs a TansferableState This constructor should be used when there isn't a valid state to construct the object with
-
-
Method Detail
-
setSerializedState
public void setSerializedState(byte[] state)
Description copied from interface:ApplicationStateSets a byte array that must be a representation of the application state- Specified by:
setSerializedStatein interfaceApplicationState- Parameters:
state- a byte array that must be a representation of the application state
-
getSerializedState
public byte[] getSerializedState()
Description copied from interface:ApplicationStateByte array that must be a representation of the application state- Specified by:
getSerializedStatein interfaceApplicationState- Returns:
- A byte array that must be a representation of the application state
-
hasState
public boolean hasState()
Indicates if the TransferableState object has a valid state- Specified by:
hasStatein interfaceApplicationState- Returns:
- true if it has a valid state, false otherwise
-
getLastCID
public int getLastCID()
Retrieves the consensus ID for the last messages batch delivered to the application- Specified by:
getLastCIDin interfaceApplicationState- Returns:
- Consensus ID for the last messages batch delivered to the application
-
getCertifiedDecision
public CertifiedDecision getCertifiedDecision(ServerViewController controller)
Retrieves the certified decision for the last consensus present in this object- Specified by:
getCertifiedDecisionin interfaceApplicationState- Parameters:
controller-- Returns:
- The certified decision for the last consensus present in this object
-
getState
public byte[] getState()
Retrieves the state associated with the last checkpoint- Returns:
- State associated with the last checkpoint
-
getStateHash
public byte[] getStateHash()
Retrieves the hash of the state associated with the last checkpoint- Specified by:
getStateHashin interfaceApplicationState- Returns:
- Hash of the state associated with the last checkpoint
-
setState
public void setState(byte[] state)
Sets the state associated with the last checkpoint- Parameters:
state- State associated with the last checkpoint
-
getMessageBatches
public CommandsInfo[] getMessageBatches()
Retrieves all batches of messages- Returns:
- Batch of messages
-
setMessageBatches
public void setMessageBatches(CommandsInfo[] messageBatches)
-
getMessageBatch
public CommandsInfo getMessageBatch(int cid)
Retrieves the specified batch of messages- Parameters:
cid- Consensus ID associated with the batch to be fetched- Returns:
- The batch of messages associated with the batch correspondent consensus ID
-
getLastCheckpointCID
public int getLastCheckpointCID()
Retrieves the consensus ID for the last checkpoint- Returns:
- Consensus ID for the last checkpoint, or -1 if no checkpoint was yet executed
-
equals
public boolean equals(java.lang.Object obj)
Description copied from interface:ApplicationStateThis method MUST be implemented. However, the attribute returned by getSerializedState() should be ignored, and getStateHash() should be used instead- Specified by:
equalsin interfaceApplicationState- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
Description copied from interface:ApplicationStateThis method MUST be implemented. However, the attribute returned by getSerializedState() should be ignored, and getStateHash() should be used instead- Specified by:
hashCodein interfaceApplicationState- Overrides:
hashCodein classjava.lang.Object
-
getLastReplies
public java.util.TreeMap<java.lang.Integer,TOMMessage> getLastReplies()
-
-