Add new Agent class to Python API, for writing Store agents

This commit is contained in:
alexhudson
2011-01-01 23:24:22 +00:00
parent c4c2dac754
commit d9e27643d2
3 changed files with 34 additions and 3 deletions
+32
View File
@@ -0,0 +1,32 @@
import logging
import time
from bongo.BongoError import BongoError
from libbongo.libs import bongojson, msgapi
from bongo.store.StoreClient import DocTypes, StoreClient
class Agent:
log = logging.getLogger("Bongo.Error")
running = True
store = None
def __init__(self, name='Undefined'):
self.name = name
self.log.debug("Starting agent '%s'" % (name))
def connect(self, user, store):
self.store = StoreClient(user, store, authPassword="bongo", eventCallback=self.callback)
def callback(self, response):
# we want to override this in the subclass
self.log.error("Callback received and not handled")
pass
# without a proper event system in the store, we
# essentially have to poll. FIXME.
def waitForEvents(self):
while self.running:
self.store.NoOp()
time.sleep(5)
self.store.Quit()
+1 -1
View File
@@ -130,7 +130,7 @@ class CommandStream:
# gets eaten.
rCode = 0
if self.eventCallback:
self.eventCallback(Response(rCode, s[5:])
self.eventCallback(Response(rCode, s[5:]))
return Response(rCode, s[5:])
+1 -2
View File
@@ -381,7 +381,7 @@ class StoreClient:
self.stream = self.connection.stream
if eventCallback:
self.stream.setEventCallback(callback)
self.stream.setEventCallback(eventCallback)
# if we authed with a cookie or password, we don't need to USER
if not authCookie and not authPassword and user is not None:
@@ -947,5 +947,4 @@ class StoreClient:
def Reset(self) :
self.stream.Write("RESET\r\n")
self.stream.GetResponse()