Thrift在windows7下的安装与实践
package com.winwill.thrift; import org.apache.thrift.protocol.TBinaryProtocol;import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TJSONProtocol;
import org.apache.thrift.protocol.TProtocolFactory;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TSimpleServer;
import org.apache.thrift.transport.TFastFramedTransport;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TTransportFactory;
import org.slf4j.*;
import java.net.ServerSocket;
public class HelloWordServer {
public static void main(String[] args) throws Exception {
int port = 7912;
String transport_type = "buffered";
String protocol_type = "binary";
String server_type = "thread-pool";
String domain_socket = "";
// ServerSocket socket = new ServerSocket(7912);
// Protocol factory
TProtocolFactory tProtocolFactory = null;
if (protocol_type.equals("json")) {
tProtocolFactory = new TJSONProtocol.Factory();
} else if (protocol_type.equals("compact")) {
tProtocolFactory = new TCompactProtocol.Factory();
} else {
tProtocolFactory = new TBinaryProtocol.Factory();
}
TTransportFactory tTransportFactory = null;
if (transport_type.equals("framed")) {
tTransportFactory = new TFramedTransport.Factory();
} else if (transport_type.equals("fastframed")) {
tTransportFactory = new TFastFramedTransport.Factory();
} else { // .equals("buffered") => default value
tTransportFactory = new TTransportFactory();
}
TServerSocket serverTransport = new TServerSocket(new TServerSocket.ServerSocketTransportArgs().port(port));;
com.winwill.thrift.HelloWordService.Processor processor = new com.winwill.thrift.HelloWordService.Processor(new HelloWordServiceImpl());
TServer.Args tServerArgs = new TServer.Args(serverTransport);
tServerArgs.processor(processor);
tServerArgs.protocolFactory(tProtocolFactory);
tServerArgs.transportFactory(tTransportFactory);
TServer server = new TSimpleServer(tServerArgs);
System.out.println("Running server...");
server.serve();
}
}
页:
[1]