Randall Smith wrote:

I'm writing an app that uses the XMLRPCServlet class. I'm writing my app so that the 'business' logic is completely unaware of Webware or XMLRPC. A class called LabRat contains all of the business logic.

does this name mean that the app is somehow related to experimental lab work? If so, could you explain a bit more?



Because Webware is multi-threaded, does the LabRat() need to know this and act accordingly? The LabRat() accesses files and changes variables, which I imagine might require a lock.aquire(), lock.release().

Yes


What is they best way to include the LabRat() in XMLRPCServlet? From the example, it is not clear how to add object methods. Some attributes of LabRat() should not be persistent and others should be persistent across all instances such that all instances see the change made by one.

Does a LabRat instance itself persist between requests, e.g. in a session, or is it instantiated anew with each request?
For things that should be available to all instances, it's easiest use a module global:


_president = 'G.W.Bush'

class LabRat(object):
   def elect(self):
      while _president  == 'G.W.Bush':
           self.recount()


I'm confused about a servlet's initialization. I thought all classes should have an __init__ method. An "__init__(self): pass" in a servlet throws an Exception.

This is because your __init__ hides the __init__ of the base class. If you don't define __init__, that of the base class will be called automatically. If you do have to do some work in __init__ (which you likely do, since you say that LabRat contains 'all the business logic'), call XMLRPCServlet.__init__(self) from your own __init__ .




I'm also confused in general about the state of variables as a servlet 'sleeps' and 'wakes'. What happens to instance variables that get set? Do they persist? Are they present only in the instance they were set in, or all instances? Is the object re-initialized when it 'wakes'?

What is and what is not re-initialized depends on what you have in your YourServlet.awake method; what persists depends on your YourServlet.sleep method.
I use awake and sleep to automatically clean out everything that has been stored on self during the request:


def awake(self, transaction):
Page.awake(self, transaction) # Call base class, which is Page in my case but would be XMLRPCServlet in your's I guess
# save the keys in the __dict__ as a template for cleaning up later
self._dictKeysStart = self.__dict__.keys()


def sleep(self, transaction):
Page.sleep(self, transaction)
# clean out everything that has been left behind
dictKeysEnd = self.__dict__.keys()
dictKeysStart = self._dictKeysStart[:] # Use a copy to avoid suicide
for key in dictKeysEnd:
if key not in dictKeysStart: del self.__dict__[key]




I'm certainly not complaining. Please don't take it that way. I like Webware most because it is simple/powerful just like Python. I guess that's saying it is Pythonic.


These are all things I think are important to understand to write solid apps.

Randall Smith


------------------------------------------------------- This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND _______________________________________________ Webware-discuss mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/webware-discuss



--

Michael Palmer
University of Waterloo
Dept. of Chemistry
200 University Ave. West
Waterloo, ON N2L 3G1
Canada

Email:  [EMAIL PROTECTED]
URL:    http://www.science.uwaterloo.ca/~mpalmer/
Phone:  (519) 888 4567 ext. 5100
Fax:    (519) 746 0435





-------------------------------------------------------
This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference
Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer
Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA
REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to