コード例 #1
0
ファイル: busserver.go プロジェクト: skOak/chestnut
func (bs *BusServer) OnRegister(regServer ServerConfig, grantService *ServiceCert) (err error) {
	log.Printf("OnRegister:regServer(%+v)\n", regServer)
	if grantService == nil {
		return errorNullPointer
	}

	ns := new(Server)
	nsAddr := fmt.Sprintf("%s:%d", regServer.Host, regServer.Port)
	ns.RPCClient, err = myrpc.Open(regServer.Network, nsAddr, myrpc.RPCDefaultMaxConn, myrpc.RPCDefaultMaxIdle, bs.OnMyRpcConnsBroken)
	if err != nil {
		return
	}
	err = ns.RPCClient.Ping()
	if err != nil {
		return
	}
	ns.ServerConfig = regServer

	err = bs.addServer(ns)
	if err != nil {
		return
	}

	grantService.ServiceId = ns.ServiceInfo.ServiceId
	grantService.Cert = ns.ServiceInfo.Cert
	log.Printf("OnRegister:serviceByType(%v)\n", bs.serviceByType)
	log.Printf("OnRegister:serviceById(%v)\n", bs.serviceById)
	log.Printf("OnRegister:serviceByMethod(%v)\n", bs.serviceByMethod)
	log.Printf("OnRegister:serviceAddrByType(%v)\n", bs.serviceAddrByType)
	log.Printf("OnRegister:priorServiceByType(%v)\n", bs.priorServiceByType)
	log.Printf("OnRegister:priorServiceByMethod(%v)\n", bs.priorServiceByMethod)
	return nil
}
コード例 #2
0
ファイル: busstub.go プロジェクト: skOak/chestnut
func (bs *BusStub) Init(selfServerInfo, busServerInfo *ServerConfig) (err error) {
	if selfServerInfo == nil || busServerInfo == nil {
		return errorNullPointer
	}
	bs.selfServer = *selfServerInfo

	bs.busServer = new(Server)
	bs.busServer.ServerConfig = *busServerInfo

	bServerAddr := fmt.Sprintf("%s:%d", bs.busServer.Host, bs.busServer.Port)
	bs.busServer.RPCClient, err = myrpc.Open(bs.busServer.Network, bServerAddr, myrpc.RPCDefaultMaxConn, myrpc.RPCDefaultMaxIdle, bs.OnMyRpcConnsBroken)
	if err != nil {
		return
	}
	if bs.busServer.RPCClient == nil {
		return errorBusServerConnect
	}

	err = bs.busServer.RPCClient.Ping()
	if err != nil {
		return
	}

	bs.serviceByType = make(map[string]*Server)
	bs.serviceById = make(map[int]*Server)
	bs.serviceByMethod = make(map[string]*Server)

	return
}
コード例 #3
0
ファイル: busstub.go プロジェクト: skOak/chestnut
// connect to the specific server
// connectType : reserved
func (bs *BusStub) connectService(dstServer *Server, connectType int) (err error) {
	if dstServer == nil {
		return errorNullPointer
	}
	serverAddr := fmt.Sprintf("%s:%d", dstServer.Host, dstServer.Port)
	dstServer.RPCClient, err = myrpc.Open(dstServer.Network, serverAddr, myrpc.RPCDefaultMaxConn, myrpc.RPCDefaultMaxIdle, bs.OnMyRpcConnsBroken)
	if err != nil {
		return
	}
	if dstServer.RPCClient == nil {
		return errorServerUnreachable
	}

	return dstServer.RPCClient.Ping()
}