pnever 2005/01/19 07:19:02 Modified: proposals/tamino/src/store/org/apache/slide/store/tamino/datastore XAuthenticator.java XConnection.java XConnectionPool.java XDbHandler.java proposals/tamino/src/store/org/apache/slide/store/tamino/common XContentHandler.java Log: Fixed some problems with Tamino connection handling Revision Changes Path 1.4 +10 -5 jakarta-slide/proposals/tamino/src/store/org/apache/slide/store/tamino/datastore/XAuthenticator.java Index: XAuthenticator.java =================================================================== RCS file: /home/cvs/jakarta-slide/proposals/tamino/src/store/org/apache/slide/store/tamino/datastore/XAuthenticator.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- XAuthenticator.java 30 Jul 2004 06:51:54 -0000 1.3 +++ XAuthenticator.java 19 Jan 2005 15:19:01 -0000 1.4 @@ -212,7 +212,12 @@ String command = "ino:ShowServerParameter(\"" + para + "\")"; value = (String)issueAdminCommandCache.get (getIssueAdminCommandKey (xCon)); - if (value != null) return value; + + // if (value != null) return value; + if (value != null) { + xCon.close(); + return value; + } TConnection tCon = xCon.getTConnection(); TAdministrationAccessor adminAccessor = tCon.newAdministrationAccessor(); 1.4 +40 -37 jakarta-slide/proposals/tamino/src/store/org/apache/slide/store/tamino/datastore/XConnection.java Index: XConnection.java =================================================================== RCS file: /home/cvs/jakarta-slide/proposals/tamino/src/store/org/apache/slide/store/tamino/datastore/XConnection.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- XConnection.java 30 Jul 2004 06:51:54 -0000 1.3 +++ XConnection.java 19 Jan 2005 15:19:01 -0000 1.4 @@ -45,6 +45,7 @@ import org.apache.slide.store.tamino.common.XDatastoreException; import org.apache.slide.util.ClassName; import org.apache.slide.util.XAssertionFailed; +import org.apache.slide.common.Domain; /** * XConnection wraps a connection to tamino. It provides methods to get @@ -63,35 +64,35 @@ * */ public class XConnection { - + private static final String LOGNAME = LoggerUtil.getThisClassName(); private static final String CLASSNAME = new ClassName(LOGNAME).getPlainName(); private static Logger logger = LoggerFactory.getLogger(LOGNAME); - + private TConnection tConnection; private TLocalTransaction tTransaction; - + /** the pool id */ private XConnectionKey dbKey; - - + + /** set to false when closed */ private boolean isActive = true; - + /** * constructs a new XConnection. Only called from XConnectionPool. */ public XConnection (TConnection tConnection) { if (logger.isLoggable (Level.FINE) ) logger.entering (CLASSNAME, "<init>", new Object[] {tConnection} ); - + this.tConnection = tConnection; this.tConnection.setLockwaitMode (TLockwaitMode.YES); - + if (logger.isLoggable(Level.FINE) ) logger.exiting (CLASSNAME, "<init>" ); } - + /** * Sets this connections id within the connection pool * @@ -106,7 +107,7 @@ XConnectionKey getPoolId () { return dbKey; } - + /** * Closes an XConnection. If this xConnection is used by more than one * dbSession, the first one will close and remove from connection pool, @@ -126,13 +127,16 @@ tConnection.close(); // debug only // ConnectionChecker.remove (this); - + + if ("true".equalsIgnoreCase(Domain.getParameter("debug_tamino", "false"))) { + System.out.println(" === ["+Thread.currentThread().getName()+"] '''''CLOSE "+dbKey); + } } catch (TConnectionCloseException e) { throw new XDatastoreException (e); } } } - + /** * Returns a newNonXMLObjectAccessor for a specific location * @@ -145,7 +149,7 @@ ensureActive(); return tConnection.newNonXMLObjectAccessor (location); } - + /** * Method newStreamAccessor * @@ -158,7 +162,7 @@ return newStreamAccessor (TAccessLocation.newInstance (collection)); } - + /** * returns a newStreamAccessor for a specific location * @@ -171,8 +175,8 @@ ensureActive(); return tConnection.newStreamAccessor (location); } - - + + /** * Method newXMLObjectAccessor * @@ -183,16 +187,15 @@ * */ public TXMLObjectAccessor newXMLObjectAccessor (String collection, - TXMLObjectModel objectModel) - { + TXMLObjectModel objectModel) { return newXMLObjectAccessor ( TAccessLocation.newInstance (collection), objectModel); } - + public TXMLObjectAccessor newXMLJObjectAccessor (String collection) { return newXMLObjectAccessor (collection, TJDOMObjectModel.getInstance()); } - + /** * returns a newXMLObjectAccessor for a specific object model and location! * @@ -207,14 +210,14 @@ ensureActive(); return tConnection.newXMLObjectAccessor (location, objectModel); } - + public void ensureActive() { if (!isActive) { // System.out.println (this); throw new IllegalStateException ("connection already closed"); } } - + /** * Starts a transaction for this connection. If already done, the call is * ignored. @@ -233,7 +236,7 @@ // System.out.println ("opened transaction " + tTransaction.toString()); } } - + /** * Commits this transaction. If more than one dbSession share this * connection, the commit is done for the first call, the next calls are @@ -244,17 +247,17 @@ */ public void commit () throws TException { if (isActive) { - + if (tTransaction != null) { tTransaction.commit(); tConnection.useAutoCommitMode(); - + // System.out.println ("committed transaction " + tTransaction.toString()); tTransaction = null; } } } - + /** * Rollback this transaction. If more than one dbSession share this * connection, the commit is done for the first call, the next calls are @@ -268,13 +271,13 @@ if (tTransaction != null) { tTransaction.rollback(); tConnection.useAutoCommitMode(); - + // System.out.println ("rolled back transaction " + tTransaction.toString()); tTransaction = null; } } } - + /** * Return the version of the Tamino server this connection points to * @@ -287,9 +290,9 @@ ensureActive(); return tConnection.newSystemAccessor().getServerVersion(); } - - - + + + /** * Return the wrapped Tconnection * @@ -300,11 +303,11 @@ public TConnection getTConnection() { return tConnection; } - + public boolean isActive () { return isActive; } - + public String toString () { return super.toString() + "; active: " + isActive; 1.6 +54 -45 jakarta-slide/proposals/tamino/src/store/org/apache/slide/store/tamino/datastore/XConnectionPool.java Index: XConnectionPool.java =================================================================== RCS file: /home/cvs/jakarta-slide/proposals/tamino/src/store/org/apache/slide/store/tamino/datastore/XConnectionPool.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- XConnectionPool.java 7 Jan 2005 14:58:17 -0000 1.5 +++ XConnectionPool.java 19 Jan 2005 15:19:01 -0000 1.6 @@ -39,6 +39,7 @@ import org.apache.slide.store.tamino.common.XDatastoreException; import org.apache.slide.util.ClassName; import org.apache.slide.util.XAssertionFailed; +import org.apache.slide.common.Domain; import com.softwareag.tamino.db.api.connection.TConnectionNotAvailableException; /** @@ -51,35 +52,35 @@ * @version $Revision$ */ public class XConnectionPool { - + private static final String LOGNAME = LoggerUtil.getThisClassName(); private static final String CLASSNAME = new ClassName(LOGNAME).getPlainName(); private static Logger logger = LoggerFactory.getLogger(LOGNAME); - + /** connection pool manager */ private TConnectionPoolManager theCpManager; - + /** the pool name */ private String poolName; - + /** number of tries if DB not available */ private int tryConnect = 1; - + /** base delay for retry */ private int tryConnectDelay = 2000; - + /** use TConnectionPool? */ private boolean useTConnectionPool = true; - + /** holds current active xconnections. Key is url, db, user and threadname */ private Map xConnections = Collections.synchronizedMap (new HashMap()); - + /** singleton instance of XConnectionPool */ private static XConnectionPool theOneAndOnly = new XConnectionPool (); - + /** cache for failed connections */ private Map failedConnections = new HashMap(); - + /** * Method getInstance * @@ -89,7 +90,7 @@ public static XConnectionPool getInstance () { return theOneAndOnly; } - + /** * Release the Tamino connection pool * @@ -111,8 +112,8 @@ } } } - - + + /** * Method close * @@ -121,9 +122,9 @@ if (useTConnectionPool) theCpManager.release(); } - - - + + + /** * creates a TConnectionPool for a specific tamino database and adds it to * the Map tConnectionPools. @@ -135,15 +136,15 @@ private void createTConnectionPool (XConnectionKey conKey) throws TException { if( logger.isLoggable(Level.FINE) ) logger.entering( CLASSNAME, "createTConnectionPool", new Object[] {conKey} ); - + String poolName = conKey.getTPoolName(); - + // should be set from outside via setX...() as attributes // of XConnectionPool??? int maxConnection = 200; int initConnection = 10; int connTimeout = 10; - + if (useTConnectionPool) { TConnectionPoolDescriptor descriptor = new TConnectionPoolDescriptor(); @@ -152,7 +153,7 @@ descriptor.setUser (conKey.getUser()); if (mydomain != null && ("".equals (mydomain) == false)) descriptor.setDomain(conKey.getDomain()); else { - if (conKey.getUser() != null) descriptor.setDomain(""); + if (conKey.getUser() != null) descriptor.setDomain(""); } descriptor.setPassword (conKey.getPwd()); descriptor.setInitConnections (initConnection); @@ -161,14 +162,14 @@ descriptor.setIsolationDegree (TIsolationDegree.COMMITTED_COMMAND); //descriptor.setNonActivityTimeout(30); descriptor.setLockwaitMode (TLockwaitMode.YES); - + theCpManager.addConnectionPool (poolName, descriptor); } if( logger.isLoggable(Level.FINE) ) logger.exiting( CLASSNAME, "createTConnectionPool" ); } - + /** * Method createXConnection. It is in the responsibility of the caller to * close the XConnection after use! @@ -186,14 +187,14 @@ throws XDatastoreException { if( logger.isLoggable(Level.FINE) ) logger.entering( CLASSNAME, "createXConnection", new Object [] {conKey}); - + TConnection tCon; int invalidTries = 0; TException tException; - + // TPreference pref = TPreference.getInstance(); // pref.setUseRetryHandler (false); - + while (true) { try { if (useTConnectionPool) { @@ -226,13 +227,13 @@ tException = e.getRootTCause(); else tException = e; - + if (++invalidTries == tryConnect) { failedConnections.put( conKey.getDatabaseUri(), new FailedConnection(System.currentTimeMillis()+FailedConnection.EXPIRE, tException.getMessage()) ); throw new XDatastoreException ("Error getting connection for " + conKey, tException); } - + else { try { int delay = tryConnectDelay * invalidTries; @@ -243,15 +244,15 @@ } } } - + XConnection xCon = new XConnection (tCon); if( logger.isLoggable(Level.FINE) ) logger.exiting( CLASSNAME, "createXConnection", xCon); - + return xCon; } - - + + /** * Method getXConnection * @@ -261,12 +262,16 @@ public XConnection getXConnection (XConnectionKey conKey) throws XDatastoreException { if( logger.isLoggable(Level.FINE) ) logger.entering( CLASSNAME, "getXConnection", new Object [] {conKey}); - + XConnection xCon = null; - + synchronized (xConnections) { if (xConnections.containsKey (conKey)) { xCon = (XConnection)xConnections.get (conKey); + + if ("true".equalsIgnoreCase(Domain.getParameter("debug_tamino", "false"))) { + System.out.println(" === ["+Thread.currentThread().getName()+"] -----REUSE "+conKey); + } if (logger.isLoggable (Level.FINE)) logger.fine ("use existing xConnection: " + xCon); } else { @@ -277,9 +282,13 @@ } if( fcon == null ) { xCon = createXConnection (conKey); - + xCon.setPoolId (conKey); xConnections.put (conKey, xCon); + + if ("true".equalsIgnoreCase(Domain.getParameter("debug_tamino", "false"))) { + System.out.println(" === ["+Thread.currentThread().getName()+"] ,,,,,CREATE "+conKey); + } } else { throw new XDatastoreException(fcon.reason); @@ -292,7 +301,7 @@ // ConnectionChecker.add (xCon); return xCon; } - + /** * Method removeXConnection * @@ -302,22 +311,22 @@ void removeXConnection (XConnectionKey key) { if( logger.isLoggable(Level.FINE) ) logger.entering( CLASSNAME, "removeXConnection", new Object [] {key}); - + synchronized (xConnections) { xConnections.remove (key); } - + if( logger.isLoggable(Level.FINE) ) logger.exiting( CLASSNAME, "removeXConnection"); } - - - + + + private static class FailedConnection { static final long EXPIRE = 20000; long expires; String reason; - + FailedConnection( long expires, String reason ) { this.expires = expires; this.reason = reason; 1.4 +5 -5 jakarta-slide/proposals/tamino/src/store/org/apache/slide/store/tamino/datastore/XDbHandler.java Index: XDbHandler.java =================================================================== RCS file: /home/cvs/jakarta-slide/proposals/tamino/src/store/org/apache/slide/store/tamino/datastore/XDbHandler.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- XDbHandler.java 30 Jul 2004 06:51:54 -0000 1.3 +++ XDbHandler.java 19 Jan 2005 15:19:01 -0000 1.4 @@ -84,7 +84,7 @@ private Map sessions = Collections.synchronizedMap (new HashMap()); /** adminDbSession **/ - XUtilDbSession adminDbSession = null; + private XUtilDbSession adminDbSession = null; /** The slide accessor */ ISlideAccessor parentStore; 1.4 +17 -10 jakarta-slide/proposals/tamino/src/store/org/apache/slide/store/tamino/common/XContentHandler.java Index: XContentHandler.java =================================================================== RCS file: /home/cvs/jakarta-slide/proposals/tamino/src/store/org/apache/slide/store/tamino/common/XContentHandler.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- XContentHandler.java 30 Jul 2004 06:51:52 -0000 1.3 +++ XContentHandler.java 19 Jan 2005 15:19:02 -0000 1.4 @@ -268,14 +268,21 @@ if( logger.isLoggable(Level.FINE) ) logger.entering( CLASSNAME, "commit", new Object[] {new Boolean(onePhase)} ); - IDbSession dbSession = getDbHandler().getDbSession(); - if( dbSession != null ) { - // commit and remove db session - dbSession.commit(onePhase); - getDbHandler().removeDbSession(); + IDbSession dbSession = null; + try { + dbSession = getDbHandler().getDbSession(); + if( dbSession != null ) { + // commit and remove db session + dbSession.commit(onePhase); + } + } + finally { + if (dbSession != null) { + getDbHandler().removeDbSession(); + } } } - + /** * <p>Roll back work done on behalf of a transaction branch. * <p>If database session is still available: rollback database and clean-up session.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]