# Path: tensor/protocol/riemann.py
# class RiemannProtobufMixin(object):
# class RiemannProtocol(Int32StringReceiver, RiemannProtobufMixin):
# class RiemannClientFactory(protocol.ReconnectingClientFactory):
# class RiemannUDP(DatagramProtocol, RiemannProtobufMixin):
#     def encodeEvent(self, event):
#     def encodeMessage(self, events):
#     def decodeMessage(self, data):
#     def sendEvents(self, events):
#     def __init__(self):
#     def stringReceived(self, string):
#     def __init__(self, hosts, failover=False):
#     def buildProtocol(self, addr):
#     def _do_failover(self, connector):
#     def clientConnectionLost(self, connector, reason):
#     def clientConnectionFailed(self, connector, reason):
#     def __init__(self, host, port):
#     def sendString(self, string):
# 
# Path: tensor/objects.py
# class Output(object):
#     """Output parent class
# 
#     Outputs can inherit this object which provides a construct
#     for a working output
# 
#     :param config: Dictionary config for this queue (usually read from the
#              yaml configuration)
#     :param tensor: A TensorService object for interacting with the queue manager
#     """
#     def __init__(self, config, tensor):
#         self.config = config
#         self.tensor = tensor
# 
#     def createClient(self):
#         """Deferred which sets up the output
#         """
#         pass
# 
#     def eventsReceived(self):
#         """Receives a list of events and processes them
# 
#         Arguments:
#         events -- list of `tensor.objects.Event`
#         """
#         pass
# 
#     def stop(self):
#         """Called when the service shuts down
#         """
#         pass


import time
import random
from twisted.internet import reactor, defer, task
from twisted.python import log
    from OpenSSL import SSL
    from twisted.internet import ssl
from tensor.protocol import riemann
from tensor.objects import Output
        self.events = []
        self.t = task.LoopingCall(self.tick)

        self.inter = float(self.config.get('interval', 1.0))  # tick interval
        self.pressure = int(self.config.get('pressure', -1))
        self.maxsize = int(self.config.get('maxsize', 250000))
        self.expire = self.config.get('expire', False)
        self.allow_nan = self.config.get('allow_nan', True)

        maxrate = int(self.config.get('maxrate', 0))

        if maxrate > 0:
            self.queueDepth = int(maxrate * self.inter)
        else:
            self.queueDepth = None

        self.tls = self.config.get('tls', False)

        if self.tls:
            self.cert = self.config['cert']
            self.key = self.config['key']

    def createClient(self):
        """Create a TCP connection to Riemann with automatic reconnection
        """

        server = self.config.get('server', 'localhost')
        port = self.config.get('port', 5555)
        failover = self.config.get('failover', False)


# Path: tensor/protocol/riemann.py
# class RiemannProtobufMixin(object):
# class RiemannProtocol(Int32StringReceiver, RiemannProtobufMixin):
# class RiemannClientFactory(protocol.ReconnectingClientFactory):
# class RiemannUDP(DatagramProtocol, RiemannProtobufMixin):
#     def encodeEvent(self, event):
#     def encodeMessage(self, events):
#     def decodeMessage(self, data):
#     def sendEvents(self, events):
#     def __init__(self):
#     def stringReceived(self, string):
#     def __init__(self, hosts, failover=False):
#     def buildProtocol(self, addr):
#     def _do_failover(self, connector):
#     def clientConnectionLost(self, connector, reason):
#     def clientConnectionFailed(self, connector, reason):
#     def __init__(self, host, port):
#     def sendString(self, string):
# 
# Path: tensor/objects.py
# class Output(object):
#     """Output parent class
# 
#     Outputs can inherit this object which provides a construct
#     for a working output
# 
#     :param config: Dictionary config for this queue (usually read from the
#              yaml configuration)
#     :param tensor: A TensorService object for interacting with the queue manager
#     """
#     def __init__(self, config, tensor):
#         self.config = config
#         self.tensor = tensor
# 
#     def createClient(self):
#         """Deferred which sets up the output
#         """
#         pass
# 
#     def eventsReceived(self):
#         """Receives a list of events and processes them
# 
#         Arguments:
#         events -- list of `tensor.objects.Event`
#         """
#         pass
# 
#     def stop(self):
#         """Called when the service shuts down
#         """
#         pass


# Path: tensor/outputs/riemann.py
import time
import random
from twisted.internet import reactor, defer, task
from twisted.python import log
    from OpenSSL import SSL
    from twisted.internet import ssl
from tensor.protocol import riemann
from tensor.objects import Output

        self.events = []
        self.t = task.LoopingCall(self.tick)

        self.inter = float(self.config.get('interval', 1.0))  # tick interval
        self.pressure = int(self.config.get('pressure', -1))
        self.maxsize = int(self.config.get('maxsize', 250000))
        self.expire = self.config.get('expire', False)
        self.allow_nan = self.config.get('allow_nan', True)

        maxrate = int(self.config.get('maxrate', 0))

        if maxrate > 0:
            self.queueDepth = int(maxrate * self.inter)
        else:
            self.queueDepth = None

        self.tls = self.config.get('tls', False)

        if self.tls:
            self.cert = self.config['cert']
            self.key = self.config['key']

    def createClient(self):
        """Create a TCP connection to Riemann with automatic reconnection
        """

        server = self.config.get('server', 'localhost')
        port = self.config.get('port', 5555)
        failover = self.config.get('failover', False)


        self.factory = riemann.RiemannClientFactory(server, failover=failover)