1
2
3
4
5
6
7
8
9
10
11
12
13
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
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
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
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
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
103 return '{%s} opt:%s' % (self.__id, str(self.__options))
104
107