Closed cristianhoyos66-zz closed 8 years ago
Thanks for this interesting question!
My recommendation would be that you should really use the singleton access pattern.
The singleton does not cause any problems that you wouldn't have with the standard access pattern (that you're currently using): Is the class itself (as opposed to the singleton) much easier to test? Not really. Does it provide memory-safety guarantees that the singleton does not provide? No.
What you certainly _can_t do is creating instances multiple times and connecting multiple times, as you have seen yourself :)
I'd really like to read your reasons by wich you recommend me use singleton and to know if you can tell me if meteor manage connection pool for the server connection, I know that mongo does, but I don't know meteor for the server.
Thank you so much.
I'm not really sure what you are referring to, sorry!
The singleton is the recommended access pattern for your case since it re-uses a single connection across all Activity
instances. If you use the normal access pattern of creating instances via new Meteor(...)
, you will have a separate connection for every single Activity
.
With that said, I'm not sure what your question regarding the connection pool is about or if that question has been answered already.
If i use singleton pattern could happen that the connection port on the server is occupated by an application in a device, and does not allow that another app in another device can connect to that server, because that port is not available?
Actually, the singleton pattern does only affect the one device and application that it's running on. There are no side effects to other devices.
Does that solve your problem?
Yes, you are so helpful, thank you so much.
Hi, I do this question with the finality to know a better way to manage the server connection
I'm doing my project connection as I would do a connection in projects made with java language and mysql as db, so we guess that I have two collections: users and companies, each one have an associated activity, and in each activity I do this:
We can see that the connection is opened and closed respectively.
I think that I can use singleton to manage the connections with my server, but I don't know if it can be a good idea, because singleton is hard to test and I don't know if
MeteorSingleton
is thread safe.I'd appreciate your help in this.
Thank you.