Exemple #1
0
// Serve starts service for the given Computation.
//
// Must be called from main() function of worker.
func Serve(comp Computation) error {
	bindAddr := os.Getenv(bolt.KConcordEnvKeyClientListenAddr)
	proxyAddr := os.Getenv(bolt.KConcordEnvKeyClientProxyAddr)

	// Init transport
	transport, err := thrift.NewTServerSocket(bindAddr)
	if err != nil {
		panic("failed to create server")
	}
	factory := thrift.NewTTransportFactory()
	transportF := thrift.NewTFramedTransportFactory(factory)

	protocolF := thrift.NewTBinaryProtocolFactoryDefault()

	proxy, err := newProxy(proxyAddr, comp.Metadata())
	if err != nil {
		panic("failed to initialize proxy")
	}

	service := newComputationService(comp, proxy)

	processor := bolt.NewComputationServiceProcessor(service)

	srv := thrift.NewTSimpleServer4(processor, transport, transportF, protocolF)
	return srv.Serve()
}
Exemple #2
0
func (t *ThriftExporter) Export(serviceName string, processor thrift.TProcessor) (err error) {
	var transport thrift.TServerTransport
	if t.Config.Secure {
		cfg := new(tls.Config)
		if cert, err := tls.LoadX509KeyPair(t.Config.CertFile, t.Config.KeyFile); err == nil {
			cfg.Certificates = append(cfg.Certificates, cert)
		} else {
			return err
		}
		transport, err = thrift.NewTSSLServerSocket(t.Provider.Addr, cfg)
	} else {
		transport, err = thrift.NewTServerSocket(t.Provider.Addr)
	}

	if err != nil {
		return err
	}
	server := thrift.NewTSimpleServer4(processor, transport, t.Config.TransFactory, t.Config.ProtocolFactory)

	err = t.Reg.Register(serviceName, t.Provider)
	if err != nil {
		fmt.Println("error when register service", err.Error())
		return
	}
	fmt.Println("Starting the simple server... on ", t.Provider.Addr)
	return server.Serve()
}
Exemple #3
0
func runServer(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string, secure bool) error {
	var transport thrift.TServerTransport
	var err error
	transport, err = thrift.NewTServerSocket(addr)
	if err != nil {
		return err
	}
	fmt.Printf("Transport: %T\n", transport)

	handler := NewAwesomeServiceHandler()

	SharedTypes = awesome_service.NewTypes()
	var f float64 = 1
	b := true
	s := "A"
	SharedTypes.ShortValue = 1
	SharedTypes.IntValue = 1
	SharedTypes.LongValue = 1
	SharedTypes.DoubleValue = &f
	SharedTypes.BoolValue = &b
	SharedTypes.StringValue = &s
	SharedTypes.ListValue = []string{"A"}
	SharedTypes.SetValue = map[string]bool{"A": true}
	SharedTypes.MapValue = make(map[string]int32)
	// var i int32
	for i := 0; i < 50000; i++ {
		SharedTypes.MapValue[strconv.Itoa(i)] = int32(i)
	}

	processor := awesome_service.NewAwesomeServiceProcessor(handler)
	server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)

	fmt.Println("Starting the simple server... on ", addr)
	return server.Serve()
}
Exemple #4
0
// NewHbaseServer starts an self-implementation hbase
func NewHbaseServer(hb Hbase) (*TestServer, error) {

	port, _ := GetPort()
	addr := fmt.Sprintf(":%d", port)

	// fork a goroutine to serve requests
	var transportFactory thrift.TTransportFactory
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	transportFactory = thrift.NewTBufferedTransportFactory(8192)
	transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
	transport, err := thrift.NewTServerSocket(addr)
	if err != nil {
		log.Fatal(err)
	}
	srv := thrift.NewTSimpleServer4(
		NewHbaseProcessor(hb),
		transport,
		transportFactory,
		protocolFactory,
	)
	if err := srv.Listen(); err != nil {
		log.Fatal(err)
	}
	go srv.AcceptLoop()

	// TODO: stop server when stop chan is closed
	return &TestServer{
		Port: port,
		stop: make(chan struct{}),
	}, nil
}
Exemple #5
0
func runServer(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string, secure bool) error {
	var transport thrift.TServerTransport
	var err error
	if secure {
		cfg := new(tls.Config)
		if cert, err := tls.LoadX509KeyPair("server.crt", "server.key"); err == nil {
			cfg.Certificates = append(cfg.Certificates, cert)
		} else {
			return err
		}
		transport, err = thrift.NewTSSLServerSocket(addr, cfg)
	} else {
		transport, err = thrift.NewTServerSocket(addr)
	}

	if err != nil {
		return err
	}
	fmt.Printf("%T\n", transport)
	handler := NewCalculatorHandler()
	processor := tutorial.NewCalculatorProcessor(handler)
	server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)

	fmt.Println("Starting the simple server... on ", addr)
	return server.Serve()
}
Exemple #6
0
//
// 两参数是必须的:  ProductName, zkAddress, frontAddr可以用来测试
//
func (p *ProxyServer) Run() {

	var transport thrift.TServerTransport
	var err error

	log.Printf(Magenta("Start Proxy at Address: %s"), p.proxyAddr)
	// 读取后端服务的配置
	isUnixDomain := false
	if !strings.Contains(p.proxyAddr, ":") {
		if FileExist(p.proxyAddr) {
			os.Remove(p.proxyAddr)
		}
		transport, err = NewTServerUnixDomain(p.proxyAddr)
		isUnixDomain = true
	} else {
		transport, err = thrift.NewTServerSocket(p.proxyAddr)
	}
	if err != nil {
		log.ErrorErrorf(err, "Server Socket Create Failed: %v, Front: %s", err, p.proxyAddr)
	}

	// 开始监听
	//	transport.Open()
	transport.Listen()

	ch := make(chan thrift.TTransport, 4096)
	defer close(ch)

	go func() {
		var address string
		for c := range ch {
			// 为每个Connection建立一个Session
			socket, ok := c.(SocketAddr)
			if isUnixDomain {
				address = p.proxyAddr
			} else if ok {
				address = socket.Addr().String()
			} else {
				address = "unknow"
			}
			x := NewSession(c, address, p.verbose)
			// Session独立处理自己的请求
			go x.Serve(p.router, 1000)
		}
	}()

	// Accept什么时候出错,出错之后如何处理呢?
	for {
		c, err := transport.Accept()
		if err != nil {
			log.ErrorErrorf(err, "Accept Error: %v", err)
			break
		} else {
			ch <- c
		}
	}
}
// run a test flume agent
func runDummyFlumeAgent(t *testing.T) {
	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTCompactProtocolFactory()
	transport, _ := thrift.NewTServerSocket("localhost:51515")

	handler := thriftSourceProtocolHandler{t}
	processor := flume.NewThriftSourceProtocolProcessor(handler)
	server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)
	server.Serve()
}
func main() {
	dcacheHandler := NewDcacheHandler()
	dcacheServiceProcessor := dcache.NewDcacheServiceProcessor(dcacheHandler)
	ssock, err := thrift.NewTServerSocket("127.0.0.1:9090")
	if err != nil {
		panic("Problem in creating transport")
	}
	server := thrift.NewTSimpleServer4(dcacheServiceProcessor, ssock,
		thrift.NewTBufferedTransportFactory(204800), thrift.NewTBinaryProtocolFactoryDefault())
	server.Serve()
}
Exemple #9
0
func runServer(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string) error {
	transport, err = thrift.NewTServerSocket(addr) //simple case
	if err != nil {
		return err
	}
	handler := &dataServiceProcessorPull{}
	processor := crawler.NewDataServiceProcessor(handler)
	server := thrift.NewTSimpleServer(processor, transport, transportFactory, protocolFactory)
	fmt.Println("Starting the simple server... on ", transport.Addr())
	server.serve()
}
Exemple #10
0
func main() {
	handler := NewCoffeeOrderHandler()
	processor := co.NewCoffeeOrderProcessor(handler)
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	transportFactory := thrift.NewTTransportFactory()
	serverTransport, err := thrift.NewTServerSocket("0.0.0.0:9090")
	if err != nil {
		log.Println(err)
	}
	server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
	server.Serve()
}
Exemple #11
0
func runServer(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string) error {
	transport, err := thrift.NewTServerSocket(addr)
	if err != nil {
		return err
	}
	handler := NewCalculatorHandler()
	processor := tutorial.NewCalculatorProcessor(handler)
	server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)

	fmt.Println("Starting the simple server... on ", transport.Addr())
	return server.Serve()
}
Exemple #12
0
func main() {
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	transport, err := thrift.NewTServerSocket("localhost:8090")
	if err != nil {
		fmt.Printf("There was an error creating your socket! Here it is %v", err)
	}
	transportFactory := thrift.NewTTransportFactory()
	processor := service.NewMakeTagsProcessor(handler.NewTagsHandler(os.Getenv("ACCESS_TOKEN")))
	server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)
	fmt.Printf("server listening on %s\n", "localhost:8090")
	server.Serve()
}
func main() {
	transport, err := thrift.NewTServerSocket("localhost:3636")
	if err != nil {
		panic(err)
	}

	proc := hello.NewHelloProcessor(&HelloHandler{})
	server := thrift.NewTSimpleServer4(
		proc,
		transport,
		thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()),
		thrift.NewTBinaryProtocolFactoryDefault())

	println(server.Serve())
}
Exemple #14
0
func main() {
	var protocolFactory thrift.TProtocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
	var transportFactory thrift.TTransportFactory = thrift.NewTBufferedTransportFactory(8192)
	transport, err := thrift.NewTServerSocket(NetworkAddr)
	if err != nil {
		fmt.Println("Error!", err)
		os.Exit(1)
	}

	handler := NewGreeterHandler()
	processor := greeter.NewGreeterProcessor(handler)
	server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)
	fmt.Println("Starting the simple server... on ", NetworkAddr)
	server.Serve()
}
Exemple #15
0
func New(addr string, processor *thrift.TProcessor) (*Server, error) {
	// Instantiate the thrift server components
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	transportFactory := thrift.NewTTransportFactory()
	transport, err := thrift.NewTServerSocket(addr)
	if err != nil {
		return nil, err
	}

	wait := make(chan error)

	s := Server{Addr: addr, wait: wait, Wait: wait}
	s.server = thrift.NewTSimpleServer4(*processor, transport, transportFactory, protocolFactory)

	return &s, nil
}
Exemple #16
0
func runServer(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string) error {
	var transport thrift.TServerTransport
	var err error
	transport, err = thrift.NewTServerSocket(addr)

	if err != nil {
		fmt.Println(err)
	}
	fmt.Printf("%T\n", transport)
	handler := NewHelloHandler()
	processor := hello.NewHelloProcessor(handler)
	server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)

	fmt.Println("Starting the simple server... on ", addr)
	return server.Serve()
}
func runServer(listenIp *string, listenPort *int, backendIp *string, backendPort *int, debug *bool) error {
	transport, err := thrift.NewTServerSocket(fmt.Sprintf("%s:%d", *listenIp, *listenPort))
	if err != nil {
		return err
	}

	transportFactory := thrift.NewTTransportFactory()
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()

	handler := NewDataStoreHandler(backendIp, backendPort, debug)
	processor := messages.NewDataStoreProcessor(handler)
	server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)

	logger.Printf("Thrift Service configured")
	return server.Serve()
}
Exemple #18
0
func main() {
	var listen string = ":10001"

	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	serverTransport, err := thrift.NewTServerSocket(listen)
	if err != nil {
		fmt.Println("error, thrift init!")
		return
	}
	handler := &Puller{0}
	processor := puller.NewPullerProcessor(handler)
	server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
	fmt.Printf("server started\n")
	server.Serve()
}
Exemple #19
0
func main() {
	handler := &HelloServiceImpl{}
	processor := hello.NewHelloServiceProcessor(handler)

	listenSocket, err := thrift.NewTServerSocket(":8787")
	if err != nil {
		panic(err)
	}

	server := thrift.NewTSimpleServer2(processor, listenSocket)
	fmt.Println("Server ready")

	if err := server.Serve(); err != nil {
		panic(err)
	}
}
Exemple #20
0
func runThriftServer(host string, port int, protocol string, framed bool, buffered bool, workerId uint64, datacenterId uint64) {
	var protocolFactory thrift.TProtocolFactory
	switch protocol {
	case "compact":
		protocolFactory = thrift.NewTCompactProtocolFactory()
	case "simplejson":
		protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
	case "json":
		protocolFactory = thrift.NewTJSONProtocolFactory()
	case "binary", "":
		protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
	default:
		fmt.Fprint(os.Stderr, "Invalid protocol specified", protocol, "\n")
		Usage()
		os.Exit(1)
	}

	var transportFactory thrift.TTransportFactory
	if buffered {
		transportFactory = thrift.NewTBufferedTransportFactory(8192)
	} else {
		transportFactory = thrift.NewTTransportFactory()
	}

	if framed {
		transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
	}

	var err error
	var transport thrift.TServerTransport
	transport, err = thrift.NewTServerSocket(fmt.Sprintf("%s:%d", host, port))
	if err != nil {
		log.Fatal(err)
		os.Exit(1)
	}

	worker, err := idworker.NewIdWorker(workerId, datacenterId)

	processor := snowflake.NewSnowflakeProcessor(worker)

	if err == nil {
		server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)
		server.Serve()
	} else {
		log.Fatal(err)
	}
}
func runFakeRender(addr string) {
	var tTS fakeRender
	processor := gopnikrpc.NewRenderProcessor(&tTS)

	transport, err := thrift.NewTServerSocket(addr)
	if err != nil {
		panic(err)
	}
	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()

	server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)

	if err = server.Serve(); err != nil {
		panic(err)
	}
}
Exemple #22
0
func rpcListen(addr string) {
	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()

	serverTransport, err := thrift.NewTServerSocket(addr)
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(1)
	}

	handler := &MessageServiceImpl{}
	processor := message.NewMessageServiceProcessor(handler)

	server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
	fmt.Println("thrift server in", addr)
	server.Serve()
}
Exemple #23
0
func startThriftService() {
	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()

	serverTransport, err := thrift.NewTServerSocket(global.ServeAddr)
	if err != nil {
		fmt.Println("Error!", err)
		os.Exit(1)
	}

	handler := &services.UUIDGenerator{}
	processor := uuid.NewGeneratorProcessor(handler)

	server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
	fmt.Println("thrift server in", global.ServeAddr)
	server.Serve()
}
Exemple #24
0
func main() {
	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()

	serverTransport, err := thrift.NewTServerSocket(NetworkAddr)
	if err != nil {
		fmt.Println("Error!", err)
		os.Exit(1)
	}

	handler := &RpcServiceImpl{}
	processor := push.NewPushServiceProcessor(handler)

	server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
	fmt.Println("thrift server in", NetworkAddr)
	server.Serve()
}
func (s *ThriftService) Start(addr string) error {
	log.Printf("[thrift] starting service at %s", addr)

	transport, err := thrift.NewTServerSocket(addr)
	if err != nil {
		log.Fatal(err)
	}

	server := thrift.NewTSimpleServer4(
		candy.NewCandyProcessor(s),
		transport,
		thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()),
		thrift.NewTBinaryProtocolFactoryDefault(),
		//thrift.NewTDebugProtocolFactory(thrift.NewTJSONProtocolFactory(), "[json]"),
	)

	return server.Serve()
}
Exemple #26
0
func serverStub() {
	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	//protocolFactory := thrift.NewTCompactProtocolFactory()

	serverTransport, err := thrift.NewTServerSocket(NetworkAddr)
	if err != nil {
		log.Error("Error!", err)
		return
	}

	handler := &RpcServiceImpl{}
	processor := demo.NewRpcServiceProcessor(handler)

	server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
	log.Trace("thrift server in", NetworkAddr)
	server.Serve()
}
func RunServer(addr string, tileServer *TileServer) error {
	tTS := &thriftTileServer{
		tileServer: tileServer,
		Service:    rpcbaseservice.NewService(),
	}
	processor := gopnikrpc.NewRenderProcessor(tTS)

	transport, err := thrift.NewTServerSocket(addr)
	if err != nil {
		return err
	}
	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()

	server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)

	return server.Serve()
}
func TestMain(m *testing.M) {
	transportFactory = thrift.NewTBufferedTransportFactory(8192)
	transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
	protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()

	serverTransport, err := thrift.NewTServerSocket("127.0.0.1:0")
	if err != nil {
		panic(err)
	}
	// call listen here to avoid synchronizing server.serve with test cases
	if err = serverTransport.Listen(); err != nil {
		panic(err)
	}
	serverAddr = serverTransport.Addr()
	handler := &ExampleHandler{}
	processor := example.NewExampleProcessor(handler)
	server := thrift.NewTSimpleServer6(processor, serverTransport, transportFactory, transportFactory, protocolFactory, protocolFactory)
	go server.Serve()
	os.Exit(m.Run())
}
Exemple #29
0
func runServer(addr string, workQueue chan ops.Work) error {
	transport, err := thrift.NewTServerSocket(addr)
	if err != nil {
		return err
	}
	fmt.Printf("%T\n", transport)

	transportFactory := thrift.NewTTransportFactory()
	if transportFactory == nil {
		fmt.Println("Failed to create new TransportFactory")
		return nil
	}
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()

	handler := NewOpsHandler(workQueue)
	processor := ops.NewProducerProcessor(handler)
	server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)

	fmt.Println("Starting the simple server... on ", addr)
	return server.Serve()
}
Exemple #30
0
func main() {
	handler := UserServicerHandler{}
	processor := shared.NewBinaryMessengerProcessor(handler)
	//addr := beego.AppConfig.String("socketAddress")
	addr := "localhost:3001"

	var transport thrift.TServerTransport
	var err error

	if transport, err = thrift.NewTServerSocket(addr); err != nil {
		panic(err)
		//panic("Unable to initialize socket!")
	}

	transportFactory := thrift.NewTTransportFactory()
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()

	server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)
	fmt.Printf("server started on %v\n", addr)
	server.Serve()
}