def openWriter(self, fname, xml, json=None): tdw = PyTango.DeviceProxy(self._sv.new_device_info_writer.name) self.assertTrue(ProxyHelper.wait(tdw, 10000)) self.setProp(tdw, "writer", "h5cpp") tdw.FileName = fname self.assertEqual(tdw.state(), PyTango.DevState.ON) self.assertEqual(tdw.status(), self.__status[tdw.state()]) tdw.OpenFile() self.assertEqual(tdw.state(), PyTango.DevState.OPEN) self.assertEqual(tdw.status(), self.__status[tdw.state()]) tdw.XMLSettings = xml self.assertEqual(tdw.state(), PyTango.DevState.OPEN) self.assertEqual(tdw.status(), self.__status[tdw.state()]) if json: tdw.JSONRecord = json self.assertEqual(tdw.status(), self.__status[tdw.state()]) self.assertEqual(tdw.state(), PyTango.DevState.OPEN) tdw.OpenEntryAsynch() self.assertTrue(ProxyHelper.wait(tdw, 10000)) self.assertEqual(tdw.status(), self.__status[tdw.state()]) self.assertEqual(tdw.state(), PyTango.DevState.EXTRACT) return tdw
def record(self, tdw, string): self.assertEqual(tdw.status(), self.__status[tdw.state()]) self.assertEqual(tdw.state(), PyTango.DevState.EXTRACT) tdw.RecordAsynch(string) self.assertTrue(ProxyHelper.wait(tdw, 10000)) self.assertEqual(tdw.status(), self.__status[tdw.state()]) self.assertEqual(tdw.state(), PyTango.DevState.EXTRACT)
def test_setData_dev_prop(self): device = 'stestp09/testss/s1r228' proxy = PyTango.DeviceProxy(device) self.assertTrue(ProxyHelper.wait(proxy, 10000)) fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) arr = { "DeviceBoolean": ["ScalarBoolean", "bool", "DevBoolean", True], # "DeviceUChar":["ScalarUChar", "uint8", "DevUChar", 23], "DeviceShort": ["ScalarShort", "int16", "DevShort", -123], "DeviceUShort": ["ScalarUShort", "uint16", "DevUShort", 1234], "DeviceLong": ["ScalarLong", "int64", "DevLong", -124], "DeviceULong": ["ScalarULong", "uint64", "DevULong", 234], # "DeviceLong64":["ScalarLong64", "int64", "DevLong64", 234], # "DeviceULong64":["ScalarULong64", "uint64", "DevULong64", 23], "DeviceFloat": ["ScalarFloat", "float32", "DevFloat", 12.234], "DeviceDouble": ["ScalarDouble", "float64", "DevDouble", -2.456673e+02], "DeviceString": ["ScalarString", "string", "DevString", "MyTrue"], } prop = self._simps.dp.get_property(list(arr.keys())) for k in prop.keys(): prop[k] = [arr[k][3]] self._simps.dp.put_property(prop) for k in arr: mb = TgMember(k, "property") da = proxy.get_property(k)[k] mb.setData(da) dt = mb.getValue() self.checkData(dt, "SCALAR", str(arr[k][3]), 'DevString', [1, 0], None, None, arr[k][4] if len(arr[k]) > 4 else 0)
def test_setData_command(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) device = 'stestp09/testss/s1r228' proxy = PyTango.DeviceProxy(device) self.assertTrue(ProxyHelper.wait(proxy, 10000)) arr = { "GetBoolean": ["ScalarBoolean", "bool", "DevBoolean", True], # "GetUChar":["ScalarUChar", "uint8", "DevUChar", 23], "GetShort": ["ScalarShort", "int16", "DevShort", -123], "GetUShort": ["ScalarUShort", "uint16", "DevUShort", 1234], "GetLong": ["ScalarLong", "int64", "DevLong", -124], "GetULong": ["ScalarULong", "uint64", "DevULong", 234], "GetLong64": ["ScalarLong64", "int64", "DevLong64", 234], "GetULong64": ["ScalarULong64", "uint64", "DevULong64", 23], "GetFloat": ["ScalarFloat", "float32", "DevFloat", 12.234, 1e-5], "GetDouble": ["ScalarDouble", "float64", "DevDouble", -2.456673e+02, 1e-14], "GetString": ["ScalarString", "string", "DevString", "MyTrue"], } for k in arr: self._simps.dp.write_attribute(arr[k][0], arr[k][3]) for k in arr: mb = TgMember(k, "command") cd = proxy.command_query(k) da = proxy.command_inout(k) mb.setData(da, cd) dt = mb.getValue() self.checkData(dt, "SCALAR", arr[k][3], arr[k][2], [1, 0], None, None, arr[k][4] if len(arr[k]) > 4 else 0)
def test_setData_scalar(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) device = 'stestp09/testss/s1r228' proxy = PyTango.DeviceProxy(device) self.assertTrue(ProxyHelper.wait(proxy, 10000)) arr1 = { "ScalarBoolean": ["bool", "DevBoolean", True], "ScalarUChar": ["uint8", "DevUChar", 23], "ScalarShort": ["int16", "DevShort", -123], "ScalarUShort": ["uint16", "DevUShort", 1234], "ScalarLong": ["int64", "DevLong", -124], "ScalarULong": ["uint64", "DevULong", 234], "ScalarLong64": ["int64", "DevLong64", 234], "ScalarULong64": ["uint64", "DevULong64", 23], "ScalarFloat": ["float32", "DevFloat", 12.234, 1e-5], "ScalarDouble": ["float64", "DevDouble", -2.456673e+02, 1e-14], "ScalarString": ["string", "DevString", "MyTrue"], } arr2 = { "State": ["string", "DevState", PyTango._PyTango.DevState.ON], } arr3 = { "ScalarEncoded": [ "string", "DevEncoded", ("UTF8", b"Hello UTF8! Pr\xc3\xb3ba \xe6\xb5\x8b") ], "SpectrumEncoded": [ "string", "DevEncoded", ('INT32', b'\xd2\x04\x00\x00.\x16\x00\x00-' b'\x00\x00\x00Y\x01\x00\x00') ], } for k in arr1: self._simps.dp.write_attribute(k, arr1[k][2]) arr = dict(arr1, **(arr2)) for k in arr: mb = TgMember(k) da = proxy.read_attribute(k) mb.setData(da) dt = mb.getValue() self.checkData(dt, "SCALAR", arr[k][2], arr[k][1], [1, 0], None, None, arr[k][3] if len(arr[k]) > 3 else 0) if not PYTG_BUG_213: for k in arr3: mb = TgMember(k, encoding=arr3[k][2][0]) da = proxy.read_attribute(k) mb.setData(da) dp = DecoderPool() dt = mb.getValue(dp) self.checkData(dt, "SCALAR", arr3[k][2], arr3[k][1], [1, 0], arr3[k][2][0], dp)
def test_getData_default(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) dname = 'writer' device = 'stestp09/testss/s1r228' # ctype = 'command' # atype = 'attribute' # host = self._dbhost # port = '10000' # encoding = 'UTF8' # group = 'common_motors' proxy = PyTango.DeviceProxy(device) self.assertTrue(ProxyHelper.wait(proxy, 10000)) mb = TgMember(dname) mb.getData(proxy) self.myAssertRaise(DataSourceSetupError, mb.getValue) mb = TgMember('ScalarString') mb.getData(proxy) dt = mb.getValue() self.checkData(dt, "SCALAR", "Hello!", "DevString", [1, 0], None, None) mb = TgMember('ScalarString') mb.getData(proxy) dt = mb.getValue() self.checkData(dt, "SCALAR", "Hello!", "DevString", [1, 0], None, None) dt = mb.getValue() self.checkData(dt, "SCALAR", "Hello!", "DevString", [1, 0], None, None) mb.reset() self.myAssertRaise(DataSourceSetupError, mb.getValue)
def test_setData_image(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) device = 'stestp09/testss/s1r228' proxy = PyTango.DeviceProxy(device) self.assertTrue(ProxyHelper.wait(proxy, 10000)) arr = { "ImageBoolean": ["bool", "DevBoolean", True, [1, 0]], "ImageUChar": ["uint8", "DevUChar", 23, [1, 0]], "ImageShort": ["int16", "DevShort", -123, [1, 0]], "ImageUShort": ["uint16", "DevUShort", 1234, [1, 0]], "ImageLong": ["int64", "DevLong", -124, [1, 0]], "ImageULong": ["uint64", "DevULong", 234, [1, 0]], "ImageLong64": ["int64", "DevLong64", 234, [1, 0]], "ImageULong64": ["uint64", "DevULong64", 23, [1, 0]], "ImageFloat": ["float32", "DevFloat", 12.234, [1, 0], 1e-5], "ImageDouble": ["float64", "DevDouble", -2.456673e+02, [1, 0], 1e-14], "ImageString": ["string", "DevString", "MyTrue", [1, 0]], } for k in arr: mlen = [ self.__rnd.randint(1, 10), self.__rnd.randint(1, 10), self.__rnd.randint(0, 3) ] if arr[k][1] != "DevBoolean": arr[k][2] = [[ arr[k][2] * self.__rnd.randint(0, 3) for r in range(mlen[1]) ] for c in range(mlen[0])] else: mlen = [self.__rnd.randint(1, 10), self.__rnd.randint(1, 10)] if arr[k][1] == 'DevBoolean': arr[k][2] = [[(True if self.__rnd.randint(0, 1) else False) for c in range(mlen[1])] for r in range(mlen[0])] arr[k][3] = [mlen[0], mlen[1]] self._simps.dp.write_attribute(k, arr[k][2]) for k in arr: mb = TgMember(k) da = proxy.read_attribute(k) mb.setData(da) dt = mb.getValue() self.checkData(dt, "IMAGE", arr[k][2], arr[k][1], arr[k][3], None, None, arr[k][4] if len(arr[k]) > 4 else 0)
def closeWriter(self, tdw, json=None): self.assertEqual(tdw.state(), PyTango.DevState.EXTRACT) if json: tdw.JSONRecord = json self.assertEqual(tdw.status(), self.__status[tdw.state()]) self.assertEqual(tdw.state(), PyTango.DevState.EXTRACT) tdw.CloseEntryAsynch() self.assertTrue(ProxyHelper.wait(tdw, 10000)) self.assertEqual(tdw.status(), self.__status[tdw.state()]) self.assertEqual(tdw.state(), PyTango.DevState.OPEN) tdw.CloseFile() self.assertEqual(tdw.state(), PyTango.DevState.ON) self.assertEqual(tdw.status(), self.__status[tdw.state()])
class GeneralClientProxy: def __init__(self,connection): self.__proxyHelper = ProxyHelper(connection) def destroy(self,type,name): return self.__proxyHelper.doOp("DESTROY", 0, None, type, name) def txnBegin(self): return self.__proxyHelper.doOp("TRXBEGIN", 0, None) def txnCommit(self): return self.__proxyHelper.doOp("TRXCOMMIT", 0, None) def txnRollback(self): return self.__proxyHelper.doOp("TRXROLLBACK", 0, None) def instances(self): return self.__proxyHelper.doOp("INSTANCES", 0, None) def members(self): return self.__proxyHelper.doOp("MEMBERS", 0, None) def ping(self): return self.__proxyHelper.doOp("PING", 0, None) def clusterTime(self): raise NotImplementedError def partitions(self): raise NotImplementedError
def __init__(self , name , connection): self.__name = name self.__proxyHelper = ProxyHelper(connection)
class MapClientProxy: def __init__(self , name , connection): self.__name = name self.__proxyHelper = ProxyHelper(connection) def addListener(self, listener, key=None, includeValue=False): """ If key is provided listener will be notified only for the key, otherwise it will notified for all entries in the map If includeValue set to True it will bring values for the keys with the event""" self.__listenerManager = ListenerManager(self.__proxyHelper) listener.listenerManager = self.__listenerManager listener.key = key listener.name = self.__name self.__listenerManager.addListenerOp(listener, key, includeValue, self.__name) def removeListener(self, listener, key=None): self.__listenerManager.removeListenerOp(listener, key, self.__name) def put(self, key, value, ttl=0): self.__proxyHelper.check(key) self.__proxyHelper.check(value) return self.__proxyHelper.doOp("MPUT", 2, (key, value), self.__name, str(ttl)) def putIfAbsent(self, key, value, ttl=0): self.__proxyHelper.check(key) self.__proxyHelper.check(value) return self.__proxyHelper.doOp("MPUTIFABSENT", 2, (key, value), self.__name, str(ttl)) def putTransient(self, key, value, ttl=0): self.__proxyHelper.check(key) self.__proxyHelper.check(value) return self.__proxyHelper.doOp("MPUTTRANSIENT", 2, (key, value), self.__name, str(ttl)) def putAll(self, entries): return self.__proxyHelper.doOp("MPUTALL", 2 * len(entries), entries, self.__name) def putAndUnlock(self, key, value): self.__proxyHelper.check(key) self.__proxyHelper.check(value) return self.__proxyHelper.doOp("MPUTANDUNLOCK", 2, (key, value), self.__name) def set(self, key, value, ttl=0): self.__proxyHelper.check(key) self.__proxyHelper.check(value) return self.__proxyHelper.doOp("MSET", 2, (key, value), self.__name, str(ttl)) def get(self, key): self.__proxyHelper.check(key) return self.__proxyHelper.doOp("MGET", 1, key, self.__name) def getAll(self, keys): #com.hazelcast.nio.Data cannot be cast to java.lang.Comparable for key in keys: self.__proxyHelper.check(key) return self.__proxyHelper.doOp("MGETALL", len(keys), keys, self.__name) def tryPut(self, key, value, timeout): self.__proxyHelper.check(key) self.__proxyHelper.check(value) return self.__proxyHelper.doOp("MTRYPUT", 2, (key, value), self.__name, str(timeout)) def tryLock(self, key, timeout): # not yet implemented on the server side self.__proxyHelper.check(key) return self.__proxyHelper.doOp("MTRYLOCK", 1, key, self.__name, str(timeout)) def isKeyLocked(self, key): # server handler doesn't give reply self.__proxyHelper.check(key) return self.__proxyHelper.doOp("MISKEYLOCKED", 1, key, self.__name) def lock(self, key, timeout): self.__proxyHelper.check(key) return self.__proxyHelper.doOp("MLOCK", 1, key, self.__name, str(timeout)) def unLock(self, key): self.__proxyHelper.check(key) return self.__proxyHelper.doOp("MUNLOCK", 1, key, self.__name) def lockMap(self, timeout): return self.__proxyHelper.doOp("MLOCKMAP", 0, None, self.__name, str(timeout)) def unlockMap(self, timeout): return self.__proxyHelper.doOp("MUNLOCKMAP", 0, None, self.__name, str(timeout)) def forceUnlock(self, key): self.__proxyHelper.check(key) return self.__proxyHelper.doOp("MFORCEUNLOCK", 1, key, self.__name) def containsKey(self, key): self.__proxyHelper.check(key) return self.__proxyHelper.doOp("MCONTAINSKEY", 1, key, self.__name) def containsValue(self, value): self.__proxyHelper.check(value) return self.__proxyHelper.doOp("MCONTAINSVALUE", 1, value, self.__name) def keySet(self): return self.__proxyHelper.doOp("KEYSET", 0, None, "map", self.__name) def remove(self, key): self.__proxyHelper.check(key) return self.__proxyHelper.doOp("MREMOVE", 1, key , self.__name) def removeIfSame(self, key, value): self.__proxyHelper.check(key) self.__proxyHelper.check(value) return self.__proxyHelper.doOp("MREMOVEIFSAME", 2, (key, value), self.__name,) def replaceIfNotNull(self, key, value): self.__proxyHelper.check(key) self.__proxyHelper.check(value) return self.__proxyHelper.doOp("MREPLACEIFNOTNULL", 2, (key, value), self.__name,) def replaceIfSame(self, key, oldValue, newValue): # ERROR 0 java.lang.String cannot be cast to com.hazelcast.impl.Keys self.__proxyHelper.check(key) self.__proxyHelper.check(oldValue) self.__proxyHelper.check(newValue) return self.__proxyHelper.doOp("MREPLACEIFSAME", 3, (key, oldValue, newValue), self.__name,) def flush(self): return self.__proxyHelper.doOp("MFLUSH", 0, None, self.__name) def evict(self, key): self.__proxyHelper.check(key) return self.__proxyHelper.doOp("MEVICT", 1, key, self.__name)
class MapClientProxy: # TODO : extract all data from calling method after making the call. # TODO : add noreply option def __init__(self , name , connection): self.__name = name self.__proxyHelper = ProxyHelper(connection) def addListener(self, listener, key=None, includeValue=False): """ If key is provided listener will be notified only for the key, otherwise it will notified for all entries in the map If includeValue set to True it will bring values for the keys with the event""" self.__listenerManager = ListenerManager() self.__listenerManager.setProxyHelper(self.__proxyHelper) listener.listenerManager = self.__listenerManager listener.key = key listener.name = self.__name self.__listenerManager.addListenerOp(listener, key, includeValue, self.__name) def removeListener(self, listener, key=None): self.__listenerManager.removeListenerOp(listener, key, self.__name) def put(self, key, value, ttl=0): self.__proxyHelper.check(key) self.__proxyHelper.check(value) response = self.__proxyHelper.doOp("MPUT", 2, (key, value), self.__name, str(ttl)) return self.__proxyHelper.readSingleObjectResponse(response) def putIfAbsent(self, key, value, ttl=0): self.__proxyHelper.check(key) self.__proxyHelper.check(value) response = self.__proxyHelper.doOp("MPUTIFABSENT", 2, (key, value), self.__name, str(ttl)) return self.__proxyHelper.readSingleObjectResponse(response) def putTransient(self, key, value, ttl=0): self.__proxyHelper.check(key) self.__proxyHelper.check(value) response = self.__proxyHelper.doOp("MPUTTRANSIENT", 2, (key, value), self.__name, str(ttl)) return self.__proxyHelper.readSingleObjectResponse(response) def putAll(self, entries): response = self.__proxyHelper.doOp("MPUTALL", 2 * len(entries), entries, self.__name) return self.__proxyHelper.readOKResponse(response) def putAndUnlock(self, key, value): self.__proxyHelper.check(key) self.__proxyHelper.check(value) response = self.__proxyHelper.doOp("MPUTANDUNLOCK", 2, (key, value), self.__name) return self.__proxyHelper.readOKResponse(response) def size(self): response = self.__proxyHelper.doOp("MSIZE", 0 , None , self.__name) return self.__proxyHelper.readSingleIntResponse(response) def set(self, key, value, ttl=0): self.__proxyHelper.check(key) self.__proxyHelper.check(value) response = self.__proxyHelper.doOp("MSET", 2, (key, value), self.__name, str(ttl)) return self.__proxyHelper.readOKResponse(response) def get(self, key): self.__proxyHelper.check(key) response = self.__proxyHelper.doOp("MGET", 1, key, self.__name) return self.__proxyHelper.readSingleObjectResponse(response) def getAll(self, keys): for key in keys: self.__proxyHelper.check(key) response = self.__proxyHelper.doOp("MGETALL", len(keys), keys, self.__name) keys = response["binaryData"][::2] values = response["binaryData"][1::2] result = dict(zip(keys,values)) return result def tryLockAndGet(self, key, timeout): self.__proxyHelper.check(key) response = self.__proxyHelper.doOp("MTRYLOCKANDGET", 1, key, self.__name, str(timeout)) return self.__proxyHelper.readSingleObjectResponse(response) def tryPut(self, key, value, timeout): self.__proxyHelper.check(key) self.__proxyHelper.check(value) response = self.__proxyHelper.doOp("MTRYPUT", 2, (key, value), self.__name, str(timeout)) return self.__proxyHelper.readSingleBoolResponse(response) def tryLock(self, key, timeout): self.__proxyHelper.check(key) response = self.__proxyHelper.doOp("MTRYLOCK", 1, key, self.__name, str(timeout)) return self.__proxyHelper.readSingleBoolResponse(response) def tryRemove(self, key, timeout): self.__proxyHelper.check(key) response = self.__proxyHelper.doOp("MTRYREMOVE", 1, key, self.__name, str(timeout)) return self.__proxyHelper.readSingleObjectResponse(response) def isKeyLocked(self, key): self.__proxyHelper.check(key) response = self.__proxyHelper.doOp("MISKEYLOCKED", 1, key, self.__name) return self.__proxyHelper.readSingleBoolResponse(response) def lock(self, key): self.__proxyHelper.check(key) response = self.__proxyHelper.doOp("MLOCK", 1, key, self.__name) return self.__proxyHelper.readSingleBoolResponse(response) def unLock(self, key): self.__proxyHelper.check(key) response = self.__proxyHelper.doOp("MUNLOCK", 1, key, self.__name) return self.__proxyHelper.readOKResponse(response) def lockMap(self, timeout): response = self.__proxyHelper.doOp("MLOCKMAP", 0, None, self.__name, str(timeout)) return self.__proxyHelper.readSingleBoolResponse(response) def unlockMap(self, timeout): return self.__proxyHelper.doOp("MUNLOCKMAP", 0, None, self.__name, str(timeout)) def forceUnlock(self, key): self.__proxyHelper.check(key) response = self.__proxyHelper.doOp("MFORCEUNLOCK", 1, key, self.__name) return self.__proxyHelper.readOKResponse(response) def containsKey(self, key): self.__proxyHelper.check(key) response = self.__proxyHelper.doOp("MCONTAINSKEY", 1, key, self.__name) return self.__proxyHelper.readSingleBoolResponse(response) def containsValue(self, value): self.__proxyHelper.check(value) response = self.__proxyHelper.doOp("MCONTAINSVALUE", 1, value, self.__name) return self.__proxyHelper.readSingleBoolResponse(response) def keySet(self): response = self.__proxyHelper.doOp("KEYSET", 0, None, "map", self.__name) return response["binaryData"] def remove(self, key): self.__proxyHelper.check(key) response = self.__proxyHelper.doOp("MREMOVE", 1, key , self.__name) return self.__proxyHelper.readSingleObjectResponse(response) def removeIfSame(self, key, value): self.__proxyHelper.check(key) self.__proxyHelper.check(value) response = self.__proxyHelper.doOp("MREMOVEIFSAME", 2, (key, value), self.__name,) return self.__proxyHelper.readSingleBoolResponse(response) def replaceIfNotNull(self, key, value): self.__proxyHelper.check(key) self.__proxyHelper.check(value) return self.__proxyHelper.doOp("MREPLACEIFNOTNULL", 2, (key, value), self.__name,) def replaceIfSame(self, key, oldValue, newValue): # ERROR 0 java.lang.String cannot be cast to com.hazelcast.impl.Keys self.__proxyHelper.check(key) self.__proxyHelper.check(oldValue) self.__proxyHelper.check(newValue) return self.__proxyHelper.doOp("MREPLACEIFSAME", 3, (key, oldValue, newValue), self.__name,) def flush(self): response = self.__proxyHelper.doOp("MFLUSH", 0, None, self.__name) return self.__proxyHelper.readOKResponse(response) def evict(self, key): self.__proxyHelper.check(key) response = self.__proxyHelper.doOp("MEVICT", 1, key, self.__name) return self.__proxyHelper.readSingleBoolResponse(response)
def __init__(self,connection): self.__proxyHelper = ProxyHelper(connection)
class GeneralClientProxy: def __init__(self, connection): self.__proxyHelper = ProxyHelper(connection) def destroy(self, type, name): response = self.__proxyHelper.doOp("DESTROY", 0, None, type, name) return self.__proxyHelper.readOKResponse(response) def txnBegin(self): response = self.__proxyHelper.doOp("TRXBEGIN", 0, None) return self.__proxyHelper.readOKResponse(response) def txnCommit(self): response = self.__proxyHelper.doOp("TRXCOMMIT", 0, None) return self.__proxyHelper.readOKResponse(response) def txnRollback(self): response = self.__proxyHelper.doOp("TRXROLLBACK", 0, None) return self.__proxyHelper.readOKResponse(response) def instances(self): response = self.__proxyHelper.doOp("INSTANCES", 0, None) response = response["commandLine"].split() types = response[1::2] names = response[2::2] return dict(zip(names, types)) def members(self): response = self.__proxyHelper.doOp("MEMBERS", 0, None) response = response["commandLine"].split() return response[1:] def ping(self): # we are getting unknown_error response = self.__proxyHelper.doOp("PING", 0, None) return self.__proxyHelper.readOKResponse(response) def clusterTime(self): response = self.__proxyHelper.doOp("CLUSTERTIME", 0, None) milis = self.__proxyHelper.readSingleIntResponse(response) return time.gmtime( (milis / 1000) ) # hazelcast returns time in miliseconds granularity but built in python methods in seconds granularity. def partitions(self, key=None): if key is None: response = self.__proxyHelper.doOp("PARTITIONS", 0, None) else: response = self.__proxyHelper.doOp("PARTITIONS", 1, key) response = response["commandLine"].split() pids = response[1::2] pids = [int(x) for x in pids] # convert string keys to int addresses = response[2::2] return dict(zip(pids, addresses))
class QueueClientProxy: def __init__(self , name , connection): self.__name = name self.__proxyHelper = ProxyHelper(connection) def addListener(self, listener, includeValue=True): self.__listenerManager = ListenerManager(self.__proxyHelper) listener.listenerManager = self.__listenerManager listener.name = self.__name self.__listenerManager.addListenerOp(listener, None, includeValue, self.__name) def offer(self, element, timeout=0): self.__proxyHelper.check(element) return self.__proxyHelper.doOp("QOFFER", 1, element, self.__name, str(timeout)) def put(self, element): return self.__proxyHelper.doOp("QPUT", 0, None, self.__name) def poll(self, timeout=0): return self.__proxyHelper.doOp("QPOLL", 0, None, self.__name, str(timeout)) def take(self, timeout=0): return self.__proxyHelper.doOp("QTAKE", 0, None, self.__name) def size(self): return self.__proxyHelper.doOp("QSIZE", 0, None, self.__name) def peek(self): return self.__proxyHelper.doOp("QPEEK", 0, None, self.__name) def remove(self, element): self.__proxyHelper.check(element) return self.__proxyHelper.doOp("QREMOVE", 1, element, self.__name) def remainingCapacity(self): return self.__proxyHelper.doOp("QREMCAPACITY", 0, None, self.__name) def entries(self): return self.__proxyHelper.doOp("QENTRIES", 0, None, self.__name)