[Zodb-checkins] CVS: StandaloneZODB/ZEO - ClientStorage.py:1.26.4.29
Jeremy Hylton
jeremy@zope.com
Mon, 7 Jan 2002 16:02:23 -0500
Update of /cvs-repository/StandaloneZODB/ZEO
In directory cvs.zope.org:/tmp/cvs-serv11395
Modified Files:
Tag: ZEO-ZRPC-Dev
ClientStorage.py
Log Message:
Use ClientDisconnectedStub for _server attribute of ClientStorage.
The CDS always raises a ClientDisconnected() error. This is simpler
than testing for _server == None and raising the error in every place
where _server is used.
=== StandaloneZODB/ZEO/ClientStorage.py 1.26.4.28 => 1.26.4.29 ===
return t
-class ClientStorage:
+class DisconnectedServerStub:
+ """Raise ClientDisconnected on all attribute access."""
+
+ def __getattr__(self, attr):
+ raise ClientDisconnected()
- _server = None
+disconnected_stub = DisconnectedServerStub()
+
+class ClientStorage:
def __init__(self, addr, storage='1', cache_size=20000000,
name='', client='', debug=0, var=None,
@@ -148,6 +154,7 @@
# Decide whether to use non-temporary files
client = client or os.environ.get('ZEO_CLIENT','')
+ self._server = disconnected_stub
self._connection = addr
self._storage = storage
self._debug = debug
@@ -174,7 +181,6 @@
#debug=debug,
tmin=min_disconnect_poll,
tmax=max_disconnect_poll)
- self._server = None
if wait_for_server_on_startup:
self._rpc_mgr.connect(sync=1)
else:
@@ -213,10 +219,10 @@
self._db = db
def is_connected(self):
- if self._server:
- return 1
- else:
+ if self._server is disconnected_stub:
return 0
+ else:
+ return 1
def notifyConnected(self, c):
log2(INFO, "Connected to storage")
@@ -224,6 +230,8 @@
self._oids = []
+ # XXX Why is this synchronous? If it were async, verification
+ # would start faster.
stub.register(str(self._storage))
self.verify_cache(stub)
@@ -250,7 +258,7 @@
def notifyDisconnected(self, ignored):
log2(PROBLEM, "Disconnected from storage")
- self._server = None
+ self._server = disconnected_stub
if self._transaction:
self._transaction = None
self.tpc_cond.notifyAll()
@@ -326,7 +334,8 @@
# Close the manager first, so that it doesn't attempt to
# re-open the connection.
self._rpc_mgr.close()
- if self._server:
+ if self._server is not disconnected_stub:
+ # XXX why doesn't the manager close this for us?
self._server.rpc.close()
if self._cache is not None:
self._cache.close()
@@ -452,7 +461,7 @@
# If _server is None, then the client disconnected during
# the tpc_begin() and notifyDisconnected() will have
# released the lock.
- if self._server is not None:
+ if self._server is not disconnected_stub:
self.tpc_cond.release()
raise