storage_server_tls.py :  » Database » Python-Remote-Objects » Pyro-3.10 » examples » sessions » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Database » Python Remote Objects 
Python Remote Objects » Pyro 3.10 » examples » sessions » storage_server_tls.py
import Pyro.core
import Pyro.naming
import sys

# server based on using TLS to store session data


print """
This is the storage server that depends on Thread Local Storage to keep track
of what the resource is for that given session. TLS only works for this if
the server runs with real threads (so every connection/session has its own
distinct TLS). If you disable multithreading, TLS will overlap for all
sessions and resources get mixed up. You can check this by looking at the
output on the screen and the contents of the datafiles."""
print """
If running with multithreading you will, after running the storage_client,
end up with a few datafiles: one for every user, and only that user's lines
in it. If not using multithreading things will break: almost all lines
(from all users) end up in a single datafile and errors might occur
because wrong stuff is closed."""
print

Pyro.config.PYRO_MULTITHREADED=raw_input("Enable multithreading y/n? ") in ('y','Y')


# The datastore.
# It will store lines of text in a file named after the 'user'.
# The resource that is owned by this user session (the file handle) is stored on the TLS.
class DataStore(Pyro.core.ObjBase):
  def init(self, username):
    tls=self.getLocalStorage()
    tls.datastore=open("datastorage_%s.txt"%username,"w")
    
  def addline(self, textline):
    tls=self.getLocalStorage()
    sys.stdout.write("adding line to "+tls.datastore.name+"\n")
    sys.stdout.flush()
    tls.datastore.write(textline+" | came from "+str(tls.caller)+"\n")
  
  def close(self):
    tls=self.getLocalStorage()
    tls.datastore.close()  
      
    

daemon=Pyro.core.Daemon()
ns=Pyro.naming.NameServerLocator().getNS()
daemon.useNameServer(ns)

try:
  ns.createGroup(":test")
except Exception:
  pass
try:
  ns.unregister(":test.datastorage")
except Exception:
  pass

daemon.connect(DataStore(), ":test.datastorage")

print "Server (TLS version) is running."
daemon.requestLoop()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.