ó
½-'Nc           @   s¸  d  d l  m Z m Z m Z d  d l m Z d  d l m Z m Z m	 Z	 m
 Z
 d  d l m Z d  d l m Z d  d l m Z d  d l m Z d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e	 f d „  ƒ  YZ d e	 f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ e
 j e ƒ e
 j e ƒ e
 j e ƒ e
 j e ƒ d S(   iÿÿÿÿ(   t   maybeDeferredt   executet   succeed(   t   RemoteObject(   t   ComponentProtocolt   ComponentProtocolFactoryt   RemoteComponentConnectort   RemoteComponentsRegistry(   t   BrokerServer(   t   BrokerClient(   t   Monitor(   t   Managert   BrokerServerProtocolc           B   s<   e  Z d  Z e j d d d d d d d d d	 d
 d g Z RS(   sK   
    Communication protocol between the broker server and its clients.
    t
   fire_eventt   get_accepted_message_typest   get_server_uuidt   is_message_pendingt   registert   register_clientt%   register_client_accepted_message_typet   reload_configurationt   send_messaget   stop_clientst   listen_events(   t   __name__t
   __module__t   __doc__R   t   methods(    (    (    s8   /usr/lib/python2.7/dist-packages/landscape/broker/amp.pyR      s   t   BrokerServerProtocolFactoryc           B   s   e  Z e Z RS(    (   R   R   R   t   protocol(    (    (    s8   /usr/lib/python2.7/dist-packages/landscape/broker/amp.pyR      s   t   RemoteBrokerc           B   s   e  Z d  „  Z d „  Z RS(   c            s2   |  j  ƒ  } ‡ ‡  ‡ f d †  } | j | ƒ | S(   s8   Call C{callable} if C{type} is an accepted message type.c            s   ˆ |  k r ˆ  ˆ Œ  Sd  S(   N(    (   t   result(   t   callablet   argst   type(    s8   /usr/lib/python2.7/dist-packages/landscape/broker/amp.pyt   got_accepted_types*   s    (   R   t   addCallback(   t   selfR"   R    R!   t   deferred_typesR#   (    (   R!   R    R"   s8   /usr/lib/python2.7/dist-packages/landscape/broker/amp.pyt   call_if_accepted&   s    c            s+   |  j  ˆ  j ƒ  ƒ } | j ‡  f d †  ƒ S(   sQ  Call a given handler as soon as a certain event occurs.

        @param handlers: A dictionary mapping event types to callables, where
            an event type is string (the name of the event). When the first of
            the given event types occurs in the broker reactor, the associated
            callable will be fired.
        c            s   ˆ  |  ƒ  S(   N(    (   t
   event_type(   t   handlers(    s8   /usr/lib/python2.7/dist-packages/landscape/broker/amp.pyt   <lambda>9   s    (   R   t   keysR$   (   R%   R)   R   (    (   R)   s8   /usr/lib/python2.7/dist-packages/landscape/broker/amp.pyt   call_on_event0   s    (   R   R   R'   R,   (    (    (    s8   /usr/lib/python2.7/dist-packages/landscape/broker/amp.pyR   $   s   	
t   FakeRemoteBrokerc           B   sG   e  Z d  Z d „  Z d „  Z d „  Z e d „ Z d „  Z d „  Z	 RS(   s@   Looks like L{RemoteBroker}, but actually talks to local objects.c         C   s"   | |  _  | |  _ t ƒ  |  _ d  S(   N(   t	   exchangert   message_storeR   R   (   R%   R.   R/   (    (    s8   /usr/lib/python2.7/dist-packages/landscape/broker/amp.pyt   __init__?   s    		c         C   s
   t  t ƒ S(   N(   R   t   True(   R%   (    (    s8   /usr/lib/python2.7/dist-packages/landscape/broker/amp.pyt   pingD   s    c         G   s,   | |  j  j ƒ  k r" t | | Œ St d  ƒ S(   N(   R/   t   get_accepted_typesR    R   t   None(   R%   R"   R    R!   (    (    s8   /usr/lib/python2.7/dist-packages/landscape/broker/amp.pyR'   G   s    c         C   s>   d d l  m } | j | ƒ s% t ‚ t |  j j | d | ƒS(   s7   Send to the previously given L{MessageExchange} object.iÿÿÿÿ(   t   MethodCallArgumentt   urgent(   t   landscape.lib.ampR5   t   checkt   AssertionErrorR   R.   t   send(   R%   t   messageR6   R5   (    (    s8   /usr/lib/python2.7/dist-packages/landscape/broker/amp.pyR   L   s    c         C   s   t  |  j j | ƒ S(   N(   R   R.   R   (   R%   R"   (    (    s8   /usr/lib/python2.7/dist-packages/landscape/broker/amp.pyR   U   s    c         C   s   t  |  j j ƒ S(   st   
        Return a deferred resulting in the list of message types accepted
        by the Landscape server.
        (   R   R/   R3   (   R%   (    (    s8   /usr/lib/python2.7/dist-packages/landscape/broker/amp.pyR   Y   s    (
   R   R   R   R0   R2   R'   t   FalseR   R   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/landscape/broker/amp.pyR-   <   s   					t   BrokerClientProtocolc           B   s!   e  Z d  Z e j d d g Z RS(   s7   Communication protocol between a client and the broker.R   R;   (   R   R   R   R   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/landscape/broker/amp.pyR=   a   s   t   BrokerClientProtocolFactoryc           B   s   e  Z e Z RS(    (   R   R   R=   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/landscape/broker/amp.pyR>   g   s   t   RemoteClientc           B   s   e  Z d  Z RS(   s8   A remote L{BrokerClient} connected to a L{BrokerServer}.(   R   R   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/landscape/broker/amp.pyR?   l   s   t   RemoteBrokerConnectorc           B   s    e  Z d  Z e Z e Z e Z RS(   s6   Helper to create connections with the L{BrokerServer}.(	   R   R   R   R>   t   factoryR   t   remoteR   t	   component(    (    (    s8   /usr/lib/python2.7/dist-packages/landscape/broker/amp.pyR@   p   s   t   RemoteClientConnectorc           B   s    e  Z d  Z e Z e Z e Z RS(   s6   Helper to create connections with the L{BrokerServer}.(	   R   R   R   R   RA   R?   RB   R	   RC   (    (    (    s8   /usr/lib/python2.7/dist-packages/landscape/broker/amp.pyRD   x   s   t   RemoteMonitorConnectorc           B   s   e  Z d  Z e Z RS(   s1   Helper to create connections with the L{Monitor}.(   R   R   R   R
   RC   (    (    (    s8   /usr/lib/python2.7/dist-packages/landscape/broker/amp.pyRE   €   s   t   RemoteManagerConnectorc           B   s   e  Z d  Z e Z RS(   s4   Helper for creating connections with the L{Monitor}.(   R   R   R   R   RC   (    (    (    s8   /usr/lib/python2.7/dist-packages/landscape/broker/amp.pyRF   †   s   N(    t   twisted.internet.deferR    R   R   R7   R   t   landscape.ampR   R   R   R   t   landscape.broker.serverR   t   landscape.broker.clientR	   t   landscape.monitor.monitorR
   t   landscape.manager.managerR   R   R   R   t   objectR-   R=   R>   R?   R@   RD   RE   RF   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/landscape/broker/amp.pyt   <module>   s*   "%