Package flumotion :: Package component :: Package plugs :: Module base
[hide private]

Source Code for Module flumotion.component.plugs.base

  1  # -*- Mode: Python -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3   
  4  # Flumotion - a streaming media server 
  5  # Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L. 
  6  # Copyright (C) 2010,2011 Flumotion Services, S.A. 
  7  # All rights reserved. 
  8  # 
  9  # This file may be distributed and/or modified under the terms of 
 10  # the GNU Lesser General Public License version 2.1 as published by 
 11  # the Free Software Foundation. 
 12  # This file is distributed without any warranty; without even the implied 
 13  # warranty of merchantability or fitness for a particular purpose. 
 14  # See "LICENSE.LGPL" in the source distribution for more information. 
 15  # 
 16  # Headers in this file shall remain intact. 
 17   
 18   
 19  from twisted.internet import defer 
 20   
 21  from flumotion.common import log 
 22   
 23  __version__ = "$Rev$" 
 24   
 25   
26 -class Plug(object, log.Loggable):
27 """ 28 Base class for plugs. Provides an __init__ method that receives the 29 plug args and sets them to the 'args' attribute. 30 """ 31
32 - def __init__(self, args):
33 """ 34 @param args: The plug args 35 @type args: dict with keys 'socket', 'type', and 'properties'. 36 'properties' has the same format as component 37 properties. 38 """ 39 self.args = args
40 41
42 -class ComponentPlug(Plug):
43 """ 44 Base class for plugs that live in a component. Subclasses can 45 implement the start and stop vmethods, which will be called with the 46 component as an argument. Both of them can return a deferred. 47 """ 48
49 - def start(self, component):
50 pass
51
52 - def stop(self, component):
53 pass
54
55 - def restart(self, component):
56 d = defer.maybeDeferred(self.stop, component) 57 return d.addCallback(lambda _: self.start(component))
58 59
60 -class ManagerPlug(Plug):
61 """ 62 Base class for plugs that live in the manager. Subclasses can 63 implement the start and stop vmethods, which will be called with the 64 manager vishnu as an argument. 65 """ 66
67 - def start(self, vishnu):
68 pass
69
70 - def stop(self, vishnu):
71 pass
72
73 - def restart(self, vishnu):
74 self.stop(vishnu) 75 self.start(vishnu)
76 77
78 -class ManagerExamplePlug(ManagerPlug):
79 """ 80 Example implementation of the ManagerLifecyle socket, just prints 81 things on the console. Pretty stupid! 82 """ 83
84 - def start(self, vishnu):
85 info = vishnu.connectionInfo 86 print ('started manager running on %s:%d (%s)' 87 % (info['host'], info['port'], 88 info['using_ssl'] and 'with ssl' or 'without ssl'))
89
90 - def stop(self, vishnu):
91 info = vishnu.connectionInfo 92 print ('stopped manager running on %s:%d (%s)' 93 % (info['host'], info['port'], 94 info['using_ssl'] and 'with ssl' or 'without ssl'))
95 96
97 -class ComponentExamplePlug(ComponentPlug):
98 """ 99 Example implementation of the ComponentLifecyle socket, just prints 100 things on the console. Pretty stupid! 101 """ 102
103 - def start(self, component):
104 print 'Component has been started'
105
106 - def stop(self, component):
107 print 'Component is stopping'
108