ó
½-'Nc           @   s   d  d l  Z  d  d l Z d  d l m Z m Z m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e	 f d
 „  ƒ  YZ
 d S(   iÿÿÿÿN(   t   MethodCallProtocolt   MethodCallFactoryt   RemoteObjectConnectort   ComponentProtocolc           B   s    e  Z d  Z d d g Z d Z RS(   s"  Communication protocol between the various Landscape components.

    It can be used both as server-side protocol for exposing the methods of a
    certain Landscape component, or as client-side protocol for connecting to
    another Landscape component we want to call the methods of.
    t   pingt   exiti<   (   t   __name__t
   __module__t   __doc__t   methodst   timeout(    (    (    s1   /usr/lib/python2.7/dist-packages/landscape/amp.pyR      s   t   ComponentProtocolFactoryc           B   s   e  Z e Z d  Z RS(   gš™™™™™©?(   R   R   R   t   protocolt   initialDelay(    (    (    s1   /usr/lib/python2.7/dist-packages/landscape/amp.pyR      s   t   RemoteComponentConnectorc           B   s/   e  Z d  Z e Z d „  Z d d e d „ Z RS(   s%  Utility superclass for creating connections with a Landscape component.

    @cvar component: The class of the component to connect to, it is expected
        to define a C{name} class attribute, which will be used to find out
        the socket to use. It must be defined by sub-classes.
    c         O   sT   | |  _  t j j | j |  j j d ƒ } t t |  ƒ j	 |  j  j
 | | | Ž d S(   s3  
        @param reactor: A L{TwistedReactor} object.
        @param config: A L{LandscapeConfiguration}.
        @param args: Positional arguments for protocol factory constructor.
        @param kwargs: Keyword arguments for protocol factory constructor.

        @see: L{MethodCallClientFactory}.
        s   .sockN(   t   _twisted_reactort   ost   patht   joint   sockets_patht	   componentt   namet   superR   t   __init__t   _reactor(   t   selft   reactort   configt   argst   kwargst   socket(    (    s1   /usr/lib/python2.7/dist-packages/landscape/amp.pyR   #   s
    		c            sx   ‡  f d †  ‰ ‡ ‡  f d †  } ‡  f d †  } t  t ˆ  ƒ j d | d | ƒ } | sg | j | ƒ n  | j | ƒ | S(   s  Connect to the remote Landscape component.

        If the connection is lost after having been established, and then
        it is established again by the reconnect mechanism, an event will
        be fired.

        @param max_retries: If given, the connector will keep trying to connect
            up to that number of times, if the first connection attempt fails.
        @param factor: Optionally a float indicating by which factor the
            delay between subsequent retries should increase. Smaller values
            result in a faster reconnection attempts pace.
        @param quiet: A boolean indicating whether to log errors.
        c            s   ˆ  j  j d ˆ  j j ƒ d  S(   Ns   %s-reconnect(   R   t   fireR   R   (   t   remote(   R   (    s1   /usr/lib/python2.7/dist-packages/landscape/amp.pyt   fire_reconnectA   s    c            s   ˆ j  j ˆ  ƒ |  S(   N(   t   _factoryt   add_notifier(   R    (   R!   R   (    s1   /usr/lib/python2.7/dist-packages/landscape/amp.pyt	   connectedE   s    c            s   t  j d ˆ  j j ƒ |  S(   Ns   Error while connecting to %s(   t   loggingt   errorR   R   (   t   failure(   R   (    s1   /usr/lib/python2.7/dist-packages/landscape/amp.pyt	   log_errorI   s    t   max_retriest   factor(   R   R   t   connectt
   addErrbackt   addCallback(   R   R)   R*   t   quietR$   R(   t   result(    (   R   R!   s1   /usr/lib/python2.7/dist-packages/landscape/amp.pyR+   2   s    N(	   R   R   R   R   t   factoryR   t   Nonet   FalseR+   (    (    (    s1   /usr/lib/python2.7/dist-packages/landscape/amp.pyR      s   	t   RemoteComponentsRegistryc           B   s2   e  Z d  Z i  Z e d „  ƒ Z e d „  ƒ Z RS(   sR   
    A global registry for looking up Landscape component connectors by name.
    c         C   s   |  j  | S(   sÂ   Get the connector class for the given Landscape component.

        @param name: Name of the Landscape component we want to connect to, for
           instance C{monitor} or C{manager}.
        (   t   _by_name(   t   clsR   (    (    s1   /usr/lib/python2.7/dist-packages/landscape/amp.pyt   get\   s    c         C   s   | |  j  | j j <d S(   sÄ   Register a connector for a Landscape component.

        @param connector_class: A sub-class of L{RemoteComponentConnector}
            that can be used to connect to a certain component.
        N(   R4   R   R   (   R5   t   connector_class(    (    s1   /usr/lib/python2.7/dist-packages/landscape/amp.pyt   registere   s    (   R   R   R   R4   t   classmethodR6   R8   (    (    (    s1   /usr/lib/python2.7/dist-packages/landscape/amp.pyR3   U   s   	(   R   R%   t   landscape.lib.ampR    R   R   R   R   R   t   objectR3   (    (    (    s1   /usr/lib/python2.7/dist-packages/landscape/amp.pyt   <module>   s   <