예제 #1
0
파일: admin.go 프로젝트: musicglue/skynet
func (a *Admin) Stop(in skynet.StopRequest) (out skynet.StopResponse, err error) {
	conn, err := net.Dial("tcp", a.Instance.Config.AdminAddr.String())
	if err != nil {
		return
	}
	rpcClient := bsonrpc.NewClient(conn)
	err = rpcClient.Call("Admin.Stop", in, &out)
	rpcClient.Close()
	return
}
예제 #2
0
파일: client.go 프로젝트: musicglue/skynet
func getConnectionFactory(s *skynet.ServiceInfo) (factory pools.Factory) {
	factory = func() (pools.Resource, error) {
		conn, err := net.Dial("tcp", s.Config.ServiceAddr.String())

		if err != nil {
			// TODO: handle failure here and attempt to connect to a different instance
			return nil, errors.New("Failed to connect to service: " + s.Config.ServiceAddr.String())
		}

		// get the service handshake
		var sh skynet.ServiceHandshake
		decoder := bsonrpc.NewDecoder(conn)

		err = decoder.Decode(&sh)
		if err != nil {
			conn.Close()
			return nil, err
		}

		ch := skynet.ClientHandshake{}
		encoder := bsonrpc.NewEncoder(conn)

		err = encoder.Encode(ch)
		if err != nil {
			conn.Close()
			return nil, err
		}

		if !sh.Registered {
			// this service has unregistered itself, look elsewhere
			conn.Close()
			return factory()
		}

		resource := ServiceResource{
			rpcClient: bsonrpc.NewClient(conn),
			service:   s,
			clientID:  sh.ClientID,
		}

		return resource, nil
	}
	return
}