bftsmart.tom.server.defaultservices

## Class DefaultApplicationState

- java.lang.Object
- - bftsmart.tom.server.defaultservices.DefaultApplicationState

All Implemented Interfaces:
  bftsmart.statemanagement.ApplicationState, java.io.Serializable

    public class DefaultApplicationState
    extends java.lang.Object
    implements bftsmart.statemanagement.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
`protected boolean` `hasState`
`protected int` `lastCID`
`protected byte[]` `state`
`protected byte[]` `stateHash`

### Constructor Summary

Constructors
Constructor and 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

### Method Summary

All Methods Instance Methods Concrete Methods
`boolean` `equals(java.lang.Object obj)` This method MUST be implemented.
`bftsmart.tom.leaderchange.CertifiedDecision` `getCertifiedDecision(bftsmart.reconfiguration.ServerViewController controller)` Retrieves the certified decision for the last consensus present in this object
`int` `getLastCheckpointCID()` Retrieves the consensus ID for the last checkpoint
`int` `getLastCID()` Retrieves the consensus ID for the last messages batch delivered to the application
`CommandsInfo` `getMessageBatch(int cid)` Retrieves the specified batch of messages
`CommandsInfo[]` `getMessageBatches()` Retrieves all batches of messages
`byte[]` `getSerializedState()` Byte array that must be a representation of the application state
`byte[]` `getState()` Retrieves the state associated with the last checkpoint
`byte[]` `getStateHash()` Retrieves the hash of the state associated with the last checkpoint
`int` `hashCode()` This method MUST be implemented.
`boolean` `hasState()` Indicates if the TransferableState object has a valid state
`void` `setMessageBatches(CommandsInfo[] messageBatches)`
`void` `setSerializedState(byte[] state)` Sets a byte array that must be a representation of the application state
`void` `setState(byte[] state)` Sets the state associated with the last checkpoint

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### state

    protected byte[] state

#### stateHash

    protected byte[] stateHash

#### lastCID

    protected int lastCID

#### hasState

    protected boolean hasState

### 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()

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: `bftsmart.statemanagement.ApplicationState`
Sets a byte array that must be a representation of the application state

Specified by:
  `setSerializedState` in interface `bftsmart.statemanagement.ApplicationState`
Parameters:
  `state` - a byte array that must be a representation of the application state

#### getSerializedState

    public byte[] getSerializedState()

Description copied from interface: `bftsmart.statemanagement.ApplicationState`
Byte array that must be a representation of the application state

Specified by:
  `getSerializedState` in interface `bftsmart.statemanagement.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 `bftsmart.statemanagement.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 `bftsmart.statemanagement.ApplicationState`
Returns:
  Consensus ID for the last messages batch delivered to the application

#### getCertifiedDecision

    public bftsmart.tom.leaderchange.CertifiedDecision getCertifiedDecision(bftsmart.reconfiguration.ServerViewController controller)

Retrieves the certified decision for the last consensus present in this object

Specified by:
  `getCertifiedDecision` in interface `bftsmart.statemanagement.ApplicationState`
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 interface `bftsmart.statemanagement.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: `bftsmart.statemanagement.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 `bftsmart.statemanagement.ApplicationState`
Overrides:
  `equals` in class `java.lang.Object`

#### hashCode

    public int hashCode()

Description copied from interface: `bftsmart.statemanagement.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 `bftsmart.statemanagement.ApplicationState`
Overrides:
  `hashCode` in class `java.lang.Object`