def CreateEventClient(self, channelId, eventLocation): '''Create event client and register events''' self.eventLocation = eventLocation self.channelId = channelId # Create event client and connect to event service. self.eventClient = EventClient(self.privateId, self.eventLocation, str(self.channelId)) self.ReceiveEvents() self.eventClient.start() self.eventClient.Send(ConnectEvent(self.channelId, self.privateId))
def ping(host, port, count): try: privId = str(GUID()) eventClient = EventClient(privId, (host, port), channel) eventClient.Start() eventClient.Send(ConnectEvent(channel, privId)) for i in range(1, count): eventClient.Send(HeartbeatEvent(channel, "%s -- %d" % (privId, i))) queue.put(0) except EventClientConnectionException: print sys.exc_type, sys.exc_value queue.put(2) except: print sys.exc_type, sys.exc_value queue.put(3) done.set()
def __init__(self, arg, url, log=None): wxApp.__init__(self, arg) """ This is the constructor for the Shared Covise. """ # Initialize state in the shared covise self.url = url self.eventQueue = Queue.Queue(5) self.log = log self.masterId = None self.numSteps = 0 self.hostName = "vision.rus.uni-stuttgart.de" self.serverPort = 31098 self.masterSocket = None # Get a handle to the application object in the venue self.log.debug("Getting application proxy (%s).", url) self.appProxy = Client.Handle(self.url).GetProxy() # Join the application object, get a private ID in response self.log.debug("Joining application.") (self.publicId, self.privateId) = self.appProxy.Join() # Get the information about our Data Channel self.log.debug("Retrieving data channel information.") (self.channelId, esl) = self.appProxy.GetDataChannel(self.privateId) # Connect to the Data Channel, using the EventClient class # The EventClient class is a general Event Channel Client, but since # we use the Event Channel for a Data Channel we can use the # Event Client Class as a Data Client. For more information on the # Event Channel look in AccessGrid\EventService.py # and AccessGrid\EventClient.py self.log.debug("Connecting to data channel.") self.eventClient = EventClient(self.privateId, esl, self.channelId) self.eventClient.start() self.eventClient.Send(ConnectEvent(self.channelId, self.privateId)) # Register callbacks with the Data Channel to handle incoming # events. self.log.debug("Registering for events.") self.eventClient.RegisterCallback(SharedCovEvent.MASTER, self.RecvMaster) self.eventClient.RegisterCallback(SharedCovEvent.CLEAN, self.CleanCovise) self.masterHost = "" self.masterPort = 0 self.masterHost = self.appProxy.GetData(self.privateId, SharedCovKey.MASTERHOST) self.masterPort = self.appProxy.GetData(self.privateId, SharedCovKey.MASTERPORT) self.frame.SetMasterHost(self.masterHost + ":" + str(self.masterPort)) self.log.debug("fit.") self.log.debug("SharedCovise V1.0") # read configueation file userapp = Platform.GetUserAppPath() configFileName = userapp + "\\SharedCovise.config" configFile = None try: configFile = file(configFileName, 'r') except: print "could no open config file" if configFile != None: entry = configFile.readline(200) if entry != "": self.hostName = entry.rstrip("\n") entry = configFile.readline(200) if entry != "": self.serverPort = int(entry) self.frame.SetPort(self.serverPort) self.frame.SetHost(self.hostName) if self.masterHost == self.hostName and self.serverPort == self.serverPort: #connect to our Daemon and find out if covise is still running message = "check" try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) s.send(message) self.masterSocket = s self.appProxy.SetData(self.privateId, SharedCovKey.MASTERHOST, self.hostName) self.appProxy.SetData(self.privateId, SharedCovKey.MASTERPORT, self.serverPort) self.eventClient.Send( Event(SharedCovEvent.MASTER, self.channelId, (self.publicId, self.publicId))) Thread(target=self.monitorMaster).start() except: self.appProxy.SetData(self.privateId, SharedCovKey.MASTERHOST, "") self.appProxy.SetData(self.privateId, SharedCovKey.MASTERPORT, 0) self.eventClient.Send( Event(SharedCovEvent.MASTER, self.channelId, (self.publicId, self.publicId))) print "could not connect to AccessGridDaemon\n"