コード例 #1
0
 def __init__(self, env, service, **kwargs):
     """
     Takes an environment and an actor service, and streams data to it.
     """
     self.service = service
     self.stream  = Stream(MESSAGE_MEAN, MESSAGE_STDDEV, SPIKE_SCALE, SPIKE_PROBABILTY, SPIKE_DURATION)
     self.values  = Normal(64, 32)
     self.last_volume = 0
     super(StreamingData, self).__init__(env)
コード例 #2
0
class StreamingData(Process, LoggingMixin):
    """
    Generates data volume via the stream dynamo.

    TODO: Move out of simulation to a helper module.
    """

    def __init__(self, env, service, **kwargs):
        """
        Takes an environment and an actor service, and streams data to it.
        """
        self.service = service
        self.stream  = Stream(MESSAGE_MEAN, MESSAGE_STDDEV, SPIKE_SCALE, SPIKE_PROBABILTY, SPIKE_DURATION)
        self.values  = Normal(64, 32)
        self.last_volume = 0
        super(StreamingData, self).__init__(env)

    def run(self):
        """
        Creates messages based on the data volume and sends to the service.
        """

        # Don't start for a few iterations
        yield self.env.timeout(5)

        while True:
            volume = int(self.stream.next())
            if volume > 0:
                self.logger.info("STREAM: NEW MESSAGES: {}".format(volume))
                for idx in xrange(volume):
                    self.service.route(Message(None, None, self.values.get(), MESSAGE_SIZE, self.env.now, None))

            self.last_volume = volume
            yield self.env.timeout(1)