Package Products :: Package ZenHub :: Module HubService |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenHub.HubService

     1  ##############################################################################
     2  #
     3  # Copyright (C) Zenoss, Inc. 2007, all rights reserved.
     4  #
     5  # This content is made available according to terms specified in
     6  # License.zenoss under the directory where your Zenoss product is installed.
     7  #
     8  ##############################################################################
     9
    10
    11  from twisted.spread import pb
    12
    13  import logging
    14  import time
    15  import socket
    16
    17 -class HubService(pb.Referenceable):
    18
    19 -    def __init__(self, dmd, instance):
    20          self.log = logging.getLogger('zen.hub')
    21          self.fqdn = socket.getfqdn()
    22          self.dmd = dmd
    23          self.zem = dmd.ZenEventManager
    24          self.instance = instance
    25          self.listeners = []
    26          self.callTime = 0.
    27          self.methodPriorityMap = {}
    28
    29 -    def getPerformanceMonitor(self):
    30          return self.dmd.Monitors.getPerformanceMonitor(self.instance)
    31
    32 -    def remoteMessageReceived(self, broker, message, args, kw):
    33          self.log.debug("Servicing %s in %s", message, self.name())
    34          now = time.time()
    35          try:
    36              return pb.Referenceable.remoteMessageReceived(self, broker, message, args, kw)
    37          finally:
    38              secs = time.time() - now
    39              self.log.debug("Time in %s: %.2f", message, secs)
    40              self.callTime += secs
    41
    42 -    def update(self, object):
    43          # FIXME: No longer called
    44          pass
    45
    46 -    def deleted(self, object):
    47          # FIXME: No longer called
    48          pass
    49
    50 -    def name(self):
    51          return self.__class__.__name__
    52
    53 -    def addListener(self, remote):
    54          remote.notifyOnDisconnect(self.removeListener)
    55          self.log.debug("adding listener for %s:%s", self.instance, self.name())
    56          self.listeners.append(remote)
    57
    58 -    def removeListener(self, listener):
    59          self.log.debug("removing listener for %s:%s", self.instance, self.name())
    60          try:
    61              self.listeners.remove(listener)
    62          except ValueError:
    63              self.warning("Unable to remove listener... ignoring")
    64
    65 -    def getMethodPriority(self, methodName):
    66          if methodName in self.methodPriorityMap:
    67              return self.methodPriorityMap[methodName]
    68          return 0.2
    69
    70 -    def sendEvents(self, events):
    71          map(self.sendEvent, events)
    72
    73 -    def sendEvent(self, event, **kw):
    74          event = event.copy()
    75          event['agent'] = 'zenhub'
    76          event['monitor'] = self.instance
    77          event['manager'] = self.fqdn
    78          event.update(kw)
    79          self.zem.sendEvent(event)
    80