Changeset - a214a9d6f2f0
[Not reviewed]
default
0 1 0
Drew Perttula - 9 years ago 2016-06-05 00:35:32
drewp@bigasterisk.com
refactor rdfdb: Client doesn't need Db at construction
Ignore-this: 9a3591d13c4ff821dd6e543bf78f8583
1 file changed with 6 insertions and 6 deletions:
0 comments (0 inline, 0 general)
bin/rdfdb
Show inline comments
 
@@ -130,27 +130,25 @@ log.setLevel(logging.DEBUG)
 
from lib.cycloneerr import PrettyErrorHandler
 

	
 
class Client(object):
 
    """
 
    one of our syncedgraph clients
 
    """
 
    def __init__(self, updateUri, label, db):
 
        self.db = db
 
    def __init__(self, updateUri, label):
 
        self.label = label
 
        self.updateUri = updateUri
 
        self.sendAll()
 

	
 
    def __repr__(self):
 
        return "<%s client at %s>" % (self.label, self.updateUri)
 

	
 
    def sendAll(self):
 
    def sendAll(self, graph):
 
        """send the client the whole graph contents"""
 
        log.info("sending all graphs to %s at %s" %
 
                 (self.label, self.updateUri))
 
        self.sendPatch(Patch(
 
            addQuads=self.db.graph.quads(ALLSTMTS),
 
            addQuads=graph.quads(ALLSTMTS),
 
            delQuads=[]))
 

	
 
    def sendPatch(self, p):
 
        return sendPatch(self.updateUri, p)
 

	
 
class WatchedFiles(object):
 
@@ -334,13 +332,15 @@ class Db(object):
 

	
 
    def addClient(self, updateUri, label):
 
        [self.clients.remove(c)
 
         for c in self.clients if c.updateUri == updateUri]
 

	
 
        log.info("new client %s at %s" % (label, updateUri))
 
        self.clients.append(Client(updateUri, label, self))
 
        c = Client(updateUri, label)
 
        c.sendAll(self.graph)
 
        self.clients.append(c)
 
        self.sendClientsToAllLivePages()
 

	
 
    def sendClientsToAllLivePages(self):
 
        sendToLiveClients({"clients":[
 
            dict(updateUri=c.updateUri, label=c.label)
 
            for c in self.clients]})
0 comments (0 inline, 0 general)