1
2
3
4
5
6
7
8
9
10
11
12
13
14 __doc__="""ZeoPoolBase
15
16 $Id: ZC.py,v 1.9 2004/02/16 17:19:31 edahl Exp $"""
17
18 __version__ = "$Revision: 1.9 $"[11:-2]
19
20 from threading import Lock
21
22 from ZEO import ClientStorage
23 from ZODB import DB
24 from ZPublisher.HTTPRequest import HTTPRequest
25 from ZPublisher.HTTPResponse import HTTPResponse
26 from ZPublisher.BaseRequest import RequestContainer
27
28 from ZenDaemon import ZenDaemon
29
30
32 """
33 A multi-threaded daemon that maintains a pool of zeo connections
34 that it can hand out to its worker threads.
35 """
36
37
42
43
45 """Return a connection from the connection pool. If path is passed
46 return the object that the path points to.
47 """
48 try:
49 self.poollock.acquire()
50 if not self.is_connected():
51 self.opendb()
52 connection=self.db.open()
53 root=connection.root()
54 app=root['Application']
55 self._getContext(app)
56 app._p_jar.sync()
57 if path:
58 return app.getObjByPath(path)
59 else:
60 return app
61 self.openconn -= 1
62 finally:
63 self.poollock.release()
64
65
67 addr = (self.options.host, self.options.port)
68 self._storage=ClientStorage.ClientStorage(addr)
69 self.db=DB(self._storage)
70 self.poollock = Lock()
71
72
74 """Close all connections in both free an inuse pools.
75 """
76 self.db.close()
77 self.db = None
78 self._storage = None
79
80
82 """Are we connected to zeo.
83 """
84 return not self._storage or self._storage.is_connected()
85
86
88 """Return the target max pool size for this database.
89 """
90 return self.db.getPoolSize()
91
92
94 """Return the number of available connection in our pool.
95 """
96 if self.db._pools:
97 pool = self.db._pools['']
98 return len(pool.available)
99 return 0
100
101
102 - def _getContext(self, app):
103 resp = HTTPResponse(stdout=None)
104 env = {
105 'SERVER_NAME':'localhost',
106 'SERVER_PORT':'8080',
107 'REQUEST_METHOD':'GET'
108 }
109 req = HTTPRequest(None, env, resp)
110 app.__of__(RequestContainer(REQUEST = req))
111 return app
112
113
115 """basic options setup sub classes can add more options here"""
116 ZenDaemon.buildOptions(self)
117 self.parser.add_option('--host',
118 dest="host",default="localhost",
119 help="hostname of zeo server")
120 self.parser.add_option('--port',
121 dest="port",type="int", default=8100,
122 help="port of zeo server")
123