source: ntrip/trunk/GnssCenter/thrift/bidi_java/server/Server.java@ 5700

Last change on this file since 5700 was 4940, checked in by mervart, 12 years ago
File size: 1.5 KB
Line 
1package com.joelpm.bidiMessages.server;
2
3import org.apache.log4j.Logger;
4
5import org.apache.thrift.TProcessor;
6import org.apache.thrift.TProcessorFactory;
7import org.apache.thrift.server.TServer;
8import org.apache.thrift.server.TThreadPoolServer;
9import org.apache.thrift.transport.TServerSocket;
10import org.apache.thrift.transport.TServerTransport;
11import org.apache.thrift.transport.TTransport;
12import com.joelpm.bidiMessages.generated.MessageService;
13
14/**
15* A simple server that accepts messages from clients and broadcasts
16* them out to all connected clients.
17*
18* @author Joel Meyer
19*/
20public class Server {
21 private static final Logger LOGGER = Logger.getLogger(Server.class);
22
23 public static void main(String[] args) throws Exception {
24 final int port = Integer.parseInt(args[0]);
25
26 final MessageDistributor messageDistributor = new MessageDistributor();
27
28 new Thread(messageDistributor).start();
29
30 // Using our own TProcessorFactory gives us an opportunity to get
31 // access to the transport right after the client connection is
32 // accepted.
33 TProcessorFactory processorFactory = new TProcessorFactory(null) {
34 @Override
35 public TProcessor getProcessor(TTransport trans) {
36 messageDistributor.addClient(new MessageServiceClient(trans));
37 return new MessageService.Processor(messageDistributor);
38 }
39 };
40
41 TServerTransport serverTransport = new TServerSocket(port);
42 TServer server = new TThreadPoolServer(processorFactory, serverTransport);
43 LOGGER.info("Server started");
44 server.serve();
45 }
46}
Note: See TracBrowser for help on using the repository browser.