コード例 #1
0
ファイル: gobbyserver_impl.go プロジェクト: postfix/gobby
func NewGobbyServer(nodeID int, numNodes int) (Gobbyserver, error) {
	server := new(gobbyserver)
	server.addrport = config.Nodes[nodeID].Address + ":" + strconv.Itoa(config.Nodes[nodeID].Port)
	server.store = make(map[string]*kstate)
	server.commandLog = make([]*command.Command, 0)
	server.nextIndex = 0
	server.replyChs = make(map[int]chan *gobbyrpc.GobbyReply)
	server.pending = NewQueue()
	if pnode, err := paxos.NewPaxosNode(nodeID, numNodes, server.getCommand); err != nil {
		return nil, err
	} else {
		server.paxosnode = pnode
	}
	if lnode, err := lease.NewLeaseNode(nodeID, numNodes); err != nil {
		return nil, err
	} else {
		server.leasenode = lnode
	}

	if err := rpc.RegisterName("gobbyServer", gobbyrpc.Wrap(server)); err != nil {
		return nil, err
	} else {
		go ReplicateRoutine(server.pending, server.paxosnode)
		return server, nil
	}

	//TODO:Now the listener is in the lease node, and we should let gobbyserver contain listener
}
コード例 #2
0
ファイル: node.go プロジェクト: postfix/gobby
func main() {
	fmt.Printf("node %d starts\n", nid)
	_, err := lease.NewLeaseNode(nid, numNodes)
	if err != nil {
		fmt.Println("Cannot start node.\n")
		fmt.Println(err)
		return
	}
	listener, err := net.Listen("tcp", fmt.Sprintf(":%d", config.Nodes[nid].Port))
	if err != nil {
		fmt.Printf("node %d cannot listen to port:%s\n", err)
		return
	}
	rpc.HandleHTTP()
	http.Serve(listener, nil)
}