RE: [Webware-discuss] At a loss please help with Sessions and Tasks

So if I read you correctly, you have a servlet that delivers a web page with
a flash object, and you only want one person to be able to view that web
page at a time? That seems very counter-productive to me. I know you say
you don't have control over that but I think you should motivate some change
of that system.
I guess there are some cases where you would really only want single user
access. In that case, you could use a flag on the session class itself. You
could mix in a thin class that provides a threading.Semaphore instance as a
class attribute. You can wrap the Semaphore's acquire and release methods or
just reference them directly from the servlet. Each time the servlet
executes, you would attempt to acquire the semaphore. You can use a
non-blocking call to acquire and loop for a certain amount of time before
giving an error message to the users. Otherwise if you do acquire it,
deliver the page as normal.
Now you have the problem of releasing it. You need to know when the user is
"done" with the flash object. If you have no way of guaranteeing that the
user will be done before their session expires, then you have to customize
the session's expiring() method. So you can have your mixin class override
the expiring() method to release the semaphore. But you dont want a session
instance to release the semaphore on expiration unless it was the one that
actually acquired it, so you'll need another flag. But this can just be a
boolean flag on the session instance. The expiring() method checks the flag
and then releases the semaphore if the flag is set. You would set the flag
just after acquiring the class's semaphore and unset the flag just before
releasing the semaphore (assuming it's possible to know when the user is
done with the flash object).
Hope that helps,
Ben
-----Original Message-----
From: webware-discuss-admin@...
[mailto:webware-discuss-admin@...]On Behalf Of jose
Sent: Wednesday, May 28, 2003 9:32 PM
To: ben@...; webware-discuss@...
Subject: RE: [Webware-discuss] At a loss please help with Sessions and
Tasks
Exclent point, Here is what I need to do, I have a web application which
allows users to interact with a flash object on a web page. Now for the
problem the flash object writes an XML file to the server (I didn't make
the flash object so I don't have control of this object), so I need to
make sure that only one person has access to the object at any given
moment. My first thought was to use sessions, but that won't work
across users, so then I thought of just making a lock file and killing
the lokc file when a session dies. But I am not all that thrilled at
changing the behavior of sessions across the entire website for this one
applicaton. Any thoughts on maintaining user control?
Jose
-----Original Message-----
From: Ben Parker [mailto:ben@...]
Sent: Wednesday, May 28, 2003 12:23 AM
To: jose@...
Subject: RE: [Webware-discuss] At a loss please help with Sessions and
Tasks
Jose, can you be a little more specific as to what you need to do when a
session expires? Then maybe I can give you some ideas.
to answer what you've said so far:
Mixing a class into session during the context __init__ will override
the session for the entire appserver. One way to use session classes on
a context-by-context basis is to override the Page.session() method with
something that wraps the session in another class. That won't help with
the expiration issue directly, but you can use that in combination with
a MixIn to achieve what you need.
For example, you can MixIn a class which overrides Session.expiring()
and performs certain logic depending on what type of session object it
is. This type would be determined by an attribute of the MixIn class.
Then in the
Page.session() method, you can set this new type attribute to identify
the Session. When the expiring functions runs, the appropriate logic
will execute.
Really though, what "file housekeeping" do you need to do at expiration
time? The best scenario is to rearchitect your use of session objects to
eliminate the need for such housekeeping.
Ben
-----Original Message-----
From: webware-discuss-admin@...
[mailto:webware-discuss-admin@...]On Behalf Of
jose@...
Sent: Tuesday, May 27, 2003 8:15 PM
To: webware-discuss@...
Subject: [Webware-discuss] At a loss please help with Sessions and Tasks
HI all.
Can someone please tell me how I can access a session variable via a
task? What I need to do is to do some file house keeping once a session
expires. I thought I could do this by using MixIn and simply over riding
the expiring method within a context, but it seems the this over rides
the method for the all contexts (not really what I had in mind). So now
the only thing I can think of is to use Tasks, but I am at a loss as to
how to proceed. Any and all help would be much appreciated
Thanks
Jose
-------------------------------------------------------
This SF.net email is sponsored by: ObjectStore.
If flattening out C++ or Java code to make your application fit in a
relational database is painful, don't do it! Check out ObjectStore. Now
part of Progress Software. http://www.objectstore.net/sourceforge
_______________________________________________
Webware-discuss mailing list Webware-discuss@...
https://lists.sourceforge.net/lists/listinfo/webware-discuss
-------------------------------------------------------
This SF.net email is sponsored by: eBay
Get office equipment for less on eBay!
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
_______________________________________________
Webware-discuss mailing list
Webware-discuss@...
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Thread view

Exclent point, Here is what I need to do, I have a web application which
allows users to interact with a flash object on a web page. Now for the
problem the flash object writes an XML file to the server (I didn't make
the flash object so I don't have control of this object), so I need to
make sure that only one person has access to the object at any given
moment. My first thought was to use sessions, but that won't work
across users, so then I thought of just making a lock file and killing
the lokc file when a session dies. But I am not all that thrilled at
changing the behavior of sessions across the entire website for this one
applicaton. Any thoughts on maintaining user control?
Jose
-----Original Message-----
From: Ben Parker [mailto:ben@...]
Sent: Wednesday, May 28, 2003 12:23 AM
To: jose@...
Subject: RE: [Webware-discuss] At a loss please help with Sessions and
Tasks
Jose, can you be a little more specific as to what you need to do when a
session expires? Then maybe I can give you some ideas.
to answer what you've said so far:
Mixing a class into session during the context __init__ will override
the session for the entire appserver. One way to use session classes on
a context-by-context basis is to override the Page.session() method with
something that wraps the session in another class. That won't help with
the expiration issue directly, but you can use that in combination with
a MixIn to achieve what you need.
For example, you can MixIn a class which overrides Session.expiring()
and performs certain logic depending on what type of session object it
is. This type would be determined by an attribute of the MixIn class.
Then in the
Page.session() method, you can set this new type attribute to identify
the Session. When the expiring functions runs, the appropriate logic
will execute.
Really though, what "file housekeeping" do you need to do at expiration
time? The best scenario is to rearchitect your use of session objects to
eliminate the need for such housekeeping.
Ben
-----Original Message-----
From: webware-discuss-admin@...
[mailto:webware-discuss-admin@...]On Behalf Of
jose@...
Sent: Tuesday, May 27, 2003 8:15 PM
To: webware-discuss@...
Subject: [Webware-discuss] At a loss please help with Sessions and Tasks
HI all.
Can someone please tell me how I can access a session variable via a
task? What I need to do is to do some file house keeping once a session
expires. I thought I could do this by using MixIn and simply over riding
the expiring method within a context, but it seems the this over rides
the method for the all contexts (not really what I had in mind). So now
the only thing I can think of is to use Tasks, but I am at a loss as to
how to proceed. Any and all help would be much appreciated
Thanks
Jose
-------------------------------------------------------
This SF.net email is sponsored by: ObjectStore.
If flattening out C++ or Java code to make your application fit in a
relational database is painful, don't do it! Check out ObjectStore. Now
part of Progress Software. http://www.objectstore.net/sourceforge
_______________________________________________
Webware-discuss mailing list Webware-discuss@...
https://lists.sourceforge.net/lists/listinfo/webware-discuss

So if I read you correctly, you have a servlet that delivers a web page with
a flash object, and you only want one person to be able to view that web
page at a time? That seems very counter-productive to me. I know you say
you don't have control over that but I think you should motivate some change
of that system.
I guess there are some cases where you would really only want single user
access. In that case, you could use a flag on the session class itself. You
could mix in a thin class that provides a threading.Semaphore instance as a
class attribute. You can wrap the Semaphore's acquire and release methods or
just reference them directly from the servlet. Each time the servlet
executes, you would attempt to acquire the semaphore. You can use a
non-blocking call to acquire and loop for a certain amount of time before
giving an error message to the users. Otherwise if you do acquire it,
deliver the page as normal.
Now you have the problem of releasing it. You need to know when the user is
"done" with the flash object. If you have no way of guaranteeing that the
user will be done before their session expires, then you have to customize
the session's expiring() method. So you can have your mixin class override
the expiring() method to release the semaphore. But you dont want a session
instance to release the semaphore on expiration unless it was the one that
actually acquired it, so you'll need another flag. But this can just be a
boolean flag on the session instance. The expiring() method checks the flag
and then releases the semaphore if the flag is set. You would set the flag
just after acquiring the class's semaphore and unset the flag just before
releasing the semaphore (assuming it's possible to know when the user is
done with the flash object).
Hope that helps,
Ben
-----Original Message-----
From: webware-discuss-admin@...
[mailto:webware-discuss-admin@...]On Behalf Of jose
Sent: Wednesday, May 28, 2003 9:32 PM
To: ben@...; webware-discuss@...
Subject: RE: [Webware-discuss] At a loss please help with Sessions and
Tasks
Exclent point, Here is what I need to do, I have a web application which
allows users to interact with a flash object on a web page. Now for the
problem the flash object writes an XML file to the server (I didn't make
the flash object so I don't have control of this object), so I need to
make sure that only one person has access to the object at any given
moment. My first thought was to use sessions, but that won't work
across users, so then I thought of just making a lock file and killing
the lokc file when a session dies. But I am not all that thrilled at
changing the behavior of sessions across the entire website for this one
applicaton. Any thoughts on maintaining user control?
Jose
-----Original Message-----
From: Ben Parker [mailto:ben@...]
Sent: Wednesday, May 28, 2003 12:23 AM
To: jose@...
Subject: RE: [Webware-discuss] At a loss please help with Sessions and
Tasks
Jose, can you be a little more specific as to what you need to do when a
session expires? Then maybe I can give you some ideas.
to answer what you've said so far:
Mixing a class into session during the context __init__ will override
the session for the entire appserver. One way to use session classes on
a context-by-context basis is to override the Page.session() method with
something that wraps the session in another class. That won't help with
the expiration issue directly, but you can use that in combination with
a MixIn to achieve what you need.
For example, you can MixIn a class which overrides Session.expiring()
and performs certain logic depending on what type of session object it
is. This type would be determined by an attribute of the MixIn class.
Then in the
Page.session() method, you can set this new type attribute to identify
the Session. When the expiring functions runs, the appropriate logic
will execute.
Really though, what "file housekeeping" do you need to do at expiration
time? The best scenario is to rearchitect your use of session objects to
eliminate the need for such housekeeping.
Ben
-----Original Message-----
From: webware-discuss-admin@...
[mailto:webware-discuss-admin@...]On Behalf Of
jose@...
Sent: Tuesday, May 27, 2003 8:15 PM
To: webware-discuss@...
Subject: [Webware-discuss] At a loss please help with Sessions and Tasks
HI all.
Can someone please tell me how I can access a session variable via a
task? What I need to do is to do some file house keeping once a session
expires. I thought I could do this by using MixIn and simply over riding
the expiring method within a context, but it seems the this over rides
the method for the all contexts (not really what I had in mind). So now
the only thing I can think of is to use Tasks, but I am at a loss as to
how to proceed. Any and all help would be much appreciated
Thanks
Jose
-------------------------------------------------------
This SF.net email is sponsored by: ObjectStore.
If flattening out C++ or Java code to make your application fit in a
relational database is painful, don't do it! Check out ObjectStore. Now
part of Progress Software. http://www.objectstore.net/sourceforge
_______________________________________________
Webware-discuss mailing list Webware-discuss@...
https://lists.sourceforge.net/lists/listinfo/webware-discuss
-------------------------------------------------------
This SF.net email is sponsored by: eBay
Get office equipment for less on eBay!
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
_______________________________________________
Webware-discuss mailing list
Webware-discuss@...
https://lists.sourceforge.net/lists/listinfo/webware-discuss

--- jose <jose@...> wrote:
> Exclent point, Here is what I need to do, I have a web application
> which
> allows users to interact with a flash object on a web page. Now for
> the
> problem the flash object writes an XML file to the server (I didn't
> make
> the flash object so I don't have control of this object), so I need
> to
> make sure that only one person has access to the object at any given
> moment.
I had a roughly similar problem, wanting to control one-at-a-time
access to a logical chunk of several MySQL tables. Along the way, I
also implemented a mechanism to limit the number of simultaneous users.
I did this by adding lock objects and dictionaries at the module level
of my SitePage.
After getting a little help here, I was able to add a feature to pickle
the state of these dictionaries and reload them when my SitePage was
reloaded (very helpful during testing). Your locks will be different
than mine, but here is my SitePage module level code to pickle and
unpickle my the dictionaries I use to control access
(spActiveUsers,spActiveFolders,spActiveUerTimeout dictionaries and
associated locks are defined elsewhere and not shown):
# variables used to preserve state across restarts
spSaveState = 1
spPickleFileName = 'PickledState.dra'
file = spConfigs['baseDirectory'] + spPickleFileName
# get previous state if there is one
try:
pFile = open(file,'r')
spActiveUsers,spActiveFolders,spActiveUserTimeout =
cPickle.load(pFile)
pFile.close()
except:
pass
# special function to save module state in case of a restart
def saveState():
'''Pickle key fields and write to disk.'''
file = spConfigs['baseDirectory'] + spPickleFileName
pFile = open(file,'w')
cPickle.dump((spActiveUsers,spActiveFolders,spActiveUserTimeout),pFile)
pFile.close()
Then within my logon process, I have a small bit of code that gets
executed the first time someone logs on. "saveState" will get called
when the AppServer is restarted.
#one time only, set means of saving global variables
global spSaveState
if spSaveState:
spSaveState = 0
self.application().addShutDownHandler(saveState)
HTH,
Roger Haase
__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com

Funny you should mention this method of using lockfile objects, that is
exactly the model we are going to use here to solve the problem. I'll let
you know if it works for us
Jose
-------- Original Message --------
Subject: RE: [Webware-discuss] At a loss please help with Sessions and
Tasks
From: Roger Haase <crosseyedpenguin@...>
Date: Thu, May 29, 2003 7:42 am
To: jose <jose@...>, webware-discuss@...
--- jose <jose@...> wrote:
> Exclent point, Here is what I need to do, I have a web application
> which
> allows users to interact with a flash object on a web page. Now for
> the
> problem the flash object writes an XML file to the server (I didn't
> make
> the flash object so I don't have control of this object), so I need
> to
> make sure that only one person has access to the object at any given
> moment.
I had a roughly similar problem, wanting to control one-at-a-time
access to a logical chunk of several MySQL tables. Along the way, I
also implemented a mechanism to limit the number of simultaneous
users. I did this by adding lock objects and dictionaries at the
module level of my SitePage.
After getting a little help here, I was able to add a feature to
pickle the state of these dictionaries and reload them when my
SitePage was reloaded (very helpful during testing). Your locks will
be different than mine, but here is my SitePage module level code to
pickle and unpickle my the dictionaries I use to control access
(spActiveUsers,spActiveFolders,spActiveUerTimeout dictionaries and
associated locks are defined elsewhere and not shown):
# variables used to preserve state across restarts
spSaveState = 1
spPickleFileName = 'PickledState.dra'
file = spConfigs['baseDirectory'] + spPickleFileName
# get previous state if there is one
try:
pFile = open(file,'r')
spActiveUsers,spActiveFolders,spActiveUserTimeout =
cPickle.load(pFile)
pFile.close()
except:
pass
# special function to save module state in case of a restart
def saveState():
'''Pickle key fields and write to disk.'''
file = spConfigs['baseDirectory'] + spPickleFileName
pFile = open(file,'w')
cPickle.dump((spActiveUsers,spActiveFolders,spActiveUserTimeout),pFile)
pFile.close()
Then within my logon process, I have a small bit of code that gets
executed the first time someone logs on. "saveState" will get called
when the AppServer is restarted.
#one time only, set means of saving global variables
global spSaveState
if spSaveState:
spSaveState = 0
self.application().addShutDownHandler(saveState)
HTH,
Roger Haase
__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com