Commit e336f50a authored by Andre Freyssinet's avatar Andre Freyssinet
Browse files

Adds statistics about pool use.

parent 60082a49
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2009 - 2013 ScalAgent Distributed Technologies
* Copyright (C) 2009 - 2019 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -110,6 +110,15 @@ public class PooledConnectionFactory implements ConnectionFactory {
return createConnection(cf.getDefaultLogin(), cf.getDefaultPassword());
}
int createdCnx = 0;
int allocatedcnx = 0;
int freedCnx = 0;
int maxUsedCnx = 0;
public String getStatistics() {
return "PooledConnectionFactory: " + allocatedcnx + " -> " + createdCnx + ", max=" + maxUsedCnx;
}
/**
* API method, creates a connection with the specified user identity.
* The connection is created in stopped mode.
......@@ -127,9 +136,11 @@ public class PooledConnectionFactory implements ConnectionFactory {
if (pool == null)
pool = createConnectionPool(maxFreeConnections);
allocatedcnx += 1;
PooledConnection cnx = pool.alloc(name, password);
if (cnx == null) {
createdCnx += 1;
cnx = new PooledConnection(this, name, password);
}
......@@ -141,6 +152,9 @@ public class PooledConnectionFactory implements ConnectionFactory {
* @throws JMSException
*/
synchronized void free(PooledConnection cnx) throws JMSException {
if ((allocatedcnx - freedCnx) > maxUsedCnx)
maxUsedCnx = allocatedcnx - freedCnx;
freedCnx += 1;
pool.free(cnx);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment