[Esbox-commits] r848 - trunk/device/org.maemo.esbox.device.launch.rse/src/org/maemo/esbox/device/launch/rse

lwang at garage.maemo.org lwang at garage.maemo.org
Thu Oct 9 01:47:47 EEST 2008


Author: lwang
Date: 2008-10-09 01:47:46 +0300 (Thu, 09 Oct 2008)
New Revision: 848

Modified:
   trunk/device/org.maemo.esbox.device.launch.rse/src/org/maemo/esbox/device/launch/rse/RSELaunchProtocolType.java
Log:
My previous change is actually not doing what's desired. Revised. And also ensure RSE is initialized in some other use cases such as when user launches an RSE-based launch configuration.

Modified: trunk/device/org.maemo.esbox.device.launch.rse/src/org/maemo/esbox/device/launch/rse/RSELaunchProtocolType.java
===================================================================
--- trunk/device/org.maemo.esbox.device.launch.rse/src/org/maemo/esbox/device/launch/rse/RSELaunchProtocolType.java	2008-10-08 22:04:43 UTC (rev 847)
+++ trunk/device/org.maemo.esbox.device.launch.rse/src/org/maemo/esbox/device/launch/rse/RSELaunchProtocolType.java	2008-10-08 22:47:46 UTC (rev 848)
@@ -14,7 +14,6 @@
 import java.text.MessageFormat;
 
 import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.debug.core.ILaunchConfiguration;
@@ -23,7 +22,6 @@
 import org.eclipse.rse.core.model.IHost;
 import org.eclipse.rse.core.model.SystemStartHere;
 import org.maemo.esbox.core.JobUtils;
-import org.maemo.esbox.core.JobUtils.IJob;
 import org.maemo.esbox.device.launch.SSHLaunchProtocolType;
 import org.maemo.esbox.internal.device.launch.rse.Activator;
 import org.maemo.esbox.launch.AbstractLaunchProtocolType;
@@ -46,10 +44,7 @@
 	 * @return
 	 */
 	static public String[] getAllRSEConnectionIDs() {
-		// make sure RSE connections are loaded.
-		safeWaitForRSEInitialization();
-		
-		IHost[] hosts = SystemStartHere.getConnections(); 
+		IHost[] hosts = getCurrentRSEConnections(); 
 		String[] names = new String[hosts.length];
 		
 		for (int i = 0 ; i < hosts.length; i++) {
@@ -89,7 +84,7 @@
 			throw new CoreException(new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), 
 					"No RSE Connection found in the launch configuration:" + configuration.getName()));
 		
-		IHost[] hosts = SystemStartHere.getConnections();
+		IHost[] hosts = getCurrentRSEConnections();
 		for (IHost h : hosts) {
 			if (h.getAliasName().equals(rseConnectionID))
 				return h;
@@ -123,7 +118,26 @@
 		configuration.setAttribute(ATTR_RSE_CONNECTION_ID, rseConnection);
 	}
 	
-	static public IStatus safeWaitForRSEInitialization() {
+	/**
+	 * Get existing RSE connections at this moment.
+	 * Note a connection can be removed or added at any time by user.
+	 *  
+	 * @return
+	 */
+	static public IHost[] getCurrentRSEConnections() {
+		IHost[] hosts = SystemStartHere.getConnections(); 
+		if (hosts.length == 0) {
+			// Make sure RSE initialization is done.
+			safeWaitForRSEInitialization();
+			
+			// Second try
+			hosts = SystemStartHere.getConnections();
+		}
+		
+		return hosts;
+	}
+
+	static public boolean safeWaitForRSEInitialization() {
 		// Make sure RSE initialization (loading of existing hosts) is done.
 		// This would ensure we get existing RSE connections for 
 		// launch configuration dialog and for launching any RSE based
@@ -132,20 +146,20 @@
 		// Note we use JobUtils below to make sure the wait won't block UI thread.
 		//
 		//	................... LWang. 10/08/08
-		return JobUtils.waitForRunnable(
-			new IJob() {
-				public IStatus run(IProgressMonitor monitor) {
-					try {
-						return RSECorePlugin.waitForInitCompletion();
-					} catch (InterruptedException e) {
-						return new Status(IStatus.ERROR, 
-								Activator.getUniqueIdentifier(), 
-								"Wating for RSE initialization was interrupted.");
-					}
+		Thread thread = new Thread("Initializing RSE ...") {
+			@Override
+			public void run() {
+				try {
+					RSECorePlugin.waitForInitCompletion();
+				} catch (InterruptedException e) {
+					Activator.getDefault().getLog().log(new Status(IStatus.ERROR, 
+							Activator.getUniqueIdentifier(), 
+							"Wating for RSE initialization was interrupted."));
 				}
-			}, 
-			null, 
-			"Loading and initializing RSE connections...");
+			}
+		};
+		thread.start();
+		return JobUtils.waitForThread(thread, 10000,	null);
 	}
 
 	// This is called when the LaunchProtocolType extension is loaded.
@@ -159,7 +173,7 @@
 	}
 
 	public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
-		IHost[] hosts = SystemStartHere.getConnections(); 
+		IHost[] hosts = getCurrentRSEConnections(); 
 		String  hostID = null;
 		
 		if (hosts.length > 0)



More information about the Esbox-commits mailing list