Statistics
| Branch: | Tag: | Revision:

root / snf-pithos-backend / pithos / backends / lib / rabbitmq / queue.py @ 73673127

History | View | Annotate | Download (2.1 kB)

1 46286f5f Antony Chazapis
# Copyright 2012 GRNET S.A. All rights reserved.
2 46286f5f Antony Chazapis
# 
3 46286f5f Antony Chazapis
# Redistribution and use in source and binary forms, with or
4 46286f5f Antony Chazapis
# without modification, are permitted provided that the following
5 46286f5f Antony Chazapis
# conditions are met:
6 46286f5f Antony Chazapis
# 
7 46286f5f Antony Chazapis
#   1. Redistributions of source code must retain the above
8 46286f5f Antony Chazapis
#      copyright notice, this list of conditions and the following
9 46286f5f Antony Chazapis
#      disclaimer.
10 46286f5f Antony Chazapis
# 
11 46286f5f Antony Chazapis
#   2. Redistributions in binary form must reproduce the above
12 46286f5f Antony Chazapis
#      copyright notice, this list of conditions and the following
13 46286f5f Antony Chazapis
#      disclaimer in the documentation and/or other materials
14 46286f5f Antony Chazapis
#      provided with the distribution.
15 46286f5f Antony Chazapis
# 
16 46286f5f Antony Chazapis
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 46286f5f Antony Chazapis
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 46286f5f Antony Chazapis
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 46286f5f Antony Chazapis
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 46286f5f Antony Chazapis
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 46286f5f Antony Chazapis
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 46286f5f Antony Chazapis
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 46286f5f Antony Chazapis
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 46286f5f Antony Chazapis
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 46286f5f Antony Chazapis
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 46286f5f Antony Chazapis
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 46286f5f Antony Chazapis
# POSSIBILITY OF SUCH DAMAGE.
28 46286f5f Antony Chazapis
# 
29 46286f5f Antony Chazapis
# The views and conclusions contained in the software and
30 46286f5f Antony Chazapis
# documentation are those of the authors and should not be
31 46286f5f Antony Chazapis
# interpreted as representing official policies, either expressed
32 46286f5f Antony Chazapis
# or implied, of GRNET S.A.
33 46286f5f Antony Chazapis
34 6e147ecc Antony Chazapis
from synnefo.lib.queue import exchange_connect, exchange_send, exchange_close, Receipt
35 46286f5f Antony Chazapis
36 46286f5f Antony Chazapis
37 46286f5f Antony Chazapis
class Queue(object):
38 46286f5f Antony Chazapis
    """Queue.
39 8d9a3fbd Antony Chazapis
       Required constructor parameters: exchange, client_id.
40 46286f5f Antony Chazapis
    """
41 46286f5f Antony Chazapis
    
42 46286f5f Antony Chazapis
    def __init__(self, **params):
43 46286f5f Antony Chazapis
        exchange = params['exchange']
44 46286f5f Antony Chazapis
        self.conn = exchange_connect(exchange)
45 fa9cae7e Antony Chazapis
        self.client_id = params['client_id']
46 46286f5f Antony Chazapis
    
47 73673127 Antony Chazapis
    def send(self, message_key, user, instance, resource, value, details):
48 73673127 Antony Chazapis
        body = Receipt(self.client_id, user, instance, resource, value, details).format()
49 8d9a3fbd Antony Chazapis
        exchange_send(self.conn, message_key, body)
50 b9a8feec root
    
51 b9a8feec root
    def close(self):
52 b9a8feec root
        exchange_close(self.conn)