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


Golang rpc.RegisterName函数代码示例

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


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

示例1: startHTTPJSONRPC

func startHTTPJSONRPC() (string, *mockSessionStatePluginProxy) {
	encr := encrypter.New(&key.PublicKey, nil)
	encr.Key = symkey
	ee := encoding.NewJsonEncoder()
	ee.SetEncrypter(encr)
	mockProxy := &mockProxy{e: ee}
	mockCollectorProxy := &mockCollectorProxy{e: ee}
	rpc.RegisterName("Collector", mockCollectorProxy)
	rpc.RegisterName("Processor", mockProxy)
	rpc.RegisterName("Publisher", mockProxy)
	session := &mockSessionStatePluginProxy{e: ee}
	rpc.RegisterName("SessionState", session)
	rpc.HandleHTTP()

	l, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil {
		panic(err)
	}
	go func() {
		http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
			defer req.Body.Close()
			w.Header().Set("Content-Type", "application/json")
			res := plugin.NewRPCRequest(req.Body).Call()
			io.Copy(w, res)
		})
		http.Serve(l, nil)
	}()

	return l.Addr().String(), session
}
开发者ID:jeffweiss,项目名称:snap,代码行数:30,代码来源:httpjsonrpc_test.go

示例2: NewLibstore

// NewLibstore creates a new instance of a TribServer's libstore. masterServerHostPort
// is the master storage server's host:port. myHostPort is this Libstore's host:port
// (i.e. the callback address that the storage servers should use to send back
// notifications when leases are revoked).
//
// The mode argument is a debugging flag that determines how the Libstore should
// request/handle leases. If mode is Never, then the Libstore should never request
// leases from the storage server (i.e. the GetArgs.WantLease field should always
// be set to false). If mode is Always, then the Libstore should always request
// leases from the storage server (i.e. the GetArgs.WantLease field should always
// be set to true). If mode is Normal, then the Libstore should make its own
// decisions on whether or not a lease should be requested from the storage server,
// based on the requirements specified in the project PDF handout.  Note that the
// value of the mode flag may also determine whether or not the Libstore should
// register to receive RPCs from the storage servers.
//
// To register the Libstore to receive RPCs from the storage servers, the following
// line of code should suffice:
//
//     rpc.RegisterName("LeaseCallbacks", librpc.Wrap(libstore))
//
// Note that unlike in the NewTribServer and NewStorageServer functions, there is no
// need to create a brand new HTTP handler to serve the requests (the Libstore may
// simply reuse the TribServer's HTTP handler since the two run in the same process).
func NewLibstore(masterServerHostPort, myHostPort string, mode LeaseMode) (Libstore, error) {
	fmt.Println("New an libstore")

	client, err := rpc.DialHTTP("tcp", masterServerHostPort)
	if err != nil {
		// log.Fatalln("dialing:", err)
		return nil, errors.New("meet error when DialHTTP")
	}

	args := &storagerpc.GetServersArgs{}
	reply := &storagerpc.GetServersReply{}

	num := 0
	for reply.Status != storagerpc.OK {

		if num >= 5 {
			return nil, errors.New("cannot find the storage server")
		}

		err = client.Call("StorageServer.GetServers", args, reply)
		if err != nil {
			return nil, errors.New("meet error when client call")

		}
		if reply.Status != storagerpc.OK {
			time.Sleep(1000 * time.Millisecond)
		}
		num++
	}

	libstore := &libstore{
		Servers: reply.Servers,
		// keyValueMutex:     make(map[string]*sync.Mutex),
		// keyListMutex:      make(map[string]*sync.Mutex),
		mutex: &sync.Mutex{},

		// client: client,
		keyValue:        make(map[string]*valuelib),
		keylist:         make(map[string]*listlib),
		keyValudhistory: make(map[string]*list.List),
		keyListhistory:  make(map[string]*list.List),
		keyValueMutex:   make(map[string]*sync.Mutex),
		keyListMutex:    make(map[string]*sync.Mutex),
		mode:            mode,
		clientmap:       make(map[string]*rpc.Client),
		myHostPort:      myHostPort,
	}
	libstore.clientmap[masterServerHostPort] = client
	err = rpc.RegisterName("LeaseCallbacks", librpc.Wrap(libstore))
	// retry until register sucessfully
	for err != nil {
		err = rpc.RegisterName("LeaseCallbacks", librpc.Wrap(libstore))
	}

	go libstore.epochtime()
	return libstore, nil
	// return nil, errors.New("not implemented")

}
开发者ID:Karthikvb,项目名称:15640_projects,代码行数:83,代码来源:libstore_impl.go

示例3: NewLibstore

// NewLibstore creates a new instance of a TribServer's libstore. masterServerHostPort
// is the master storage server's host:port. myHostPort is this Libstore's host:port
// (i.e. the callback address that the storage servers should use to send back
// notifications when leases are revoked).
//
// The mode argument is a debugging flag that determines how the Libstore should
// request/handle leases. If mode is Never, then the Libstore should never request
// leases from the storage server (i.e. the GetArgs.WantLease field should always
// be set to false). If mode is Always, then the Libstore should always request
// leases from the storage server (i.e. the GetArgs.WantLease field should always
// be set to true). If mode is Normal, then the Libstore should make its own
// decisions on whether or not a lease should be requested from the storage server,
// based on the requirements specified in the project PDF handout.  Note that the
// value of the mode flag may also determine whether or not the Libstore should
// register to receive RPCs from the storage servers.
//
// To register the Libstore to receive RPCs from the storage servers, the following
// line of code should suffice:
//
//     rpc.RegisterName("LeaseCallbacks", librpc.Wrap(libstore))
//
// Note that unlike in the NewTribServer and NewStorageServer functions, there is no
// need to create a brand new HTTP handler to serve the requests (the Libstore may
// simply reuse the TribServer's HTTP handler since the two run in the same process).
func NewLibstore(masterServerHostPort, myHostPort string, mode LeaseMode) (Libstore, error) {
	client, err := rpc.DialHTTP("tcp", masterServerHostPort)
	if err != nil {
		return nil, errors.New("Error DialHTTP in NewLibstore")
	}
	args := &storagerpc.GetServersArgs{}
	reply := &storagerpc.GetServersReply{}
	storageReady := false
	for i := 0; i < 5; i++ {
		err = client.Call("StorageServer.GetServers", args, reply)
		if err != nil {
			return nil, errors.New("Error Call in NewLibstore")
		}
		if reply.Status == storagerpc.OK {
			storageReady = true
			break
		} else {
			time.Sleep(1 * time.Second)
		}
	}
	if storageReady == false {
		return nil, errors.New("Storage not ready after 5 trial in NewLibstore")
	}
	ls := &libstore{
		StorageServers: reply.Servers,
		connectionMap:  make(map[string]*rpc.Client),
		HostPort:       myHostPort,
		CacheValueSet:  make(map[string]*valueCache),
		CacheListSet:   make(map[string]*listCache),
		queryGetQueue:  make(map[string]*list.List),
		queryListQueue: make(map[string]*list.List),
		queryGetMutex:  make(map[string]*sync.Mutex),
		queryListMutex: make(map[string]*sync.Mutex),
		mutex:          &sync.Mutex{},
		mode:           mode,
	}
	ls.connectionMap[masterServerHostPort] = client
	err = rpc.RegisterName("LeaseCallbacks", librpc.Wrap(ls))
	for err != nil {
		fmt.Println("Error LeaseCallbacks in NewLibstore")
		// return nil, errors.New("Error LeaseCallbacks in NewLibstore")
		err = rpc.RegisterName("LeaseCallbacks", librpc.Wrap(ls))
	}
	go func() {
		for {
			select {
			case <-time.After(time.Duration(storagerpc.LeaseSeconds/2) * time.Second):
				ls.updateCache()
			case <-time.After(time.Duration(storagerpc.QueryCacheSeconds/2) * time.Second):
				ls.updateQueue()
			}
		}
	}()
	return ls, nil
}
开发者ID:thuhujin,项目名称:Tribbler,代码行数:79,代码来源:libstore_impl.go

示例4: NewCentralServer

func NewCentralServer(port, numGameServers int) (CentralServer, error) {
	LOGV.Println("New Central Server is starting up")
	if numGameServers < 1 {
		return nil, errors.New("numGameServers must be at least 1")
	}

	cs := &centralServer{
		numGameServers:       numGameServers,
		gameServers:          make(map[uint32]*gameServer),
		hostPortToGameServer: make(map[string]*gameServer),
		gameServersSlice:     nil,
	}

	// Serve up information for the game client

	http.HandleFunc("/", cs.gameClientViewHandler)
	go http.ListenAndServe(fmt.Sprintf(":%d", port), nil)

	rpc.RegisterName("CentralServer", centralrpc.Wrap(cs))
	rpc.HandleHTTP()
	l, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
	if err != nil {
		return nil, err
	}
	go http.Serve(l, nil)

	return cs, nil
}
开发者ID:papmech,项目名称:Distributed-2048,代码行数:28,代码来源:centralserver_impl.go

示例5: main

func main() {
	scribeService := new(scribeServiceImplementation)
	rpc.RegisterName("Thrift", &scribe.ScribeServer{Implementation: scribeService})
	flag.IntVar(&port, "p", 1463, "Scribe Listen Port")
	flag.StringVar(&kafka_hostname, "o", "localhost:9092", "host:port string for the kafka server")
	flag.IntVar(&partition, "r", 1, "partition to publish to")
	flag.IntVar(&buffer_size, "s", 10, "Buffer Size")
	flag.IntVar(&buffer_time, "t", 10, "Buffer Time")

	flag.Parse()

	fmt.Printf("Quiet! I'm trying to listen to port %d and send to kafka at %s", port, kafka_hostname)
	ln, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
	if err != nil {
		log.Println(err)
	}
	for {
		conn, err := ln.Accept()
		if err != nil {
			fmt.Printf("ERROR: %+v\n", err)
			continue
		}
		fmt.Printf("New connection %+v\n", conn)
		go rpc.ServeCodec(thrift.NewServerCodec(thrift.NewFramedReadWriteCloser(conn, 0), thrift.NewBinaryProtocol(true, false)))
	}
}
开发者ID:siliconcow,项目名称:scribe_kafka_translator,代码行数:26,代码来源:skt.go

示例6: NewStockServer

func NewStockServer(masterHostPort, myHostPort string) (StockServer, error) {
	s := rpc.NewServer()

	ls, err := libstore.NewLibstore(masterHostPort, myHostPort)
	if err != nil {
		return nil, err
	}

	sMap := make(map[string]string)
	ss := &stockServer{
		server:     s,
		ls:         ls,
		sessionMap: sMap,
	}

	listener, err := net.Listen("tcp", myHostPort)
	if err != nil {
		return nil, err
	}

	log.Println("StockServer listening on address: ", myHostPort)

	err = rpc.RegisterName("StockServer", stockrpc.Wrap(ss))
	if err != nil {
		log.Println("Failed to register StockServer RPC")
		return nil, err
	}

	rpc.HandleHTTP()
	go http.Serve(listener, nil)

	return ss, nil
}
开发者ID:investislife,项目名称:p3,代码行数:33,代码来源:stockserver_impl.go

示例7: NewLoadBalancer

func NewLoadBalancer(hostPort string) (LoadBalancer, error) {
	loadBalancer := new(loadBalancer)
	loadBalancer.hostPort = hostPort
	loadBalancer.numCurrentNodes = 0
	loadBalancer.nodes = make([]loadbalancerrpc.Node, loadbalancerrpc.InitCliNum)
	loadBalancer.nodesClientNum = make([]int, loadbalancerrpc.InitCliNum)
	loadBalancer.nodesFailed = make([]bool, loadbalancerrpc.InitCliNum)
	loadBalancer.nodesFailedNumber = 0
	loadBalancer.numOKs = 0

	listener, err := net.Listen("tcp", hostPort)
	if err != nil {
		return nil, err
	}
	// Wrap the tribServer before registering it for RPC.
	err = rpc.RegisterName("LoadBalancer", loadbalancerrpc.Wrap(loadBalancer))
	if err != nil {
		return nil, err
	}

	rpc.HandleHTTP()
	go http.Serve(listener, nil)

	return loadBalancer, nil
}
开发者ID:subnr01,项目名称:chat_with_paxos,代码行数:25,代码来源:loadbalancer_impl.go

示例8: Setup

func Setup(objSrv objectserver.ObjectServer, lg *log.Logger) *htmlWriter {
	objectServer = objSrv
	logger = lg
	rpc.RegisterName("ObjectServer", new(rpcType))
	http.HandleFunc("/GetObjects", getObjectsHandler)
	return &htmlWriter{}
}
开发者ID:JohnTheodore,项目名称:Dominator,代码行数:7,代码来源:api.go

示例9: RPCRegisterName

/**
 * Same as rpc.RegisterName, but wil panic if anything goes wrong
 */
func RPCRegisterName(name string, rcvr interface{}) bool {
	err := rpc.RegisterName(name, rcvr)
	if err != nil {
		return false
	}
	return true
}
开发者ID:kelsebo,项目名称:go-chord,代码行数:10,代码来源:comm.go

示例10: NewLibpaxos

func NewLibpaxos(nodeID uint32, hostport string, allNodes []paxosrpc.Node) (Libpaxos, error) {
	lp := &libpaxos{
		allNodes:                  allNodes,
		majorityCount:             len(allNodes)/2 + 1,
		myNode:                    paxosrpc.Node{nodeID, hostport},
		nodes:                     make(map[uint32]*node),
		newValueCh:                make(chan *paxosrpc.ProposalValue),
		highestProposalNumberSeen: &paxosrpc.ProposalNumber{0, nodeID},
		slotBox:                   NewSlotBox(),
		triggerHandlerCallCh:      make(chan struct{}, 1000),
		newValuesQueue:            list.New(),
	}

	for _, node := range allNodes {
		lp.nodes[node.ID] = NewNode(node)
	}

	// Start the RPC handlers
	rpc.RegisterName("PaxosNode", paxosrpc.Wrap(lp))
	rpc.HandleHTTP()
	l, err := net.Listen("tcp", fmt.Sprintf(hostport))
	if err != nil {
		return nil, err
	}
	go http.Serve(l, nil)

	go lp.controller()
	if DUMP_SLOTS { // Writes the contents of slotbox to file at fixed intervals
		go lp.dumpSlots()
	}

	return lp, nil
}
开发者ID:papmech,项目名称:Distributed-2048,代码行数:33,代码来源:paxos_impl.go

示例11: NewTribServer

// NewTribServer creates, starts and returns a new TribServer. masterServerHostPort
// is the master storage server's host:port and port is this port number on which
// the TribServer should listen. A non-nil error should be returned if the TribServer
// could not be started.
//
// For hints on how to properly setup RPC, see the rpc/tribrpc package.
func NewTribServer(masterServerHostPort, myHostPort string) (TribServer, error) {
	tribServer := new(tribServer)
	ls, err := libstore.NewLibstore(masterServerHostPort, myHostPort, libstore.Normal)
	if err != nil {
		return nil, errors.New("Libstore failed.")
	}

	tribServer.lib_store = ls

	// Create the server socket that will listen for incoming RPCs.
	_, port, _ := net.SplitHostPort(myHostPort)
	listener, err := net.Listen("tcp", fmt.Sprintf(":%s", port))
	if err != nil {
		return nil, err
	}

	// Wrap the tribServer before registering it for RPC.
	err = rpc.RegisterName("TribServer", tribrpc.Wrap(tribServer))
	if err != nil {
		return nil, err
	}

	// Setup the HTTP handler that will server incoming RPCs and
	// serve requests in a background goroutine.
	rpc.HandleHTTP()
	go http.Serve(listener, nil)

	return tribServer, nil
	// return nil, errors.New("not implemented")
}
开发者ID:mallocanswer,项目名称:Tribbler,代码行数:36,代码来源:tribserver_impl.go

示例12: NewCentral

func NewCentral(port int) (Central, error) {
	common.LOGV.Println("$PearCentral on ", port)
	c := central{}
	c.port = port
	c.clientIdCnt = 0
	c.docMap = make(map[string]map[string]bool)
	c.serverMap = make(map[string]map[string]bool)
	c.connMap = make(map[string]*rpc.Client)

	c.myHostPort = fmt.Sprintf("localhost:%d", port)

	// Create the server socket that will listen for incoming RPCs.
	listener, err := net.Listen("tcp", c.myHostPort)
	if err != nil {
		return nil, err
	}

	// Wrap the tribServer before registering it for RPC.
	err = rpc.RegisterName("PearCentral", centralrpc.Wrap(&c))
	if err != nil {
		return nil, err
	}

	// Setup the HTTP handler that will server incoming RPCs and
	// serve requests in a background goroutine.
	rpc.HandleHTTP()
	go http.Serve(listener, nil)

	http.HandleFunc("/", c.NewClient)
	http.ListenAndServe(":"+strconv.Itoa(port), nil)
	return &c, nil
}
开发者ID:CharlesChong,项目名称:PearProgramming,代码行数:32,代码来源:central_impl.go

示例13: NewCoordinator

// NewCoordinator returns the central Coordinator that deals with initial requests from all
// users and dispatch the load to paxos servers
func NewCoordinator(myhostPort string, numPaxos int, hostMap map[int]string) (Coordinator, error) {
	if numPaxos < 1 {
		return nil, errors.New("numPaxos should be more than 0")
	}

	c := &coordinator{
		numPaxos:     numPaxos,
		serversMutex: &sync.Mutex{},
		nextPaxosID:  0,
		serversMap:   make(map[int]string),
		hostMap:      make(map[int]string),
	}
	for nodeID, hostPort := range hostMap {
		c.hostMap[nodeID] = hostPort
	}

	http.HandleFunc("/", c.clientViewHandler)
	go http.ListenAndServe(myhostPort, nil)

	rpc.RegisterName("Coordinator", coordinatorrpc.Wrap(c))
	rpc.HandleHTTP()
	listener, err := net.Listen("tcp", myhostPort)
	if err != nil {
		return nil, err
	}
	go http.Serve(listener, nil)

	return c, nil
}
开发者ID:thuhujin,项目名称:Paxos,代码行数:31,代码来源:coordinator_imp.go

示例14: initTribServer

func initTribServer(masterServerHostPort string, tribServerPort int) error {
	//	l, err := net.Listen("tcp", tribServerHostPort)
	//	if err != nil {
	//		LOGE.Println("Failed to listen:", err)
	//		return nil, err
	//	}

	tribServerHostPort := net.JoinHostPort("localhost", strconv.Itoa(tribServerPort))
	proxyCounter, err := proxycounter.NewProxyCounter(masterServerHostPort, tribServerHostPort)
	if err != nil {
		LOGE.Println("Failed to setup test:", err)
		return err
	}
	pc = proxyCounter

	rpc.RegisterName("StorageServer", storagerpc.Wrap(pc))
	//rpc.HandleHTTP()
	//go http.Serve(l, nil)

	// Create and start the TribServer.
	tribServer, err := tribserver.NewTribServer(masterServerHostPort, tribServerPort)
	if err != nil {
		LOGE.Println("Failed to create TribServer:", err)
		return err
	}
	ts = tribServer
	//rpc.RegisterName("TribServer", tribrpc.Wrap(ts))
	return nil
}
开发者ID:CarterAppleton,项目名称:p2,代码行数:29,代码来源:tribtest.go

示例15: NewTribServer

// NewTribServer creates, starts and returns a new TribServer. masterServerHostPort
// is the master storage server's host:port and port is this port number on which
// the TribServer should listen. A non-nil error should be returned if the TribServer
// could not be started.
//
// For hints on how to properly setup RPC, see the rpc/tribrpc package.
func NewTribServer(masterServerHostPort, myHostPort string) (TribServer, error) {
	newStore, err := libstore.NewLibstore(masterServerHostPort, myHostPort, libstore.Never)
	if err != nil {
		return nil, err
	}

	ts := &tribServer{
		myHostPort: myHostPort,
		Libstore:   newStore,
	}

	err = rpc.RegisterName("TribServer", tribrpc.Wrap(ts))
	if err != nil {
		return nil, err
	}

	rpc.HandleHTTP()
	l, err := net.Listen("tcp", myHostPort)
	if err != nil {
		return nil, err
	}
	go http.Serve(l, nil)

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


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