Commit 456b5d9c authored by Jeremy Hylton's avatar Jeremy Hylton

Update to use transaction and BTrees packages.

parent 30944096
import sys, time, os, random import sys, time, os, random
import transaction
from persistent import Persistent
from ZEO import ClientStorage from ZEO import ClientStorage
import ZODB import ZODB
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
from Persistence import Persistent from BTrees import OOBTree
import BTree
class ChatSession(Persistent): class ChatSession(Persistent):
...@@ -28,7 +30,7 @@ class ChatSession(Persistent): ...@@ -28,7 +30,7 @@ class ChatSession(Persistent):
self.name = name self.name = name
# Internal attribute: _messages holds all the chat messages. # Internal attribute: _messages holds all the chat messages.
self._messages = BTree.BTree() self._messages = OOBTree.OOBTree()
def new_messages(self): def new_messages(self):
...@@ -58,7 +60,7 @@ class ChatSession(Persistent): ...@@ -58,7 +60,7 @@ class ChatSession(Persistent):
try: try:
now = time.time() now = time.time()
self._messages[ now ] = message self._messages[ now ] = message
get_transaction().commit() transaction.commit()
except ConflictError: except ConflictError:
# Conflict occurred; this process should pause and # Conflict occurred; this process should pause and
# wait for a little bit, then try again. # wait for a little bit, then try again.
...@@ -80,8 +82,8 @@ def get_chat_session(conn, channelname): ...@@ -80,8 +82,8 @@ def get_chat_session(conn, channelname):
root = conn.root() root = conn.root()
if not root.has_key('chat_sessions'): if not root.has_key('chat_sessions'):
print 'Creating chat_sessions B-tree' print 'Creating chat_sessions B-tree'
root['chat_sessions'] = BTree.BTree() root['chat_sessions'] = OOBTree.OOBTree()
get_transaction().commit() transaction.commit()
sessions = root['chat_sessions'] sessions = root['chat_sessions']
...@@ -90,7 +92,7 @@ def get_chat_session(conn, channelname): ...@@ -90,7 +92,7 @@ def get_chat_session(conn, channelname):
if not sessions.has_key( channelname ): if not sessions.has_key( channelname ):
print 'Creating new session:', channelname print 'Creating new session:', channelname
sessions[ channelname ] = ChatSession(channelname) sessions[ channelname ] = ChatSession(channelname)
get_transaction().commit() transaction.commit()
session = sessions[ channelname ] session = sessions[ channelname ]
return session return session
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment