28 |
28 |
29 |
29 |
30 def _GetLocalConnectorClassFactory(name): |
30 def _GetLocalConnectorClassFactory(name): |
31 return lambda:getattr(__import__(name,globals(),locals()), name + "_connector_factory") |
31 return lambda:getattr(__import__(name,globals(),locals()), name + "_connector_factory") |
32 |
32 |
33 connectors = {name:_GetLocalConnectorClassFactory(name) |
33 connectors = {name:_GetLocalConnectorClassFactory(name) |
34 for name in listdir(_base_path) |
34 for name in listdir(_base_path) |
35 if path.isdir(path.join(_base_path, name)) |
35 if path.isdir(path.join(_base_path, name)) |
36 and not name.startswith("__")} |
36 and not name.startswith("__")} |
37 |
37 |
38 def ConnectorFactory(uri, confnodesroot): |
38 def ConnectorFactory(uri, confnodesroot): |
39 """ |
39 """ |
40 Return a connector corresponding to the URI |
40 Return a connector corresponding to the URI |
41 or None if cannot connect to URI |
41 or None if cannot connect to URI |
42 """ |
42 """ |
43 servicetype = uri.split("://")[0] |
43 servicetype = uri.split("://")[0].upper() |
44 if servicetype in connectors: |
44 if servicetype == "LOCAL": |
45 # import module according to uri type |
45 # Local is special case |
46 connectorclass = connectors[servicetype]() |
46 # pyro connection to local runtime |
47 elif servicetype == "LOCAL": |
47 # started on demand, listening on random port |
48 from PYRO import PYRO_connector_factory as connectorclass |
48 servicetype = "PYRO" |
49 runtime_port = confnodesroot.AppFrame.StartLocalRuntime(taskbaricon=True) |
49 runtime_port = confnodesroot.AppFrame.StartLocalRuntime( |
|
50 taskbaricon=True) |
50 uri="PYRO://127.0.0.1:"+str(runtime_port) |
51 uri="PYRO://127.0.0.1:"+str(runtime_port) |
|
52 elif servicetype in connectors: |
|
53 pass |
|
54 elif servicetype[-1]=='S' and servicetype[:-1] in connectors: |
|
55 servicetype = servicetype[:-1] |
51 else : |
56 else : |
52 return None |
57 return None |
|
58 |
|
59 # import module according to uri type |
|
60 connectorclass = connectors[servicetype]() |
53 return connectorclass(uri, confnodesroot) |
61 return connectorclass(uri, confnodesroot) |
54 |
62 |