ó
½-'Nc           @   s÷   d  Z  d d l Z d d l m Z d d l m Z m Z d d l m Z m	 Z	 d d l
 m Z d d l 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 d l m Z d d l m Z d e f d „  ƒ  YZ d „  Z d S(   s    Deployment code for the monitor.iÿÿÿÿN(   t   fetch_async(   t   LandscapeServicet   run_landscape_service(   t   RegistrationHandlert   Identity(   t   BrokerConfiguration(   t   HTTPTransportt   PayloadRecorder(   t   MessageExchange(   t   ExchangeStore(   t   Pinger(   t   get_default_message_store(   t   BrokerServer(   t   BrokerServerProtocolFactoryt   BrokerServicec           B   sG   e  Z d  Z e Z e Z e j Z	 d „  Z
 d „  Z d „  Z d „  Z RS(   sô  The core C{Service} of the Landscape Broker C{Application}.

    The Landscape broker service handles all the communication between the
    client and server.  When started it creates and runs all necessary
    components to exchange messages with the Landscape server.

    @cvar service_name: C{broker}

    @ivar persist_filename: Path to broker-specific persistent data.
    @ivar persist: A L{Persist} object saving and loading data from
        C{self.persist_filename}.
    @ivar message_store: A L{MessageStore} used by the C{exchanger} to
        queue outgoing messages.
    @ivar transport: An L{HTTPTransport} used by the C{exchanger} to deliver
        messages.
    @ivar identity: The L{Identity} of the Landscape client the broker runs on.
    @ivar exchanger: The L{MessageExchange} exchanges messages with the server.
    @ivar pinger: The L{Pinger} checks if the server has new messages for us.
    @ivar registration: The L{RegistrationHandler} performs the initial
        registration.
    c         C   s¥  t  j j | j d |  j f ƒ |  _ t t |  ƒ j | ƒ | j	 d k	 r_ t | j ƒ |  _ n	 d |  _ |  j | j | j |  j ƒ |  _ t |  j | j ƒ |  _ t |  j |  j ƒ |  _ t |  j j ƒ } t |  j |  j |  j |  j | | ƒ |  _ |  j |  j | j |  j |  j ƒ |  _  t! | |  j |  j |  j |  j  |  j t" ƒ |  _# |  j j$ d |  j% ƒ t& |  j |  j |  j |  j# |  j ƒ |  _' t( d |  j' ƒ |  _) d S(   s:   
        @param config: A L{BrokerConfiguration}.
        s
   %s.bpickles	   post-exitt   objectN(*   t   ost   patht   joint	   data_patht   service_namet   persist_filenamet   superR   t   __init__t   recordt   NoneR   t   record_directoryt   payload_recordert   transport_factoryt   urlt   ssl_public_keyt	   transportR   t   persistt   message_store_patht   message_storeR   t   configt   identityR	   t   exchange_store_pathR   t   reactort	   exchangert   pinger_factoryt   ping_urlt   pingerR   R    t   registrationt   call_ont   _exitR   t   brokerR   t   factory(   t   selfR#   t   exchange_store(    (    s<   /usr/lib/python2.7/dist-packages/landscape/broker/service.pyR   ,   s0    		c         C   s   d d l  m } | j ƒ  d  S(   Niÿÿÿÿ(   R&   (   t   twisted.internetR&   t   stop(   R0   R&   (    (    s<   /usr/lib/python2.7/dist-packages/landscape/broker/service.pyR-   K   s    c         C   s1   t  t |  ƒ j ƒ  |  j j ƒ  |  j j ƒ  d S(   sá   Start the broker.

        Create a L{BrokerServer} listening on C{broker_socket_path} for clients
        connecting with the L{BrokerClientProtocol}, and start the
        L{MessageExchange} and L{Pinger} services.
        N(   R   R   t   startServiceR'   t   startR*   (   R0   (    (    s<   /usr/lib/python2.7/dist-packages/landscape/broker/service.pyR4   S   s    c         C   s$   |  j  j ƒ  t t |  ƒ j ƒ  d S(   s   Stop the broker.N(   R'   R3   R   R   t   stopService(   R0   (    (    s<   /usr/lib/python2.7/dist-packages/landscape/broker/service.pyR6   ^   s    (   t   __name__t
   __module__t   __doc__R   R   R
   R(   R   t   nameR   R   R-   R4   R6   (    (    (    s<   /usr/lib/python2.7/dist-packages/landscape/broker/service.pyR      s   				c         C   s   t  t t |  ƒ d S(   s7   Run the application, given some command line arguments.N(   R   R   R   (   t   args(    (    s<   /usr/lib/python2.7/dist-packages/landscape/broker/service.pyt   rund   s    (   R9   R   t   landscape.lib.fetchR    t   landscape.serviceR   R   t   landscape.broker.registrationR   R   t   landscape.broker.configR   t   landscape.broker.transportR   R   t   landscape.broker.exchangeR   t   landscape.broker.exchangestoreR	   t   landscape.broker.pingR
   t   landscape.broker.storeR   t   landscape.broker.serverR   t   landscape.broker.ampR   R   R<   (    (    (    s<   /usr/lib/python2.7/dist-packages/landscape/broker/service.pyt   <module>   s   S