blob: 352a6de9c4efceee77df69af82d9790bb662d3a5 [file] [log] [blame]
Mark Slee83c52a82006-06-07 06:51:18 +00001package com.facebook.thrift.server;
2
3import com.facebook.thrift.TException;
4import com.facebook.thrift.TProcessor;
5import com.facebook.thrift.transport.TServerTransport;
6import com.facebook.thrift.transport.TTransport;
7import com.facebook.thrift.transport.TTransportException;
8
9/**
10 * Simple singlethreaded server for testing.
11 *
12 * @author Mark Slee <mcslee@facebook.com>
13 */
14public class TSimpleServer extends TServer {
15
16 private TServerTransport serverTransport_;
17
18 public TSimpleServer(TProcessor processor,
19 TServer.Options options,
20 TServerTransport serverTransport) {
21 super(processor, options);
22 serverTransport_ = serverTransport;
23 }
24
25 public void run() {
26 try {
27 serverTransport_.listen();
28 } catch (TTransportException ttx) {
29 ttx.printStackTrace();
30 return;
31 }
32
33 while (true) {
34 TTransport client = null;
35 try {
36 client = serverTransport_.accept();
37 if (client != null) {
38 while (processor_.process(client, client));
39 }
40 } catch (TException tx) {
41 tx.printStackTrace();
42 }
43
44 if (client != null) {
45 client.close();
46 client = null;
47 }
48 }
49 }
50}