summaryrefslogtreecommitdiff
path: root/datastore/interactive.py
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2013-01-11 20:01:09 +0100
committerYves Fischer <yvesf-git@xapek.org>2013-01-11 20:01:09 +0100
commit934d642b410d75dae1966c993fc61c371959876e (patch)
treeca9bcd22d98d88424be0d21d6387ddba779a9daa /datastore/interactive.py
parent69fbdff8e8ba69034111038ce01184ef5472728a (diff)
downloadebus-alt-934d642b410d75dae1966c993fc61c371959876e.tar.gz
ebus-alt-934d642b410d75dae1966c993fc61c371959876e.zip
datastore
Diffstat (limited to 'datastore/interactive.py')
-rw-r--r--datastore/interactive.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/datastore/interactive.py b/datastore/interactive.py
new file mode 100644
index 0000000..76a9636
--- /dev/null
+++ b/datastore/interactive.py
@@ -0,0 +1,51 @@
+from IPython import embed
+from time import time
+from stompclient import PublishSubscribeClient
+import config
+from uuid import uuid1 as uuid
+from threading import Thread, Event
+
+client = PublishSubscribeClient(config.STOMP_HOST, config.STOMP_PORT)
+listener = Thread(target=client.listen_forever, name='Frame-Receiver')
+listener.start()
+client.listening_event.wait()
+r = client.connect(config.STOMP_LOGIN, config.STOMP_PASSCODE)
+if not client.connection:
+ print r
+ exit(1)
+
+def put(valuemap):
+ body="\n".join(map(lambda (k,v): "{0}={1}".format(k,v), valuemap.iteritems()))
+ client.send(config.STOMP_QUEUE_PUT,
+ body=body,
+ extra_headers={"timestamp":int(time()*1000)})
+
+def get(name,query=None,timeout=5.0):
+ reply=[]
+ def unlock(frame,reply):
+ reply.append(frame.body)
+ cond.set()
+
+ replyTo='/topic/reply-' + str(uuid())
+ cond = Event()
+ client.subscribe(replyTo, lambda frame: unlock(frame,reply))
+ client.send(config.STOMP_QUEUE_GET,
+ body=query,
+ extra_headers={'name':name,
+ 'reply-to':replyTo})
+ cond.wait(timeout)
+ client.unsubscribe(replyTo)
+ return len(reply)>0 and reply[0] or None
+
+print """
+EXAMPLES
+ put({"org.xapek.test1":"asd1234"})
+ get("org.xapek.test1")
+
+"""
+
+embed()
+
+client.disconnect()
+
+