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 boolean
hasState
protected int
lastCID
protected java.util.TreeMap<java.lang.Integer,TOMMessage>
lastReplies
protected byte[]
lastRepliesHash
protected byte[]
state
protected 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 boolean
equals(java.lang.Object obj)
This method MUST be implemented.CertifiedDecision
getCertifiedDecision(ServerViewController controller)
Retrieves the certified decision for the last consensus present in this objectint
getLastCheckpointCID()
Retrieves the consensus ID for the last checkpointint
getLastCID()
Retrieves the consensus ID for the last messages batch delivered to the applicationjava.util.TreeMap<java.lang.Integer,TOMMessage>
getLastReplies()
CommandsInfo
getMessageBatch(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 checkpointint
hashCode()
This method MUST be implemented.boolean
hasState()
Indicates if the TransferableState object has a valid statevoid
setMessageBatches(CommandsInfo[] messageBatches)
void
setSerializedState(byte[] state)
Sets a byte array that must be a representation of the application statevoid
setState(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:ApplicationState
Sets a byte array that must be a representation of the application state- Specified by:
setSerializedState
in interfaceApplicationState
- Parameters:
state
- a byte array that must be a representation of the application state
-
getSerializedState
public byte[] getSerializedState()
Description copied from interface:ApplicationState
Byte array that must be a representation of the application state- Specified by:
getSerializedState
in 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:
hasState
in 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:
getLastCID
in 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:
getCertifiedDecision
in 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:
getStateHash
in 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:ApplicationState
This method MUST be implemented. However, the attribute returned by getSerializedState() should be ignored, and getStateHash() should be used instead- Specified by:
equals
in interfaceApplicationState
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
Description copied from interface:ApplicationState
This method MUST be implemented. However, the attribute returned by getSerializedState() should be ignored, and getStateHash() should be used instead- Specified by:
hashCode
in interfaceApplicationState
- Overrides:
hashCode
in classjava.lang.Object
-
getLastReplies
public java.util.TreeMap<java.lang.Integer,TOMMessage> getLastReplies()
-
-