Author: rfm
Date: Sat Jul 5 10:40:42 2014
New Revision: 37984
URL: http://svn.gna.org/viewcvs/gnustep?rev=37984&view=rev
Log:
Report max and min connections, try to keep at least min connections in pool
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=37984&r1=37983&r2=37984&view=diff
==============================================================================
--- libs/sqlclient/trunk/SQLClient.h (original)
+++ libs/sqlclient/trunk/SQLClient.h Sat Jul 5 10:40:42 2014
@@ -1440,6 +1440,14 @@
max: (int)maxConnections
min: (int)minConnections;
+/** Return the maximum number of database connections in the pool.
+ */
+- (int) maxConnections;
+
+/** Return the minimum number of database connections in the pool.
+ */
+- (int) minConnections;
+
/** Fetches an (autoreleased) client from the pool.<br />
* This method blocks indefinitely waiting for a client to become
* available in the pool.
Modified: libs/sqlclient/trunk/SQLClientPool.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/SQLClientPool.m?rev=37984&r1=37983&r2=37984&view=diff
==============================================================================
--- libs/sqlclient/trunk/SQLClientPool.m (original)
+++ libs/sqlclient/trunk/SQLClientPool.m Sat Jul 5 10:40:42 2014
@@ -107,6 +107,16 @@
[self setMax: maxConnections min: minConnections];
}
return self;
+}
+
+- (int) maxConnections
+{
+ return max;
+}
+
+- (int) minConnections
+{
+ return min;
}
- (SQLClient*) provideClient
@@ -462,9 +472,30 @@
}
}
}
- [oldest disconnect];
+ NS_DURING
+ [oldest disconnect];
+ NS_HANDLER
+ NSLog(@"Failed to disconnect %@ ... %@", oldest, localException);
+ NS_ENDHANDLER
idle--;
}
+
+ /* If we have fewer connections than we want, connect clients until we
+ * are back up to the minimum.
+ */
+ for (index = 0; index < max && (used + idle) < min; index++)
+ {
+ if (NO == u[index] && NO == [c[index] connected])
+ {
+ NS_DURING
+ [c[index] connect];
+ NS_HANDLER
+ NSLog(@"Failed to connect %@ ... %@", c[index], localException);
+ NS_ENDHANDLER
+ idle++;
+ }
+ }
+
[lock unlockWithCondition: cond];
}
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs