Package gofer :: Package rmi :: Module container
[hide private]
[frames] | no frames]

Source Code for Module gofer.rmi.container

  1  # 
  2  # Copyright (c) 2011 Red Hat, Inc. 
  3  # 
  4  # This software is licensed to you under the GNU Lesser General Public 
  5  # License as published by the Free Software Foundation; either version 
  6  # 2 of the License (LGPLv2) or (at your option) any later version. 
  7  # There is NO WARRANTY for this software, express or implied, 
  8  # including the implied warranties of MERCHANTABILITY, 
  9  # NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should 
 10  # have received a copy of LGPLv2 along with this software; if not, see 
 11  # http://www.gnu.org/licenses/old-licenses/lgpl-2.0.txt. 
 12  # 
 13  # Jeff Ortel <jortel@redhat.com> 
 14  # 
 15   
 16   
 17  """ 
 18  Agent base classes. 
 19  """ 
 20   
 21  from gofer.messaging import * 
 22  from gofer.rmi.stub import Stub 
 23  from gofer.rmi.window import Window 
 24  from logging import getLogger 
 25   
 26  log = getLogger(__name__) 
 27   
 28           
29 -class Container:
30 """ 31 The stub container 32 @ivar __id: The peer ID. 33 @type __id: str 34 @ivar __producer: An AMQP producer. 35 @type __producer: L{gofer.messaging.producer.Producer} 36 @ivar __options: Container options. 37 @type __options: L{Options} 38 """ 39
40 - def __init__(self, uuid, producer, **options):
41 """ 42 @param uuid: The peer ID. 43 @type uuid: str 44 @param producer: An AMQP producer. 45 @type producer: L{gofer.messaging.producer.Producer} 46 @param options: keyword options. 47 Options: 48 - async : Indicates that requests asynchronous. 49 Default = False 50 - ctag : The asynchronous correlation tag. 51 When specified, it implies all requests are asynchronous. 52 - window : The request window. See I{Window}. 53 Default = any time. 54 - secret : A shared secret used for request authentication. 55 - timeout : The request timeout (seconds). 56 Default = (10,90) seconds. 57 @type options: dict 58 """ 59 self.__id = uuid 60 self.__producer = producer 61 self.__options = Options(window=Window()) 62 self.__options += options
63
64 - def __destination(self):
65 """ 66 Get the stub destination(s). 67 @return: Either a queue destination or a list of queues. 68 @rtype: list 69 """ 70 if isinstance(self.__id, (list,tuple)): 71 queues = [] 72 for d in self.__id: 73 queues.append(Queue(d)) 74 return queues 75 else: 76 return Queue(self.__id)
77
78 - def __getattr__(self, name):
79 """ 80 Get a stub by name. 81 @param name: The name of a stub class. 82 @type name: str 83 @return: A stub object. 84 @rtype: L{Stub} 85 """ 86 return Stub.stub( 87 name, 88 self.__producer, 89 self.__destination(), 90 self.__options)
91
92 - def __getitem__(self, name):
93 """ 94 Get a stub by name. 95 @param name: The name of a stub class. 96 @type name: str 97 @return: A stub object. 98 @rtype: L{Stub} 99 """ 100 return getattr(self, name)
101
102 - def __str__(self):
103 return '{%s} opt:%s' % (self.__id, str(self.__options))
104
105 - def __repr__(self):
106 return str(self)
107