from msstruct import CMyStruct from spa import CUQueue from decimal import Decimal import uuid, time msOriginal = CMyStruct.MakeOne() q = CUQueue() msOriginal.SaveTo(q) ms = CMyStruct() ms.LoadFrom(q) with CUQueue() as q: q.SaveInt(123).SaveInt(-1) n = q.LoadInt() assert (n == 123) n = q.LoadInt() assert (n == -1) assert (q.Size == 0) q.SaveInt(234).SaveAString('test me') n = q.LoadInt() assert (n == 234) s = q.LoadAString() assert (s == 'test me') assert (q.Size == 0) us = u'test' q.SaveString(us).SaveString(None) s = q.LoadString() assert (s == u'test') s = q.LoadString()
from hello_world.client.asynchelloworld import CHelloWorld from spa import CScopeUQueue as Sb, CServerError from spa.clientside import CSocketPool, CConnectionContext, CSocketError from consts import hwConst from msstruct import CMyStruct import sys with CSocketPool(CHelloWorld) as sp: cc = CConnectionContext('localhost', 20901, 'PythonUser', 'TooMuchSecret') # sp.QueueName = 'pqueue' # turn on client message queue for backing up requests if not sp.StartSocketPool(cc, 1): print('Cannot connect to server with error message: ' + sp.Sockets[0].ErrMsg) else: hw = sp.Seek() ms = CMyStruct.MakeOne() # make a complex structure print(ms) # process requests one by one synchronously -- three round trips try: print(hw.say_hello(u'Jack', u'Smith')) hw.sleep(4000) print(hw.echo(ms)) except CServerError as ex: # an exception from remote server print(ex) except CSocketError as ex: # a communication error print(ex) except Exception as ex: # invalid parameter, bad de-serialization, and so on print('Unexpected error: ' + str(ex)) print('')
def echo(self): # return self.UQueue #this also works ms = CMyStruct() ms.LoadFrom(self.UQueue) return ms.SaveTo(Sb())
def echo(self): assert (Sps.IsMainThread) ms = CMyStruct() ms.LoadFrom(self.UQueue) return ms.SaveTo(Sb())
from asynchelloworld import CHelloWorld from spa.clientside import CSocketPool, CConnectionContext, CUQueue from consts import hwConst from msstruct import CMyStruct import sys with CSocketPool(CHelloWorld) as sp: cc = CConnectionContext('localhost', 20901, 'PythonUser', 'TooMuchSecret') ok = sp.StartSocketPool(cc, 1, 1) hw = sp.Seek() ok = hw.AttachedClientSocket.ClientQueue.StartQueue('pqueue', 3600, False) #process requests one by one synchronously -- three round trips print(hw.sayHello(u'Jack', u'Smith')) hw.sleep(5000) ms = CMyStruct.MakeOne() res = hw.echo(ms) # asynchronously process all three requests with inline batching for best network efficiency def cbSayHello(ar): ret = ar.LoadString() print(ret) ok = hw.SendRequest(hwConst.idSayHelloHelloWorld, CUQueue().SaveString('Jack').SaveString('Smith'), cbSayHello) ok = hw.SendRequest(hwConst.idSleepHelloWorld, CUQueue().SaveUInt(5000), None) def cbEcho(ar): hw.ms = ar.Load(CMyStruct())
def cbEcho(ar): hw.ms = ar.Load(CMyStruct())
from msstruct import CMyStruct from spa import CUQueue, CScopeUQueue from decimal import Decimal import uuid from datetime import datetime msOrig = CMyStruct.MakeOne() print(msOrig) with CScopeUQueue() as sb: sb.Save(msOrig) res = sb.LoadByClass(CMyStruct) print(res) with CUQueue() as q: q.Empty() q.SaveInt(123).SaveInt(-1) n = q.LoadInt() assert (n == 123) n = q.LoadInt() assert (n == -1) assert (q.Size == 0) q.SaveInt(234).SaveAString('test me') n = q.LoadInt() assert (n == 234) s = q.LoadAString() assert (s == 'test me') assert (q.Size == 0) us = u'test' q.SaveString(us).SaveString(None)
def echo(self, ms): return self.sendRequest(hwConst.idEcho, Sb().Save(ms)).result().Load(CMyStruct())
from spa.clientside import * from consts import hwConst from msstruct import CMyStruct class CHelloWorld(CAsyncServiceHandler): def __init__(self): super(CHelloWorld, self).__init__(hwConst.sidHelloWorld) if CUQueue.DEFAULT_OS == tagOperationSystem.osWin: CClientSocket.QueueConfigure.WorkDirectory = "c:\\sp_test" else: CClientSocket.QueueConfigure.WorkDirectory = "/home/yye/sp_test/" CClientSocket.QueueConfigure.MessageQueuePassword = "******" rs = ReplicationSetting() with CReplication(CHelloWorld, rs) as rep: ConnQueue = {} cc = CConnectionContext("127.0.0.1", 20901, "replication", "p4localhost") ConnQueue["Tolocal"] = cc cc = CConnectionContext("192.168.1.122", 20901, "remote_rep", "PassOne") ConnQueue["ToLinux"] = cc ok = rep.Start(ConnQueue, "hw_root_queue_name") ok = rep.StartJob() ok = rep.Send(hwConst.idSayHelloHelloWorld, Sb().SaveString(u'Jack').SaveString(u'Smith')) ok = rep.Send(hwConst.idEchoHelloWorld, Sb().Save(CMyStruct.MakeOne())) ok = rep.EndJob() print('Read a line to continue ......') line = sys.stdin.readline()
def echo(self): ms = CMyStruct() ms.LoadFrom(self.UQueue) q = CUQueue() ms.SaveTo(q) return q
def arh(ar): self._res_echo = ar.Load(CMyStruct())