[teiid-commits] teiid SVN: r1512 - trunk/runtime/src/main/java/org/teiid/transport.
teiid-commits at lists.jboss.org
teiid-commits at lists.jboss.org
Thu Oct 1 12:00:09 EDT 2009
Author: rareddy
Date: 2009-10-01 12:00:08 -0400 (Thu, 01 Oct 2009)
New Revision: 1512
Modified:
trunk/runtime/src/main/java/org/teiid/transport/LocalServerConnection.java
Log:
TEIID-867: Adding the ping support from the local connection. Even though technically local connections do not require ping, engine code does not distinguish between embedded vs socket connection, so server contract must be followed.
Modified: trunk/runtime/src/main/java/org/teiid/transport/LocalServerConnection.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/LocalServerConnection.java 2009-10-01 14:46:23 UTC (rev 1511)
+++ trunk/runtime/src/main/java/org/teiid/transport/LocalServerConnection.java 2009-10-01 16:00:08 UTC (rev 1512)
@@ -27,6 +27,8 @@
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Properties;
+import java.util.Timer;
+import java.util.TimerTask;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@@ -56,7 +58,10 @@
private ClassLoader classLoader;
ClientServiceRegistry clientServices;
SessionServiceInterface sessionService;
+ private Timer pingTimer;
+ private ILogon logon;
+
public LocalServerConnection(Properties connectionProperties, ClientServiceRegistry clientServices, SessionServiceInterface sessionService) throws CommunicationException, ConnectionException{
@@ -71,11 +76,37 @@
this.classLoader = Thread.currentThread().getContextClassLoader();
this.sessionService = sessionService;
+
+ this.logon = this.getService(ILogon.class);
+ this.pingTimer = new Timer("LocalPing", true); //$NON-NLS-1$
+
+ schedulePing();
}
+
+ private void schedulePing() {
+ if (this.pingTimer != null) {
+ this.pingTimer.schedule(new TimerTask() {
+ @Override
+ public void run() {
+ try {
+ if (isOpen()) {
+ logon.ping();
+ return;
+ }
+ } catch (InvalidSessionException e) {
+ shutdown(false);
+ } catch (MetaMatrixComponentException e) {
+ shutdown();
+ }
+ this.cancel();
+ }
+ }, PING_INTERVAL, PING_INTERVAL);
+ }
+ }
public synchronized LogonResult authenticate(Properties connProps) throws ConnectionException, CommunicationException {
try {
- LogonResult logonResult = getService(ILogon.class).logon(connProps);
+ LogonResult logonResult = this.logon.logon(connProps);
return logonResult;
} catch (LogonException e) {
// Propagate the original message as it contains the message we want
@@ -126,26 +157,31 @@
}
public void shutdown() {
+ shutdown(true);
+ }
+
+ private void shutdown(boolean logoff) {
if (shutdown) {
return;
}
- try {
- //make a best effort to send the logoff
- Future<?> writeFuture = getService(ILogon.class).logoff();
- if (writeFuture != null) {
- writeFuture.get(5000, TimeUnit.MILLISECONDS);
+ if (logoff) {
+ try {
+ //make a best effort to send the logoff
+ Future<?> writeFuture = this.logon.logoff();
+ if (writeFuture != null) {
+ writeFuture.get(5000, TimeUnit.MILLISECONDS);
+ }
+ } catch (InvalidSessionException e) {
+ //ignore
+ } catch (InterruptedException e) {
+ //ignore
+ } catch (ExecutionException e) {
+ //ignore
+ } catch (TimeoutException e) {
+ //ignore
}
- } catch (InvalidSessionException e) {
- //ignore
- } catch (InterruptedException e) {
- //ignore
- } catch (ExecutionException e) {
- //ignore
- } catch (TimeoutException e) {
- //ignore
}
-
this.shutdown = true;
}
More information about the teiid-commits
mailing list