Author: shawkins
Date: 2010-06-21 17:31:14 -0400 (Mon, 21 Jun 2010)
New Revision: 2271
Modified:
branches/7.0.x/client/src/main/java/org/teiid/adminapi/AdminFactory.java
branches/7.0.x/client/src/main/java/org/teiid/net/ServerConnection.java
branches/7.0.x/client/src/main/java/org/teiid/net/socket/SocketServerConnection.java
branches/7.0.x/runtime/src/main/java/org/teiid/transport/LocalServerConnection.java
Log:
TEIID-1125 changing adminproxy to perform a ping to validate the connection, rather than
retrying the operation after the fact.
Modified: branches/7.0.x/client/src/main/java/org/teiid/adminapi/AdminFactory.java
===================================================================
--- branches/7.0.x/client/src/main/java/org/teiid/adminapi/AdminFactory.java 2010-06-21
20:28:17 UTC (rev 2270)
+++ branches/7.0.x/client/src/main/java/org/teiid/adminapi/AdminFactory.java 2010-06-21
21:31:14 UTC (rev 2271)
@@ -27,9 +27,11 @@
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Properties;
+import java.util.concurrent.ExecutionException;
import org.teiid.client.security.LogonException;
import org.teiid.client.util.ExceptionUtil;
+import org.teiid.client.util.ResultsFuture;
import org.teiid.core.TeiidRuntimeException;
import org.teiid.core.util.PropertiesUtils;
import org.teiid.net.CommunicationException;
@@ -66,8 +68,18 @@
if (closed) {
throw new
AdminComponentException(NetPlugin.Util.getString("ERR.014.001.0001"));
//$NON-NLS-1$
}
- if (target != null && registry.isOpen()) {
- return target;
+ if (target != null) {
+ ResultsFuture<?> ping = registry.isOpen();
+ if (ping != null) {
+ try {
+ ping.get();
+ return target;
+ } catch (InterruptedException e) {
+ throw new CommunicationException(e);
+ } catch (ExecutionException e) {
+ //assume recoverable
+ }
+ }
}
try {
registry = serverConnectionFactory.getConnection(p);
@@ -88,23 +100,19 @@
return null;
}
Throwable t = null;
- for (int i = 0; i < 3; i++) {
- try {
- return method.invoke(getTarget(), args);
- } catch (InvocationTargetException e) {
- if (ExceptionUtil.getExceptionOfType(e, CommunicationException.class) != null) {
- // communication exception occurred, lose the old connection and try again.
- this.target = null;
- if (method.getName().endsWith("restart")) { //$NON-NLS-1$
- bounceSystem(true);
- return null;
- }
- continue;
+ try {
+ return method.invoke(getTarget(), args);
+ } catch (InvocationTargetException e) {
+ if (ExceptionUtil.getExceptionOfType(e, CommunicationException.class) != null) {
+ this.target = null;
+ if (method.getName().endsWith("restart")) { //$NON-NLS-1$
+ bounceSystem(true);
+ return null;
}
- throw e.getTargetException();
- } catch (CommunicationException e) {
- t = e;
}
+ throw e.getTargetException();
+ } catch (CommunicationException e) {
+ t = e;
}
throw t;
}
@@ -222,7 +230,6 @@
p = PropertiesUtils.clone(p);
p.remove(TeiidURL.JDBC.VDB_NAME);
p.remove(TeiidURL.JDBC.VDB_VERSION);
- p.setProperty(TeiidURL.CONNECTION.AUTO_FAILOVER, Boolean.TRUE.toString());
p.setProperty(TeiidURL.CONNECTION.ADMIN, Boolean.TRUE.toString());
try {
Modified: branches/7.0.x/client/src/main/java/org/teiid/net/ServerConnection.java
===================================================================
--- branches/7.0.x/client/src/main/java/org/teiid/net/ServerConnection.java 2010-06-21
20:28:17 UTC (rev 2270)
+++ branches/7.0.x/client/src/main/java/org/teiid/net/ServerConnection.java 2010-06-21
21:31:14 UTC (rev 2271)
@@ -23,6 +23,7 @@
package
org.teiid.net;
import org.teiid.client.security.LogonResult;
+import org.teiid.client.util.ResultsFuture;
public interface ServerConnection {
@@ -32,7 +33,7 @@
void close();
- boolean isOpen();
+ ResultsFuture<?> isOpen();
LogonResult getLogonResult();
Modified:
branches/7.0.x/client/src/main/java/org/teiid/net/socket/SocketServerConnection.java
===================================================================
---
branches/7.0.x/client/src/main/java/org/teiid/net/socket/SocketServerConnection.java 2010-06-21
20:28:17 UTC (rev 2270)
+++
branches/7.0.x/client/src/main/java/org/teiid/net/socket/SocketServerConnection.java 2010-06-21
21:31:14 UTC (rev 2271)
@@ -49,6 +49,7 @@
import org.teiid.client.security.LogonException;
import org.teiid.client.security.LogonResult;
import org.teiid.client.util.ExceptionUtil;
+import org.teiid.client.util.ResultsFuture;
import org.teiid.core.TeiidComponentException;
import org.teiid.net.CommunicationException;
import org.teiid.net.ConnectionException;
@@ -100,20 +101,25 @@
private void schedulePing() {
if (this.pingTimer != null) {
this.pingTimer.schedule(new TimerTask() {
+
+ private ResultsFuture<?> ping;
+
@Override
public void run() {
- try {
- if (isOpen()) {
- logon.ping();
- return;
- }
- } catch (InvalidSessionException e) {
- shutdown(false);
- } catch (TeiidComponentException e) {
- close();
+ if (ping == null || !ping.isDone()) {
+ ping = isOpen();
}
- this.cancel();
+ if (ping != null && ping.isDone()) {
+ try {
+ ping.get();
+ return;
+ } catch (Throwable e) {
+ handlePingError(e);
+ }
+ }
+ this.cancel();
}
+
}, PING_INTERVAL, PING_INTERVAL);
}
}
@@ -128,10 +134,8 @@
if (closed) {
throw new
CommunicationException(NetPlugin.Util.getString("SocketServerConnection.closed"));
//$NON-NLS-1$
}
- if (this.serverInstance != null) {
- if (this.serverInstance.isOpen()) {
- return this.serverInstance;
- }
+ if (this.serverInstance != null && (!failOver || this.serverInstance.isOpen()))
{
+ return this.serverInstance;
}
List<HostInfo> hostKeys = new
ArrayList<HostInfo>(this.serverDiscovery.getKnownHosts(logonResult,
this.serverInstance));
closeServerInstance();
@@ -221,15 +225,10 @@
} catch (Throwable t) {
exception = t;
}
- if (exception instanceof SingleInstanceCommunicationException
- || exception.getCause() instanceof SingleInstanceCommunicationException) {
- if (!failOver || !isOpen()) {
- break;
- }
- invalidateTarget();
- } else {
+ if (!failOver || ExceptionUtil.getExceptionOfType(exception,
SingleInstanceCommunicationException.class) == null) {
break;
}
+ invalidateTarget();
//TODO: look for invalid session exception
}
throw ExceptionUtil.convertException(method, exception);
@@ -275,18 +274,33 @@
this.closed = true;
this.serverDiscovery.shutdown();
}
-
- public synchronized boolean isOpen() {
+
+ public synchronized ResultsFuture<?> isOpen() {
if (this.closed) {
- return false;
+ return null;
}
try {
- return selectServerInstance().isOpen();
+ if (!selectServerInstance().isOpen()) {
+ return null;
+ }
} catch (CommunicationException e) {
- return false;
+ return null;
}
+ try {
+ return logon.ping();
+ } catch (Throwable th) {
+ return null;
+ }
}
+ private void handlePingError(Throwable th) {
+ if (ExceptionUtil.getExceptionOfType(th, InvalidSessionException.class) != null) {
+ shutdown(false);
+ } else {
+ close();
+ }
+ }
+
public LogonResult getLogonResult() {
return logonResult;
}
Modified:
branches/7.0.x/runtime/src/main/java/org/teiid/transport/LocalServerConnection.java
===================================================================
---
branches/7.0.x/runtime/src/main/java/org/teiid/transport/LocalServerConnection.java 2010-06-21
20:28:17 UTC (rev 2270)
+++
branches/7.0.x/runtime/src/main/java/org/teiid/transport/LocalServerConnection.java 2010-06-21
21:31:14 UTC (rev 2271)
@@ -38,6 +38,7 @@
import org.teiid.client.security.LogonException;
import org.teiid.client.security.LogonResult;
import org.teiid.client.util.ExceptionUtil;
+import org.teiid.client.util.ResultsFuture;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidRuntimeException;
import org.teiid.dqp.internal.process.DQPWorkContext;
@@ -90,7 +91,7 @@
return iface.cast(Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[]
{iface}, new InvocationHandler() {
public Object invoke(Object arg0, final Method arg1, final Object[] arg2) throws
Throwable {
- if (!isOpen()) {
+ if (shutdown) {
throw ExceptionUtil.convertException(arg1, new
TeiidComponentException(NetPlugin.Util.getString("LocalTransportHandler.Transport_shutdown")));
//$NON-NLS-1$
}
try {
@@ -109,8 +110,12 @@
}));
}
- public boolean isOpen() {
- return !shutdown;
+ @Override
+ public ResultsFuture<?> isOpen() {
+ if (shutdown) {
+ return null;
+ }
+ return ResultsFuture.NULL_FUTURE;
}
public void close() {