blob: c3c844e0afd1d6497a35186f49dcbd50399eacb8 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001#!/usr/bin/env python
2
3import sys
4import logging
5sys.path.append('../../../target/gen-py')
6
7from packetstreamer import PacketStreamer
8from packetstreamer.ttypes import *
9
10from thrift.transport import TSocket
11from thrift.transport import TTransport
12from thrift.protocol import TBinaryProtocol
13from thrift.server import TServer
14
15class PacketStreamerHandler:
16 def __init__(self):
17 logging.handlers.codecs = None
18 self.log = logging.getLogger("packetstreamer")
19 self.log.setLevel(logging.DEBUG)
20 handler = logging.handlers.SysLogHandler("/dev/log")
21 handler.setFormatter(logging.Formatter("%(name)s: %(levelname)s %(message)s"))
22 self.log.addHandler(handler)
23
24 def ping(self):
25 self.log.debug('ping()')
26 return true
27
28 def pushPacketSync(self, packet):
29 self.log.debug('receive a packet synchronously: %s' %(packet))
30 return 0
31
32 def pushPacketAsync(self, packet):
33 self.log.debug('receive a packet Asynchronously: %s' %(packet))
34
35handler = PacketStreamerHandler()
36processor = PacketStreamer.Processor(handler)
37transport = TSocket.TServerSocket(9090)
38tfactory = TTransport.TBufferedTransportFactory()
39pfactory = TBinaryProtocol.TBinaryProtocolFactory()
40
41server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
42
43# You could do one of these for a multithreaded server
44#server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
45#server = TServer.TThreadPoolServer(processor, transport, tfactory, pfactory)
46
47print 'Starting the server...'
48server.serve()
49print 'done.'