mò òDc @sdZdklZlZlZdklZdklZdk l Z defd„ƒYZ defd„ƒYZ d fd „ƒYZ d efd „ƒYZd e fd„ƒYZdefd„ƒYZdfd„ƒYZddd„Zdd„Zddd d d ddddg ZdS(sœService architecture for Twisted Services are arranged in a hierarchy. At the leafs of the hierarchy, the services which actually interact with the outside world are started. Services can be named or anonymous -- usually, they will be named if there is need to access them through the hierarchy (from a parent or a sibling). API Stability: unstable Maintainer: U{Moshe Zadka} (s implementss Interfaces Attribute(s components(sdefer(ssobt IServiceMakercBs;tZdZedƒZedƒZedƒZd„ZRS(sç An object which can be used to construct services in a flexible way. This interface should most often be implemented along with twisted.plugin.IPlugin, and will most often be used by the 'twistd' command. sA short string naming this Twisted plugin, for example 'web' or 'pencil'. This name will be used as the subcommand of 'twistd'.sLA brief summary of the features provided by this Twisted application plugin.sbA C{twisted.python.usage.Options} subclass defining theconfiguration options for this application.cCsdS(s Create and return an object providing L{twisted.application.service.IService}. @param options: A mapping (typically a C{dict} or C{twisted.python.usage.Options} instance) of configuration options to desired configuration values. N((toptions((ts/home/radix/Projects/Twisted/branches/releases/twisted-core-2.5.x-2329-2/Twisted.exp/twisted/application/service.pyt makeService/s(t__name__t __module__t__doc__t Attributettapnamet descriptionRR(((RRs    tIServicecBsDtZdZd„Zd„Zd„Zd„Zd„Zd„ZRS(s A service. Run start-up and shut-down code at the appropriate times. @type name: C{string} @ivar name: The name of the service (or None) @type running: C{boolean} @ivar running: Whether the service is running. cCsdS(sŠSet the name of the service. @type name: C{str} @raise RuntimeError: Raised if the service already has a parent. N((tname((RtsetNameHscCsdS(søSet the parent of the service. @type name: L{IServiceCollection} @raise RuntimeError: Raised if the service already has a parent or if the service has a name and the parent already has a child by that name. N((tparent((RtsetServiceParentOscCsdS(sûRemove the parent of the service. @rtype: L{Deferred} @return: a deferred which is triggered when the service has finished shutting down. If shutting down is immediate, a value can be returned (usually, None). N((((RtdisownServiceParentXscCsdS(sStart the service.N((((Rt startServiceascCsdS(sëStop the service. @rtype: L{Deferred} @return: a deferred which is triggered when the service has finished shutting down. If shutting down is immediate, a value can be returned (usually, None). N((((Rt stopServicedscCsdS(s Do preparation work for starting the service. Here things which should be done before changing directory, root or shedding privileges are done.N((((RtprivilegedStartServicems( RRRR RRRRR(((RR ;s    tServicecBsitZdZeeƒdZeZeZd„Z d„Z d„Z d„Z d„Z d„Zd„ZRS( sÜ Base class for services Most services should inherit from this class. It handles the book-keeping reponsibilities of starting and stopping, as well as not serializing this book-keeping information. icCs.|iiƒ}|idƒo |d=n|S(Ntrunning(tselft__dict__tcopytdictthas_key(RR((Rt __getstate__„s cCs-|idj otdƒ‚n||_dS(Ns%cannot change name when parent exists(RR tNonet RuntimeErrorR (RR ((RR ŠscCsJ|idj o|iƒnt||ƒ}||_|ii|ƒdS(N(RR RRtIServiceCollectiont addService(RR ((RRs  cCs|ii|ƒ}d|_|S(N(RR t removeServicetdR(RR ((RR–s cCsdS(N((R((RR›scCs d|_dS(Ni(RR(R((RRžscCs d|_dS(Ni(RR(R((RR¡s(RRRt implementsR RRR R RR RRRRR(((RRts        RcBs2tZdZd„Zd„Zd„Zd„ZRS(sÎCollection of services. Contain several services, and manage their start-up/shut-down. Services can be accessed by name if they have a name, and it is always possible to iterate over them. cCsdS(sÂGet the child service with a given name. @type name: C{str} @rtype: L{IService} @raise KeyError: Raised if the service has no child with the given name. N((R ((RtgetServiceNamed¯scCsdS(s'Get an iterator over all child servicesN((((Rt__iter__¸scCsdS(sAdd a child service. @type service: L{IService} @raise RuntimeError: Raised if the service has a child with the given name. N((tservice((RR»scCsdS(s[Remove a child service. @type service: L{IService} @raise ValueError: Raised if the given service is not a child. @rtype: L{Deferred} @return: a deferred which is triggered when the service has finished shutting down. If shutting down is immediate, a value can be returned (usually, None). N((R$((RRÃs (RRRR"R#RR(((RR¦s   t MultiServicecBs`tZdZeeƒd„Zd„Zd„Zd„Zd„Z d„Z d„Z d„Z RS( sÿStraightforward Service Container Hold a collection of services, and manage them in a simplistic way. No service will wait for another, but this object itself will not finish shutting down until all of its child services will finish. cCsg|_h|_d|_dS(N(Rtservicest namedServicesRR (R((Rt__init__Üs  cCs,ti|ƒx|D]}|iƒqWdS(N(RRRR$(RR$((RRás cCs,ti|ƒx|D]}|iƒqWdS(N(RRRR$(RR$((RRæs cCs`ti|ƒg}t|ƒ}|iƒx'|D]}|it i |iƒƒq0Wt i |ƒS(N( RRRtltlistR&treverseR$tappendtdefert maybeDeferredt DeferredList(RR$R)R&((RRës   cCs |i|S(N(RR'R (RR ((RR"ôscCs t|iƒS(N(titerRR&(R((RR#÷scCs‡|idj oA|ii|iƒotd|iƒ‚n||i|i