Skip to content

Commit

Permalink
Meta client creation done.
Browse files Browse the repository at this point in the history
Next step is meta lookups.
  • Loading branch information
CurleySamuel committed Jul 14, 2015
1 parent 672724e commit d6d4963
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import zk.zk as zk
from pybase import *

print zk.LocateMeta("localhost")
a = NewClient("localhost")
14 changes: 14 additions & 0 deletions pybase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import zk.zk as zk
import region.region as region


class Client:
def __init__(self, zkquorum, client):
self.zkquorum = zkquorum
self.meta_client = client


def NewClient(zkquorum):
ip, port = zk.LocateMeta(zkquorum)
meta_client = region.NewClient(ip, port)
return Client(zkquorum, meta_client)
Empty file added region/__init__.py
Empty file.
25 changes: 25 additions & 0 deletions region/region.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import socket
from struct import pack, unpack
from pb.RPC_pb2 import ConnectionHeader, UserInformation

class Client:
def __init__(self, host, port, sock):
s.host = host
s.port = port
s.sock = sock


def NewClient(host, port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
_send_hello(s)
return


def _send_hello(sock):
ch = ConnectionHeader()
ch.user_info.effective_user = "pybase"
ch.service_name = "ClientService"
serialized = ch.SerializeToString()
message = "HBas\x00\x50" + pack(">I", len(serialized)) + serialized
sock.send(message)

0 comments on commit d6d4963

Please sign in to comment.