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 from Products.ZenUtils.Utils import unused
31
33 """
34 A multi-threaded daemon that maintains a pool of zeo connections
35 that it can hand out to its worker threads.
36 """
37
38
39 - def __init__(self, noopts=0, app=None, keeproot=False):
44
45
47 """Return a connection from the connection pool. If path is passed
48 return the object that the path points to.
49 """
50 try:
51 self.poollock.acquire()
52 if not self.is_connected():
53 self.opendb()
54 connection=self.db.open()
55 root=connection.root()
56 app=root['Application']
57 self._getContext(app)
58 app._p_jar.sync()
59 if path:
60 return app.getObjByPath(path)
61 else:
62 return app
63 self.openconn -= 1
64 finally:
65 self.poollock.release()
66
67
69 addr = (self.options.host, self.options.port)
70 self._storage=ClientStorage.ClientStorage(addr)
71 self.db=DB(self._storage)
72 self.poollock = Lock()
73
74
76 """Close all connections in both free an inuse pools.
77 """
78 self.db.close()
79 self.db = None
80 self._storage = None
81
82
84 """Are we connected to zeo.
85 """
86 return not self._storage or self._storage.is_connected()
87
88
90 """Return the target max pool size for this database.
91 """
92 return self.db.getPoolSize()
93
94
96 """Return the number of available connection in our pool.
97 """
98 if self.db._pools:
99 pool = self.db._pools['']
100 return len(pool.available)
101 return 0
102
103
104 - def _getContext(self, app):
105 resp = HTTPResponse(stdout=None)
106 env = {
107 'SERVER_NAME':'localhost',
108 'SERVER_PORT':'8080',
109 'REQUEST_METHOD':'GET'
110 }
111 req = HTTPRequest(None, env, resp)
112 app.__of__(RequestContainer(REQUEST = req))
113 return app
114
115
117 """basic options setup sub classes can add more options here"""
118 ZenDaemon.buildOptions(self)
119 self.parser.add_option('--host',
120 dest="host",default="localhost",
121 help="hostname of zeo server")
122 self.parser.add_option('--port',
123 dest="port",type="int", default=8100,
124 help="port of zeo server")
125