Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

CVS update of sequoia (6 files): msg#00112

db.sequoia.cvs

Subject: CVS update of sequoia (6 files)

Date: Friday, November 24, 2006 @ 15:40:19
Author: stephane
Path: /cvsroot/sequoia/sequoia

Modified: config/controller_default.properties (1.9 -> 1.10)

src/org/continuent/sequoia/controller/connection/AbstractConnectionManager.java
(1.26 -> 1.27)

src/org/continuent/sequoia/controller/connection/AbstractPoolConnectionManager.java
(1.12 -> 1.13)

src/org/continuent/sequoia/controller/connection/SimpleConnectionManager.java
(1.7 -> 1.8)

src/org/continuent/sequoia/controller/connection/VariablePoolConnectionManager.java
(1.20 -> 1.21)
src/org/continuent/sequoia/controller/core/ControllerConstants.java
(1.22 -> 1.23)

Fix for SEQUOIA-855

A thread now checks if an idle persistent connection is still opened on the
backend.
This is deactivated by default. Change the
"default.timeout.for.idle.persistent.connections" property of the
controller_default.properties to have it enabled. It corresponds to the time in
seconds after which an idle persistent connection will be tested.


-------------------------------------------------------------------------------------+
config/controller_default.properties
| 4

src/org/continuent/sequoia/controller/connection/AbstractConnectionManager.java
| 229 +++++++++-

src/org/continuent/sequoia/controller/connection/AbstractPoolConnectionManager.java
| 7
src/org/continuent/sequoia/controller/connection/SimpleConnectionManager.java
| 7

src/org/continuent/sequoia/controller/connection/VariablePoolConnectionManager.java
| 7
src/org/continuent/sequoia/controller/core/ControllerConstants.java
| 10
6 files changed, 249 insertions(+), 15 deletions(-)


Index: sequoia/config/controller_default.properties
diff -u sequoia/config/controller_default.properties:1.9
sequoia/config/controller_default.properties:1.10
--- sequoia/config/controller_default.properties:1.9 Fri Oct 13 15:37:55 2006
+++ sequoia/config/controller_default.properties Fri Nov 24 15:40:19 2006
@@ -58,3 +58,7 @@

# Name of the report file generated by the controller
controller.report.file=sequoia.report
+
+# Default ping interval in ms for idle persistent connection
+# if set to 0, idle persistent connection won't be pinged at all
+default.timeout.for.idle.persistent.connection=0
\ No newline at end of file
Index:
sequoia/src/org/continuent/sequoia/controller/connection/AbstractConnectionManager.java
diff -u
sequoia/src/org/continuent/sequoia/controller/connection/AbstractConnectionManager.java:1.26

sequoia/src/org/continuent/sequoia/controller/connection/AbstractConnectionManager.java:1.27
---
sequoia/src/org/continuent/sequoia/controller/connection/AbstractConnectionManager.java:1.26
Wed Jun 21 11:32:41 2006
+++
sequoia/src/org/continuent/sequoia/controller/connection/AbstractConnectionManager.java
Fri Nov 24 15:40:19 2006
@@ -26,12 +26,14 @@
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Hashtable;
+import java.util.LinkedList;

import org.continuent.sequoia.common.exceptions.UnreachableBackendException;
import org.continuent.sequoia.common.i18n.Translate;
import org.continuent.sequoia.common.log.Trace;
import org.continuent.sequoia.common.xml.DatabasesXmlTags;
import org.continuent.sequoia.common.xml.XmlComponent;
+import org.continuent.sequoia.controller.core.ControllerConstants;
import org.continuent.sequoia.controller.requests.AbstractRequest;

/**
@@ -41,6 +43,7 @@
* @author <a
href="mailto:Emmanuel.Cecchet-MZpvjPyXg2s@xxxxxxxxxxxxxxxx";>Emmanuel Cecchet
</a>
* @author <a
href="mailto:Mathieu.Peltier-xhhIRkXa/2pvynnTyRI/EA@xxxxxxxxxxxxxxxx";>Mathieu
Peltier </a>
* @author <a
href="mailto:Nicolas.Modrzyk-xhhIRkXa/2pvynnTyRI/EA@xxxxxxxxxxxxxxxx";>Nicolas
Modrzyk </a>
+ * @author <a
href="mailto:Stephane.Giron-NAAfj4rwCWC8rjiVs5Nzzw@xxxxxxxxxxxxxxxx";>Stephane
Giron </a>
* @version 1.0
*/
public abstract class AbstractConnectionManager
@@ -58,53 +61,78 @@
//

/** Logger instance. */
- static Trace logger = Trace
-
.getLogger("org.continuent.sequoia.controller.connection");
+ static Trace logger
= Trace
+
.getLogger("org.continuent.sequoia.controller.connection");

/** URL of the <code>DatabaseBackend</code> owning this connection manager.
*/
- protected String backendUrl;
+ protected String backendUrl;

/**
* Name of the <code>DatabaseBackend</code> owning this connection manager.
*/
- protected String backendName;
+ protected String backendName;

/** Backend connection login to be used by this connection manager. */
- protected String rLogin;
+ protected String rLogin;

/** Backend connection password to be used by this connection manager. */
- protected String rPassword;
+ protected String rPassword;

/** The class name of the driver */
- protected String driverClassName;
+ protected String driverClassName;

/**
* The path to the driver if null the default directory is used
*/
- protected String driverPath;
+ protected String driverPath;

/** <code>true</code> if the connection pool has been initialized. */
- protected boolean initialized;
+ protected boolean initialized;

/**
* <code>true</code> if the connection manager has been shutdown and should
* no longer hand out Connections.
*/
- protected boolean isShutdown;
+ protected boolean isShutdown;

/** Hastable of connections associated to a transaction (tid->Connection) */
- private transient Hashtable connectionForTransaction;
+ private transient Hashtable connectionForTransaction;

/**
* Hashtable&lt;Long, PooledConnection&gt; which associates a persistent
* connection id (encapsulated in a Long) with a PooledConnection.
*/
- protected transient Hashtable persistentConnections;
+ protected transient Hashtable persistentConnections;

/** Virtual Login used this connection manager */
- private String vLogin;
+ private String vLogin;

- protected String connectionTestStatement;
+ protected String connectionTestStatement;
+
+ /**
+ * Stores the time on which persistent connections have been last used.
+ */
+ protected LinkedList
persistentConnectionsIdleTime;
+
+ /**
+ * Stack of idle persistent connections
+ */
+ protected LinkedList idlePersistentConnections;
+
+ /**
+ * Allow to check idle persistent connections against the backend.
+ */
+ protected IdlePersistentConnectionsPingerThread
persistentConnectionPingerThread;
+
+ /**
+ * Time after which an idle persistent connection will be checked.
+ */
+ protected int
idlePersistentConnectionPingInterval;
+
+ /**
+ * Indicates if the idle persistent connections checker thread is running.
+ */
+ protected boolean
idlePersistentConnectionPingRunning = false;

/*
* Constructor(s)
@@ -160,6 +188,14 @@
this.driverClassName = driverClassName;
connectionForTransaction = new Hashtable();
persistentConnections = new Hashtable();
+
+ idlePersistentConnectionPingInterval =
ControllerConstants.IDLE_PERSISTENT_CONNECTION_PING_INTERVAL;
+ if (idlePersistentConnectionPingInterval > 0)
+ {
+ this.idlePersistentConnections = new LinkedList();
+ this.persistentConnectionsIdleTime = new LinkedList();
+ }
+
}

/**
@@ -172,6 +208,14 @@
{
if (isInitialized())
finalizeConnections();
+
+ if (idlePersistentConnectionPingRunning)
+ {
+ stopPersistentConnectionPingerThread();
+ idlePersistentConnections.clear();
+ persistentConnectionsIdleTime.clear();
+ }
+
super.finalize();
}

@@ -273,7 +317,18 @@
*/
public void deletePersistentConnection(long persistentConnectionId)
{
- persistentConnections.remove(new Long(persistentConnectionId));
+ Long connectionId = new Long(persistentConnectionId);
+ if (idlePersistentConnectionPingRunning
+ && idlePersistentConnections.contains(persistentConnections
+ .get(connectionId)))
+ {
+ PooledConnection c = (PooledConnection) persistentConnections
+ .get(connectionId);
+ persistentConnectionsIdleTime
+ .remove(idlePersistentConnections.indexOf(c));
+ idlePersistentConnections.remove(c);
+ }
+ persistentConnections.remove(connectionId);
}

/**
@@ -528,6 +583,14 @@
if (c != null)
persistentConnections.put(id, c);
}
+ if (idlePersistentConnectionPingRunning
+ && idlePersistentConnections.contains(c))
+ {
+ persistentConnectionsIdleTime.remove(idlePersistentConnections
+ .indexOf(c));
+ idlePersistentConnections.remove(c);
+ }
+
return c;
}
else
@@ -547,7 +610,18 @@
PooledConnection c)
{
if ((request != null) && request.isPersistentConnection())
+ {
+ if (idlePersistentConnectionPingRunning)
+ synchronized (this)
+ {
+ persistentConnectionsIdleTime.addLast(new Long(System
+ .currentTimeMillis()));
+ idlePersistentConnections.addLast(c);
+ if (persistentConnectionsIdleTime.size() > 0)
+ notifyPersistentConnectionPingerThread();
+ }
return;
+ }

try
{
@@ -568,6 +642,14 @@
releaseConnection(c);
}

+ protected void notifyPersistentConnectionPingerThread()
+ {
+ synchronized (persistentConnectionPingerThread)
+ {
+ persistentConnectionPingerThread.notify();
+ }
+ }
+
/**
* Releases a connection used for a persistent connection. The corresponding
* connection is released by calling
@@ -587,7 +669,16 @@
logger.error(Translate.get("connection.persistent.id.unknown",
persistentConnectionId));
else
+ {
+ if (idlePersistentConnectionPingRunning
+ && idlePersistentConnections.contains(c))
+ {
+ persistentConnectionsIdleTime.remove(idlePersistentConnections
+ .indexOf(c));
+ idlePersistentConnections.remove(c);
+ }
releaseConnection(c);
+ }
}

/**
@@ -704,4 +795,112 @@
return info.toString();
}

+ protected void stopPersistentConnectionPingerThread()
+ {
+ synchronized (persistentConnectionPingerThread)
+ {
+ persistentConnectionPingerThread.isKilled = true;
+ idlePersistentConnectionPingRunning = false;
+ persistentConnectionPingerThread.notify();
+ }
+ try
+ {
+ persistentConnectionPingerThread.join();
+ }
+ catch (InterruptedException e)
+ {
+ }
+ }
+
+ /*
+ * this will test that persistent connections that are idled are still
+ * available
+ */
+ class IdlePersistentConnectionsPingerThread extends Thread
+ {
+ private boolean isKilled = false;
+ protected IdlePersistentConnectionsPingerThread(String pBackendName,
+ AbstractConnectionManager thisConnectionManager)
+ {
+ super("IdlePersistentConnectionsPingerThread for backend:" +
pBackendName);
+ }
+
+ /**
+ * @see java.lang.Runnable#run()
+ */
+ public void run()
+ {
+ long idleTime, releaseTime;
+ synchronized (this)
+ {
+ try
+ {
+ while (!isKilled)
+ {
+ if (idlePersistentConnections.isEmpty())
+ {
+ this.wait();
+ }
+
+ if (isKilled)
+ continue; // Just exit
+
+ PooledConnection c = null;
+
+ if (persistentConnectionsIdleTime.isEmpty())
+ {
+ continue; // Sanity check
+ }
+ releaseTime = ((Long) persistentConnectionsIdleTime.getFirst())
+ .longValue();
+ idleTime = System.currentTimeMillis() - releaseTime;
+
+ if (idleTime >= idlePersistentConnectionPingInterval)
+ {
+ c = (PooledConnection) idlePersistentConnections.removeFirst();
+ persistentConnectionsIdleTime.removeFirst();
+ }
+
+ if (c == null)
+ { // Nothing to free, wait for next deadline
+ wait(idlePersistentConnectionPingInterval - idleTime);
+ }
+ else
+ {
+ try
+ {
+ // check the connection is still valid
+ c.getConnection().createStatement().execute(
+ connectionTestStatement);
+ // and put it again in the pool
+ persistentConnectionsIdleTime.addLast(new Long(System
+ .currentTimeMillis()));
+ idlePersistentConnections.addLast(c);
+ }
+ catch (SQLException e)
+ {
+ // Connection lost... we release it... and open a new
connection
+ try
+ {
+ c.getConnection().close();
+ }
+ catch (SQLException e1)
+ {
+ String msg = "An error occured while closing idle connection
after the timeout: "
+ + e;
+ logger.error(msg);
+ }
+ }
+ }
+ }
+ }
+ catch (InterruptedException e)
+ {
+ logger
+ .error("Wait on IdlePersistentConnectionsPingerThread
interrupted in ConnectionManager: "
+ + e);
+ }
+ }
+ }
+ }
}
\ No newline at end of file
Index:
sequoia/src/org/continuent/sequoia/controller/connection/AbstractPoolConnectionManager.java
diff -u
sequoia/src/org/continuent/sequoia/controller/connection/AbstractPoolConnectionManager.java:1.12

sequoia/src/org/continuent/sequoia/controller/connection/AbstractPoolConnectionManager.java:1.13
---
sequoia/src/org/continuent/sequoia/controller/connection/AbstractPoolConnectionManager.java:1.12
Thu Aug 24 03:14:31 2006
+++
sequoia/src/org/continuent/sequoia/controller/connection/AbstractPoolConnectionManager.java
Fri Nov 24 15:40:19 2006
@@ -119,6 +119,13 @@
protected synchronized void doConnectionInitialization() throws SQLException
{
doConnectionInitialization(poolSize);
+ if (idlePersistentConnectionPingInterval > 0)
+ {
+ persistentConnectionPingerThread = new
IdlePersistentConnectionsPingerThread(
+ backendName, this);
+ persistentConnectionPingerThread.start();
+ idlePersistentConnectionPingRunning = true;
+ }
}

/**
Index:
sequoia/src/org/continuent/sequoia/controller/connection/SimpleConnectionManager.java
diff -u
sequoia/src/org/continuent/sequoia/controller/connection/SimpleConnectionManager.java:1.7

sequoia/src/org/continuent/sequoia/controller/connection/SimpleConnectionManager.java:1.8
---
sequoia/src/org/continuent/sequoia/controller/connection/SimpleConnectionManager.java:1.7
Wed Jun 14 19:55:49 2006
+++
sequoia/src/org/continuent/sequoia/controller/connection/SimpleConnectionManager.java
Fri Nov 24 15:40:19 2006
@@ -88,6 +88,13 @@
protected void doConnectionInitialization() throws SQLException
{
initialized = true;
+ if (idlePersistentConnectionPingInterval > 0)
+ {
+ persistentConnectionPingerThread = new
IdlePersistentConnectionsPingerThread(
+ backendName, this);
+ persistentConnectionPingerThread.start();
+ idlePersistentConnectionPingRunning = true;
+ }
}

/**
Index:
sequoia/src/org/continuent/sequoia/controller/connection/VariablePoolConnectionManager.java
diff -u
sequoia/src/org/continuent/sequoia/controller/connection/VariablePoolConnectionManager.java:1.20

sequoia/src/org/continuent/sequoia/controller/connection/VariablePoolConnectionManager.java:1.21
---
sequoia/src/org/continuent/sequoia/controller/connection/VariablePoolConnectionManager.java:1.20
Tue Nov 21 18:04:27 2006
+++
sequoia/src/org/continuent/sequoia/controller/connection/VariablePoolConnectionManager.java
Fri Nov 24 15:40:19 2006
@@ -255,6 +255,13 @@
}
}
}
+ if (idlePersistentConnectionPingInterval > 0)
+ {
+ persistentConnectionPingerThread = new
IdlePersistentConnectionsPingerThread(
+ backendName, this);
+ persistentConnectionPingerThread.start();
+ idlePersistentConnectionPingRunning = true;
+ }
}

/**
Index:
sequoia/src/org/continuent/sequoia/controller/core/ControllerConstants.java
diff -u
sequoia/src/org/continuent/sequoia/controller/core/ControllerConstants.java:1.22

sequoia/src/org/continuent/sequoia/controller/core/ControllerConstants.java:1.23
---
sequoia/src/org/continuent/sequoia/controller/core/ControllerConstants.java:1.22
Fri Oct 13 15:37:55 2006
+++ sequoia/src/org/continuent/sequoia/controller/core/ControllerConstants.java
Fri Nov 24 15:40:19 2006
@@ -211,6 +211,16 @@

"sequoia.report");

/**
+ * Ping interval of idle persistent connections. A value of 0 will mean that
+ * it will never be checked.
+ */
+ public static final int
IDLE_PERSISTENT_CONNECTION_PING_INTERVAL = Integer
+
.parseInt(CONTROLLER_PROPERTIES
+
.getProperty(
+
"default.timeout.for.idle.persistent.connection",
+
"0"));
+
+ /**
* Return default path and name for saving of configuration file
*
* @param resource name of the resource to get save file for


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
drivers.mtd/200...    security.firewa...    java.openamf.cv...    rpm.yum/2003-08...    telephony.sipp....    file-systems.oc...    qnx.openqnx.dev...    voip.linphone.u...    hardware.sony/2...    network.simulat...    boot-loaders.gr...    ietf.usenet.for...    culture.languag...    emacs.latex.pre...    music.jamiroqua...    xfree86.neomagi...    user-groups.lin...    ltp/2006-08/msg...    kde.kst/2005-08...    programming.too...    os.freebsd.deve...    window-managers...    audio.cd-record...    gnu.fiasco.bugs...   
Home | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation