# Path: amfast/remoting/tornado_channel.py
# class TornadoChannelSet(ChannelSet):
#     def scheduleClean(self):
#         cleaner = PeriodicCallback(self.clean, self.clean_freq * 1000,
#             IOLoop.instance())
#         cleaner.start()
# 
#     def clean(self):
#         if amfast.log_debug is True:
#             amfast.logger.debug("Cleaning channel.")
# 
#         current_time = time.time()
#         iter = self.connection_manager.iterConnectionIds()
#         def _clean():
#             try:
#                 connection_id = iter.next()
#                 def _callback():
#                     self.cleanConnection(connection_id, current_time)
#                 IOLoop.instance().add_callback(_callback)
#                 IOLoop.instance().add_callback(_clean)
#             except StopIteration:
#                 pass
#         _clean()
# 
#     def notifyConnections(self, topic, sub_topic):
#         for connection_id in self.subscription_manager.iterSubscribers(topic, sub_topic):
#             self.notifyConnection(connection_id)
# 
#     def notifyConnection(self, connection_id):
#         def _notify():
#             self._notifyConnection(connection_id)
#         IOLoop.instance().add_callback(_notify)
# 
#     def _notifyConnection(self, connection_id):
#         try:
#             connection = self.connection_manager.getConnection(connection_id, False)
#         except cm.NotConnectedError:
#             return
# 
#         if connection.notify_func is not None:
#             IOLoop.instance().add_callback(connection.notify_func)
# 
# class StreamingTornadoChannel(TornadoChannel):
#     """Handles streaming http connections."""
# 
#     def __init__(self, name, max_connections=-1, endpoint=None,
#         timeout=1200, wait_interval=0, heart_interval=30000):
#         TornadoChannel.__init__(self, name, max_connections, endpoint,
#             timeout, wait_interval)
# 
#         self.heart_interval = heart_interval
# 	
#     def processRequest(self, request_handler):
#         if request_handler.request.headers['Content-Type'] == self.CONTENT_TYPE:
# 	    # Regular AMF message
# 	    return TornadoChannel.processRequest(self, request_handler)
# 
#         request_handler.set_header('Content-Type', self.CONTENT_TYPE)
#         msg = messaging.StreamingMessage()
# 	msg.parseArgs(request_handler.request.arguments)
# 
# 	if msg.operation == msg.OPEN_COMMAND:
# 	    def _open():
# 	        self.startStream(msg, request_handler)
# 	    IOLoop.instance().add_callback(request_handler.async_callback(_open))
# 	elif msg.operation == msg.CLOSE_COMMAND:
#             pass
# 
#     def startStream(self, msg, request_handler):
#         """Get this stream rolling!"""
# 
#         connection = self.channel_set.connection_manager.getConnection(msg.headers.get(msg.FLEX_CLIENT_ID_HEADER))
# 
#         if self.channel_set.notify_connections is True:
#             poller = None
#         else:
#             # Call _notify multiple times if polling.
#             poller = PeriodicCallback(None, self.poll_interval, IOLoop.instance())
# 
#         # Handle new message.
# 	def _notify():
#             if connection.connected is False:
#                 if poller is not None:
#                     poller.stop()
# 
# 	        connection.unSetNotifyFunc()
# 		if request_handler.request.connection.stream.closed() is False:
# 		    msg = messaging.StreamingMessage.getDisconnectMsg()
# 		    self.sendMsgs((msg,), request_handler)
# 		    request_handler.finish()
# 		return
# 		    
# 	    msgs = self.channel_set.subscription_manager.pollConnection(connection)
#             if len(msgs) > 0:
# 	        self.sendMsgs(msgs, request_handler)
# 	connection.setNotifyFunc(_notify)
# 
#         if poller is not None:
#            poller.callback = _notify
#            poller.start() 
# 
#         # Handle dropped connection.
# 	def _connectionLost():
#             if poller is not None:
#                 poller.stop()
# 	    self.channel_set.disconnect(connection)
# 	    connection.unSetNotifyFunc()   
#         request_handler.request.connection.stream.set_close_callback(_connectionLost)
# 
# 	# Send acknowledge message
# 	response = msg.acknowledge()
# 	response.body = connection.id
# 	self.sendMsgs((response,), request_handler)
# 
#         request_handler.write(chr(messaging.StreamingMessage.NULL_BYTE) * self.KICKSTART_BYTES)
#         request_handler.flush()
# 
# 	self.startBeat(connection, request_handler)
# 
#     def sendMsgs(self, msgs, request_handler):
#         """Send messages to the client."""
# 	for msg in msgs:
# 	    request_handler.write(messaging.StreamingMessage.prepareMsg(msg, self.endpoint))
# 	request_handler.flush()
# 
#     def startBeat(self, connection, request_handler):
#         beater = PeriodicCallback(None, self.heart_interval, IOLoop.instance())
#         def _beat():
#             if connection.connected is False:
# 	        beater.stop()
# 	    else:
# 		request_handler.write(chr(messaging.StreamingMessage.NULL_BYTE))
# 		request_handler.flush()
# 	beater.callback = _beat
# 	beater.start()


import logging
import optparse
import os
import sys
import tornado.httpserver
import tornado.ioloop
import amfast
    import dummy_threading
from amfast.remoting.tornado_channel import TornadoChannelSet, StreamingTornadoChannel




class MainHandler (tornado.web.RequestHandler):
    def get(self):
        self.write("Hello World!")


# Path: amfast/remoting/tornado_channel.py
# class TornadoChannelSet(ChannelSet):
#     def scheduleClean(self):
#         cleaner = PeriodicCallback(self.clean, self.clean_freq * 1000,
#             IOLoop.instance())
#         cleaner.start()
# 
#     def clean(self):
#         if amfast.log_debug is True:
#             amfast.logger.debug("Cleaning channel.")
# 
#         current_time = time.time()
#         iter = self.connection_manager.iterConnectionIds()
#         def _clean():
#             try:
#                 connection_id = iter.next()
#                 def _callback():
#                     self.cleanConnection(connection_id, current_time)
#                 IOLoop.instance().add_callback(_callback)
#                 IOLoop.instance().add_callback(_clean)
#             except StopIteration:
#                 pass
#         _clean()
# 
#     def notifyConnections(self, topic, sub_topic):
#         for connection_id in self.subscription_manager.iterSubscribers(topic, sub_topic):
#             self.notifyConnection(connection_id)
# 
#     def notifyConnection(self, connection_id):
#         def _notify():
#             self._notifyConnection(connection_id)
#         IOLoop.instance().add_callback(_notify)
# 
#     def _notifyConnection(self, connection_id):
#         try:
#             connection = self.connection_manager.getConnection(connection_id, False)
#         except cm.NotConnectedError:
#             return
# 
#         if connection.notify_func is not None:
#             IOLoop.instance().add_callback(connection.notify_func)
# 
# class StreamingTornadoChannel(TornadoChannel):
#     """Handles streaming http connections."""
# 
#     def __init__(self, name, max_connections=-1, endpoint=None,
#         timeout=1200, wait_interval=0, heart_interval=30000):
#         TornadoChannel.__init__(self, name, max_connections, endpoint,
#             timeout, wait_interval)
# 
#         self.heart_interval = heart_interval
# 	
#     def processRequest(self, request_handler):
#         if request_handler.request.headers['Content-Type'] == self.CONTENT_TYPE:
# 	    # Regular AMF message
# 	    return TornadoChannel.processRequest(self, request_handler)
# 
#         request_handler.set_header('Content-Type', self.CONTENT_TYPE)
#         msg = messaging.StreamingMessage()
# 	msg.parseArgs(request_handler.request.arguments)
# 
# 	if msg.operation == msg.OPEN_COMMAND:
# 	    def _open():
# 	        self.startStream(msg, request_handler)
# 	    IOLoop.instance().add_callback(request_handler.async_callback(_open))
# 	elif msg.operation == msg.CLOSE_COMMAND:
#             pass
# 
#     def startStream(self, msg, request_handler):
#         """Get this stream rolling!"""
# 
#         connection = self.channel_set.connection_manager.getConnection(msg.headers.get(msg.FLEX_CLIENT_ID_HEADER))
# 
#         if self.channel_set.notify_connections is True:
#             poller = None
#         else:
#             # Call _notify multiple times if polling.
#             poller = PeriodicCallback(None, self.poll_interval, IOLoop.instance())
# 
#         # Handle new message.
# 	def _notify():
#             if connection.connected is False:
#                 if poller is not None:
#                     poller.stop()
# 
# 	        connection.unSetNotifyFunc()
# 		if request_handler.request.connection.stream.closed() is False:
# 		    msg = messaging.StreamingMessage.getDisconnectMsg()
# 		    self.sendMsgs((msg,), request_handler)
# 		    request_handler.finish()
# 		return
# 		    
# 	    msgs = self.channel_set.subscription_manager.pollConnection(connection)
#             if len(msgs) > 0:
# 	        self.sendMsgs(msgs, request_handler)
# 	connection.setNotifyFunc(_notify)
# 
#         if poller is not None:
#            poller.callback = _notify
#            poller.start() 
# 
#         # Handle dropped connection.
# 	def _connectionLost():
#             if poller is not None:
#                 poller.stop()
# 	    self.channel_set.disconnect(connection)
# 	    connection.unSetNotifyFunc()   
#         request_handler.request.connection.stream.set_close_callback(_connectionLost)
# 
# 	# Send acknowledge message
# 	response = msg.acknowledge()
# 	response.body = connection.id
# 	self.sendMsgs((response,), request_handler)
# 
#         request_handler.write(chr(messaging.StreamingMessage.NULL_BYTE) * self.KICKSTART_BYTES)
#         request_handler.flush()
# 
# 	self.startBeat(connection, request_handler)
# 
#     def sendMsgs(self, msgs, request_handler):
#         """Send messages to the client."""
# 	for msg in msgs:
# 	    request_handler.write(messaging.StreamingMessage.prepareMsg(msg, self.endpoint))
# 	request_handler.flush()
# 
#     def startBeat(self, connection, request_handler):
#         beater = PeriodicCallback(None, self.heart_interval, IOLoop.instance())
#         def _beat():
#             if connection.connected is False:
# 	        beater.stop()
# 	    else:
# 		request_handler.write(chr(messaging.StreamingMessage.NULL_BYTE))
# 		request_handler.flush()
# 	beater.callback = _beat
# 	beater.start()


# Path: examples/streaming/python/tornado_server.py
import logging
import optparse
import os
import sys
import tornado.httpserver
import tornado.ioloop
import amfast
    import dummy_threading
from amfast.remoting.tornado_channel import TornadoChannelSet, StreamingTornadoChannel





class MainHandler (tornado.web.RequestHandler):
    def get(self):
        self.write("Hello World!")


if __name__ == '__main__':