Skip to content
Snippets Groups Projects
replica.h 2.44 KiB
Newer Older
Irene Y Zhang's avatar
Irene Y Zhang committed
// -*- mode: c++; c-file-style: "k&r"; c-basic-offset: 4 -*-
// vim: set ts=4 sw=4:
/***********************************************************************
 *
 * replication/ir/replica.h:
 *   IR Replica server
 *
 **********************************************************************/

#ifndef _IR_REPLICA_H_
#define _IR_REPLICA_H_

#include "lib/assert.h"
#include "lib/message.h"
#include "lib/udptransport.h"
#include "lib/configuration.h"
Irene Y Zhang's avatar
Irene Y Zhang committed
#include "replication/ir/record.h"
#include "replication/common/replica.h"
#include "replication/ir/ir-proto.pb.h"
Irene Y Zhang's avatar
Irene Y Zhang committed
namespace replication {
Irene Y Zhang's avatar
Irene Y Zhang committed
namespace ir {

Irene Y Zhang's avatar
Irene Y Zhang committed
class IRAppReplica : public AppReplica
Irene Y Zhang's avatar
Irene Y Zhang committed
{
public:
Irene Y Zhang's avatar
Irene Y Zhang committed
    IRAppReplica() { };
    virtual ~IRAppReplica() { };
Irene Y Zhang's avatar
Irene Y Zhang committed
    // Invoke inconsistent operation, no return value
    virtual void ExecInconsistentUpcall(const string &str1);
    // Invoke consensus operation
Irene Y Zhang's avatar
Irene Y Zhang committed
    virtual void ExecConsensusUpcall(const string &str1, string &str2);
    // Invoke unreplicated operation
    virtual void UnloggedUpcall(const string &str1, string &str2);
Irene Y Zhang's avatar
Irene Y Zhang committed
};

    
class IRReplica : TransportReceiver
{
private:

    view_t view;

    // Index of 'this' replica, and handle to transport layer.
    int myIdx;
    Transport *transport;

Irene Y Zhang's avatar
Irene Y Zhang committed
    IRAppReplica *app;
    ReplicaStatus status;

    // record for this replica
    Record record;

Irene Y Zhang's avatar
Irene Y Zhang committed
public:
Irene Y Zhang's avatar
Irene Y Zhang committed
    IRReplica(transport::Configuration config, int myIdx,
              Transport *transport, IRAppReplica *app);
Irene Y Zhang's avatar
Irene Y Zhang committed
    ~IRReplica();

    void ReceiveMessage(const TransportAddress &remote,
                        const std::string &type, const std::string &data);

    void HandleMessage(const TransportAddress &remote,
                       const std::string &type, const std::string &data);
    void HandleProposeInconsistent(const TransportAddress &remote,
                                   const proto::ProposeInconsistentMessage &msg);
    void HandleFinalizeInconsistent(const TransportAddress &remote,
                                    const proto::FinalizeInconsistentMessage &msg);
    void HandleProposeConsensus(const TransportAddress &remote,
                                const proto::ProposeConsensusMessage &msg);
    void HandleFinalizeConsensus(const TransportAddress &remote,
                                 const proto::FinalizeConsensusMessage &msg);
    void HandleUnlogged(const TransportAddress &remote,
                        const proto::UnloggedRequestMessage &msg);

};

} // namespace ir
Irene Y Zhang's avatar
Irene Y Zhang committed
} // namespace replication
Irene Y Zhang's avatar
Irene Y Zhang committed

#endif /* _IR_REPLICA_H_ */