21
21
import xact .host .util
22
22
import xact .log
23
23
import xact .proc
24
- import xact .queue
25
24
26
25
27
26
FIFO_HOST_CONTROL = "xact_host_control"
@@ -153,23 +152,35 @@ def _group_edges_by_class(cfg, id_host_local):
153
152
154
153
"""
155
154
map_id_by_class = {
156
- 'ipc' : set (),
157
- 'server' : set (),
158
- 'client' : set ()
155
+ 'intra_process' : set (),
156
+ 'inter_process' : set (),
157
+ 'inter_host_server' : set (),
158
+ 'inter_host_client' : set ()
159
159
}
160
160
161
161
for cfg_edge in cfg ['edge' ]:
162
162
id_edge = cfg_edge ['id_edge' ]
163
163
164
- if id_host_local not in cfg_edge ['list_id_host' ]:
164
+ # Ignore edges that don't impact the current host.
165
+ #
166
+ is_on_host_local = id_host_local in cfg_edge ['list_id_host' ]
167
+ if not is_on_host_local :
165
168
continue
166
- if cfg_edge ['ipc_type' ] == 'inter_process' :
167
- map_id_by_class ['ipc' ].add (id_edge )
169
+
170
+ # Inter-host (i.e. remote) queues have a server end and a client end.
171
+ #
168
172
if cfg_edge ['ipc_type' ] == 'inter_host' :
169
173
if id_host_local == cfg_edge ['id_host_owner' ]:
170
- map_id_by_class [ 'server' ]. add ( id_edge )
174
+ queue_type = 'inter_host_server'
171
175
else :
172
- map_id_by_class ['client' ].add (id_edge )
176
+ queue_type = 'inter_host_client'
177
+
178
+ # Inter-process and intra-process queues are the same class both ends.
179
+ #
180
+ else :
181
+ queue_type = cfg_edge ['ipc_type' ] # inter_process or intra_process
182
+
183
+ map_id_by_class [cfg_edge ['ipc_type' ]].add (id_edge )
173
184
174
185
return map_id_by_class
175
186
@@ -180,16 +191,22 @@ def _construct_queues(cfg, map_cfg_edge, map_id_by_class, id_host_local):
180
191
Return a map from edge id to queue instance.
181
192
182
193
"""
183
- map_queues = dict ()
184
- for id_edge in map_id_by_class ['server' ]:
185
- map_queues [id_edge ] = xact .queue .RemoteQueueServer (
186
- cfg , map_cfg_edge [id_edge ], id_host_local )
187
-
188
- for id_edge in map_id_by_class ['ipc' ]:
189
- map_queues [id_edge ] = xact .queue .LocalQueue ()
194
+ # Ensure queue implementations are loaded.
195
+ #
196
+ map_queue_impl = dict ()
197
+ for (id_edge_class , spec_module ) in cfg ['queue' ].items ():
198
+ module = xact .proc .ensure_imported (spec_module )
199
+ if 'Queue' not in module .__dict__ :
200
+ raise xact .signal .NonRecoverableError (
201
+ cause = 'No Queue class in specified module.' )
202
+ map_queue_impl [id_edge_class ] = module .Queue
190
203
191
- for id_edge in map_id_by_class ['client' ]:
192
- map_queues [id_edge ] = xact .queue .RemoteQueueClient (
204
+ # Select the correct queue implementation for each edge.
205
+ #
206
+ map_queues = dict ()
207
+ for (id_edge_class , queue_impl ) in map_queue_impl .items ():
208
+ for id_edge in map_id_by_class [id_edge_class ]:
209
+ map_queues [id_edge ] = queue_impl (
193
210
cfg , map_cfg_edge [id_edge ], id_host_local )
194
211
195
212
return map_queues
0 commit comments