[Zodb-checkins] CVS: Zope/lib/python/ZODB - ConnectionPolicy.py:1.1.2.1 ZApplication.py:1.13.24.1

Chris McDonough chrism at zope.com
Wed Oct 1 00:35:26 EDT 2003


Update of /cvs-repository/Zope/lib/python/ZODB
In directory cvs.zope.org:/tmp/cvs-serv22765

Modified Files:
      Tag: chrism-zserver-connection-policies-branch
	ZApplication.py 
Added Files:
      Tag: chrism-zserver-connection-policies-branch
	ConnectionPolicy.py 
Log Message:
Experimental branch which allows ZServer servers to specify a different
thread pool than the default thread pool, and a ZODB 'connection policy'.

The advantages of this include:

- Thread resource exhaustion will not effect servers which specify
  a different thread pool.

- The connection policy can be used for many purposes (including,
  for instance, specifying in the future, whether MVCC should be used for a i
  particular connection), but its main purpose in this context is             
  to allow us to define a 'temporary' connection policy which obtains
  a connection outside of a (possibly exhausted) database connection
  pool.



=== Added File Zope/lib/python/ZODB/ConnectionPolicy.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
""" ZODB connection policies """

class SimpleConnectionPolicy:
    """ A class which encapsulates a simple ZODB connection policy
    by using replaceable keyword arguments to db.open against a supplied
    ZODB.DB object """
    def __init__(self, **default_kw):
        self.default_kw = default_kw

    def getConnection(self, db, **update_kw):
        print self, self.default_kw, update_kw
        kw = self.default_kw.copy()
        if update_kw is not None:
            kw.update(update_kw)
        return db.open(**kw)

# a registry of connection policies, with typical initial entries
connection_policy_registry = {
    # the default connection policy
    'default':SimpleConnectionPolicy(version='',
                                     transaction=None,
                                     temporary=0,
                                     force=None,
                                     waitflag=1),
    # temporary connections can be used when the thread pool is exhausted
    'temporary':SimpleConnectionPolicy(version='',
                                       transaction=None,
                                       temporary=1,
                                       force=None,
                                       waitflag=1),
    }


=== Zope/lib/python/ZODB/ZApplication.py 1.13 => 1.13.24.1 ===
--- Zope/lib/python/ZODB/ZApplication.py:1.13	Tue Apr  8 14:48:22 2003
+++ Zope/lib/python/ZODB/ZApplication.py	Wed Oct  1 00:35:26 2003
@@ -20,6 +20,7 @@
 
 StringType=type('')
 connection_open_hooks = []
+from ZODB.ConnectionPolicy import connection_policy_registry
 
 class ZApplicationWrapper:
 
@@ -44,8 +45,12 @@
         db, aname, version_support = self._stuff
         if version_support is not None and REQUEST is not None:
             version=REQUEST.get(version_support,'')
-        else: version=''
-        conn=db.open(version)
+        else:
+            version=''
+
+        policy_name = getattr(REQUEST, '_connection_policy', 'default')
+        policy = connection_policy_registry[policy_name]
+        conn = policy.getConnection(db, version=version)
 
         if connection_open_hooks:
             for hook in connection_open_hooks:
@@ -72,10 +77,13 @@
     def __call__(self, connection=None):
         db, aname, version_support = self._stuff
 
+        # XXX we don't have a request to get the policy from here
+        policy = connection_policy_registry['default']
+
         if connection is None:
-            connection=db.open()
+            connection = policy.getConnection(db)
         elif type(connection) is StringType:
-            connection=db.open(connection)
+            connection = policy.getConnection(db, version=connection)
 
         return connection.root()[aname]
 




More information about the Zodb-checkins mailing list