diff --git a/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/SubSystem.java b/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/SubSystem.java index a453d67d7c1..59d9d64de4a 100644 --- a/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/SubSystem.java +++ b/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/SubSystem.java @@ -48,7 +48,7 @@ * David McKnight (IBM) - [262930] Remote System Details view not restoring filter memento input * David McKnight (IBM) - [272882] [api] Handle exceptions in IService.initService() * David McKnight (IBM) - [284018] concurrent SubSystem.connect() calls can result in double login-prompt - ********************************************************************************/ + * ********************************************************************************/ package org.eclipse.rse.core.subsystems; import java.lang.reflect.InvocationTargetException; @@ -2443,6 +2443,41 @@ implements IAdaptable, ISubSystem, ISystemFilterPoolReferenceManagerProvider _isInitialized = false; } + + private static class ConnectorServicePool { + + private static List _connectingConnectorServices = new ArrayList(); + + public synchronized void add(IConnectorService cs) { + _connectingConnectorServices.add(cs); + } + + public synchronized void remove(IConnectorService cs) { + _connectingConnectorServices.remove(cs); + notifyAll(); + } + + public synchronized boolean contains(IConnectorService cs) { + return _connectingConnectorServices.contains(cs); + } + + public synchronized void waitUntilNotContained(IConnectorService cs) { + while (contains(cs)){ // wait until the connector service is no longer in the list + try { + wait(); + } + catch (InterruptedException e){ + e.printStackTrace(); + } + catch (Exception e){ + e.printStackTrace(); + } + } + } + } + + private static ConnectorServicePool _connectorServicePool = new ConnectorServicePool(); + /* * Connect to a remote system with a monitor. * Required for Bug 176603 @@ -2462,9 +2497,20 @@ implements IAdaptable, ISubSystem, ISystemFilterPoolReferenceManagerProvider final Exception[] exception=new Exception[1]; exception[0]=null; - IConnectorService conServ = getConnectorService(); - synchronized (conServ){ - if (!conServ.isConnected()){ + IConnectorService connectorService = getConnectorService(); + // is this connector service already connecting? + boolean alreadyConnecting = _connectorServicePool.contains(connectorService); + + if (alreadyConnecting){ + // connector service already attempting connect + // need to wait for it to complete + // before we can return out of this method + _connectorServicePool.waitUntilNotContained(connectorService); + } + else { + _connectorServicePool.add(connectorService); + + try { Display.getDefault().syncExec(new Runnable() { public void run() { try @@ -2475,9 +2521,7 @@ implements IAdaptable, ISubSystem, ISystemFilterPoolReferenceManagerProvider } } }); - } - try { Exception e = exception[0]; if (e == null) { getConnectorService().connect(monitor); @@ -2490,13 +2534,14 @@ implements IAdaptable, ISubSystem, ISystemFilterPoolReferenceManagerProvider } }); } - } else { + } else { throw e; } } finally { + _connectorServicePool.remove(connectorService); monitor.done(); } - } + } } }