Well I didn't want to focus too much on DataSource specifically, but if
a pooling data source (like apache-commons dbcp) has a close method,
because after you get/close a connection it stays open in the pool. Of
course for apache-commons dbcp specifically you can start up an idle
reaper (I assume it starts a thread) that will eventually close those
connections, but it would be nice if you were done with that stage of
the program if you could close it certainly. And there are other
resources out there that aren't so "automatic"... Would one ever use
Guice to inject things like Swing frames? I suppose yes if the goal is
to eliminate "new" entirely. So a swing frame has to be disposed.
Maybe I should just try it in a real app and maybe it's not a problem.
In a Swing app you can dispose on close... with an "FTP resource"
someone is going to "get" it and then "close" it... for things like
pooling JDBC sources they have features to automatically clean up. I
can't think of a good example of a shared resource like DataSource that
doesn't implicitly clean itself up.
I've been realizing to start up a "subtask" I don't really need a child
injector. If I have a class like FtpUploader and it takes FtpConnection
which takes a Socket or something, if I ask for an FtpUploader Guice
will instantiate a new FtpConnection and Socket for it. And whatever
uses the FtpUploader will eventually cause it to close the connection,
so it will be cleaned up in the end. And of course I can create as many
FtpUploader as I want. I just don't know immediately how I would
parametrize that (I would want FtpUploader for site.example.com because
the user typed that in), without creating a new injector though. I'll
have to figure that out. Maybe the intention is that construction
doesn't take the parameters but I have set/connect methods instead.
Jason
On 7/4/2010 3:32 PM, Kartik Kumar wrote:
You only have to shut down a connection generated from DataSource. You
can inject a DataSource binding into a Provider<Connection>
implementation and implement get() method to return a Connection to be
injected.
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en.