Example #1
0
def state_post(context, request):
    id = request.matchdict["id"]
    object_type = request.POST.get('type', 'string')
    operation_type = request.POST.get("op", "set")
    
    parameters = {}
    for k, v in request.POST.iteritems():
        if k not in ["op", "type"]:
            parameters[k] = v
            
    # Create redis client
    client = redisconnect.connect()

    # Create top level         
    st = state.State("user", client)

    obj = st.get_or_create(id, object_type)
        
    obj.op(operation_type, **parameters)
        
    resp = Response()
    resp.content_type = "text/plain"
    resp.text = u"OK"
    # return the old value of the key
    return resp
Example #2
0
def state_post(context, request):
    id = request.matchdict["id"]
    object_type = request.POST.get('type', 'string')
    operation_type = request.POST.get("op", "set")

    parameters = {}
    for k, v in request.POST.iteritems():
        if k not in ["op", "type"]:
            parameters[k] = v

    # Create redis client
    client = redisconnect.connect()

    # Create top level
    st = state.State("user", client)

    obj = st.get_or_create(id, object_type)

    obj.op(operation_type, **parameters)

    resp = Response()
    resp.content_type = "text/plain"
    resp.text = u"OK"
    # return the old value of the key
    return resp
Example #3
0
    def _run(self):
        # Create redis client
        client = redisconnect.connect()
        self.dict = redis_dict.RedisDict(client)
        # Create the broker
        self.state = state.State(self.user, client)
        self.subscriber = self.state.subscriber()
        self.lastTime = {}

        # Subscribe to the "wake-up" signal
        self.subscriber.subscribe(self.wake_up_channel)
        self.ready = True

        self.prepare()

        try:
            # Create top level redis dict
            for operation in self.subscriber:
                operation = operation[1]
                id = operation["id"]
                if operation.get("op") == "listen":
                    self.subscriber.subscribe(self.state.id_to_key(id))

                    try:
                        operation = self.state.get_agregated_operation(id)
                    except KeyError:
                        # We will only get subscribe messages, as the object does exist yet
                        continue

                    self.emit(operation)
                    self.lastTime[id] = operation["time"]
                else:
                    t = operation["time"]

                    if id in self.lastTime and t > self.lastTime[id]:
                        go_on = self.emit(operation)
                        self.lastTime[id] = t
                    if not go_on:
                        break
        finally:
            self.queue.put(StopIteration)
Example #4
0
    def _run(self):
        # Create redis client
        client = redisconnect.connect()
        self.dict = redis_dict.RedisDict(client)
        # Create the broker
        self.state = state.State(self.user, client)
        self.subscriber = self.state.subscriber()
        self.lastTime = {}

        # Subscribe to the "wake-up" signal
        self.subscriber.subscribe(self.wake_up_channel)
        self.ready = True

        self.prepare()

        try:
            # Create top level redis dict
            for operation in self.subscriber:
                operation = operation[1]
                id = operation["id"]
                if operation.get("op") == "listen":
                    self.subscriber.subscribe(self.state.id_to_key(id))

                    try:
                        operation = self.state.get_agregated_operation(id)
                    except KeyError:
                        # We will only get subscribe messages, as the object does exist yet
                        continue

                    self.emit(operation)
                    self.lastTime[id] = operation["time"]
                else:
                    t = operation["time"]

                    if id in self.lastTime and t > self.lastTime[id]:
                        go_on = self.emit(operation)
                        self.lastTime[id] = t
                    if not go_on:
                        break
        finally:
            self.queue.put(StopIteration)
Example #5
0
 def connect(self):
     if self.client == None:
         self.client = redisconnect.connect()
     return self.client
Example #6
0
 def connect(self):
     if self.client == None:
         self.client = redisconnect.connect()
     return self.client