def run(self): configuration = fileToJson('config.json') container = {} designDocumentName = configuration['designDocumentName'] subscriberPort = configuration['subscriberPort'] publisherPort = configuration['publisherPort'] couchbaseUrl = configuration['couchbaseUrl'] samplesViewName = configuration['samplesViewName'] metricsViewName = configuration['metricsViewName'] myScheduler = scheduler(60) #The scheduler checks every minute for a possible model update databaseConfiguration = couchbaseConfiguration(designDocumentName, couchbaseUrl) container['repository'] = lambda: repository(couchbaseUrl, designDocumentName, "") container['samplesRepository'] = lambda: repository(couchbaseUrl, designDocumentName, samplesViewName) container['metricsRepository'] = lambda: repository(couchbaseUrl, designDocumentName, metricsViewName) container['csvRepository'] = lambda: csvRepository(configuration['csvFileLocation']) container['subscriber'] = lambda: zmqProxy(str(subscriberPort), container['repository'](), container['scheduler'](), lambda x: container['modelUpdateTask']().createModelIfOld(x)) container['nupic'] = lambda: nupicProxy(container['repository']()) container['nupicConfiguration'] = lambda: nupicConfiguration(configuration['swarmConfiguration'], container['repository'](), configuration['csvFileLocation']) container['modelCreationTask'] = lambda: modelCreationTask(container['nupicConfiguration'] (), container['samplesRepository'](), container['metricsRepository'](), container['csvRepository'](), container['nupic']()) container['modelUpdateTask'] = lambda: modelUpdateTask(container['nupicConfiguration'](), container['modelCreationTask'](), configuration['swarmIntervalInHours']) container['espresso'] = lambda: espresso(publisherPort, subscriberPort) container['scheduler'] = lambda: myScheduler databaseConfiguration.createMapView(configuration['samplesViewName'], configuration['samplesMapFunction'], None) databaseConfiguration.createMapView(configuration['metricsViewName'], configuration['metricsMapFunction'], None) serviceLocator.setServiceLocator(container)
def startBroker(self): # Start child threads ctx = zmq.Context.instance() pipe = self.zpipe(ctx) print ("Broker binding to subscriber port " + self._subscriberPort) subscriber = ctx.socket(zmq.XSUB) subscriber.bind("tcp://*:" + self._subscriberPort) print ("Broker binding to publisher port " + self._publisherPort) publisher = ctx.socket(zmq.XPUB) publisher.bind("tcp://*:" + self._publisherPort) l_thread = Thread(target=self.listener_thread, args=(pipe[1],)) l_thread.start() print("Broker online...") try: monitored_queue(subscriber, publisher, pipe[0], 'pub', 'sub') except KeyboardInterrupt: print ("Interrupted") del subscriber, publisher, pipe ctx.term() if __name__ == '__main__': configuration = fileToJson('config.json') espresso(configuration['publisherPort'], configuration['subscriberPort']).startBroker()