Changeset - 13f758eda3b4
[Not reviewed]
default
0 1 0
Drew Perttula - 9 years ago 2016-06-05 00:49:15
drewp@bigasterisk.com
refactor rdfdb: sendGraphToClient
Ignore-this: 77dc47e091494adabca4cf04173547de
1 file changed with 10 insertions and 9 deletions:
bin/rdfdb
10
9
0 comments (0 inline, 0 general)
bin/rdfdb
Show inline comments
 
@@ -126,31 +126,32 @@ from light9.rdfdb.patchreceiver import m
 
from twisted.internet.inotify import INotify
 
from run_local import log
 
log.setLevel(logging.DEBUG)
 

	
 
from lib.cycloneerr import PrettyErrorHandler
 

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

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

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

	
 
    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=graph.quads(ALLSTMTS),
 
            delQuads=[]))
 

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

	
 
class WatchedFiles(object):
 
    """
 
    find files, notice new files.
 
@@ -332,13 +333,13 @@ class Db(object):
 

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

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

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