Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Commit

Permalink
TMultiplexed{Service|Protocol} Proof of Concept
Browse files Browse the repository at this point in the history
Fixes #102
  • Loading branch information
fmoo committed Aug 19, 2015
1 parent f1187e9 commit e7b956f
Show file tree
Hide file tree
Showing 12 changed files with 665 additions and 7 deletions.
20 changes: 20 additions & 0 deletions demo/tnonblock_thrift.py
Expand Up @@ -7,8 +7,28 @@
from sparts.vservice import VService
from sparts.tasks.thrift import NBServerTask
from sparts.tasks.fb303 import FB303HandlerTask
from sparts.tasks.thrift.handler import ThriftHandlerTask

from sparts.gen.sparts_examples import SpartsFooService, SpartsBarService

class FooServiceHandler(ThriftHandlerTask):
MODULE = SpartsFooService
def foo(self):
return "foo is better!"

FooServiceHandler.register()

class BarServiceHandler(ThriftHandlerTask):
MODULE = SpartsBarService
def bar(self):
return "bar is better!"

BarServiceHandler.register()


NBServerTask.register()
NBServerTask.MULTIPLEX = True

FB303HandlerTask.register()


Expand Down
92 changes: 92 additions & 0 deletions sparts/gen/sparts_examples/SpartsBarService-remote
@@ -0,0 +1,92 @@
#!/usr/bin/env python
#
# Autogenerated by Thrift Compiler (1.0.0-dev)
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
#
# options string: py:new_style
#

import sys
import pprint
from urlparse import urlparse
from thrift.transport import TTransport
from thrift.transport import TSocket
from thrift.transport import TSSLSocket
from thrift.transport import THttpClient
from thrift.protocol import TBinaryProtocol

from sparts_examples import SpartsBarService
from sparts_examples.ttypes import *

epilog = """Functions:
string bar()
"""
import argparse

ap = argparse.ArgumentParser(epilog=epilog,
formatter_class=argparse.RawTextHelpFormatter)
ap.add_argument('-H', '--hostport', metavar='HOST[:PORT]')
ap.add_argument('-u', '--url', metavar='URL')
ap.add_argument('-f', '--framed', action='store_true')
ap.add_argument('-s', '--ssl', action='store_true')
ap.add_argument('-k', '--insecure', action='store_true')
ap.add_argument('function')
ap.add_argument('args', nargs='*')

ns = ap.parse_args()

pp = pprint.PrettyPrinter(indent = 2)
host = 'localhost'
port = 9090
uri = ''
http = False
argi = 1

if ns.hostport:
parts = ns.hostport.split(':')
host = parts[0]
if len(parts) > 1:
port = int(parts[1])

if ns.url:
url = urlparse(ns.url)
parts = url[1].split(':')
host = parts[0]
if len(parts) > 1:
port = int(parts[1])
else:
port = 80
uri = url[2]
if url[4]:
uri += '?%s' % url[4]
http = True

if http:
transport = THttpClient.THttpClient(host, port, uri)
else:
if ns.ssl:
check_ssl = not ns.insecure
socket = TSSLSocket.TSSLSocket(host, port,
not ns.insecure)
else:
socket = TSocket.TSocket(host, port)
if ns.framed:
transport = TTransport.TFramedTransport(socket)
else:
transport = TTransport.TBufferedTransport(socket)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = SpartsBarService.Client(protocol)
transport.open()

if ns.function == 'bar':
if len(ns.args) != 0:
print 'bar requires 0 args'
sys.exit(1)
pp.pprint(client.bar())

else:
print 'Unrecognized method %s' % ns.function
sys.exit(1)

transport.close()
192 changes: 192 additions & 0 deletions sparts/gen/sparts_examples/SpartsBarService.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e7b956f

Please sign in to comment.