[teiid-commits] teiid SVN: r1152 - in trunk/embedded/src/main/java: org/teiid and 1 other directory.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Fri Jul 17 18:07:25 EDT 2009


Author: rareddy
Date: 2009-07-17 18:07:25 -0400 (Fri, 17 Jul 2009)
New Revision: 1152

Modified:
   trunk/embedded/src/main/java/com/metamatrix/jdbc/EmbeddedConnectionFactoryImpl.java
   trunk/embedded/src/main/java/org/teiid/Server.java
Log:
TEIID-679 : No need for file lock based duplicate checking in the EmbeddedConnectionFactory as this is already imposed by the EmbeddedProfile and Server objects.

Modified: trunk/embedded/src/main/java/com/metamatrix/jdbc/EmbeddedConnectionFactoryImpl.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/jdbc/EmbeddedConnectionFactoryImpl.java	2009-07-17 21:38:57 UTC (rev 1151)
+++ trunk/embedded/src/main/java/com/metamatrix/jdbc/EmbeddedConnectionFactoryImpl.java	2009-07-17 22:07:25 UTC (rev 1152)
@@ -26,14 +26,11 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.io.RandomAccessFile;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.net.InetAddress;
 import java.net.URL;
-import java.nio.channels.FileChannel;
-import java.nio.channels.FileLock;
 import java.util.Date;
 import java.util.Properties;
 
@@ -97,7 +94,6 @@
     private SocketTransport socketTransport;
     private JMXUtil jmxServer;
     private boolean restart = false;
-    private FileLock pidLock;
     
 	@Override
 	public ServerConnection createConnection(Properties connectionProperties) throws CommunicationException, ConnectionException {
@@ -162,11 +158,6 @@
 			throw new ApplicationInitializationException(e);
 		}
 		
-		// check for a duplicate process and exit if one found.
-		if(isDuplicateProcess(processName)) {
-			throw new ApplicationInitializationException(DQPEmbeddedPlugin.Util.getString("DQPEmbeddedManager.duplicate_process", processName)); //$NON-NLS-1$
-		}
-		
 		this.jmxServer = new JMXUtil(processName);
 		
         EmbeddedGuiceModule config = new EmbeddedGuiceModule(bootstrapURL, props, this.jmxServer);
@@ -203,19 +194,6 @@
         DQPEmbeddedPlugin.logInfo("DQPEmbeddedManager.start_dqp", new Object[] {new Date(System.currentTimeMillis()).toString()}); //$NON-NLS-1$
     }
     
-	private boolean isDuplicateProcess(String processName) {
-		try {
-			File f = new File(this.workspaceDirectory, "teiid_"+processName+".pid"); //$NON-NLS-1$ //$NON-NLS-2$			
-			FileChannel channel = new RandomAccessFile(f, "rw").getChannel(); //$NON-NLS-1$
-			this.pidLock = channel.tryLock();
-			return (this.pidLock == null); 
-		} catch (Exception e) {
-			// ignore
-		}
-		return true;
-	}
-
-
 	private ClientServiceRegistry createClientServices(ConfigurationService configService) {
     	ClientServiceRegistry services  = new ClientServiceRegistry();
     
@@ -374,12 +352,6 @@
             
             this.init = false;
             
-            try {
-				this.pidLock.release();
-			} catch (IOException e) {
-				//ignore..
-			}
-            
             this.restart = restart;
         }    	
     }

Modified: trunk/embedded/src/main/java/org/teiid/Server.java
===================================================================
--- trunk/embedded/src/main/java/org/teiid/Server.java	2009-07-17 21:38:57 UTC (rev 1151)
+++ trunk/embedded/src/main/java/org/teiid/Server.java	2009-07-17 22:07:25 UTC (rev 1152)
@@ -32,6 +32,7 @@
 import com.metamatrix.common.application.exception.ApplicationInitializationException;
 import com.metamatrix.common.util.JMXUtil.FailedToRegisterException;
 import com.metamatrix.core.MetaMatrixRuntimeException;
+import com.metamatrix.dqp.embedded.DQPEmbeddedPlugin;
 import com.metamatrix.dqp.embedded.DQPEmbeddedProperties;
 import com.metamatrix.jdbc.EmbeddedConnectionFactoryImpl;
 
@@ -69,10 +70,14 @@
 		}
 	}
 		
-	public static boolean duplicateProcess(Properties props) {
+	private static boolean duplicateProcess(Properties props) {
 		try {
-			String parent = new File(new File(props.getProperty(DQPEmbeddedProperties.BOOTURL)).getParent(), props.getProperty(DQPEmbeddedProperties.DQP_WORKDIR)).getCanonicalPath();
-			File f = new File(parent, "teiid.pid"); //$NON-NLS-1$			
+			String teiidHome = props.getProperty(DQPEmbeddedProperties.TEIID_HOME);
+			String workDir = props.getProperty(DQPEmbeddedProperties.DQP_WORKDIR, "work"); //$NON-NLS-1$
+			String processName = props.getProperty(DQPEmbeddedProperties.PROCESSNAME); 
+			
+			String parent = new File(teiidHome, workDir).getCanonicalPath();
+			File f = new File(parent, "teiid_"+processName+".pid"); //$NON-NLS-1$ //$NON-NLS-2$ 			
 			FileChannel channel = new RandomAccessFile(f, "rw").getChannel(); //$NON-NLS-1$
 			return (channel.tryLock() == null); 
 		} catch (IOException e) {
@@ -98,7 +103,7 @@
 			// enable socket communication by default.
 			props.setProperty(DQPEmbeddedProperties.ENABLE_SOCKETS, Boolean.TRUE.toString());
 			props.setProperty(DQPEmbeddedProperties.BOOTURL, f.getCanonicalPath());
-			props.setProperty(DQPEmbeddedProperties.TEIID_HOME,f.getParentFile().getCanonicalPath());
+			props.setProperty(DQPEmbeddedProperties.TEIID_HOME, System.getProperty(DQPEmbeddedProperties.TEIID_HOME,f.getParentFile().getCanonicalPath()));
 		} catch (IOException e) {
 			System.out.println("Failed to load bootstrap properties file."); //$NON-NLS-1$
 			e.printStackTrace();
@@ -153,8 +158,9 @@
 		Properties props = loadConfiguration(args[0]);
 		
 		// check for duplicate process
+		String processName = props.getProperty(DQPEmbeddedProperties.PROCESSNAME);
 		if (duplicateProcess(props)) {
-			System.out.println("There is already another Server process running! Failed to start"); //$NON-NLS-1$
+			System.out.println(DQPEmbeddedPlugin.Util.getString("DQPEmbeddedManager.duplicate_process", processName)); //$NON-NLS-1$
 			System.exit(-2);			
 		}
 		



More information about the teiid-commits mailing list