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