Skip to content

Commit

Permalink
cleaning up, sticking to one file to start
Browse files Browse the repository at this point in the history
  • Loading branch information
joerussbowman committed May 12, 2011
1 parent 23e9c03 commit a998bbe
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 125 deletions.
37 changes: 0 additions & 37 deletions playground/pubsubtest-server.py

This file was deleted.

81 changes: 79 additions & 2 deletions playground/scale0.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,83 @@

import sys
import zmq
from multiprocessing import Process
import time
import uuid
from zmq import devices
from multiprocessing import Process

class Worker():
"""
Normally these would be separate programs, these are included for testing
purposes right now. The goal is that this could eventually grow into a
class that others can use in their applications.
Not really focused on that now. Right now just trying things out to see
how they work.
"""
def __init__(self, connect_to):
self.my_id = str(uuid.uuid4())
self.context = zmq.Context()
self.broker_socket = context.socket(zmq.XREQ)

broker_socket.setsockopt(zmq.IDENTITY, self.zmq_id)
broker_socket.connect(connect_to)

poller = zmq.Poller()
poller.register(broker_socket, zmq.POLLIN)

while True:
sock = dict(poller.poll())

if sock.get(broker_socket) == zmq.POLLIN:
multi_message = work_receiver.recv_multipart()
message = json.loads(multi_message[1])
# This worker just adds a reply with the same content
# as the request. This way we can verify the replies
# are matching.
message["reply"] = "%s" % (message["request"])

broker_socket.send_json(message)

class Dispatcher():
def __init__(self,
client_socket_uri="tcp://127.0.0.1:8080",
worker_socket_uri="tcp://127.0.0.1:8081",
router_socket_base="ipc:///var/tmp/",
my_id=str(uuid.uuid4())):

self.my_id = my_id
self.LRU = []
self.WQ = []

self.context = zmq.Context()

self.client_socket = context.socket(zmq.XREP)
self.worker_socket = context.socket(zmq.XREP)
self.router_socket = context.socket(zmq.XREP)

self.client_socket.setsockopt(zmq.IDENTITY, "%s-client" % self.my_id)
self.worker_socket.setsockopt(zmq.IDENTITY, "%s-worker" % self.my_id)
self.router_socket.setsockopt(zmq.IDENTITY, "%s-router" % self.my_id)

self.client_socket.bind(client_socket_uri)
self.worker_socket.bind(worker_socket_url)
self.router_socket.bind("%s/%s_router_listener" % (router_socket_base, self.my_id)


class Router():
def__init__(self, context, my_id=str(uuid.uuid4())):
self.context = context
self.my_id = my_id
self.context = context

self.dispatcher_socket = context.socket(zmq.XREQ)
# have to pass context, how so I access sockets on context?









86 changes: 0 additions & 86 deletions playground/xreqxrep-server.py

This file was deleted.

Empty file removed playground/xreqxreptest-client.py
Empty file.

0 comments on commit a998bbe

Please sign in to comment.