[monitorlib] Obtain UTMClientSessions via factory rather than direct construction#1413
Conversation
| return self._sessions[key] | ||
|
|
||
|
|
||
| utm_client_session_factory = UTMClientSessionFactory() |
There was a problem hiding this comment.
nit: I would have made it a class method and just use UTMClientSessionFactory.get_session(..) instead of having that shared variable
There was a problem hiding this comment.
This assumes that it could only ever make sense to have a single UTMClientSessionFactory and that doesn't seem necessarily true. I think it is probably true with the current implementation, but patterns of access (like UTMClientSessionFactory.get_session(..)) are part of the interface rather than the implementation and should therefore generally survive changes in the implementation. Since it doesn't seem necessarily non-sensical to have, e.g., 2 factories, then the choice to have just 1 factory currently doesn't seem like it should be part of the contract/interface of the factory.
This PR implements the concept of #1409 using a factory pattern instead of construction interception (and is an alternative to #1409). Instead of constructing UTMClientSessions directly, a UTMClientSessionFactory singleton is used to obtain the desired UTMClientSessions, and the factory reuses existing UTMClientSessions when possible (when all construction parameters are the same). This partially addresses #1407 and should also increase efficiency by reusing connections more often.
The substantive change in this PR is in infrastructure.py. All other changes should be changing from the UTMClientSession constructor to the singleton factory's get_session method.