Author: rfm
Date: Wed May 27 08:28:02 2015
New Revision: 38576

URL: http://svn.gna.org/viewcvs/gnustep?rev=38576&view=rev
Log:
Add pool p[urging

Modified:
    libs/sqlclient/trunk/SQLClient.h
    libs/sqlclient/trunk/SQLClientPool.m

Modified: libs/sqlclient/trunk/SQLClient.h
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/SQLClient.h?rev=38576&r1=38575&r2=38576&view=diff
==============================================================================
--- libs/sqlclient/trunk/SQLClient.h    (original)
+++ libs/sqlclient/trunk/SQLClient.h    Wed May 27 08:28:02 2015
@@ -1599,6 +1599,14 @@
 - (SQLClient*) provideClientBeforeDate: (NSDate*)when;
 
 /**
+ * Disconnects the least recently active unused database clients in the
+ * pool, but only while there are more than the minimum number of clients
+ * currently connected to the database, and only if the client has been
+ * idle for at least ten seconds.
+ */
+- (void) purge;
+
+/**
  * Sets the cache for all the clients in the pool.
  */
 - (void) setCache: (GSCache*)aCache;

Modified: libs/sqlclient/trunk/SQLClientPool.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/SQLClientPool.m?rev=38576&r1=38575&r2=38576&view=diff
==============================================================================
--- libs/sqlclient/trunk/SQLClientPool.m        (original)
+++ libs/sqlclient/trunk/SQLClientPool.m        Wed May 27 08:28:02 2015
@@ -37,6 +37,9 @@
 #import        <Performance/GSCache.h>
 #import        "SQLClient.h"
 
+/** Connections idle for morew than this time are candidates for purging.
+ */
+static NSTimeInterval   purgeTime = 10.0;
 
 @interface      SQLClient(Pool)
 - (void) _clearPool: (SQLClientPool*)p;
@@ -132,7 +135,6 @@
   return s;
 }
 
-
 - (id) initWithConfiguration: (NSDictionary*)config
                        name: (NSString*)reference
                          max: (int)maxConnections
@@ -301,6 +303,52 @@
       NSLog(@"%@ provides %p", self, c[found]);
     }
   return [c[found] autorelease];
+}
+
+- (void) purge
+{
+  BOOL  more = YES;
+
+  [self _lock];
+
+  while (YES == more)
+    {
+      SQLClient *found = nil;
+      int       connected = 0;
+      int       index;
+
+      more = NO;
+      for (index = 0; index < max; index++)
+        {
+          if (YES == [c[index] connected])
+            {
+              /* This is a connected client.
+               */
+              connected++;
+              if (NO == u[index])
+                {
+                  /* Not in use; so a candidate to be purged
+                   */
+                  found = [c[index] longestIdle: found];
+                }
+            }
+        }
+      if (connected > min && nil != found
+        && [[found lastOperation] timeIntervalSinceNow] < -purgeTime)
+        {
+          NS_DURING
+            {
+              [found disconnect];
+              more = YES;
+            }
+          NS_HANDLER
+            {
+              NSLog(@"Error disconnecting client in pool: %@", localException);
+            }
+          NS_ENDHANDLER
+        }
+    }
+  [self _unlock];
 }
 
 - (void) setCache: (GSCache*)aCache


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to