def on_start(self): log.warn('Entering On Start!!!') # Get the stream(s) stream_id = self.CFG.get_safe('process.stream_id', {}) self.greenlet_queue = [] # Stream creation is done in SA, but to make the example go for demonstration create one here if it is not provided... if not stream_id: pubsub_cli = PubsubManagementServiceClient( node=self.container.node) stream_def_id = pubsub_cli.create_stream_definition( name='Producer stream %s' % str(uuid4()), container=self.outgoing_stream_def) stream_id = pubsub_cli.create_stream( name='Example CTD Data', stream_definition_id=stream_def_id, original=True, encoding='ION R2') self.stream_publisher_registrar = StreamPublisherRegistrar( process=self, node=self.container.node) # Needed to get the originator's stream_id self.stream_id = stream_id self.publisher = self.stream_publisher_registrar.create_publisher( stream_id=stream_id) self.last_time = 0 g = Greenlet(self._trigger_func, stream_id) log.debug('Starting publisher thread for simple ctd data.') g.start() log.warn('Publisher Greenlet started in "%s"' % self.__class__.__name__) self.greenlet_queue.append(g)
def _set_publisher_endpoints(self, service_instance, publisher_streams=None): service_instance.stream_publisher_registrar = StreamPublisherRegistrar( process=service_instance, node=self.container.node) publisher_streams = publisher_streams or {} for name, stream_id in publisher_streams.iteritems(): # problem is here pub = service_instance.stream_publisher_registrar.create_publisher( stream_id) setattr(service_instance, name, pub)
def on_start(self): log.warn('Entering On Start!!!') # Get the stream(s) stream_id = self.CFG.get_safe('process.stream_id',{}) self.greenlet_queue = [] # Stream creation is done in SA, but to make the example go for demonstration create one here if it is not provided... if not stream_id: pubsub_cli = PubsubManagementServiceClient(node=self.container.node) stream_def_id = pubsub_cli.create_stream_definition(name='Producer stream %s' % str(uuid4()),container=self.outgoing_stream_def) stream_id = pubsub_cli.create_stream( name='Example CTD Data', stream_definition_id = stream_def_id, original=True, encoding='ION R2') self.stream_publisher_registrar = StreamPublisherRegistrar(process=self,node=self.container.node) # Needed to get the originator's stream_id self.stream_id= stream_id self.publisher = self.stream_publisher_registrar.create_publisher(stream_id=stream_id) self.last_time = 0 g = Greenlet(self._trigger_func, stream_id) log.debug('Starting publisher thread for simple ctd data.') g.start() log.warn('Publisher Greenlet started in "%s"' % self.__class__.__name__) self.greenlet_queue.append(g)
class SimpleCtdPublisher(StandaloneProcess): def __init__(self, *args, **kwargs): super(SimpleCtdPublisher, self).__init__(*args,**kwargs) #@todo Init stuff outgoing_stream_def = SBE37_CDM_stream_definition() def on_start(self): log.warn('Entering On Start!!!') # Get the stream(s) stream_id = self.CFG.get_safe('process.stream_id',{}) self.greenlet_queue = [] # Stream creation is done in SA, but to make the example go for demonstration create one here if it is not provided... if not stream_id: pubsub_cli = PubsubManagementServiceClient(node=self.container.node) stream_def_id = pubsub_cli.create_stream_definition(name='Producer stream %s' % str(uuid4()),container=self.outgoing_stream_def) stream_id = pubsub_cli.create_stream( name='Example CTD Data', stream_definition_id = stream_def_id, original=True, encoding='ION R2') self.stream_publisher_registrar = StreamPublisherRegistrar(process=self,node=self.container.node) # Needed to get the originator's stream_id self.stream_id= stream_id self.publisher = self.stream_publisher_registrar.create_publisher(stream_id=stream_id) self.last_time = 0 g = Greenlet(self._trigger_func, stream_id) log.debug('Starting publisher thread for simple ctd data.') g.start() log.warn('Publisher Greenlet started in "%s"' % self.__class__.__name__) self.greenlet_queue.append(g) def on_quit(self): for greenlet in self.greenlet_queue: greenlet.kill() super(SimpleCtdPublisher,self).on_quit() def _trigger_func(self, stream_id): while True: length = random.randint(1,20) ctd_packet = self._get_ctd_packet(stream_id, length) log.info('SimpleCtdPublisher sending %d values!' % length) self.publisher.publish(ctd_packet) time.sleep(2.0) def _get_ctd_packet(self, stream_id, length): c = [random.uniform(0.0,75.0) for i in xrange(length)] t = [random.uniform(-1.7, 21.0) for i in xrange(length)] p = [random.lognormvariate(1,2) for i in xrange(length)] lat = [random.uniform(-90.0, 90.0) for i in xrange(length)] lon = [random.uniform(0.0, 360.0) for i in xrange(length)] tvar = [self.last_time + i for i in xrange(1,length+1)] self.last_time = max(tvar) ctd_packet = ctd_stream_packet(stream_id=stream_id, c=c, t=t, p=p, lat=lat, lon=lon, time=tvar) return ctd_packet
class SimpleCtdPublisher(StandaloneProcess): def __init__(self, *args, **kwargs): super(SimpleCtdPublisher, self).__init__(*args, **kwargs) #@todo Init stuff outgoing_stream_def = SBE37_CDM_stream_definition() def on_start(self): log.warn('Entering On Start!!!') # Get the stream(s) stream_id = self.CFG.get_safe('process.stream_id', {}) self.greenlet_queue = [] # Stream creation is done in SA, but to make the example go for demonstration create one here if it is not provided... if not stream_id: pubsub_cli = PubsubManagementServiceClient( node=self.container.node) stream_def_id = pubsub_cli.create_stream_definition( name='Producer stream %s' % str(uuid4()), container=self.outgoing_stream_def) stream_id = pubsub_cli.create_stream( name='Example CTD Data', stream_definition_id=stream_def_id, original=True, encoding='ION R2') self.stream_publisher_registrar = StreamPublisherRegistrar( process=self, node=self.container.node) # Needed to get the originator's stream_id self.stream_id = stream_id self.publisher = self.stream_publisher_registrar.create_publisher( stream_id=stream_id) self.last_time = 0 g = Greenlet(self._trigger_func, stream_id) log.debug('Starting publisher thread for simple ctd data.') g.start() log.warn('Publisher Greenlet started in "%s"' % self.__class__.__name__) self.greenlet_queue.append(g) def on_quit(self): for greenlet in self.greenlet_queue: greenlet.kill() super(SimpleCtdPublisher, self).on_quit() def _trigger_func(self, stream_id): while True: length = random.randint(1, 20) ctd_packet = self._get_ctd_packet(stream_id, length) log.info('SimpleCtdPublisher sending %d values!' % length) self.publisher.publish(ctd_packet) time.sleep(2.0) def _get_ctd_packet(self, stream_id, length): c = [random.uniform(0.0, 75.0) for i in xrange(length)] t = [random.uniform(-1.7, 21.0) for i in xrange(length)] p = [random.lognormvariate(1, 2) for i in xrange(length)] lat = [random.uniform(-90.0, 90.0) for i in xrange(length)] lon = [random.uniform(0.0, 360.0) for i in xrange(length)] tvar = [self.last_time + i for i in xrange(1, length + 1)] self.last_time = max(tvar) ctd_packet = ctd_stream_packet(stream_id=stream_id, c=c, t=t, p=p, lat=lat, lon=lon, time=tvar) return ctd_packet