bftsmart.tom.server.defaultservices

## Class DefaultSingleRecoverable

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

All Implemented Interfaces:
  Executable, Recoverable, SingleExecutable

    public abstract class DefaultSingleRecoverable
    extends java.lang.Object
    implements Recoverable, SingleExecutable

This class provides a basic state transfer protocol using the interface 'SingleExecutable'.

### Field Summary

Fields
`protected ReplicaContext` `replicaContext`

### Constructor Summary

Constructors
Constructor and Description
`DefaultSingleRecoverable()`

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`abstract byte[]` `appExecuteOrdered(byte[] command, MessageContext msgCtx)`
`abstract byte[]` `appExecuteUnordered(byte[] command, MessageContext msgCtx)`
`byte[]` `computeHash(byte[] data)`
`byte[]` `executeOrdered(byte[] command, MessageContext msgCtx)` Method called to execute a request totally ordered.
`byte[]` `executeUnordered(byte[] command, MessageContext msgCtx)` Method called to execute a request totally ordered.
`abstract byte[]` `getSnapshot()`
`bftsmart.statemanagement.ApplicationState` `getState(int cid, boolean sendState)` This method should return a representation of the application state
`bftsmart.statemanagement.StateManager` `getStateManager()` Recoverers implementing this interface will have to chose among different options of state managers like DurableStateManager or StandardStateManager.
`protected void` `initLog()`
`abstract void` `installSnapshot(byte[] state)`
`void` `noOp(int CID, MessageContext msgCtx)` This method is invoked by ServiceReplica to indicate that a consensus instance finished without delivering anything to the application (e.g., an instance only decided a single reconfiguration operation.
`void` `Op(int CID, byte[] requests, MessageContext msgCtx)` This method is invoked by ServiceReplica to pass information that was decided in a particular consensus instance.
`void` `setReplicaContext(ReplicaContext replicaContext)`
`int` `setState(bftsmart.statemanagement.ApplicationState recvState)` Sets the state to the representation obtained in the state transfer protocol

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

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

### Field Detail

#### replicaContext

    protected ReplicaContext replicaContext

### Constructor Detail

#### DefaultSingleRecoverable

    public DefaultSingleRecoverable()

### Method Detail

#### executeOrdered

    public byte[] executeOrdered(byte[] command,
                                 MessageContext msgCtx)

Description copied from interface: `SingleExecutable`
Method called to execute a request totally ordered. The message context contains a lot of information about the request, such as timestamp, nonces and sender. The code for this method MUST use the value of timestamp instead of relying on its own local clock, and nonces instead of trying to generated its own random values. This is important because this values are the same for all replicas, and therefore, ensure the determinism required in a replicated state machine.

Specified by:
  `executeOrdered` in interface `SingleExecutable`
Parameters:
  `command` - the command issue by the client
  `msgCtx` - information related with the command
Returns:
  the reply for the request issued by the client

#### computeHash

    public final byte[] computeHash(byte[] data)

#### getState

    public bftsmart.statemanagement.ApplicationState getState(int cid,
                                                              boolean sendState)

Description copied from interface: `Recoverable`
This method should return a representation of the application state

Specified by:
  `getState` in interface `Recoverable`
Parameters:
  `cid` - Consensus up to which the application should return an Application state
  `sendState` - true if the replica should send a complete representation of the state instead of only the hash. False otherwise
Returns:
  A representation of the application state

#### setState

    public int setState(bftsmart.statemanagement.ApplicationState recvState)

Description copied from interface: `Recoverable`
Sets the state to the representation obtained in the state transfer protocol

Specified by:
  `setState` in interface `Recoverable`
Parameters:
  `recvState` - State obtained in the state transfer protocol
Returns:

#### setReplicaContext

    public void setReplicaContext(ReplicaContext replicaContext)

Specified by:
  `setReplicaContext` in interface `Recoverable`

#### getStateManager

    public bftsmart.statemanagement.StateManager getStateManager()

Description copied from interface: `Recoverable`
Recoverers implementing this interface will have to chose among different options of state managers like DurableStateManager or StandardStateManager. The recoverer class can also define a new strategy to manage the state and return it in this method.

Specified by:
  `getStateManager` in interface `Recoverable`
Returns:
  the implementation of state manager that suplies the strategy defined

#### initLog

    protected void initLog()

#### executeUnordered

    public byte[] executeUnordered(byte[] command,
                                   MessageContext msgCtx)

Description copied from interface: `Executable`
Method called to execute a request totally ordered. The message context contains some useful information such as the command sender.

Specified by:
  `executeUnordered` in interface `Executable`
Parameters:
  `command` - the command issue by the client
  `msgCtx` - information related with the command
Returns:
  the reply for the request issued by the client

#### Op

    public void Op(int CID,
                   byte[] requests,
                   MessageContext msgCtx)

Description copied from interface: `Recoverable`
This method is invoked by ServiceReplica to pass information that was decided in a particular consensus instance. This method is always invoked before the executor. However, multiple invocations for the same consensus ID may occur, so developers must take this behavior into consideration when developing their own logging and checkpointing. If there is no information to be passed to the application, noOp(...) is invoked instead.

Specified by:
  `Op` in interface `Recoverable`
Parameters:
  `CID` - the consensus instance ID associated with the request
  `requests` - A request decided in CID
  `msgCtx` - Message context associated with the client request and the consensus instance where it was ordered. msgCtx.getConsensusId() will be equal to CID.

#### noOp

    public void noOp(int CID,
                     MessageContext msgCtx)

Description copied from interface: `Recoverable`
This method is invoked by ServiceReplica to indicate that a consensus instance finished without delivering anything to the application (e.g., an instance only decided a single reconfiguration operation. or an instance where the client operation was not delivered because its view was outdated). To allow the underlying state transfer protocol to execute correctly, it needs to be notified of this special case In the current protocols included, it suffices to register a NOOP operation in the logs used within the state transfer, but never deliver it to the application

Specified by:
  `noOp` in interface `Recoverable`
Parameters:
  `CID` - the consensus instance where the aforementioned condition occurred
  `msgCtx` - Message context associated with the consensus instance. furthermore msgCtx.getConsensusId() will be equal to CID.

#### installSnapshot

    public abstract void installSnapshot(byte[] state)

#### getSnapshot

    public abstract byte[] getSnapshot()

#### appExecuteOrdered

    public abstract byte[] appExecuteOrdered(byte[] command,
                                             MessageContext msgCtx)

#### appExecuteUnordered

    public abstract byte[] appExecuteUnordered(byte[] command,
                                               MessageContext msgCtx)