mirror of
https://github.com/wassname/ray.git
synced 2026-06-30 01:57:09 +08:00
add plasma manager
This commit is contained in:
+24
-1
@@ -9,8 +9,13 @@ ID = ctypes.c_ubyte * 20
|
||||
class PlasmaID(ctypes.Structure):
|
||||
_fields_ = [("plasma_id", ID)]
|
||||
|
||||
# these must be in sync with plasma_request_type in plasma.h
|
||||
# these must be in sync with plasma_request_type in plasma.h (can we have a test for that?)
|
||||
PLASMA_CREATE = 0
|
||||
PLASMA_GET = 1
|
||||
PLASMA_SEAL = 2
|
||||
PLASMA_TRANSFER = 3
|
||||
PLASMA_DATA = 4
|
||||
PLASMA_REGISTER = 5
|
||||
|
||||
class PlasmaRequest(ctypes.Structure):
|
||||
_fields_ = [("type", ctypes.c_int),
|
||||
@@ -32,6 +37,24 @@ def make_plasma_id(string):
|
||||
object_id = map(ord, string)
|
||||
return PlasmaID(plasma_id=ID(*object_id))
|
||||
|
||||
class PlasmaManager(object):
|
||||
|
||||
def __init__(self, addr, port):
|
||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.sock.connect((addr, port))
|
||||
|
||||
def register(self, manager_id, addr, port):
|
||||
"Register another object manager."
|
||||
req = PlasmaRequest(type=PLASMA_REGISTER, manager_id=manager_id,
|
||||
addr=Addr(*map(int, addr.split("."))), port=port)
|
||||
self.sock.send(buffer(req)[:])
|
||||
|
||||
def transfer(self, manager_id, object_id):
|
||||
"Transfer local object with id object_id to manager with id manager_id."
|
||||
req = PlasmaRequest(type=PLASMA_TRANSFER, manager_id=manager_id,
|
||||
object_id=make_plasma_id(object_id))
|
||||
self.sock.send(buffer(req)[:])
|
||||
|
||||
class PlasmaClient(object):
|
||||
def __init__(self, socket_name):
|
||||
plasma_client_library = os.path.join(os.path.abspath(os.path.dirname(__file__)), "../../build/plasma_client.so")
|
||||
|
||||
Reference in New Issue
Block a user