Subversion Repositories SmartDukaan

Rev

Rev 1013 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package in.shop2020.test;

import in.shop2020.test.TestService.Iface;
import in.shop2020.test.TestService.Processor;

import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocolFactory;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TThreadPoolServer;
import org.apache.thrift.server.TThreadPoolServer.Args;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TServerTransport;
import org.apache.thrift.transport.TTransportException;
import org.apache.thrift.transport.TTransportFactory;


public class TestServer {
        private String port = null;
        
        public TestServer(){
                        port = "9000";
        }
        
        public void startServer(){
                try {
                        
                        TServerTransport t1 = new TServerSocket(Integer.parseInt(port));
                        TTransportFactory tFactory = new TFramedTransport.Factory();
                        TProtocolFactory pFactory = new TBinaryProtocol.Factory();
                        
                        Processor<Iface> p = new Processor<TestService.Iface>(new TestHandler());
                        
                        System.out.println("Starting server at port 9000");
                        
                        Args args = new Args(t1);
                        args.processor(p);
                        args.transportFactory(tFactory);
                        args.protocolFactory(pFactory);
                        TServer server = new TThreadPoolServer(args);
                                              
        //              TServer server = new TThreadPoolServer(p, t, new TFramedTransport.Factory(), new TBinaryProtocol.Factory());
                        server.serve();
                } catch (NumberFormatException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (TTransportException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        }
        
        public static void main(String[] args){
                TestServer server = new TestServer();
                server.startServer();
        }

}