当前位置: 首页>>代码示例>>Golang>>正文


Golang storagerpc.RegisterReply类代码示例

本文整理汇总了Golang中github.com/cmu440/tribbler/rpc/storagerpc.RegisterReply的典型用法代码示例。如果您正苦于以下问题:Golang RegisterReply类的具体用法?Golang RegisterReply怎么用?Golang RegisterReply使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了RegisterReply类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: RegisterServer

func (ss *storageServer) RegisterServer(args *storagerpc.RegisterArgs, reply *storagerpc.RegisterReply) error {
	//will fix registering and race conditions after checkpoint
	node := args.ServerInfo
	nodeID := int(node.NodeID)

	_, in := ss.registerMap[nodeID]

	if !in {
		ss.ring = append(ss.ring, node)
		ss.registerMapLock.Lock()
		ss.registerMap[nodeID] = &node
		ss.registerMapLock.Unlock()
	}

	if len(ss.registerMap)+1 != ss.numNodes {
		reply.Status = storagerpc.NotReady
		reply.Servers = nil
	} else {
		reply.Status = storagerpc.OK
		reply.Servers = ss.ring
		_, in := ss.okdMap[nodeID]
		if !in {
			ss.okdMap[nodeID] = 0
		}
	}

	if len(ss.okdMap)+1 == ss.numNodes {
		ss.nodeCount = ss.numNodes
		ss.allConnected <- 1
	}

	return nil
}
开发者ID:jbuckman,项目名称:p2-440,代码行数:33,代码来源:storageserver_impl.go

示例2: RegisterServer

func (ss *storageServer) RegisterServer(args *storagerpc.RegisterArgs, reply *storagerpc.RegisterReply) error {

	serverID := args.ServerInfo.NodeID
	seen := false

	for i := 0; i < ss.count; i++ {
		if ss.servers[i].NodeID == serverID {
			seen = true
		}
	}

	// Add this server to the list
	if seen == false {
		ss.countLock.Lock()
		ss.servers[ss.count] = args.ServerInfo
		ss.count++
		ss.countLock.Unlock()
	}
	// If all servers have connected, send the OK and reply with server list
	if ss.count == len(ss.servers) {
		reply.Status = storagerpc.OK
		reply.Servers = ss.servers
	} else {
		reply.Status = storagerpc.NotReady
		reply.Servers = nil
	}
	return nil
}
开发者ID:pyurky,项目名称:p2,代码行数:28,代码来源:storageserver_impl.go

示例3: RegisterServer

func (ss *storageServer) RegisterServer(args *storagerpc.RegisterArgs, reply *storagerpc.RegisterReply) error {
	if !ss.isMaster {
		return errors.New("I am not a master!")
	}
	ss.registerLocker.Lock()
	defer ss.registerLocker.Unlock()
	/* Check if the node has already registered. */
	hasRegistered := false
	for _, node := range ss.nodes {
		if args.ServerInfo.NodeID == node.NodeID {
			hasRegistered = true
		}
	}
	/* Register new node */
	if !hasRegistered {
		fmt.Printf("Register node %d, NodeID is %d\n", ss.registerCnt, args.ServerInfo.NodeID)
		ss.nodes[ss.registerCnt] = args.ServerInfo
		ss.registerCnt += 1
	}
	/* If all nodes has registered, return OK */
	if ss.registerCnt == ss.numNodes {
		sort.Sort(SortNodeByNodeID(ss.nodes))
		reply.Status = storagerpc.OK
		reply.Servers = ss.nodes
	} else {
		reply.Status = storagerpc.NotReady
	}
	return nil
}
开发者ID:mallocanswer,项目名称:Tribbler,代码行数:29,代码来源:storageserver_impl.go

示例4: RegisterServer

// RegisterServer adds a storage server to the ring. It replies with
// status NotReady if not all nodes in the ring have joined. Once
// all nodes have joined, it should reply with status OK and a list
// of all connected nodes in the ring.
func (ss *storageServer) RegisterServer(args *storagerpc.RegisterArgs, reply *storagerpc.RegisterReply) error {

	ss.rMutex.Lock()
	defer ss.rMutex.Unlock()

	// check if this server has already joined
	_, ok := ss.ringSet[args.ServerInfo]
	if !ok {
		fmt.Println("MasterSide: Register a new Slave Storage Server.", args.ServerInfo)
		ss.ring = append(ss.ring, args.ServerInfo)
		ss.ringSet[args.ServerInfo] = 1
	} else {
		//		fmt.Println("MasterSide: Ignore one slave storage server.", args.ServerInfo);
	}

	if len(ss.ring) == ss.totalNode {
		// if the connection is finished
		reply.Servers = ss.ring
		reply.Status = storagerpc.OK
		//ss.iCond.Signal()
		if !ok {
			ss.masterReady <- 1
		}
		fmt.Println("****Register Function: all node registered.")
	} else {
		reply.Status = storagerpc.NotReady
		//		fmt.Println("Registration not ready:", len(ss.ring), ss.totalNode)
	}

	return nil
}
开发者ID:wentianqi7,项目名称:15640-distributed-systems,代码行数:35,代码来源:storageserver_impl.go

示例5: RegisterServer

func (ss *storageServer) RegisterServer(args *storagerpc.RegisterArgs, reply *storagerpc.RegisterReply) error {
	ss.serverMutex.Lock()
	defer ss.serverMutex.Unlock()
	if ss.isMaster == true {
		serverInfo := args.ServerInfo
		exist := ss.serverExist(serverInfo)
		if exist == false {
			ss.serverList.PushBack(serverInfo)
		}
		if ss.serverList.Len() < ss.numNodes {
			reply.Status = storagerpc.NotReady
			reply.Servers = nil
		} else if ss.serverList.Len() == ss.numNodes {
			reply.Status = storagerpc.OK
			reply.Servers = list2SliceNode(ss.serverList)
			sort.Sort(serverList(reply.Servers))
			ss.serverList.Init()
			// ss.serverList = *list.New()
			for i := 0; i < len(reply.Servers); i++ {
				ss.serverList.PushBack(reply.Servers[i])
			}
			reply.Servers = list2SliceNode(ss.serverList)
			if exist == false {
				ss.isReady = true
				ss.storageServerReady <- 1
			}
		} else {
			return errors.New("Error registered server number overflow")
		}
	} else {
		fmt.Println("Fatal Error")
		return errors.New("Error register with slave server")
	}
	return nil
}
开发者ID:thuhujin,项目名称:Tribbler,代码行数:35,代码来源:storageserver_impl.go

示例6: RegisterServer

func (ss *storageServer) RegisterServer(args *storagerpc.RegisterArgs, reply *storagerpc.RegisterReply) error {
	if !ss.isMaster {
		return errors.New("server is not a master")
	}

	ss.infoRWL.Lock()
	defer ss.infoRWL.Unlock()

	if ss.isReady {
		reply.Status = storagerpc.OK
	} else {
		reply.Status = storagerpc.NotReady

		// add to cluster
		if _, exisit := ss.servers[args.ServerInfo.NodeID]; !exisit {
			ss.servers[args.ServerInfo.NodeID] = &args.ServerInfo
		}
		if len(ss.servers) == ss.numNodes {
			ss.isReady = true
			reply.Status = storagerpc.OK
			close(ss.readyChan)
		}
	}

	for k := range ss.servers {
		reply.Servers = append(reply.Servers, *ss.servers[k])
	}

	return nil
}
开发者ID:oldady,项目名称:ds_p2,代码行数:30,代码来源:storageserver_impl.go

示例7: RegisterServer

func (ss *storageServer) RegisterServer(args *storagerpc.RegisterArgs, reply *storagerpc.RegisterReply) error {
	ss.dataLock.Lock()
	defer ss.dataLock.Unlock()
	node := args.ServerInfo
	_, ok := ss.seenNodes[node.NodeID]
	if !ok {
		ss.seenNodes[node.NodeID] = true
		ss.servers[ss.nextNode] = node
		ss.nextNode++
	}
	if ss.nextNode == ss.numNodes {
		reply.Status = storagerpc.OK
		reply.Servers = ss.servers
		if !ss.allServersReadyBool {
			ss.allServersReady <- 1
		}
	} else {
		reply.Status = storagerpc.NotReady
		reply.Servers = nil
	}
	return nil
}
开发者ID:aditij1,项目名称:p2aditijakkamat,代码行数:22,代码来源:storageserver_impl.go

示例8: RegisterServer

func (ss *storageServer) RegisterServer(args *storagerpc.RegisterArgs, reply *storagerpc.RegisterReply) error {
	serverInfo := args.ServerInfo
	_, ok := ss.nodeIdMap[serverInfo.NodeID]
	if !ok {
		ss.nodeIdMap[serverInfo.NodeID] = args.ServerInfo
		ss.nodesList = append(ss.nodesList, args.ServerInfo)
	}

	if len(ss.nodeIdMap) < ss.nodeSize {
		reply.Status = storagerpc.NotReady
	} else {
		reply.Status = storagerpc.OK
		reply.Servers = ss.nodesList
		ss.cMutex.Lock()
		ss.informedCount += 1
		ss.cMutex.Unlock()
		if ss.informedCount == ss.nodeSize-1 {
			ss.serverFull <- 1
		}
	}
	return nil
}
开发者ID:iedwardwangi,项目名称:Tribbler,代码行数:22,代码来源:storageserver_impl.go

示例9: RegisterServer

func (ss *storageServer) RegisterServer(args *storagerpc.RegisterArgs, reply *storagerpc.RegisterReply) error {
	//Add to node map if it's a new slave
	_, exist := ss.nodeMap[args.ServerInfo.NodeID]
	if !exist {
		ss.nodeMap[args.ServerInfo.NodeID] = args.ServerInfo
	}

	//RPC reply
	if len(ss.nodeMap) < ss.numNodes {
		reply.Status = storagerpc.NotReady
	} else {
		i := 0
		for _, node := range ss.nodeMap {
			ss.nodeList[i] = node
			i = i + 1
		}

		reply.Status = storagerpc.OK
		reply.Servers = ss.nodeList
	}

	return nil
}
开发者ID:oldady,项目名称:Tribbler,代码行数:23,代码来源:storageserver_impl.go


注:本文中的github.com/cmu440/tribbler/rpc/storagerpc.RegisterReply类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。