Browse files

Python work #203

  • Loading branch information...
1 parent cd8ec6c commit c36fecb13ecf5224dfb62f2b88bc054589713949 @ccotter ccotter committed Nov 12, 2012
View
2 servers/python/coweb/bayeux/connection.py
@@ -316,4 +316,4 @@ def _publish(self, req):
self.on_publish(cl, req, res)
except Exception:
log.exception('publish delegate')
- cl.should_flush()
+ cl.should_flush()
View
1 servers/python/coweb/bot/wrapper/bayeux/websocket.py
@@ -182,6 +182,7 @@ def collect_incoming_data(self, data):
def found_terminator(self):
'''Called when a complete "chunk" is received.'''
self._handler(b''.join(self._inBuffer))
+ print(b''.join(self._inBuffer))
self._inBuffer = []
def _on_request_line(self, field):
View
1 servers/python/coweb/bot/wrapper/bayeux/wrapper.py
@@ -61,6 +61,7 @@ def on_connect(self, msg):
def on_subscribe(self, msg):
'''Called when subscribe to private bot channel succeeds'''
+ print("on_subscribe")
assert(msg['subscription'] == self._privateCh+'*')
# create bot instance now that we're subscribed for requests
try:
View
4 servers/python/coweb/bot/wrapper/object.py
@@ -10,7 +10,7 @@
import weakref
import functools
# coweb
-from base import BotWrapperBase
+from .base import BotWrapperBase
log = logging.getLogger('coweb.bot')
@@ -62,4 +62,4 @@ def add_timer(self, delay, callback, *args, **kwargs):
def remove_timer(self, timer):
'''Remove a one-shot timer.'''
- self._ioLoop.remove_timeout(timer)
+ self._ioLoop.remove_timeout(timer)
View
62 servers/python/coweb/moderator.py
@@ -0,0 +1,62 @@
+
+
+# TODO document
+
+_moderators = {}
+
+class SessionModerator:
+ def __init__(self):
+ print("hello from moderator")
+ def canClientJoinSession(self):
+ raise NotImplementedError()
+ def canClientMakeServiceRequest(self):
+ raise NotImplementedError()
+ def canClientSubscribeService(self):
+ raise NotImplementedError()
+ def onClientJoinSession(self):
+ raise NotImplementedError()
+ def onClientLeaveSession(self):
+ raise NotImplementedError()
+ def onServiceResponse(self):
+ raise NotImplementedError()
+ def onSessionEnd(self):
+ raise NotImplementedError()
+ def onSessionReady(self):
+ raise NotImplementedError()
+ def onSync(self):
+ raise NotImplementedError()
+ def getLateJoinState(self):
+ raise NotImplementedError()
+
+ @staticmethod
+ def getInstance(klass, key):
+ moderator = _moderators.get(key, None)
+ if moderator is not None:
+ return moderator
+
+ _moderators[key] = moderator = klass()
+ return moderator
+
+class DefaultSessionModerator(SessionModerator):
+ def canClientJoinSession(self):
+ return True
+ def canClientMakeServiceRequest(self):
+ return True
+ def canClientSubscribeService(self):
+ return True
+ def onClientJoinSession(self):
+ pass
+ def onClientLeaveSession(self):
+ pass
+ def onServiceResponse(self):
+ pass
+ def onSessionEnd(self):
+ pass
+ def onSessionReady(self):
+ pass
+ def onSync(self):
+ pass
+ def getLateJoinState(self):
+ print("in late get state")
+ return {}
+
View
8 servers/python/coweb/runner.py
@@ -17,8 +17,10 @@
log = logging.getLogger('coweb')
# app command line options
-tornado.options.define('port', type=int, default=None, help='server port number (default: use app specified)')
-tornado.options.define('debug', type=bool, default=False, help='run in debug mode with autoreload (default: false)')
+tornado.options.define('port', type=int, default=None,
+ help='server port number (default: use app specified)')
+tornado.options.define('debug', type=bool, default=False,
+ help='run in debug mode with autoreload (default: false)')
def run_server(containerCls):
'''Runs a coweb server instance given an AppContainer subclass.'''
@@ -40,4 +42,4 @@ def run_server(containerCls):
http_server.listen(container.httpPort)
ioloop = tornado.ioloop.IOLoop.instance()
log.info('started on port: %d', container.httpPort)
- ioloop.start()
+ ioloop.start()
View
4 servers/python/coweb/scripts/verbose.tmpl
@@ -49,7 +49,7 @@ class CoWebApp(coweb.AppContainer):
# window in seconds before a coweb client is considered disconnected
# self.cowebIdleTimeout = 30
- # paths where bots are located for local bot launchers
+ # paths where bots and moderators are located
# self.cowebBotLocalPaths = ['../bots']
# coweb.auth.AuthBase subclass defining user authentication; default
@@ -115,4 +115,4 @@ class CoWebApp(coweb.AppContainer):
return super(CoWebApp, self).on_build_web_app(handlers, settings)
if __name__ == '__main__':
- coweb.run_server(CoWebApp)
+ coweb.run_server(CoWebApp)
View
1 servers/python/coweb/service/__init__.py
@@ -6,4 +6,5 @@
'''
from .bridge import ServiceSessionBridge
from .manager.base import ServiceManagerBase
+from .manager.object import ObjectServiceManager
from .launcher.base import ServiceLauncherBase
View
2 servers/python/coweb/service/bridge.py
@@ -141,6 +141,8 @@ def on_user_sync(self, user, req):
if bot.acls & ACL_SERVICE_SYNC:
# forward sync events if allowed
msg = self.manager.on_user_sync(bot.serviceName, username, data)
+ print(msg)
+ print(bot.is_subscribed())
# decide whether to queue or send now based on bot state
if bot.is_subscribed():
self.manager.send_message(msg, bot.impl)
View
4 servers/python/coweb/service/manager/object.py
@@ -3,7 +3,7 @@
Copyright (c) IBM Corporation 2008, 2011. All Rights Reserved.
'''
# coweb
-from base import ServiceManagerBase
+from .base import ServiceManagerBase
from ...bot.wrapper.object import ObjectBotWrapper
class ObjectServiceManager(ServiceManagerBase):
@@ -67,4 +67,4 @@ def on_bot_publish(self, serviceName, data):
self._bridge.on_bot_publish(serviceName, data)
def on_bot_response(self, serviceName, replyToken, data):
- self._bridge.on_bot_response(serviceName, replyToken, data)
+ self._bridge.on_bot_response(serviceName, replyToken, data)
View
1 servers/python/coweb/session/collab.py
@@ -117,7 +117,6 @@ def on_publish(self, cl, req, res):
elif '/engine' == matches.group(2):
# Engine sync.
if self._manager._opengine:
- print("did sync inbound")
self._manager._opengine.engineSyncInbound(req['data'])
# delegate all other handling to base class
super(CollabSessionConnection, self).on_publish(cl, req, res)
View
49 servers/python/coweb/session/moderator_late_join_handler.py
@@ -0,0 +1,49 @@
+
+from .late_join_handler import LateJoinHandler
+import logging
+
+log = logging.getLogger('coweb.session')
+
+class ModeratorLateJoinHandler(LateJoinHandler):
+
+ def __init__(self, session):
+ super(ModeratorLateJoinHandler, self).__init__(session)
+ self._moderator = session._moderator
+
+ def queue_updatee(self, client):
+ '''Overrides to have the moderator immediatelty send late join state'''
+ clientId = client.clientId
+
+ try:
+ # get site id already assigned
+ siteid = self.get_site_for_client(client)
+ except ValueError:
+ # get new site id
+ siteid = self.add_site_for_client(client)
+
+ # get the roster list to return before adding anyone
+ roster = self._get_roster_list(client)
+
+ data = self._moderator.getLateJoinState()
+
+ # send site id to client
+ client.add_message({
+ 'channel':'/service/session/join/siteid',
+ 'data': siteid
+ })
+ # send roster to client
+ client.add_message({
+ 'channel':'/service/session/join/roster',
+ 'data': roster
+ })
+ # Send application data.
+ client.add_message({
+ 'channel':'/service/session/join/state',
+ 'data': data
+ })
+
+ if len(self._updaters) == 0:
+ self.add_updater(client, False)
+ else:
+ self.add_updater(client, True)
+

0 comments on commit c36fecb

Please sign in to comment.