I think there is a better place than the controller's constructor to do that. Because the controller creates the model, you do actually have a place to implement your own "setup()", outside the constructor. But as you have pointed out, figuring out when the model is done is a lot harder.
The control flow is something like this. *see go method http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/mav/maverick/src/java/org /infohazard/maverick/flow/CommandBase.java?rev=1.2&content-type=text/vnd .viewcvs-markup -- Web request comes into the dispatcher -- Controller is found/created -- Controller.Perform() returns Controller.Result object Your controller does its processing... Connects to DB, Creates Model, closes DB connections. If you don't close your resources here (at the end of perform), you will need to do so with the new interface below. -- Resulting view name is retrieved (via Controller.Result.view()) -- View.go called, with the resulting Model (via Controller.Result.model()) This is when your model will be given to the view for processing. It is probably the setup event your are looking for. -- If View supports ModelLifetime interface, discard is called. This will signal the end of your model, at least its usefulness in our framework. So your setup event is really when your Controller.Result object gets its map() method called. Note: class Throwaway implements Controller, Controller.Result class ThrowawayBean extends Throwaway HTH, Scott PS. If you really want your model to have setup and teardown methods, then you could create a base class for your models, and your own interface. Then you can call setup when you create your model, or on Controller.Result.model(). And you can call teardown at ModelLifetime.discard(). This should get you where you want to be. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Dan Finkelstein Sent: Monday, March 18, 2002 10:28 AM To: [EMAIL PROTECTED] Subject: RE: [Mav-user] 2.0rc works fine and a "preDiscard" question Right, I think that's the right approach. You know, the creation of the connection to the database can be handled through the current architecture using the controller's constructor. But to keep things symmetric, maybe ModelLifetime could expose two methods: something like setup() and teardown(). This notification on initialization and finalization would make clear the tasks. Thanks for your attention to this, Best, Dan PS. Have fun at Maxis. I worked for a few years at Berkeley Systems, which was a blast. :-) At 09:41 AM 3/17/02 -0800, Jeff Schnitzer wrote: >Ah, I see. Something like this interface that a model can optionally >implement: > >public interface ModelLifetime >{ > public void discard(); >} > >I have no objection to adding it, although be aware that this is >probably an anti-pattern... usually you want to have all your data >access completed by the time perform() returns. > >Since the RC seems to be solid, we want to build the final release of >Maverick 2.0 RSN, probably tomorrow. I'll probably slip this change in >anyways since it doesn't require any refactoring. > >Sound good? > >BTW, if I'm slow to respond to mail, it's because I just started a short >contract at Maxis doing WebLogic development and they're keeping me >occupied. That, and I'm still couch-surfing, so I'm either busy or >don't have a stable net connection available :-) > >Jeff Schnitzer >[EMAIL PROTECTED] > > > -----Original Message----- > > From: Dan Finkelstein [mailto:[EMAIL PROTECTED]] > > Sent: Saturday, March 16, 2002 8:26 PM > > To: [EMAIL PROTECTED] > > Subject: RE: [Mav-user] 2.0rc works fine and a "preDiscard" question > > > > Hi Jeff, > > > > Let me try to explain. In my controller (which is _not_ > > ControllerSingleton), I have a perform() method which opens a database > > connection. This controller might be used by a number of templates >and > > have methods which might be used by some and not others, methods like > > getPerformers(), getServices(), etc. Each of these methods uses the >open > > database connection. I'm using JDO and like other systems, it wants >me to > > close my database connection. > > > > So, as I understand it, the flow is something like this: > > 1. Mav calls perform()...and within it, I open the database > > connection > > 2. Mav processes my velocity templates, which call methods >in my > > controller, using $model.performers > > 3. Mav deletes the controller object > > > > What I would like is notification between steps 2 and 3 of the pending > > deletion so I can close the database connection. Does this make more > > sense? > > > > Thanks, > > Dan > > > > At 07:13 AM 3/13/02 -0800, Jeff Schnitzer wrote: > > >I'm not quite sure what you mean. Why not just at the end of your > > >perform() method? Or are you using a ControllerSingleton, and you >want > > >to be notified when a new configuration is loaded and the old is >being > > >discarded? > > > > > >Jeff Schnitzer > > >[EMAIL PROTECTED] > > > > > > > -----Original Message----- > > > > From: Dan Finkelstein [mailto:[EMAIL PROTECTED]] > > > > Sent: Thursday, March 14, 2002 9:35 PM > > > > To: [EMAIL PROTECTED] > > > > Subject: [Mav-user] 2.0rc works fine and a "preDiscard" question > > > > > > > > Just a little feedback... I'm now on 2.0rc and am not having any > > > > problems.... Great work!! > > > > > > > > One question though: In my controller objects, I would like to be > > > > notified > > > > when an instance is about to be deleted. I'd like to use this > > >opportunity > > > > to "clean-up", in this case closing a database connection. > > > > > > > > Can you suggest a way to do this? I would like something more >reliable > > > > than > > > > Java's finalize() method. Or can an overidable method be easily >added > > >at > > > > this point in the release cycle? > > > > > > > > Thanks, > > > > Dan > > > > > > > > > > > > _______________________________________________ > > > > Mav-user mailing list > > > > [EMAIL PROTECTED] > > > > https://lists.sourceforge.net/lists/listinfo/mav-user > > > > > >_______________________________________________ > > >Mav-user mailing list > > >[EMAIL PROTECTED] > > >https://lists.sourceforge.net/lists/listinfo/mav-user > > > > > > _______________________________________________ > > Mav-user mailing list > > [EMAIL PROTECTED] > > https://lists.sourceforge.net/lists/listinfo/mav-user > >_______________________________________________ >Mav-user mailing list >[EMAIL PROTECTED] >https://lists.sourceforge.net/lists/listinfo/mav-user _______________________________________________ Mav-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/mav-user _______________________________________________ Mav-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/mav-user
