# Path: cloudify/amqp_client.py
# class AMQPClient(object):
#     EVENTS_EXCHANGE_NAME = 'cloudify-events'
#     SOCKET_TIMEOUT = 5
#     CONNECTION_ATTEMPTS = 3
#     LOGS_EXCHANGE_NAME = 'cloudify-logs'
#     def __init__(self,
#                  amqp_user,
#                  amqp_pass,
#                  amqp_host,
#                  amqp_vhost,
#                  ssl_enabled,
#                  ssl_cert_path):
#     def _connect(self):
#     def publish_message(self, message, message_type):
#     def close(self):
# def create_client(amqp_host=None,
#                   amqp_user=None,
#                   amqp_pass=None,
#                   amqp_vhost=None,
#                   ssl_enabled=None,
#                   ssl_cert_path=None):
# 
# Path: cloudify/exceptions.py
# class ClosedAMQPClientException(Exception):
#     """Raised when attempting to use a closed AMQP client"""
#     pass


from threading import Thread, RLock, Event
from Queue import Queue
from cloudify import amqp_client
from cloudify.exceptions import ClosedAMQPClientException
        self._client_kwargs = client_kwargs

    def register_caller(self):
        with self._connect_lock:
            if not self.client_started.is_set():
                self._connect()
            self._callers += 1

    def unregister_caller(self):
        with self._connect_lock:
            self._callers -= 1
            if self._callers == 0:
                self._disconnect()
                self._thread.join()

    def __enter__(self):
        self.register_caller()
        return self

    def __exit__(self, exc, val, tb):
        self.unregister_caller()

    def publish_message(self, message, message_type):
        self._queue.put((message, message_type))

    def close(self):
        self.unregister_caller()
        self._client.close()

    def _make_client(self):

# Path: cloudify/amqp_client.py
# class AMQPClient(object):
#     EVENTS_EXCHANGE_NAME = 'cloudify-events'
#     SOCKET_TIMEOUT = 5
#     CONNECTION_ATTEMPTS = 3
#     LOGS_EXCHANGE_NAME = 'cloudify-logs'
#     def __init__(self,
#                  amqp_user,
#                  amqp_pass,
#                  amqp_host,
#                  amqp_vhost,
#                  ssl_enabled,
#                  ssl_cert_path):
#     def _connect(self):
#     def publish_message(self, message, message_type):
#     def close(self):
# def create_client(amqp_host=None,
#                   amqp_user=None,
#                   amqp_pass=None,
#                   amqp_vhost=None,
#                   ssl_enabled=None,
#                   ssl_cert_path=None):
# 
# Path: cloudify/exceptions.py
# class ClosedAMQPClientException(Exception):
#     """Raised when attempting to use a closed AMQP client"""
#     pass


# Path: cloudify/amqp_client_utils.py
from threading import Thread, RLock, Event
from Queue import Queue
from cloudify import amqp_client
from cloudify.exceptions import ClosedAMQPClientException

        self._client_kwargs = client_kwargs

    def register_caller(self):
        with self._connect_lock:
            if not self.client_started.is_set():
                self._connect()
            self._callers += 1

    def unregister_caller(self):
        with self._connect_lock:
            self._callers -= 1
            if self._callers == 0:
                self._disconnect()
                self._thread.join()

    def __enter__(self):
        self.register_caller()
        return self

    def __exit__(self, exc, val, tb):
        self.unregister_caller()

    def publish_message(self, message, message_type):
        self._queue.put((message, message_type))

    def close(self):
        self.unregister_caller()
        self._client.close()

    def _make_client(self):

        return amqp_client.create_client(*self._client_args,