[teiid-commits] teiid SVN: r569 - in trunk: client/src/main/java/com/metamatrix/common/comm/platform/socket/client and 4 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Tue Mar 17 16:02:26 EDT 2009


Author: shawkins
Date: 2009-03-17 16:02:26 -0400 (Tue, 17 Mar 2009)
New Revision: 569

Modified:
   trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/SocketUtil.java
   trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/ObjectChannelFactory.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/SocketServerConnection.java
   trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerConnectionFactory.java
   trunk/client/src/main/resources/teiid-client-settings.properties
   trunk/client/src/test/java/com/metamatrix/common/comm/platform/socket/client/TestSocketServerConnection.java
   trunk/client/src/test/java/com/metamatrix/common/comm/platform/socket/client/TestSocketServerInstanceImpl.java
   trunk/common-core/src/main/java/com/metamatrix/common/util/PropertiesUtils.java
   trunk/server/src/test/java/com/metamatrix/common/comm/platform/socket/server/TestCommSockets.java
Log:
TEIID-424 TEIID-292, TEIID-425 updating client configuration, adding back socket pooling

Modified: trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/SocketUtil.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/SocketUtil.java	2009-03-17 19:08:09 UTC (rev 568)
+++ trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/SocketUtil.java	2009-03-17 20:02:26 UTC (rev 569)
@@ -53,13 +53,13 @@
  */
 public class SocketUtil {
     
-    static final String TRUSTSTORE_PASSWORD = "com.metamatrix.ssl.trustStorePassword"; //$NON-NLS-1$
-    public static final String TRUSTSTORE_FILENAME = "com.metamatrix.ssl.trustStore"; //$NON-NLS-1$
-    static final String KEYSTORE_ALGORITHM = "com.metamatrix.ssl.algorithm"; //$NON-NLS-1$
-    static final String PROTOCOL = "com.metamatrix.ssl.protocol"; //$NON-NLS-1$
-    static final String KEYSTORE_TYPE = "com.metamatrix.ssl.keyStoreType"; //$NON-NLS-1$
-    static final String KEYSTORE_PASSWORD = "com.metamatrix.ssl.keyStorePassword"; //$NON-NLS-1$
-    static final String KEYSTORE_FILENAME = "com.metamatrix.ssl.keyStore"; //$NON-NLS-1$
+    static final String TRUSTSTORE_PASSWORD = "org.teiid.ssl.trustStorePassword"; //$NON-NLS-1$
+    public static final String TRUSTSTORE_FILENAME = "org.teiid.ssl.trustStore"; //$NON-NLS-1$
+    static final String KEYSTORE_ALGORITHM = "org.teiid.ssl.algorithm"; //$NON-NLS-1$
+    static final String PROTOCOL = "org.teiid.ssl.protocol"; //$NON-NLS-1$
+    static final String KEYSTORE_TYPE = "org.teiid.ssl.keyStoreType"; //$NON-NLS-1$
+    static final String KEYSTORE_PASSWORD = "org.teiid.ssl.keyStorePassword"; //$NON-NLS-1$
+    static final String KEYSTORE_FILENAME = "org.teiid.ssl.keyStore"; //$NON-NLS-1$
     
     static final String DEFAULT_KEYSTORE_PROTOCOL = "SSLv3"; //$NON-NLS-1$
     static final String DEFAULT_KEYSTORE_TYPE = "JKS"; //$NON-NLS-1$
@@ -89,19 +89,12 @@
     }
     
     public static SSLSocketFactory getSSLSocketFactory(Properties props) throws IOException, GeneralSecurityException{
-    	// -Dcom.metamatrix.ssl.keyStore
         String keystore = props.getProperty(KEYSTORE_FILENAME); 
-        // -Dcom.metamatrix.ssl.keyStorePassword
         String keystorePassword = props.getProperty(KEYSTORE_PASSWORD); 
-        // -Dcom.metamatrix.ssl.keyStoreType (default JKS)
         String keystoreType = props.getProperty(KEYSTORE_TYPE, DEFAULT_KEYSTORE_TYPE); 
-        // -Dcom.metamatrix.ssl.protocol (default SSLv3)
         String keystoreProtocol = props.getProperty(PROTOCOL, DEFAULT_KEYSTORE_PROTOCOL); 
-        // -Dcom.metamatrix.ssl.algorithm (default SunX509)
         String keystoreAlgorithm = props.getProperty(KEYSTORE_ALGORITHM); 
-        // -Dcom.metamatrix.ssl.trustStore (if null; keystore filename used)
         String truststore = props.getProperty(TRUSTSTORE_FILENAME, keystore); 
-        // -Dcom.metamatrix.ssl.trustStorePassword (if null; keystore password used)
         String truststorePassword = props.getProperty(TRUSTSTORE_PASSWORD, keystorePassword); 
         
         boolean anon = NONE.equalsIgnoreCase(truststore);

Modified: trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/ObjectChannelFactory.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/ObjectChannelFactory.java	2009-03-17 19:08:09 UTC (rev 568)
+++ trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/ObjectChannelFactory.java	2009-03-17 20:02:26 UTC (rev 569)
@@ -33,4 +33,6 @@
 	ObjectChannel createObjectChannel(SocketAddress address, boolean ssl) throws IOException,
 			CommunicationException;
 	
+	int getSoTimeout();
+	
 }
\ No newline at end of file

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	2009-03-17 19:08:09 UTC (rev 568)
+++ trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/OioOjbectChannelFactory.java	2009-03-17 20:02:26 UTC (rev 569)
@@ -44,12 +44,13 @@
 import com.metamatrix.common.comm.platform.socket.ObjectChannel;
 import com.metamatrix.common.comm.platform.socket.SocketUtil;
 import com.metamatrix.common.comm.platform.socket.SocketUtil.SSLSocketFactory;
+import com.metamatrix.common.util.PropertiesUtils;
 import com.metamatrix.dqp.client.ResultsFuture;
 
-final class OioOjbectChannelFactory implements ObjectChannelFactory {
+public final class OioOjbectChannelFactory implements ObjectChannelFactory {
 	
 	private final static int STREAM_BUFFER_SIZE = 1<<15;
-	private final static int SO_TIMEOUT = 3000;
+	private final static int MAX_OBJECT_SIZE = 1 << 25;
 	
 	private static Logger log = Logger.getLogger("org.teiid.client.sockets"); //$NON-NLS-1$
 	
@@ -62,7 +63,6 @@
 		private OioObjectChannel(Socket socket) throws IOException {
 			log.fine("creating new OioObjectChannel"); //$NON-NLS-1$
 			this.socket = socket;
-            socket.setSoTimeout(SO_TIMEOUT);
             BufferedOutputStream bos = new BufferedOutputStream( socket.getOutputStream(), STREAM_BUFFER_SIZE);
             outputStream = new ObjectEncoderOutputStream( new DataOutputStream(bos), 512);
             //The output stream must be flushed on creation in order to write some initialization data
@@ -70,7 +70,7 @@
             outputStream.flush();
             final ClassLoader cl = Thread.currentThread().getContextClassLoader();
             BufferedInputStream bis = new BufferedInputStream(socket.getInputStream(), STREAM_BUFFER_SIZE);
-            inputStream = new ObjectDecoderInputStream(new DataInputStream(bis), cl, 1 << 25);
+            inputStream = new ObjectDecoderInputStream(new DataInputStream(bis), cl, MAX_OBJECT_SIZE);
 		}
 
 		@Override
@@ -141,17 +141,15 @@
 	}
 
 	private Properties props;
-	private int inputBufferSize;
-	private int outputBufferSize;
+	private int receiveBufferSize = 0;
+	private int sendBufferSize = 0;
 	private boolean conserveBandwidth;
+	private int soTimeout = 3000;
 	private volatile SSLSocketFactory sslSocketFactory;
 
-	public OioOjbectChannelFactory(boolean conserveBandwidth,
-			int inputBufferSize, int outputBufferSize, Properties props) {
-		this.conserveBandwidth = conserveBandwidth;
-		this.inputBufferSize = inputBufferSize;
-		this.outputBufferSize = outputBufferSize;
+	public OioOjbectChannelFactory(Properties props) {
 		this.props = props;
+		PropertiesUtils.setBeanProperties(this, props, "org.teiid.sockets"); //$NON-NLS-1$
 	}
 
 	@Override
@@ -170,14 +168,47 @@
 		} else {
 			socket = new Socket();
 		}
-		if (inputBufferSize > 0) {
-			socket.setReceiveBufferSize(inputBufferSize);
+		if (receiveBufferSize > 0) {
+			socket.setReceiveBufferSize(receiveBufferSize);
 		}
-		if (outputBufferSize > 0) {
-			socket.setSendBufferSize(outputBufferSize);
+		if (sendBufferSize > 0) {
+			socket.setSendBufferSize(sendBufferSize);
 		}
 	    socket.setTcpNoDelay(!conserveBandwidth); // enable Nagle's algorithm to conserve bandwidth
 	    socket.connect(address);
+	    socket.setSoTimeout(soTimeout);
 	    return new OioObjectChannel(socket);
 	}
+	
+	public int getSendBufferSize() {
+		return sendBufferSize;
+	}
+
+	public void setSendBufferSize(int sendBufferSize) {
+		this.sendBufferSize = sendBufferSize;
+	}
+
+	public int getReceiveBufferSize() {
+		return receiveBufferSize;
+	}
+
+	public void setReceiveBufferSize(int receiveBufferSize) {
+		this.receiveBufferSize = receiveBufferSize;
+	}
+
+	public boolean isConserveBandwidth() {
+		return conserveBandwidth;
+	}
+
+	public void setConserveBandwidth(boolean conserveBandwidth) {
+		this.conserveBandwidth = conserveBandwidth;
+	}
+	
+	public void setSoTimeout(int soTimeout) {
+		this.soTimeout = soTimeout;
+	}
+
+	public int getSoTimeout() {
+		return soTimeout;
+	}
 }
\ No newline at end of file

Modified: trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerConnection.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerConnection.java	2009-03-17 19:08:09 UTC (rev 568)
+++ trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerConnection.java	2009-03-17 20:02:26 UTC (rev 569)
@@ -32,9 +32,7 @@
 import java.lang.reflect.Proxy;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 import java.util.Properties;
 import java.util.Timer;
 import java.util.TimerTask;
@@ -68,7 +66,6 @@
 	
 	private static final int RETRY_COUNT = 3;
 
-	private Map<HostInfo, SocketServerInstance> existingConnections = new HashMap<HostInfo, SocketServerInstance>();
 	private SocketServerInstanceFactory connectionFactory;
     private ServerDiscovery serverDiscovery;
     private static Logger log = Logger.getLogger("org.teiid.client.sockets"); //$NON-NLS-1$
@@ -122,23 +119,13 @@
 		while (hostKeys.size() > 0) {
 			HostInfo hostInfo = hostKeys.remove((int) (Math.random() * hostKeys.size()));
 
-			SocketServerInstance instance = existingConnections.get(hostInfo);
-			if (instance != null) {
-				if (instance.isOpen()) {
-					this.serverInstance = instance;
-					return this.serverInstance;
-				}
-				existingConnections.remove(hostInfo);
-				hostKeys.add(hostInfo);
-			}
 			Exception ex = null;
 			try {
-				instance = connectionFactory.getServerInstance(hostInfo, secure);
+				SocketServerInstance instance = connectionFactory.getServerInstance(hostInfo, secure);
 				if (this.logonResult != null) {
 					ILogon newLogon = instance.getService(ILogon.class);
 					newLogon.assertIdentity(logonResult.getSessionID());
 				}
-				this.existingConnections.put(hostInfo, instance);
 				this.serverDiscovery.connectionSuccessful(hostInfo, instance);
 				this.serverInstance = instance;
 				return this.serverInstance;
@@ -286,11 +273,12 @@
 		} catch (TimeoutException e) {
 			//ignore
 		}
-
-		for (SocketServerInstance instance : existingConnections.values()) {
-			instance.shutdown();
+		
+		if (this.serverInstance != null) {
+			this.serverInstance.shutdown();
+			this.serverInstance = null;
 		}
-		existingConnections.clear();
+
 		this.closed = true;
 		this.serverDiscovery.shutdown();
 	}
@@ -318,9 +306,11 @@
 		try {
 			ServerConnectionInvocationHandler handler = (ServerConnectionInvocationHandler)Proxy.getInvocationHandler(service);
 			ServerConnectionInvocationHandler otherHandler = (ServerConnectionInvocationHandler)Proxy.getInvocationHandler(otherService);
-			return handler.getInstance().getHostInfo().equals(otherHandler.getInstance().getHostInfo());
+			return handler.getInstance().getHostInfo().getInetAddress().equals(otherHandler.getInstance().getHostInfo().getInetAddress());
 		} catch (IllegalArgumentException e) {
 			return false;
+		} catch (UnknownHostException e) {
+			throw new CommunicationException(e);
 		}
 	}
 	

Modified: trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerConnectionFactory.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerConnectionFactory.java	2009-03-17 19:08:09 UTC (rev 568)
+++ trunk/client/src/main/java/com/metamatrix/common/comm/platform/socket/client/SocketServerConnectionFactory.java	2009-03-17 20:02:26 UTC (rev 569)
@@ -24,14 +24,25 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
-import java.util.HashMap;
-import java.util.List;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Timer;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicInteger;
 
+import com.metamatrix.admin.api.exception.security.InvalidSessionException;
+import com.metamatrix.api.exception.MetaMatrixComponentException;
 import com.metamatrix.common.api.HostInfo;
 import com.metamatrix.common.api.MMURL;
 import com.metamatrix.common.comm.api.ServerConnectionFactory;
@@ -41,38 +52,97 @@
 import com.metamatrix.common.util.PropertiesUtils;
 import com.metamatrix.core.MetaMatrixCoreException;
 import com.metamatrix.core.util.ReflectionHelper;
+import com.metamatrix.platform.security.api.ILogon;
 
 public class SocketServerConnectionFactory implements ServerConnectionFactory, SocketServerInstanceFactory {
 
-	/**Java system property.  The loglevel that SocketLog will use.  Should be a String value {NONE|CRITICAL|ERROR|WARNING|INFO|DETAIL|TRACE}*/
-	public static final String SOCKET_LOG_LEVEL   = "metamatrix.sockets.log.level";  //$NON-NLS-1$
-	/**Java system property.  Maximum number of threads used to read sockets*/
-	public static final String SOCKET_MAX_THREADS   = "metamatrix.sockets.max.threads"; //$NON-NLS-1$
-	/**Java system property.  Maximum time to live for a socket reader thread asynchronous calls.  If it times out, it will be removed, and recreated later when needed.*/
-	public static final String SOCKET_TTL           = "metamatrix.sockets.ttl"; //$NON-NLS-1$
-	/**Java system property.  Maximum time to live for a socket reader thread synchronous calls.  If it times out, it will be removed, and recreated later when needed.*/    
-	public static final String SYNCH_SOCKET_TTL           = "metamatrix.synchronous.sockets.ttl"; //$NON-NLS-1$
-	/**Java system property.  Input buffer size of the physical sockets.*/
-	public static final String SOCKET_INPUT_BUFFER_SIZE           = "metamatrix.sockets.inputBufferSize"; //$NON-NLS-1$
-	/**Java system property.  Output buffer size of the physical sockets.*/
-	public static final String SOCKET_OUTPUT_BUFFER_SIZE           = "metamatrix.sockets.outputBufferSize"; //$NON-NLS-1$
-	/**Java system property.  Value of the conserve-bandwidth flag of the physical sockets.*/
-	public static final String SOCKET_CONSERVE_BANDWIDTH           = "metamatrix.sockets.conserveBandwidth"; //$NON-NLS-1$
-	public static final String DEFAULT_SOCKET_LOG_LEVEL = "ERROR"; //$NON-NLS-1$
-	public static final int DEFAULT_MAX_THREADS = 15;
-	public static final long DEFAULT_TTL = 120000L;
-	public static final long DEFAULT_SYNCH_TTL = 120000L;
-	public static final int DEFAULT_SOCKET_INPUT_BUFFER_SIZE = 0;
-	public static final int DEFAULT_SOCKET_OUTPUT_BUFFER_SIZE = 0;
-	
 	private static final String URL = "URL"; //$NON-NLS-1$
 	
 	private static SocketServerConnectionFactory INSTANCE;
 	
+	private final class ShutdownHandler implements InvocationHandler {
+		private final CachedInstance key;
+
+		private ShutdownHandler(CachedInstance key) {
+			this.key = key;
+		}
+
+		@Override
+		public Object invoke(Object arg0, Method arg1, Object[] arg2)
+				throws Throwable {
+			if (arg1.getName().equals("shutdown")) { //$NON-NLS-1$
+				CachedInstance purge = null;
+				if (!key.actual.isOpen()) {
+					return null; //nothing to do
+				}
+				synchronized (instancePool) {
+					instancePool.put(key, key);
+					if (instancePool.size() > maxCachedInstances) {
+						Iterator<CachedInstance> iter = instancePool.keySet().iterator();
+						purge = iter.next();
+						iter.remove();
+					}
+				}
+				if (purge != null) {
+					purge.actual.shutdown();
+				}
+				return null;
+			}
+			try {
+				return arg1.invoke(key.actual, arg2);
+			} catch (InvocationTargetException e) {
+				throw e.getTargetException();
+			}
+		}
+	}
+
+	private static class CachedInstance {
+		HostInfo info;
+		Integer instance;
+		boolean ssl;
+		SocketServerInstance actual;
+		SocketServerInstance proxy;
+		
+		public CachedInstance(HostInfo info, boolean ssl) {
+			this.info = info;
+			this.ssl = ssl;
+		}
+
+		@Override
+		public int hashCode() {
+			return info.hashCode();
+		}
+		
+		@Override
+		public boolean equals(Object obj) {
+			if (this == obj) {
+				return true;
+			}
+			if (!(obj instanceof CachedInstance)) {
+				return false;
+			}
+			CachedInstance other = (CachedInstance) obj;
+			if (!info.equals(other.info) || ssl != other.ssl) {
+				return false;
+			}
+			if (instance == null || other.instance == null) {
+				return true;
+			} 
+			return instance.equals(other.instance);
+		}
+	}
+	
     private ObjectChannelFactory channelFactory;
 	private Timer pingTimer;
-	private Properties props;
 	
+	//instance pooling
+	private AtomicInteger instanceCount = new AtomicInteger();
+	private Map<CachedInstance, CachedInstance> instancePool = new LinkedHashMap<CachedInstance, CachedInstance>();
+
+	//config properties
+	private long synchronousTtl = 120000l;
+	private int maxCachedInstances=16;
+
 	public static synchronized SocketServerConnectionFactory getInstance() {
 		if (INSTANCE == null) {
 			INSTANCE = new SocketServerConnectionFactory();
@@ -99,16 +169,61 @@
 	public SocketServerConnectionFactory() {
 		
 	}
-	
+		
 	public void init(final Properties props) {
-		this.props = props;
+		PropertiesUtils.setBeanProperties(this, props, "org.teiid.sockets"); //$NON-NLS-1$
 		this.pingTimer = new Timer("SocketPing", true); //$NON-NLS-1$
-		this.channelFactory = new OioOjbectChannelFactory(getConserveBandwidth(), getInputBufferSize(), getOutputBufferSize(), props);
+		this.channelFactory = new OioOjbectChannelFactory(props);
 	}
 			
 	public SocketServerInstance getServerInstance(HostInfo info, boolean ssl) throws CommunicationException, IOException {
-		SocketServerInstanceImpl ssii = new SocketServerInstanceImpl(info, ssl, getSynchronousTTL());
+		CachedInstance key = null;
+		CachedInstance instance = null;
+		boolean useCache = this.maxCachedInstances > 0; 
+		if (useCache) {
+			key = new CachedInstance(info, ssl);
+			synchronized (instancePool) {
+				instance = instancePool.remove(key);
+			}
+			if (instance != null) {
+				ILogon logon = instance.actual.getService(ILogon.class);
+				boolean valid = false;
+				try {
+					Future<?> success = logon.ping();
+					success.get(this.channelFactory.getSoTimeout(), TimeUnit.MICROSECONDS);
+					valid = true;
+				} catch (MetaMatrixComponentException e) {
+				} catch (InvalidSessionException e) {
+				} catch (InterruptedException e) {
+				} catch (ExecutionException e) {
+				} catch (TimeoutException e) {
+				}
+				if (valid) {
+					return instance.proxy;
+				}
+				instance.actual.shutdown();
+				//technically we only want to remove instances with the same inetaddress 
+				while (true) {
+					CachedInstance invalid = null;
+					synchronized (instancePool) {
+						invalid = instancePool.remove(key);
+					}
+					if (invalid == null) {
+						break;
+					}
+					invalid.actual.shutdown();
+				}
+			}
+		}
+		SocketServerInstanceImpl ssii = new SocketServerInstanceImpl(info, ssl, getSynchronousTtl());
 		ssii.connect(this.channelFactory);
+		if (useCache) {
+			key.actual = ssii;
+			key.instance = instanceCount.getAndIncrement();
+			//create a proxied socketserverinstance that will pool itself on shutdown
+			key.proxy = (SocketServerInstance)Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[] {SocketServerInstance.class}, new ShutdownHandler(key));
+			return key.proxy;
+		}
 		return ssii;
 	}
 	
@@ -140,48 +255,6 @@
 		return new SocketServerConnection(this, url.isUsingSSL(), discovery, connectionProperties, pingTimer);
 	}
 
-	/*
-	 * Retrieve the asynchronous call Time-To-Live
-	 *  
-	 * @return number of ms 
-	 * @since 4.2
-	 */
-	public long getTTL() {
-	    return PropertiesUtils.getLongProperty(props, SOCKET_TTL, DEFAULT_TTL);
-	}
-
-	/*
-	 * Retrieve the synchronous call Time-To-Live
-	 *  
-	 * @return number of ms 
-	 * @since 4.2
-	 */
-	public long getSynchronousTTL() {
-	    return PropertiesUtils.getLongProperty(props, SYNCH_SOCKET_TTL, DEFAULT_SYNCH_TTL);
-	}
-
-	/* 
-	 * Get the max number of threads
-	 * 
-	 * @return max number
-	 * @since 4.2
-	 */
-	public int getMaxThreads() {
-	    return PropertiesUtils.getIntProperty(props, SOCKET_MAX_THREADS, DEFAULT_MAX_THREADS);
-	}
-
-	public int getInputBufferSize() {
-	    return PropertiesUtils.getIntProperty(props, SOCKET_INPUT_BUFFER_SIZE, DEFAULT_SOCKET_INPUT_BUFFER_SIZE);
-	}
-
-	public int getOutputBufferSize() {
-	    return PropertiesUtils.getIntProperty(props, SOCKET_OUTPUT_BUFFER_SIZE, DEFAULT_SOCKET_OUTPUT_BUFFER_SIZE);
-	}
-
-	public boolean getConserveBandwidth() {
-	    return PropertiesUtils.getBooleanProperty(props, SOCKET_CONSERVE_BANDWIDTH, false); 
-	}
-
 	static void updateConnectionProperties(Properties connectionProperties) {
 		try {
 			InetAddress addr = NetUtils.getInstance().getInetAddress();
@@ -192,4 +265,20 @@
         }
 	}
 
+	public long getSynchronousTtl() {
+		return synchronousTtl;
+	}
+
+	public void setSynchronousTtl(long synchronousTTL) {
+		this.synchronousTtl = synchronousTTL;
+	}
+
+	public int getMaxCachedInstances() {
+		return maxCachedInstances;
+	}
+	
+	public void setMaxCachedInstances(int maxCachedInstances) {
+		this.maxCachedInstances = maxCachedInstances;
+	}
+
 }

Modified: trunk/client/src/main/resources/teiid-client-settings.properties
===================================================================
--- trunk/client/src/main/resources/teiid-client-settings.properties	2009-03-17 19:08:09 UTC (rev 568)
+++ trunk/client/src/main/resources/teiid-client-settings.properties	2009-03-17 20:02:26 UTC (rev 569)
@@ -7,20 +7,20 @@
 ########################################
 
 #
-# Set the key store type.  Defaults to JKS
+# The key store type.  Defaults to JKS
 #
 
-com.metamatrix.ssl.keyStoreType=JKS
+org.teiid.ssl.keyStoreType=JKS
 
 #
-# Set the key store algorithm, defaults to 
+# The key store algorithm, defaults to 
 # the system property "ssl.TrustManagerFactory.algorithm"
 #
 
-#com.metamatrix.ssl.algorithm=
+#org.teiid.ssl.algorithm=
 
 #
-# Set to the classpath or filesystem location of the
+# The classpath or filesystem location of the
 # key store.
 # 
 # This property is required only if performing 2-way
@@ -28,16 +28,16 @@
 # key.
 #
 
-#com.metamatrix.ssl.keyStore=
+#org.teiid.ssl.keyStore=
 
 #
-# Set the key store password (not required)
+# The key store password (not required)
 #
 
-#com.metamatrix.ssl.keyStorePassword=
+#org.teiid.ssl.keyStorePassword=
 
 #
-# Set to the classpath or filesystem location of the
+# The classpath or filesystem location of the
 # trust store.
 # 
 # This property is required if performing 1-way
@@ -48,58 +48,77 @@
 # the TLS_DH_anon_WITH_AES_128_CBC_SHA cipher suite 
 #
 
-#com.metamatrix.ssl.trustStore=
+#org.teiid.ssl.trustStore=
 
 #
-# Set the trust store password (not required)
+# The trust store password (not required)
 #
 
-#com.metamatrix.ssl.trustStorePassword=
+#org.teiid.ssl.trustStorePassword=
 
 #
-# Set the cipher protocol, defaults to SSLv3
+# The cipher protocol, defaults to SSLv3
 #
 
-com.metamatrix.ssl.protocol=SSLv3
+org.teiid.ssl.protocol=SSLv3
 
-
 ########################################
 # Misc Socket Configuration
 ########################################
 
 #
-# Set the max number of NIO worker threads
+# The time in milliseconds for socket timeouts.
+# A timeout during the initialization, handshake, or
+# a server ping will be treated as an error.
 #
-metamatrix.sockets.max.threads=15
+# Setting this value too low may cause read errors.
+#
 
+org.teiid.sockets.soTimeout=3000
+
 #
-# Set the max time to live for an NIO worker thread
+# The max number of cached server instances
+# to reuse. A server instance is a connected
+# socket to a particular cluster member with 
+# client encryption and or SSL already established.
+#  
+# Caching instances helps in 2 circumstances:
+#  - when Connection pooling is not being used.
+#  - load-balancing performance to a cluster 
+#    when using Connection pooling of the DataSource.
+#  
+# This value should typically be a multiple of the
+# cluster size.  
+# 
+# Set to 0 to disable instance caching.
 #
 
-metamatrix.sockets.ttl=120000
+org.teiid.sockets.maxCachedInstances=16
 
 #
-# Set the max time to live for non-execution synchrnous
-# calls.
+# Set the max time to live (in milliseconds) for non-execution 
+# synchronous calls.
 #
 
-metamatrix.synchronous.sockets.ttl=120000
+org.teiid.sockets.synchronousttl=120000
 
 #
-# Set the socket receive buffer size
+# Set the socket receive buffer size (in bytes)
+# 0 indicates that the default socket setting will be used.
 #
 
-metamatrix.sockets.inputBufferSize=0
+org.teiid.sockets.receiveBufferSize=0
 
 #
-# Set the socket send buffer size
+# Set the socket send buffer size (in bytes)
+# 0 indicates that the default socket setting will be used.
 #
 
-metamatrix.sockets.outputBufferSize=0
+org.teiid.sockets.sendBufferSize=0
 
 #
 # Set to true to enable Nagle's algorithm to conserve bandwidth 
 # by minimizing the number of segments that are sent.
 #
 
-metamatrix.sockets.conserveBandwidth=false
+org.teiid.sockets.conserveBandwidth=false

Modified: trunk/client/src/test/java/com/metamatrix/common/comm/platform/socket/client/TestSocketServerConnection.java
===================================================================
--- trunk/client/src/test/java/com/metamatrix/common/comm/platform/socket/client/TestSocketServerConnection.java	2009-03-17 19:08:09 UTC (rev 568)
+++ trunk/client/src/test/java/com/metamatrix/common/comm/platform/socket/client/TestSocketServerConnection.java	2009-03-17 20:02:26 UTC (rev 569)
@@ -188,8 +188,8 @@
 	}
 	
 	public void testIsSameInstance() throws Exception {
-		SocketServerConnection conn = createConnection(null, new HostInfo("foo", 1)); //$NON-NLS-1$
-		SocketServerConnection conn1 = createConnection(null, new HostInfo("bar", 1)); //$NON-NLS-1$
+		SocketServerConnection conn = createConnection(null, new HostInfo("0.0.0.0", 1)); //$NON-NLS-1$
+		SocketServerConnection conn1 = createConnection(null, new HostInfo("0.0.0.1", 1)); //$NON-NLS-1$
 		
 		ClientSideDQP dqp = conn.getService(ClientSideDQP.class);
 		ClientSideDQP dqp1 = conn1.getService(ClientSideDQP.class);

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	2009-03-17 19:08:09 UTC (rev 568)
+++ trunk/client/src/test/java/com/metamatrix/common/comm/platform/socket/client/TestSocketServerInstanceImpl.java	2009-03-17 20:02:26 UTC (rev 569)
@@ -98,6 +98,11 @@
 			return this;
 		}
 		
+		@Override
+		public int getSoTimeout() {
+			return 1;
+		}
+		
 	}
 
 	public void testHandshakeTimeout() throws Exception {

Modified: trunk/common-core/src/main/java/com/metamatrix/common/util/PropertiesUtils.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/util/PropertiesUtils.java	2009-03-17 19:08:09 UTC (rev 568)
+++ trunk/common-core/src/main/java/com/metamatrix/common/util/PropertiesUtils.java	2009-03-17 20:02:26 UTC (rev 569)
@@ -956,7 +956,7 @@
 	            String shortName = propertyName.toLowerCase();
 	            String propertyValue = null;
 	            if (prefix != null) {
-	            	propertyValue = connProps.getProperty(prefix + "." + shortName);
+	            	propertyValue = connProps.getProperty(prefix + "." + shortName); //$NON-NLS-1$
 	            } else {
 	            	propertyValue = connProps.getProperty(shortName);
 	            }

Modified: trunk/server/src/test/java/com/metamatrix/common/comm/platform/socket/server/TestCommSockets.java
===================================================================
--- trunk/server/src/test/java/com/metamatrix/common/comm/platform/socket/server/TestCommSockets.java	2009-03-17 19:08:09 UTC (rev 568)
+++ trunk/server/src/test/java/com/metamatrix/common/comm/platform/socket/server/TestCommSockets.java	2009-03-17 20:02:26 UTC (rev 569)
@@ -32,6 +32,7 @@
 
 import javax.net.ssl.SSLEngine;
 
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -44,7 +45,6 @@
 import com.metamatrix.common.comm.platform.socket.SocketUtil;
 import com.metamatrix.common.comm.platform.socket.client.SocketServerConnection;
 import com.metamatrix.common.comm.platform.socket.client.SocketServerConnectionFactory;
-import com.metamatrix.common.comm.platform.socket.client.SocketServerInstanceImpl;
 import com.metamatrix.common.comm.platform.socket.client.UrlServerDiscovery;
 import com.metamatrix.common.queue.WorkerPoolFactory;
 import com.metamatrix.common.util.crypto.NullCryptor;
@@ -56,15 +56,20 @@
 public class TestCommSockets {
 
 	SocketListener listener;
+	private SocketServerConnectionFactory sscf;
+	private InetSocketAddress addr;
 
-	@Before public void tearDown() throws Exception {
+	@Before public void setUp() {
+		addr = new InetSocketAddress(0);
+	}
+	
+	@After public void tearDown() throws Exception {
 		if (listener != null) {
 			listener.stop();
 		}
 	}
 
 	@Test public void testFailedConnect() throws Exception {
-		InetSocketAddress addr = new InetSocketAddress(0);
 		ClientServiceRegistry csr = new ClientServiceRegistry();
 		SessionServiceInterface sessionService = mock(SessionServiceInterface.class);
 		csr.registerClientService(ILogon.class, new LogonImpl(sessionService, "fakeCluster"), "foo"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -83,8 +88,10 @@
 		}
 	}
 
-	@Test public void testConnect() throws Exception {
-		SocketServerConnection conn = helpEstablishConnection(false, null);
+	@Test public void testConnectWithoutPooling() throws Exception {
+		Properties p = new Properties();
+		p.setProperty("org.teiid.sockets.maxCachedInstances", String.valueOf(0)); //$NON-NLS-1$
+		SocketServerConnection conn = helpEstablishConnection(false, null, true, p);
 		SocketListenerStats stats = listener.getStats();
 		assertEquals(2, stats.objectsRead); // handshake response, logon,
 		assertEquals(1, stats.sockets);
@@ -100,11 +107,29 @@
 		stats = listener.getStats();
 		assertEquals(0, stats.sockets);
 	}
+	
+	@Test public void testConnectWithPooling() throws Exception {
+		SocketServerConnection conn = helpEstablishConnection(false, null);
+		SocketListenerStats stats = listener.getStats();
+		assertEquals(2, stats.objectsRead); // handshake response, logon,
+		assertEquals(1, stats.sockets);
+		conn.shutdown();
+		stats = listener.getStats();
+		assertEquals(1, stats.maxSockets);
+		assertEquals(3, stats.objectsRead); // handshake response, logon, logoff
+		stats = listener.getStats();
+		assertEquals(1, stats.sockets);
+		conn = helpEstablishConnection(false, null);
+		conn.shutdown();
+		stats = listener.getStats();
+		assertEquals(1, stats.sockets);
+		assertEquals(1, stats.maxSockets);
+	}
 
+
 	@Test public void testConnectWithoutClientEncryption() throws Exception {
 		SocketServerConnection conn = helpEstablishConnection(false, null, false, new Properties());
-		assertTrue(((SocketServerInstanceImpl) conn
-				.selectServerInstance()).getCryptor() instanceof NullCryptor);
+		assertTrue(conn.selectServerInstance().getCryptor() instanceof NullCryptor);
 		conn.shutdown();
 	}
 
@@ -116,32 +141,34 @@
 	private SocketServerConnection helpEstablishConnection(boolean secure,
 			SSLEngine serverSSL, boolean isClientEncryptionEnabled, Properties socketConfig) throws CommunicationException,
 			ConnectionException {
-		InetSocketAddress addr = new InetSocketAddress(0);
-		SessionServiceInterface sessionService = mock(SessionServiceInterface.class);
-		ClientServiceRegistry csr = new ClientServiceRegistry();
-		csr.registerClientService(ILogon.class, new LogonImpl(sessionService, "fakeCluster") { //$NON-NLS-1$
-			@Override
-			public LogonResult logon(Properties connProps)
-					throws LogonException, ComponentNotFoundException {
-				return new LogonResult();
-			}
-		}, "foo"); //$NON-NLS-1$
-		listener = new SocketListener(addr.getPort(), addr.getAddress().getHostAddress(),
-				csr, 1024, 1024, WorkerPoolFactory.newWorkerPool(
-						"testIO", 1, 120000), serverSSL, isClientEncryptionEnabled, sessionService); //$NON-NLS-1$
+		if (listener == null) {
+			SessionServiceInterface sessionService = mock(SessionServiceInterface.class);
+			ClientServiceRegistry csr = new ClientServiceRegistry();
+			csr.registerClientService(ILogon.class, new LogonImpl(sessionService, "fakeCluster") { //$NON-NLS-1$
+				@Override
+				public LogonResult logon(Properties connProps)
+						throws LogonException, ComponentNotFoundException {
+					return new LogonResult();
+				}
+			}, "foo"); //$NON-NLS-1$
+			listener = new SocketListener(addr.getPort(), addr.getAddress().getHostAddress(),
+					csr, 1024, 1024, WorkerPoolFactory.newWorkerPool(
+							"testIO", 1, 120000), serverSSL, isClientEncryptionEnabled, sessionService); //$NON-NLS-1$
+			SocketListenerStats stats = listener.getStats();
+			assertEquals(0, stats.maxSockets);
+			assertEquals(0, stats.objectsRead);
+			assertEquals(0, stats.objectsWritten);
+			assertEquals(0, stats.sockets);
+		}
 
-		SocketListenerStats stats = listener.getStats();
-		assertEquals(0, stats.maxSockets);
-		assertEquals(0, stats.objectsRead);
-		assertEquals(0, stats.objectsWritten);
-		assertEquals(0, stats.sockets);
-
 		Properties p = new Properties();
 		p.setProperty(MMURL.CONNECTION.SERVER_URL, new MMURL(addr.getHostName(), listener.getPort(),
 				secure).getAppServerURL()); 
 		p.setProperty(MMURL.CONNECTION.DISCOVERY_STRATEGY, UrlServerDiscovery.class.getName());
-		SocketServerConnectionFactory sscf = new SocketServerConnectionFactory();
-		sscf.init(socketConfig);
+		if (sscf == null) {
+			sscf = new SocketServerConnectionFactory();
+			sscf.init(socketConfig);
+		}
 		return sscf.createConnection(p);
 	}
 




More information about the teiid-commits mailing list