diff geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEConnection.java @ 553:5b536542ef56

Another attempt to fix gnv/issue34. Implemented an internal idle time checking. geo-backend/trunk@619 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 25 Jan 2010 12:12:31 +0000
parents 1f6e2b256247
children 12f88239fb33
line wrap: on
line diff
--- a/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEConnection.java	Fri Jan 15 20:57:13 2010 +0000
+++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEConnection.java	Mon Jan 25 12:12:31 2010 +0000
@@ -43,22 +43,55 @@
 	private SeConnection seConnection = null;
 	
 	private long serverRoundtripInterval;
+
+    private long inactiveInterval;
+
+    private long lastTouch;
 	
 
-
 	/**
 	 * Constructor
 	 */
-	public ArcSDEConnection(String server,String port,String database,String username,String credentials, long serverRoundtripInterval) throws ConnectionException {
+	public ArcSDEConnection(
+        String server,
+        String port,
+        String database,
+        String username,
+        String credentials, 
+        long   serverRoundtripInterval,
+        long   inactiveInterval
+    ) 
+    throws ConnectionException
+    {
+        this.serverRoundtripInterval = serverRoundtripInterval;
+        this.inactiveInterval        = inactiveInterval;
+        lastTouch                    = System.currentTimeMillis();
+
 		try {
-	        seConnection = new SeConnection(server,port,database,username,credentials);
-	        this.serverRoundtripInterval = serverRoundtripInterval;
-        } catch (SeException e) {
+	        seConnection = new SeConnection( server, port, database, username, credentials);
+        }
+        catch (SeException e) {
 	        log.error(e,e);
 	        throw new ConnectionException(e);
         }
 	}
 
+    public boolean isActive() {
+        long current = System.currentTimeMillis();
+        long last;
+        synchronized (this) {
+            last = lastTouch;
+        }
+        return Math.abs(current - last) < inactiveInterval;
+    }
+
+    public void touch() {
+        long time = System.currentTimeMillis();
+        synchronized (this) {
+            lastTouch = time;
+        }
+    }
+
 	/**
 	 * @see java.sql.Connection#clearWarnings()
 	 */

http://dive4elements.wald.intevation.org