本文整理匯總了Golang中git/apache/org/thrift/git/lib/go/thrift.NewTBufferedTransportFactory函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewTBufferedTransportFactory函數的具體用法?Golang NewTBufferedTransportFactory怎麽用?Golang NewTBufferedTransportFactory使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewTBufferedTransportFactory函數的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewHbaseServer
// 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
}
示例2: SendSms
func SendSms(msgSend string, phones_slice []int64) {
// random choice host
hosts := []string{"10.231.144.136", "10.231.144.137"}
rk := GenRandn(len(hosts))
host := hosts[rk]
port := "9090"
transport, err := thrift.NewTSocket(net.JoinHostPort(host, port))
if err != nil {
fmt.Fprintln(os.Stderr, "error resolving address:", err)
os.Exit(1)
}
transportFactory := thrift.NewTBufferedTransportFactory(10240)
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
useTransport := transportFactory.GetTransport(transport)
client := sms.NewMessageServiceClientFactory(useTransport, protocolFactory)
if err := transport.Open(); err != nil {
fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err)
os.Exit(1)
}
defer transport.Close()
msg := sms.NewMessage()
msg.Phones = phones_slice
msg.BusinessId = 200100000
msg.Message = msgSend
client.SendMessage(msg)
}
示例3: main
func main() {
flag.Usage = Usage
protocol := flag.String("P", "binary", "Specify the protocol (binary, compact, json, simplejson)")
transport := flag.String("transport", "binary", "Specify transport (framed, buffered, file, memory, zlib)")
buffered := flag.String("buffered", "off", "Use buffered transport")
framed := flag.String("framed", "off", "Use framed transport")
addr := flag.String("addr", "localhost:9090", "Address to listen to")
secure := flag.Bool("secure", false, "Use tls secure transport")
conf_path := flag.String("conf", "nil", "配置文件路徑")
flag.Parse()
if *conf_path == "nil" {
Usage()
os.Exit(1)
}
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 == "on" {
transportFactory = thrift.NewTBufferedTransportFactory(8192)
} else {
transportFactory = thrift.NewTTransportFactory()
}
if *framed == "on" {
transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
}
//獲取配置文件的路徑
complete_path(conf_path)
//初始化控製層
handler.Init(*conf_path)
if err := runServer(transportFactory, *transport, protocolFactory, *addr, *secure); err != nil {
fmt.Println("error running server:", err)
}
}
示例4: main
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()
}
示例5: main
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()
}
示例6: main
func main() {
flag.Usage = Usage
server := flag.Bool("server", false, "Run server")
protocol := flag.String("P", "binary", "Specify the protocol (binary, compact, json, simplejson)")
framed := flag.Bool("framed", false, "Use framed transport")
buffered := flag.Bool("buffered", false, "Use buffered transport")
addr := flag.String("addr", nats.DefaultURL, "NATS address to connect to")
secure := flag.Bool("secure", false, "Use tls secure transport")
flag.Parse()
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)
}
if *server {
if err := runServer(transportFactory, protocolFactory, *addr, *secure); err != nil {
fmt.Println("error running server:", err)
}
} else {
if err := runClient(transportFactory, protocolFactory, *addr, *secure); err != nil {
fmt.Println("error running client:", err)
}
}
}
示例7: runThriftServer
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)
}
}
示例8: ToFront
func ToFront(m *calendar.Message) {
flag.Usage = Usage
client := flag.Bool("client", true, "Run client")
protocol := flag.String("P1", "binary", "Specify the protocol (binary, compact, json, simplejson)")
framed := flag.Bool("framed1", false, "Use framed transport")
buffered := flag.Bool("buffered1", true, "Use buffered transport")
addr := flag.String("addr1", "localhost:9090", "Address to listen to")
secure := flag.Bool("secure1", false, "Use tls secure transport")
flag.Parse()
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)
}
if *client {
if err := runClient(transportFactory, protocolFactory, *addr, *secure, *m); err != nil {
fmt.Println("error running client:", err)
}
} else {
fmt.Println("error running client:")
}
}
示例9: main
func main() {
flag.Usage = Usage
// always be a client in this copy
//server := flag.Bool("server", false, "Run server")
protocol := flag.String("P", "binary", "Specify the protocol (binary, compact, json, simplejson)")
framed := flag.Bool("framed", false, "Use framed transport")
buffered := flag.Bool("buffered", false, "Use buffered transport")
addr := flag.String("addr", "localhost:9090", "Address to listen to")
secure := flag.Bool("secure", false, "Use tls secure transport")
flag.Parse()
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)
}
// always be client
fmt.Printf("*secure = '%v'\n", *secure)
fmt.Printf("*addr = '%v'\n", *addr)
if err := runClient(transportFactory, protocolFactory, *addr, *secure); err != nil {
fmt.Println("error running client:", err)
}
}
示例10: startThriftServer
func startThriftServer() {
protocol := "binary" // "Specify the protocol (binary, compact, json, simplejson)"
framed := false // "Use framed transport"
buffered := false // "Use buffered transport"
addr := ":" + g.ThriftPort // "Address to listen to"
secure := false // "Use tls secure transport"
cpuNum := runtime.NumCPU()
if cpuNum > 1 {
runtime.GOMAXPROCS(cpuNum - 1)
}
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")
os.Exit(1)
}
var transportFactory thrift.TTransportFactory
if buffered {
transportFactory = thrift.NewTBufferedTransportFactory(8192)
} else {
transportFactory = thrift.NewTTransportFactory()
}
if framed {
transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
}
if err := runServer(transportFactory, protocolFactory, addr, secure); err != nil {
fmt.Println("error running server:", err)
g.Log.Error("error running server, error:%s", err.Error())
}
}
示例11: TestMain
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())
}
示例12: main
func main() {
flag.Usage = Usage
protocol := flag.String("P", "binary", "Specify the protocol (binary,compact,simplejson)")
framed := flag.Bool("framed", true, "Use framed transport")
bufferd := flag.Bool("bufferd", true, "Use bufferd transport")
addr := flag.String("addr", "localhost:9090", "Address to listen to")
flag.Parse()
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 *bufferd {
transportFactory = thrift.NewTBufferedTransportFactory(8192)
} else {
transportFactory = thrift.NewTTranspotFactory()
}
if *framed {
transportFactory = thrift.NewTFramedTranspotFactory(transportFactory)
}
if err := runServer(transportFactory, protocolFactory, addr); err != nil {
fmt.Println("error running server:", err)
}
}
示例13: main
func main() {
transportFactory := thrift.NewTBufferedTransportFactory(8192)
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
var client [20]*greeter.GreeterClient
//warm up
for i := 0; i < 20; i++ {
transport, err := thrift.NewTSocket(address)
if err != nil {
fmt.Fprintln(os.Stderr, "error resolving address:", err)
os.Exit(1)
}
useTransport := transportFactory.GetTransport(transport)
defer transport.Close()
if err := transport.Open(); err != nil {
fmt.Fprintln(os.Stderr, "Error opening socket to localhost:9090", " ", err)
os.Exit(1)
}
client[i] = greeter.NewGreeterClientFactory(useTransport, protocolFactory)
client[i].SayHello(defaultName)
}
sync := true
if len(os.Args) > 1 {
sync, _ = strconv.ParseBool(os.Args[1])
}
if sync {
syncTest(client[0], defaultName)
} else {
asyncTest(client, defaultName)
}
}
示例14: testHappyPath
func testHappyPath(t *testing.T, proto thrift.TProtocolFactory, buffered, framed bool) {
options := nats.DefaultOptions
options.Servers = []string{fmt.Sprintf("nats://localhost:%d", port)}
serverConn, err := options.Connect()
if err != nil {
t.Fatal("Failed to connect to gnatsd", err)
}
defer serverConn.Close()
clientConn, err := options.Connect()
if err != nil {
t.Fatal("Failed to connect to gnatsd", err)
}
defer clientConn.Close()
var transportFactory thrift.TTransportFactory
if buffered {
transportFactory = thrift.NewTBufferedTransportFactory(8192)
} else {
transportFactory = thrift.NewTTransportFactory()
}
if framed {
transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
}
processor := tutorial.NewCalculatorProcessor(NewCalculatorHandler())
server := thrift_nats.NewNATSServer(serverConn, subject, -1, -1, processor,
transportFactory, proto)
wait := make(chan bool)
go func() {
wait <- true
if err := server.Serve(); err != nil {
t.Fatal("Failed to start thrift server", err)
}
}()
<-wait
defer server.Stop()
// Give the server a chance to start.
time.Sleep(500 * time.Millisecond)
transport, err := thrift_nats.NATSTransportFactory(clientConn, subject, time.Second, -1)
if err != nil {
t.Fatal("Failed to create NATS transport", err)
}
transport = transportFactory.GetTransport(transport)
if err := transport.Open(); err != nil {
t.Fatal("Failed to open transport", err)
}
defer transport.Close()
client := tutorial.NewCalculatorClientFactory(transport, proto)
if err := client.Ping(); err != nil {
t.Fatal("Ping failed", err)
}
if err := client.Zip(); err != nil {
t.Fatal("Zip failed", err)
}
sum, err := client.Add(1, 1)
if err != nil {
t.Fatal("Sum failed", err)
}
if sum != 2 {
t.Fatalf("Expected Sum result 2, got %d", sum)
}
work := tutorial.NewWork()
work.Op = tutorial.Operation_DIVIDE
work.Num1 = 8
work.Num2 = 4
quotient, err := client.Calculate(1, work)
if err != nil {
t.Fatal("Calculate failed", err)
}
if sum != 2 {
t.Fatalf("Expected Calculate result 4, got %d", quotient)
}
work.Op = tutorial.Operation_DIVIDE
work.Num1 = 1
work.Num2 = 0
_, err = client.Calculate(2, work)
switch v := err.(type) {
case *tutorial.InvalidOperation:
break
default:
t.Fatalf("Expected Calculate to return InvalidOperation, got %s", v)
}
log, err := client.GetStruct(1)
if err != nil {
t.Fatal("GetStruct failed", err)
}
if log.Value != "2" {
t.Fatalf("Expected struct value `2`, got `%s`", log.Value)
}
log, err = client.GetStruct(2)
if err != nil {
//.........這裏部分代碼省略.........