Ejemplo n.º 1
0
    def __init__(self):
        #self.setDaemon(True)
        #self.setName('WebServer')
        
        channel_set = WsgiChannelSet()
        rpc_channel = WsgiChannel('amf')
        channel_set.mapChannel(rpc_channel)
        app.utils.setup_channel_set(channel_set)

        try:
            log.info('Listening for connections')
            server = wsgi.WSGIServer(('', 8000), channel_set).serve_forever()
            server.handler_class(channel_set)
         
        except (KeyboardInterrupt, SystemExit):
            raise

        return None
Ejemplo n.º 2
0
    def initServices(self):

        connectionManager = SaConnectionManager(self.engine, sqlalchemy.MetaData())
        connectionManager.createTables()
        subscriptionManager = SaSubscriptionManager(self.engine, sqlalchemy.MetaData())
        subscriptionManager.createTables()

        self.channelSet = WsgiChannelSet()

        self.channelSet.mapChannel(StreamingGeventChannel("streaming"))
        self.channelSet.mapChannel(WsgiChannel("basic"))
        self.channelSet.service_mapper = ServiceMapper()


        self.channelSet.service_mapper.mapService(MyService(self))
Ejemplo n.º 3
0
                      default=8000,
                      dest="port",
                      help="port number to serve")
    parser.add_option("-d",
                      default="localhost",
                      dest="domain",
                      help="domain to serve")
    parser.add_option("-l",
                      action="store_true",
                      dest="log_debug",
                      help="log debugging output")
    (options, args) = parser.parse_args()

    amfast.log_debug = options.log_debug

    channel_set = WsgiChannelSet()
    rpc_channel = WsgiChannel('amf')
    channel_set.mapChannel(rpc_channel)
    utils.setup_channel_set(channel_set)

    server = simple_server.WSGIServer((options.domain, int(options.port)),
                                      simple_server.WSGIRequestHandler)

    server.set_app(channel_set)

    try:
        print "Serving on %s:%s" % (options.domain, options.port)
        print "Press ctrl-c to halt."
        server.serve_forever()
    except KeyboardInterrupt:
        pass
Ejemplo n.º 4
0
class Node(object):
    def __init__(self, config):
        self.config = config
        self.ctx = zmq.Context()
        self.pub_socket = self.ctx.socket(zmq.PUB)
        self.pub_socket.connect("tcp://127.0.0.1:5001")
        self.paths = {}
        self.initDb()
        self.initServices()
        self.initWeb()

    def initDb(self):
        self.engine = create_engine('postgresql+psycopg2://thc:thc@localhost/thc')

    def initServices(self):

        connectionManager = SaConnectionManager(self.engine, sqlalchemy.MetaData())
        connectionManager.createTables()
        subscriptionManager = SaSubscriptionManager(self.engine, sqlalchemy.MetaData())
        subscriptionManager.createTables()

        self.channelSet = WsgiChannelSet()

        self.channelSet.mapChannel(StreamingGeventChannel("streaming"))
        self.channelSet.mapChannel(WsgiChannel("basic"))
        self.channelSet.service_mapper = ServiceMapper()


        self.channelSet.service_mapper.mapService(MyService(self))


    def initWeb(self):
        self.web_handler = web.application((), globals()).wsgifunc()


    def getHandler(self):

        session_opts = {
            'session.type': 'file',
            'session.cookie_expires': 300,
            'session.data_dir': './data',
            'session.auto': True
        }

        return  StripPathMiddleware(SessionMiddleware(self.__call, session_opts))

    def __call(self, env, start_response):

        if env['PATH_INFO'].startswith("/amf"):
            env['PATH_INFO'] = env['PATH_INFO'][4:]
            try:
                return self.channelSet(env, start_response)
            except KeyError:
                start_response('500', [('Content-Type', 'text/html')])
                return  "AMF calls only"
        else:
            if env['PATH_INFO'] == '/pull':
                write = start_response('200 OK', [('Content-Type', 'text/plain'),
                    ("Transfer-Encoding", "chunked")])
                print "serving pull"
                write('start')
                gevent.sleep(100)

                return []
Ejemplo n.º 5
0
    handler = logging.StreamHandler(sys.stdout)
    handler.setLevel(logging.DEBUG)
    amfast.logger.addHandler(handler)

    cp_options = {
        'global': {
            'server.socket_port': int(options.port),
            'server.socket_host': str(options.domain),
        },
        '/': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': os.path.join(os.getcwd(), '../flex/deploy')
        }
    }

    channel_set = WsgiChannelSet(notify_connections=False)

    # Clients connect every x seconds
    # to polling channels to check for messages.
    # If messages are available, they are
    # returned to the client.
    polling_channel = WsgiChannel('amf')
    channel_set.mapChannel(polling_channel)

    # Long-poll channels do not return
    # a response to the client until
    # a message is available, or channel.max_interval
    # is reached.
    long_poll_channel = WsgiChannel('longPoll', wait_interval=90)
    channel_set.mapChannel(long_poll_channel)
Ejemplo n.º 6
0
    amfast.logger.addHandler(handler)

    cp_options = {
        'global':
        {
            'server.socket_port': int(options.port),
            'server.socket_host': str(options.domain),
        },
        '/':
        {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': os.path.join(os.getcwd(), '../flex/deploy')
        }
    }

    channel_set = WsgiChannelSet(notify_connections=False)

    # Clients connect every x seconds
    # to polling channels to check for messages.
    # If messages are available, they are
    # returned to the client.
    polling_channel = WsgiChannel('amf')
    channel_set.mapChannel(polling_channel)

    # Long-poll channels do not return
    # a response to the client until
    # a message is available, or channel.max_interval
    # is reached.
    long_poll_channel = WsgiChannel('longPoll', wait_interval=90)
    channel_set.mapChannel(long_poll_channel)
Ejemplo n.º 7
0
import utils

if __name__ == '__main__':
    usage = """usage: %s [options]""" % __file__
    parser = optparse.OptionParser(usage=usage)
    parser.add_option("-p", default=8000,
        dest="port", help="port number to serve")
    parser.add_option("-d", default="localhost",
        dest="domain", help="domain to serve")
    parser.add_option("-l", action="store_true",
        dest="log_debug", help="log debugging output")
    (options, args) = parser.parse_args()

    amfast.log_debug = options.log_debug

    channel_set = WsgiChannelSet()
    rpc_channel = WsgiChannel('amf')
    channel_set.mapChannel(rpc_channel)
    utils.setup_channel_set(channel_set)

    server = simple_server.WSGIServer((options.domain, int(options.port)),
        simple_server.WSGIRequestHandler)

    server.set_app(channel_set)

    try:
        print "Serving on %s:%s" % (options.domain, options.port)
        print "Press ctrl-c to halt."
        server.serve_forever()
    except KeyboardInterrupt:
        pass