def __init__(self, pars={}, **kwargs): p = u.Param(self.DEFAULT) p.update(pars) p.update(kwargs) self.p = p # sanity check for port range: if str(p.port_range) == p.port_range: from ptypy.utils import str2range p.port_range = str2range(p.port_range) self.req_address = p.primary_address self.req_port = p.primary_port self.poll_timeout = p.poll_timeout self.pinginterval = p.pinginterval # Initially not connected self.connected = False # A name for us. self.name = self.__class__.__name__ # Command queue self.cmds = [] # Data container self.data = {} # Status container self.status = {} # ticket counter self.masterticket = 0 # ticket status self.tickets = {} # list of pending transactions self.pending = [] # list of completed transactions self.completed = [] self.lastping = 0 self._thread = None self._stopping = False
def __init__(self, pars={}, **kwargs): """ Interaction server, meant to run asynchronously with process 0 to manage client requests. Constructor parameters: address: primary address TODO:test this port: primary port params: parameter dictionary (takes precedence if interactor.address and interactor.port are defined) """ ################################# # Initialize all parameters ################################# p = u.Param(self.DEFAULT) p.update(pars) p.update(kwargs) self.p = p # sanity check for port range: if str(p.port_range) == p.port_range: from ptypy.utils import str2range p.port_range = str2range(p.port_range) self.address = p.primary_address self.port = p.primary_port self.poll_timeout = p.poll_timeout self.pinginterval = p.pinginterval self.pingtimeout = p.pingtimeout # Object list, from which data can be transferred self.objects = dict() # Client names (might not be unique, but can be informative) self.names = {} # Ping times for all connected Clients self.pings = {} # Last time a ping check was done self.pingtime = time.time() # Command queue self.queue = Queue.Queue() # Initialize flags to communicate state between threads. self._need_process = False self._can_process = False self._thread = None self._stopping = False # Bind command names to methods self.cmds = { 'CONNECT': self._cmd_connect, # Initial connection from client 'DISCONNECT': self._cmd_disconnect, # Disconnect from client 'DO': self._cmd_queue_do, # Execute a command (synchronous) 'GET': self._cmd_queue_get, # Send an object to the client (synchronous) 'GETNOW': self._cmd_get_now, # Send an object to the client (asynchronous) 'SET': self. _cmd_queue_set, # Set an object sent by the client (synchronous) 'PING': self._cmd_ping, # Regular ping from client 'AVAIL': self._cmd_avail, # Send list of available objects 'SHUTDOWN': self._cmd_shutdown } # Shut down the server # Initial ID pool IDlist = [] # This loop ensures all IDs are unique while len(IDlist) < len(p.port_range): newID = ID_generator() if newID not in IDlist: IDlist.append(newID) self.ID_pool = zip(IDlist, p.port_range)
def __init__(self, pars={}, **kwargs): """ Interaction server, meant to run asynchronously with process 0 to manage client requests. Constructor parameters: address: primary address TODO:test this port: primary port params: parameter dictionary (takes precedence if interactor.address and interactor.port are defined) """ ################################# # Initialize all parameters ################################# p = u.Param(self.DEFAULT) p.update(pars) p.update(kwargs) self.p = p # sanity check for port range: if str(p.port_range) == p.port_range: from ptypy.utils import str2range p.port_range = str2range(p.port_range) self.address = p.primary_address self.port = p.primary_port self.poll_timeout = p.poll_timeout self.pinginterval = p.pinginterval self.pingtimeout = p.pingtimeout # Object list, from which data can be transferred self.objects = dict() # Client names (might not be unique, but can be informative) self.names = {} # Ping times for all connected Clients self.pings = {} # Last time a ping check was done self.pingtime = time.time() # Command queue self.queue = Queue.Queue() # Initialize flags to communicate state between threads. self._need_process = False self._can_process = False self._thread = None self._stopping = False # Bind command names to methods self.cmds = { "CONNECT": self._cmd_connect, # Initial connection from client "DISCONNECT": self._cmd_disconnect, # Disconnect from client "DO": self._cmd_queue_do, # Execute a command (synchronous) "GET": self._cmd_queue_get, # Send an object to the client (synchronous) "GETNOW": self._cmd_get_now, # Send an object to the client (asynchronous) "SET": self._cmd_queue_set, # Set an object sent by the client (synchronous) "PING": self._cmd_ping, # Regular ping from client "AVAIL": self._cmd_avail, # Send list of available objects "SHUTDOWN": self._cmd_shutdown, } # Shut down the server # Initial ID pool IDlist = [] # This loop ensures all IDs are unique while len(IDlist) < len(p.port_range): newID = ID_generator() if newID not in IDlist: IDlist.append(newID) self.ID_pool = zip(IDlist, p.port_range)