Class 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
    • 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 with
      DefaultApplicationState​(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 with
      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
    • 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 checkpoint
        stateHash - 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 interface ApplicationState
        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 interface ApplicationState
        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 interface ApplicationState
        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 interface ApplicationState
        Returns:
        Consensus ID for the last messages batch delivered to the application
      • 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 interface ApplicationState
        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 interface ApplicationState
        Overrides:
        equals in class java.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 interface ApplicationState
        Overrides:
        hashCode in class java.lang.Object
      • getLastReplies

        public java.util.TreeMap<java.lang.Integer,​TOMMessage> getLastReplies()