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 with self.poollock:
51 if not self.is_connected():
52 self.opendb()
53 connection=self.db.open()
54 root=connection.root()
55 app=root['Application']
56 self._getContext(app)
57 app._p_jar.sync()
58 if path:
59 return app.getObjByPath(path)
60 else:
61 return app
62 self.openconn -= 1
63
64
66 addr = (self.options.host, self.options.port)
67 self._storage=ClientStorage.ClientStorage(addr)
68 self.db=DB(self._storage)
69 self.poollock = Lock()
70
71
73 """Close all connections in both free an inuse pools.
74 """
75 self.db.close()
76 self.db = None
77 self._storage = None
78
79
81 """Are we connected to zeo.
82 """
83 return not self._storage or self._storage.is_connected()
84
85
87 """Return the target max pool size for this database.
88 """
89 return self.db.getPoolSize()
90
91
93 """Return the number of available connection in our pool.
94 """
95 if self.db._pools:
96 pool = self.db._pools['']
97 return len(pool.available)
98 return 0
99
100
101 - def _getContext(self, app):
102 resp = HTTPResponse(stdout=None)
103 env = {
104 'SERVER_NAME':'localhost',
105 'SERVER_PORT':'8080',
106 'REQUEST_METHOD':'GET'
107 }
108 req = HTTPRequest(None, env, resp)
109 app.__of__(RequestContainer(REQUEST = req))
110 return app
111
112
114 """basic options setup sub classes can add more options here"""
115 ZenDaemon.buildOptions(self)
116 self.parser.add_option('--host',
117 dest="host",default="localhost",
118 help="hostname of zeo server")
119 self.parser.add_option('--port',
120 dest="port",type="int", default=8100,
121 help="port of zeo server")
122