def onSessionOpen(self): """ When connection is established, we create our model instances and register them for RPC. that's it. """ # all websocket signals and slots must use # current protocol as the communication channel, # so pass 'self' to signalNamespace method of models # first of all, create and setup chart models self.memoryChartVirt = MemoryChart("virt") self.memoryChartVirt.signalNamespace(self, "memoryChartVirt") self.registerMethodForRpc(self.uri + '/memoryChartVirt.data', self.memoryChartVirt, self.memoryChartVirt.data) self.memoryChartSwap = MemoryChart("swap") self.memoryChartSwap.signalNamespace(self, "memoryChartSwap") self.registerMethodForRpc(self.uri + '/memoryChartSwap.data', self.memoryChartSwap, self.memoryChartSwap.data) # thereafter, setup memory info models self.memoryInfoVirt = MemoryInfo("virt") self.memoryInfoVirt.signalNamespace(self, "memoryInfoVirt") self.registerMethodForRpc(self.uri + '/memoryInfoVirt.getCounters', self.memoryInfoVirt, lambda i: self.memoryInfoVirt.getCounters()) self.memoryInfoSwap = MemoryInfo("swap") self.memoryInfoSwap.signalNamespace(self, "memoryInfoSwap") self.registerMethodForRpc(self.uri + '/memoryInfoSwap.getCounters', self.memoryInfoSwap, lambda i: self.memoryInfoSwap.getCounters())
class MemoryMonitorServerProtocol(WampServerProtocol): """ This is simple memory monitor server protocol. As with other server classes model is created, when new connection is established, and deleted when client closes websocket connection """ uri = "http://system-monitor.com" def onSessionOpen(self): """ When connection is established, we create our model instances and register them for RPC. that's it. """ # all websocket signals and slots must use # current protocol as the communication channel, # so pass 'self' to signalNamespace method of models # first of all, create and setup chart models self.memoryChartVirt = MemoryChart("virt") self.memoryChartVirt.signalNamespace(self, "memoryChartVirt") self.registerMethodForRpc(self.uri + '/memoryChartVirt.data', self.memoryChartVirt, self.memoryChartVirt.data) self.memoryChartSwap = MemoryChart("swap") self.memoryChartSwap.signalNamespace(self, "memoryChartSwap") self.registerMethodForRpc(self.uri + '/memoryChartSwap.data', self.memoryChartSwap, self.memoryChartSwap.data) # thereafter, setup memory info models self.memoryInfoVirt = MemoryInfo("virt") self.memoryInfoVirt.signalNamespace(self, "memoryInfoVirt") self.registerMethodForRpc(self.uri + '/memoryInfoVirt.getCounters', self.memoryInfoVirt, lambda i: self.memoryInfoVirt.getCounters()) self.memoryInfoSwap = MemoryInfo("swap") self.memoryInfoSwap.signalNamespace(self, "memoryInfoSwap") self.registerMethodForRpc(self.uri + '/memoryInfoSwap.getCounters', self.memoryInfoSwap, lambda i: self.memoryInfoSwap.getCounters()) def connectionLost(self, reason): """ When connection is gone (i.e. client close window, navigated away from the page), stop the model timer, which holds last reference to model, and delete the model """ WampServerProtocol.connectionLost(self, reason) self.memoryChartVirt.timer.stop() self.memoryChartVirt = None self.memoryChartSwap.timer.stop() self.memoryChartSwap = None self.memoryInfoVirt.timer.stop() self.memoryInfoVirt = None self.memoryInfoSwap.timer.stop() self.memoryInfoSwap = None
def onSessionOpen(self): Signal.wampProtocol = self Slot.wampProtocol = self # when connection is established, we create our # model instances and register them for RPC. that's it. # first of all, create and setup chart models self.memoryChartVirt = MemoryChart("virt") self.memoryChartVirt.signalNamespace("memoryChartVirt") self.registerMethodForRpc(self.uri + '/memoryChartVirt.data', self.memoryChartVirt, self.memoryChartVirt.data) self.memoryChartSwap = MemoryChart("swap") self.memoryChartSwap.signalNamespace("memoryChartSwap") self.registerMethodForRpc(self.uri + '/memoryChartSwap.data', self.memoryChartSwap, self.memoryChartSwap.data) # thereafter, setup memory info models self.memoryInfoVirt = MemoryInfo("virt") self.memoryInfoVirt.signalNamespace("memoryInfoVirt")
class MemoryMonitorServerProtocol(WampServerProtocol): """ Demonstrates creating a simple server with Autobahn WebSockets that responds to RPC calls. """ uri = "http://example.com/simple" def onSessionOpen(self): Signal.wampProtocol = self Slot.wampProtocol = self # when connection is established, we create our # model instances and register them for RPC. that's it. # first of all, create and setup chart models self.memoryChartVirt = MemoryChart("virt") self.memoryChartVirt.signalNamespace("memoryChartVirt") self.registerMethodForRpc(self.uri + '/memoryChartVirt.data', self.memoryChartVirt, self.memoryChartVirt.data) self.memoryChartSwap = MemoryChart("swap") self.memoryChartSwap.signalNamespace("memoryChartSwap") self.registerMethodForRpc(self.uri + '/memoryChartSwap.data', self.memoryChartSwap, self.memoryChartSwap.data) # thereafter, setup memory info models self.memoryInfoVirt = MemoryInfo("virt") self.memoryInfoVirt.signalNamespace("memoryInfoVirt") def connectionLost(self, reason): WampServerProtocol.connectionLost(self, reason) self.memoryChartVirt.timer.stop() self.memoryChartVirt = None self.memoryChartSwap.timer.stop() self.memoryChartSwap = None