1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """
17 Contains stub classes.
18 Proxies (stubs) are the I{local} representation of I{remote}
19 classes on which we invoke methods.
20 """
21
22 from pulp.messaging import *
23 from pulp.messaging.dispatcher import Request
24 from pulp.messaging.window import Window
25
26
28 """
29 A dynamic method object used to wrap the RMI call.
30 @ivar classname: The target class name.
31 @type classname: str
32 @ivar name: The target method name.
33 @type name: str
34 @ivar stub: The stub object used to send the AMQP message.
35 @type stub: L{Stub}
36 """
37
38 - def __init__(self, classname, name, stub):
39 """
40 @param classname: The target class name.
41 @type classname: str
42 @param name: The target method name.
43 @type name: str
44 @param stub: The stub object used to send the AMQP message.
45 @type stub: L{Stub}
46 """
47 self.classname = classname
48 self.name = name
49 self.stub = stub
50
52 """
53 Invoke the method .
54 @param args: The args.
55 @type args: list
56 @param kws: The I{keyword} arguments.
57 @type kws: dict
58 """
59 opts = Options()
60 for k,v in kws.items():
61 if k in ('window', 'any',):
62 opts[k] = v
63 del kws[k]
64 request = Request(
65 classname=self.classname,
66 method=self.name,
67 args=args,
68 kws=kws)
69 return self.stub._send(request, opts)
70
71
73 """
74 The stub class for remote objects.
75 @ivar __pid: The peer ID.
76 @type __pid: str
77 @ivar __options: Stub options.
78 @type __options: dict.
79 """
80
82 """
83 @param pid: The peer ID.
84 @type pid: str
85 @param options: Stub options.
86 @type options: dict
87 """
88 self.__pid = pid
89 self.__options = options
90
91 - def _send(self, request, options):
92 """
93 Send the request using the configured request method.
94 @param request: An RMI request.
95 @type request: str
96 """
97 opts = Options(self.__options)
98 opts.update(options)
99 method = self.__options.method
100 if isinstance(self.__pid, (list,tuple)):
101 return method.broadcast(
102 self.__pid,
103 request,
104 window=opts.window,
105 any=opts.any)
106 else:
107 return method.send(
108 self.__pid,
109 request,
110 window=opts.window,
111 any=opts.any)
112
114 """
115 Python vodo.
116 Get a I{Method} object for any requested attribte.
117 @param name: The attribute name.
118 @type name: str
119 @return: A method object.
120 @rtype: L{Method}
121 """
122 cn = self.__class__.__name__
123 return Method(cn, name, self)
124