Permalink
Browse files

Cleaning up python code #203

  • Loading branch information...
1 parent fc82d23 commit 638595173b5091be46c1ea565aba132ef736b8cc @ccotter ccotter committed Nov 12, 2012
@@ -324,7 +324,7 @@ private void sendRosterAvailable(ServerSession client) {
* @param client The old client.
*/
protected void sendRosterUnavailable(ServerSession client) {
- log.fine("CollabSessionHandler::sendRosterAvailable");
+ log.fine("CollabSessionHandler::sendRosterUnavailable");
/* create channel */
BayeuxServer server = this.sessionManager.getBayeux();
ServerChannel.Initializer initializer = new ServerChannel.Initializer() {
@@ -50,8 +50,9 @@ public boolean onClientJoin(ServerSession client, Message message) {
engState.put("value", this.sessionHandler.getEngineState());
data[cnt++] = engState;
- /* 3) Paused sync buffer. Since the moderator never pauses itself from processing sync events, we can safely
- ignore sending this (we would be sending an empty array otherwise). */
+ /* 3) Paused sync buffer. Since the moderator never pauses itself from
+ * processing sync events, we can safely ignore sending this
+ * (we would be sending an empty array otherwise). */
/* HashMap<String, Object> pauseState = new HashMap<String, Object>();
pauseState.put("topic", "coweb.pause.state");
pauseState.put("value", new Object[0]);
@@ -65,7 +66,8 @@ ignore sending this (we would be sending an empty array otherwise). */
this.addUpdater(client, true);
}
- client.batch(new BatchUpdateMessage(client, siteId, roster, data, true));
+ client.batch(new BatchUpdateMessage(client, siteId, roster, data,
+ true));
return first;
}
@@ -116,7 +116,6 @@ def on_publish(self, cl, req, res):
no error occurred beforehand. No expected return value.
'''
if res['successful'] and not req['channel'].startswith('/service/'):
- print(req)
self._manager.publish(req)
def on_unknown_client(self, res):
@@ -37,14 +37,14 @@ def __init__(self, *args, **kwargs):
# TODO make this optional
self._opengine = OEHandler(self, 0)
- # Moderator? TODO
+ # Moderator?
self._moderator = SessionModerator.getInstance(
self._container.moderatorClass, self.key)
if self._container.moderatorIsUpdater:
- self._late_join_handler = ModeratorLateJoinHandler(self)
+ self._lateJoinHandler = ModeratorLateJoinHandler(self)
else:
- self._late_join_handler = LateJoinHandler(self)
+ self._lateJoinHandler = LateJoinHandler(self)
def get_order(self):
'''Gets the next operation order sequence number.'''
@@ -63,16 +63,13 @@ def on_purging_client(self, cid, client):
'''Override to remove updater and end a session when none left.'''
# notify all bots of unsubscribing user
self._services.on_user_unsubscribe_all(client)
- self._late_join_handler.remove_updater(client)
- if not self._late_join_handler.get_updater_count():
+ self._lateJoinHandler.removeUpdater(client)
+ if self._lateJoinHandler.getUpdaterCount() == 0:
# kill the session
self.end_session()
- def queue_updatee(self, client):
- self._late_join_handler.queue_updatee(client)
-
- def unqueue_updatee(self, updater, data):
- self._late_join_handler.unqueue_updatee(updater, data)
+ def onUpdaterSendState(self, updater, data):
+ self._lateJoinHandler.onUpdaterSendState(updater, data)
class CollabSessionConnection(session.SessionConnection):
'''Connection for collaborative sessions.'''
@@ -83,7 +80,7 @@ def on_publish(self, cl, req, res):
# handle updater response
data = req.get('data', None)
try:
- self._manager.unqueue_updatee(cl, data)
+ self._manager.onUpdaterSendState(cl, data)
except Exception:
# bad updater, disconnect and assign a new one
self._manager.remove_bad_client(cl)
@@ -95,18 +92,18 @@ def on_publish(self, cl, req, res):
try:
# put siteId on message
req['data']['siteId'] = cl.siteId
- self._manager._late_join_handler.ensure_updater(cl)
+ self._manager._lateJoinHandler.ensureUpdater(cl)
except (KeyError, AttributeError):
# not allowed to publish syncs, disconnect
self._manager.remove_bad_client(cl)
return
# last state no longer valid
- self._manager._late_join_handler.clear_last_state()
+ self._manager._lateJoinHandler.clearLastState()
if '/app' == matches.group(2):
# App sync.
# Put total order sequence number on message
req['data']['order'] = self._manager.get_order()
- # let manager deal with the sync if forwarding it to services
+ # let manager deal with sync if forwarding it to services
self._manager.sync_for_service(cl, req)
if self._manager._opengine:
# Push sync to op engine.
@@ -133,10 +130,10 @@ def on_subscribe(self, cl, req, res):
coweb = ext['coweb']
updaterType = coweb['updaterType']
cl.updaterType = updaterType
- self._manager._late_join_handler.onClientJoin(cl)
+ self._manager._lateJoinHandler.onClientJoin(cl)
didSub = True
elif sub == '/service/session/updater':
- self._manager._late_join_handler.addUpdater(cl)
+ self._manager._lateJoinHandler.addUpdater(cl)
didSub = True
if didSub:
# don't run default handling if sub failed
@@ -30,20 +30,11 @@ def __init__(self, session):
# list that helps us assign the lowest available site id
self._siteids = ['reserved'] + [None] * 5
- def addAttendee(self, cl):
- self._attendees.append(cl)
-
- def removeAttendee(self, cl):
- try:
- self._attendees.remove(cl)
- except ValueError:
- pass
-
- def clear_last_state(self):
+ def clearLastState(self):
'''Clears the last updater state response. No longer valid.'''
self._lastState = None
- def get_updater_count(self):
+ def getUpdaterCount(self):
'''Gets the number of updaters.'''
return len(self._updaters)
@@ -65,7 +56,7 @@ def addSiteForClient(self, client):
client.siteId = siteId
return siteId
- def remove_site_for_client(self, client):
+ def removeSiteForClient(self, client):
'''Disassociates site ID from client.'''
try:
clientId = self._siteids[client.siteId]
@@ -88,15 +79,15 @@ def addUpdater(self, client, notify=True):
if notify:
self._sendRosterAvailable(client)
- def ensure_updater(self, client):
+ def ensureUpdater(self, client):
'''Ensures a client is an updater. Exception if not.'''
# just try to access to ensure
self._updaters[client.clientId]
- def remove_updater(self, client):
+ def removeUpdater(self, client):
'''Removes a client as an updater.'''
# remove this client from the assigned siteids
- self.remove_site_for_client(client)
+ self.removeSiteForClient(client)
try:
# remove this client from updaters
tokenList = self._updaters[client.clientId]
@@ -118,9 +109,9 @@ def remove_updater(self, client):
del self._updatees[token]
except KeyError:
continue
- self.assign_updater(updatee)
+ self.assignUpdater(updatee)
- def assign_updater(self, updatee):
+ def assignUpdater(self, updatee):
'''Assigns an updater to a late-joiner.'''
if not len(self._updaters):
# no updaters left, this is now the only updater
@@ -134,7 +125,7 @@ def assign_updater(self, updatee):
updaterId = None
if updatee.updaterType is not 'default':
matchedType = self._container.updaterTypeMatcher.match(
- updatee.updaterType, self.get_available_updater_types())
+ updatee.updaterType, self.getAvailableUpdaterTypes())
if matchedType is not None:
for clientId in self._updaters:
updater = self._session.get_client(clientId)
@@ -158,7 +149,7 @@ def assign_updater(self, updatee):
'data': token
})
- def get_available_updater_types(self):
+ def getAvailableUpdaterTypes(self):
updaterTypes = [];
for clientId in self._updaters:
updater = self._session.get_client(clientId)
@@ -174,7 +165,6 @@ def _getRosterList(self, client):
roster[updater.siteId] = updater.username
return roster
- # TODO see java server
def _sendRosterAvailable(self, client):
# Sends a roster addition to all clients.
msg = {
@@ -217,7 +207,7 @@ def onClientJoin(self, client):
data = []
sendState = True
elif self._lastState is None:
- self.assign_updater(client)
+ self.assignUpdater(client)
else:
data = self._lastState
sendState = True
@@ -236,14 +226,11 @@ def onClientJoin(self, client):
'data': data
})
- def unqueue_updatee(self, updater, data):
+ def onUpdaterSendState(self, updater, data):
'''Sends full state to a late-joiner waiting for it.'''
clientId = updater.clientId
token = None
- #log.debug('onStateResponse data: %s', str(data))
- #log.debug('clientId = %s', clientId)
-
# let exception bubble if data is missing token
token = data['token']
# let exception bubble if this is not really an updater
@@ -259,7 +246,6 @@ def unqueue_updatee(self, updater, data):
# store this state as the last known up-to-date state
if self._session.cacheState is True:
- log.info('using cached state')
self._lastState = data['state']
# send state to updatee
@@ -10,40 +10,37 @@ def __init__(self, session):
super(ModeratorLateJoinHandler, self).__init__(session)
self._moderator = session._moderator
- def queue_updatee(self, client):
+ def onClientJoin(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)
+ siteid = self.getSiteForClient(client)
except ValueError:
# get new site id
- siteid = self.add_site_for_client(client)
+ siteid = self.addSiteForClient(client)
# get the roster list to return before adding anyone
- roster = self._get_roster_list(client)
+ roster = self._getRosterList(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)
+ if 0 == self.getUpdaterCount():
+ self.addUpdater(client, False)
else:
- self.add_updater(client, True)
+ self.addUpdater(client, True)

0 comments on commit 6385951

Please sign in to comment.