Skip to content

Commit

Permalink
Working on python moderator.
Browse files Browse the repository at this point in the history
A moderator object is created for each session, but otherwise it does
nothing at this point.
  • Loading branch information
ccotter committed Oct 15, 2012
1 parent 0086bc1 commit 3efc466
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 10 deletions.
2 changes: 1 addition & 1 deletion servers/python/coweb/__init__.py
Expand Up @@ -2,6 +2,6 @@
Copyright (c) The Dojo Foundation 2011. All Rights Reserved.
Copyright (c) IBM Corporation 2008, 2011. All Rights Reserved.
'''
VERSION = '0.8.3'
VERSION = '0.8.4-SNAPSHOT'
from runner import run_server
from container import AppContainer
4 changes: 4 additions & 0 deletions servers/python/coweb/admin.py
Expand Up @@ -57,11 +57,15 @@ def post(self):
access = self._container.access
sessionInfo = access.on_admin_request(username, key, collab)

config = {}
config['sessionModerator'] = None

if sessionId is None:
# create a new session if not started yet
# if we made it here, user has permission to do so
sess = session.create_session(
collab,
config,
key=key,
cacheState=cacheState,
container=self._container,
Expand Down
2 changes: 1 addition & 1 deletion servers/python/coweb/cowebpyoe/OperationEngine.py
Expand Up @@ -33,7 +33,7 @@ def __init__(self, siteId):
self.hb = HistoryBuffer()
self.siteCount = 1

VERSION = "0.8.3"
VERSION = "0.8.4-SNAPSHOT"

"""
Gets the state of this engine instance to seed a new instance.
Expand Down
4 changes: 2 additions & 2 deletions servers/python/coweb/session/__init__.py
Expand Up @@ -7,7 +7,7 @@
from session import Session
from collab import CollabSession

def create_session(collab, *args, **kwargs):
def create_session(collab, config, *args, **kwargs):
'''Builds a cooperative or non-cooperative session.'''
cls = CollabSession if collab else Session
return cls(*args, **kwargs)
return cls(config, *args, **kwargs)
8 changes: 6 additions & 2 deletions servers/python/coweb/session/collab.py
Expand Up @@ -15,6 +15,7 @@
# coweb
import session
from .. import OEHandler
from .. import session_moderator

OEHandler = OEHandler.OEHandler
session_sync_regex = re.compile("/session/([A-z0-9]+)/sync(.*)");
Expand All @@ -25,8 +26,8 @@ class CollabSession(session.Session):
'''
Manages a session instance that supports services and cooperative events.
'''
def __init__(self, *args, **kwargs):
super(CollabSession, self).__init__(*args, **kwargs)
def __init__(self, config, *args, **kwargs):
super(CollabSession, self).__init__(config, *args, **kwargs)
self.collab = True
self._connectionClass = CollabSessionConnection

Expand All @@ -50,6 +51,9 @@ def __init__(self, *args, **kwargs):

# TODO make this optional
self._opengine = OEHandler(self, 0)

# Moderator? TODO
self._moderator = session_moderator.get_instance(self.config['sessionModerator'], self.key)

def get_order(self):
'''Gets the next operation order sequence number.'''
Expand Down
5 changes: 3 additions & 2 deletions servers/python/coweb/session/session.py
Expand Up @@ -24,9 +24,10 @@ class Session(bayeux.BayeuxManager):
Manages a session instance that supports services but no user cooperative
events.
'''
def __init__(self, container, key, cacheState, *args, **kwargs):
def __init__(self, config, container, key, cacheState, *args, **kwargs):
super(Session, self).__init__(*args, **kwargs)
self.collab = False
self.config = config
# produce unique session ID
self.sessionId = uuid.uuid4().hex
self.key = key
Expand Down Expand Up @@ -202,4 +203,4 @@ def on_publish(self, cl, req, res):
res['error'] = '402:%s:not-allowed' % client.clientId
res['successful'] = False
return
super(SessionConnection, self).on_publish(cl, req, res)
super(SessionConnection, self).on_publish(cl, req, res)
74 changes: 74 additions & 0 deletions servers/python/coweb/session_moderator.py
@@ -0,0 +1,74 @@

_moderators = {}

# Adopted from hasen j's answer to
# http://stackoverflow.com/questions/452969/does-python-have-an-equivalent-to-java-class-forname
def _get_class( kls ):
try:
parts = kls.split('.')
module = ".".join(parts[:-1])
m = __import__( module )
for comp in parts[1:]:
m = getattr(m, comp)
return m
except Exception:
return None

def get_instance(class_name, key):
moderator = _moderators.get(key, None)
if moderator is not None:
return moderator

# Must create a new moderator for the given cowebkey.
if not class_name:
class_name = 'coweb.session_moderator.session_moderator'

clss = _get_class(class_name)
if clss is None:
clss = session_moderator

moderator = clss(key)
_moderators[key] = moderator
return moderator

class session_moderator:

def __init__(self, key):
self.key = key

def canClientJoinState(self, client):
pass

def canClientMakeServiceRequest(self, client):
pass

def canClientSubscribeService(self, client):
pass

def getLateJoinState(self):
pass

def getLocalSession(self):
pass

def getServerSession(self):
pass

def onClientJoinSession(self, client):
pass

def onClientLeaveSession(self, client):
pass

def onServiceResponse(self, botResponse):
pass

def onSessionEnd(self):
pass

def onSync(self, data):
pass

def setSessionAttribute(self, key, value):
pass

4 changes: 2 additions & 2 deletions servers/python/setup.py
Expand Up @@ -11,7 +11,7 @@
import shutil
import subprocess

VERSION = '0.8.3'
VERSION = '0.8.4-SNAPSHOT'

isSDist = len(sys.argv) > 1 and sys.argv[1] == 'sdist'
srcDir = os.path.join(os.environ['PWD'], '../../js/release/coweb-%s' % VERSION)
Expand Down Expand Up @@ -61,7 +61,7 @@
'coweb.service.manager',
'coweb.session',
'coweb.updater',
'cowebpyoe'
'coweb.cowebpyoe'
],
data_files = cowebJSFiles,
package_data={
Expand Down

0 comments on commit 3efc466

Please sign in to comment.