[teiid-commits] teiid SVN: r1724 - in trunk: client/src/main/java/com/metamatrix/common/comm/platform/socket/client and 3 other directories.
teiid-commits at lists.jboss.org
teiid-commits at lists.jboss.org
Fri Jan 8 15:39:32 EST 2010
Author: shawkins
Date: 2010-01-08 15:39:31 -0500 (Fri, 08 Jan 2010)
New Revision: 1724
Modified:
trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/ObjectChannel.java
trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/OioOjbectChannelFactory.java
trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerInstanceImpl.java
trunk/client/src/main/resources/teiid-client-settings.properties
trunk/client/src/test/java/com/metamatrix/common/comm/platform/socket/client/TestSocketServerInstanceImpl.java
trunk/runtime/src/main/java/org/teiid/transport/SSLAwareChannelHandler.java
Log:
TEIID-916 re-updating client timeouts to values that are safer under load
Modified: trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/ObjectChannel.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/ObjectChannel.java 2010-01-08 19:51:25 UTC (rev 1723)
+++ trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/ObjectChannel.java 2010-01-08 20:39:31 UTC (rev 1724)
@@ -28,10 +28,7 @@
public interface ObjectChannel {
- /**
- * Callers must obtain a lock prior to calling read
- */
- Object read(int timeout) throws IOException, ClassNotFoundException;
+ Object read() throws IOException, ClassNotFoundException;
SocketAddress getRemoteAddress();
Modified: trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/OioOjbectChannelFactory.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/OioOjbectChannelFactory.java 2010-01-08 19:51:25 UTC (rev 1723)
+++ trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/OioOjbectChannelFactory.java 2010-01-08 20:39:31 UTC (rev 1724)
@@ -58,6 +58,7 @@
private final Socket socket;
private ObjectOutputStream outputStream;
private ObjectInputStream inputStream;
+ private Object readLock = new Object();
private OioObjectChannel(Socket socket) throws IOException {
log.fine("creating new OioObjectChannel"); //$NON-NLS-1$
@@ -116,16 +117,17 @@
//## JDBC4.0-begin ##
@Override
//## JDBC4.0-end ##
- public Object read(int timeout) throws IOException, ClassNotFoundException {
+ public Object read() throws IOException, ClassNotFoundException {
log.finer("reading message from socket"); //$NON-NLS-1$
- socket.setSoTimeout(timeout);
- try {
- return inputStream.readObject();
- } catch (SocketTimeoutException e) {
- throw e;
- } catch (IOException e) {
- close();
- throw e;
+ synchronized (readLock) {
+ try {
+ return inputStream.readObject();
+ } catch (SocketTimeoutException e) {
+ throw e;
+ } catch (IOException e) {
+ close();
+ throw e;
+ }
}
}
@@ -152,7 +154,7 @@
private int receiveBufferSize = 0;
private int sendBufferSize = 0;
private boolean conserveBandwidth;
- private int soTimeout = 30000;
+ private int soTimeout = 3000;
private volatile SSLSocketFactory sslSocketFactory;
public OioOjbectChannelFactory(Properties props) {
@@ -185,7 +187,7 @@
socket.setSendBufferSize(sendBufferSize);
}
socket.setTcpNoDelay(!conserveBandwidth); // enable Nagle's algorithm to conserve bandwidth
- socket.connect(address, soTimeout);
+ socket.connect(address);
socket.setSoTimeout(soTimeout);
return new OioObjectChannel(socket);
}
Modified: trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerInstanceImpl.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerInstanceImpl.java 2010-01-08 19:51:25 UTC (rev 1723)
+++ trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerInstanceImpl.java 2010-01-08 20:39:31 UTC (rev 1724)
@@ -69,6 +69,8 @@
*/
public class SocketServerInstanceImpl implements SocketServerInstance {
+ static final int HANDSHAKE_RETRIES = 10;
+
private AtomicInteger MESSAGE_ID = new AtomicInteger();
private HostInfo hostInfo;
@@ -95,7 +97,7 @@
InetSocketAddress address = new InetSocketAddress(hostInfo.getInetAddress(), hostInfo.getPortNumber());
this.socketChannel = channelFactory.createObjectChannel(address, ssl);
try {
- doHandshake(channelFactory.getSoTimeout());
+ doHandshake();
} catch (CommunicationException e) {
this.socketChannel.close();
throw e;
@@ -123,18 +125,25 @@
return ApplicationInfo.getInstance().getMajorReleaseNumber();
}
- private void doHandshake(int timeout) throws IOException, CommunicationException {
- final Handshake handshake;
- try {
- Object obj = this.socketChannel.read(timeout);
-
- if (!(obj instanceof Handshake)) {
- throw new CommunicationException(CommPlatformPlugin.Util.getString("SocketServerInstanceImpl.handshake_error")); //$NON-NLS-1$
+ private void doHandshake() throws IOException, CommunicationException {
+ Handshake handshake = null;
+ for (int i = 0; i < HANDSHAKE_RETRIES; i++) {
+ try {
+ Object obj = this.socketChannel.read();
+
+ if (!(obj instanceof Handshake)) {
+ throw new CommunicationException(CommPlatformPlugin.Util.getString("SocketServerInstanceImpl.handshake_error")); //$NON-NLS-1$
+ }
+ handshake = (Handshake)obj;
+ break;
+ } catch (ClassNotFoundException e1) {
+ throw new CommunicationException(e1);
+ } catch (SocketTimeoutException e) {
+ if (i == HANDSHAKE_RETRIES - 1) {
+ throw e;
+ }
}
- handshake = (Handshake)obj;
- } catch (ClassNotFoundException e1) {
- throw new CommunicationException(e1);
- }
+ }
try {
if (!getVersionInfo().equals(handshake.getVersion())) {
@@ -288,7 +297,7 @@
}
@Override
- public Object get() throws InterruptedException, ExecutionException {
+ public synchronized Object get() throws InterruptedException, ExecutionException {
try {
return this.get(SocketServerConnectionFactory.getInstance().getSynchronousTtl(), TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
@@ -301,27 +310,26 @@
* the actual reads.
*/
@Override
- public Object get(long timeout, TimeUnit unit)
+ public synchronized Object get(long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException,
TimeoutException {
int timeoutMillis = (int)Math.min(unit.toMillis(timeout), Integer.MAX_VALUE);
- synchronized (SocketServerInstanceImpl.this) {
- while (!isDone()) {
- if (timeoutMillis <= 0) {
- throw new TimeoutException();
- }
- long start = System.currentTimeMillis();
- try {
- receivedMessage(socketChannel.read(timeoutMillis));
- timeoutMillis -= (System.currentTimeMillis() - start);
- } catch (SocketTimeoutException e) {
- throw new TimeoutException();
- } catch (IOException e) {
- exceptionOccurred(e);
- } catch (ClassNotFoundException e) {
- exceptionOccurred(e);
- }
+ while (!isDone()) {
+ if (timeoutMillis <= 0) {
+ throw new TimeoutException();
}
+ long start = System.currentTimeMillis();
+ try {
+ receivedMessage(socketChannel.read());
+ } catch (SocketTimeoutException e) {
+ } catch (IOException e) {
+ exceptionOccurred(e);
+ } catch (ClassNotFoundException e) {
+ exceptionOccurred(e);
+ }
+ if (!isDone()) {
+ timeoutMillis -= (System.currentTimeMillis() - start);
+ }
}
return super.get(timeout, unit);
}
Modified: trunk/client/src/main/resources/teiid-client-settings.properties
===================================================================
--- trunk/client/src/main/resources/teiid-client-settings.properties 2010-01-08 19:51:25 UTC (rev 1723)
+++ trunk/client/src/main/resources/teiid-client-settings.properties 2010-01-08 20:39:31 UTC (rev 1724)
@@ -71,8 +71,10 @@
# A timeout during the initialization, handshake, or
# a server ping will be treated as an error.
#
+# Setting this value too low may cause read errors.
+#
-org.teiid.sockets.soTimeout=30000
+org.teiid.sockets.soTimeout=3000
#
# The max number of cached server instances
Modified: trunk/client/src/test/java/com/metamatrix/common/comm/platform/socket/client/TestSocketServerInstanceImpl.java
===================================================================
--- trunk/client/src/test/java/com/metamatrix/common/comm/platform/socket/client/TestSocketServerInstanceImpl.java 2010-01-08 19:51:25 UTC (rev 1723)
+++ trunk/client/src/test/java/com/metamatrix/common/comm/platform/socket/client/TestSocketServerInstanceImpl.java 2010-01-08 20:39:31 UTC (rev 1724)
@@ -80,7 +80,7 @@
//## JDBC4.0-begin ##
@Override
//## JDBC4.0-end ##
- public Object read(int timeout) throws IOException,
+ public Object read() throws IOException,
ClassNotFoundException {
Object msg = readMsgs.get(readCount++);
if (msg instanceof IOException) {
@@ -120,7 +120,9 @@
}
public void testHandshakeTimeout() throws Exception {
- final FakeObjectChannel channel = new FakeObjectChannel(Arrays.asList(new SocketTimeoutException()));
+ SocketTimeoutException[] exs = new SocketTimeoutException[SocketServerInstanceImpl.HANDSHAKE_RETRIES];
+ Arrays.fill(exs, new SocketTimeoutException());
+ final FakeObjectChannel channel = new FakeObjectChannel(Arrays.asList(exs));
try {
createInstance(channel);
Modified: trunk/runtime/src/main/java/org/teiid/transport/SSLAwareChannelHandler.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/transport/SSLAwareChannelHandler.java 2010-01-08 19:51:25 UTC (rev 1723)
+++ trunk/runtime/src/main/java/org/teiid/transport/SSLAwareChannelHandler.java 2010-01-08 20:39:31 UTC (rev 1724)
@@ -86,7 +86,7 @@
}
@Override
- public Object read(int timeout) throws IOException,
+ public Object read() throws IOException,
ClassNotFoundException {
throw new UnsupportedOperationException();
}
More information about the teiid-commits
mailing list