Michael Palmer wrote:
> 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?
It parses text files that contain lab results, manipulates the data,
then uploads it to a database.
>> 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().
>> 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':
I have flexibility in the design of LabRat. Some requests may depend on
the result of a previous request, so I will need some form of
persistence. I do not know how to implement sessions using XMLRPC.
I like Webware's session storage because it lasts between process
restarts. Could I use Webware's session storage and couple it with a
simple client id system? Client requests id -> server sends id ->
client sends data to store and id -> server stores data in session using
id as key.
>> 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__ .
Sorry, that was a stupid question. I knew that.
>> 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
> 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