Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-06-09 07:16:54 +0000
committerEike Stepper2012-06-09 07:16:54 +0000
commite06eb8fcf933e268547740d9d8be91ba0c77c320 (patch)
treeb9b3b529136b34a4502f39f7479f6193c33933c0 /plugins/org.eclipse.emf.cdo.admin
parent8b302724b3162c54c16788d9a709195d83a170e5 (diff)
downloadcdo-e06eb8fcf933e268547740d9d8be91ba0c77c320.tar.gz
cdo-e06eb8fcf933e268547740d9d8be91ba0c77c320.tar.xz
cdo-e06eb8fcf933e268547740d9d8be91ba0c77c320.zip
[381472] Design a repository administration API
https://bugs.eclipse.org/bugs/show_bug.cgi?id=381472
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.admin')
-rw-r--r--plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClientImpl.java82
-rw-r--r--plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClientManagerImpl.java2
2 files changed, 53 insertions, 31 deletions
diff --git a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClientImpl.java b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClientImpl.java
index cc4496614e..987911ca49 100644
--- a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClientImpl.java
+++ b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClientImpl.java
@@ -14,11 +14,11 @@ import org.eclipse.emf.cdo.admin.CDOAdminClient;
import org.eclipse.emf.cdo.common.CDOCommonRepository.State;
import org.eclipse.emf.cdo.common.CDOCommonRepository.Type;
import org.eclipse.emf.cdo.common.admin.CDOAdminRepository;
+import org.eclipse.emf.cdo.internal.admin.bundle.OM;
import org.eclipse.emf.cdo.internal.admin.protocol.CDOAdminClientProtocol;
import org.eclipse.emf.cdo.spi.common.admin.AbstractCDOAdmin;
import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
import org.eclipse.net4j.util.concurrent.ExecutorServiceFactory;
import org.eclipse.net4j.util.container.IManagedContainer;
import org.eclipse.net4j.util.lifecycle.ILifecycle;
@@ -38,8 +38,6 @@ public class CDOAdminClientImpl extends AbstractCDOAdmin implements CDOAdminClie
{
private static final String URL_SEPARATOR = "://";
- private final CDOAdminClientManagerImpl manager;
-
private final String url;
private final IManagedContainer container;
@@ -48,24 +46,17 @@ public class CDOAdminClientImpl extends AbstractCDOAdmin implements CDOAdminClie
private boolean connected;
- private CDOAdminClientProtocol protocol;
+ private ConnectLock connectLock = new ConnectLock();
- public CDOAdminClientImpl(String url, long timeout, IManagedContainer container)
- {
- this(url, timeout, container, null);
- }
+ private long connectAttempt;
- protected CDOAdminClientImpl(String url, long timeout, CDOAdminClientManagerImpl manager)
- {
- this(url, timeout, manager.getContainer(), manager);
- }
+ private CDOAdminClientProtocol protocol;
- protected CDOAdminClientImpl(String url, long timeout, IManagedContainer container, CDOAdminClientManagerImpl manager)
+ public CDOAdminClientImpl(String url, long timeout, IManagedContainer container)
{
super(timeout);
this.url = url;
this.container = container;
- this.manager = manager;
executorService = ExecutorServiceFactory.get(container);
activate();
@@ -81,11 +72,6 @@ public class CDOAdminClientImpl extends AbstractCDOAdmin implements CDOAdminClie
return container;
}
- public CDOAdminClientManagerImpl getManager()
- {
- return manager;
- }
-
public boolean isConnected()
{
return connected;
@@ -197,11 +183,6 @@ public class CDOAdminClientImpl extends AbstractCDOAdmin implements CDOAdminClie
super.doDeactivate();
}
- protected void connect()
- {
- executorService.submit(new ConnectRunnable());
- }
-
protected void setConnected(final boolean on)
{
connected = on;
@@ -230,15 +211,42 @@ public class CDOAdminClientImpl extends AbstractCDOAdmin implements CDOAdminClie
});
}
+ protected void connect()
+ {
+ if (LifecycleUtil.isActive(executorService))
+ {
+ synchronized (connectLock)
+ {
+ executorService.submit(new ConnectRunnable());
+ }
+ }
+ }
+
/**
* @author Eike Stepper
*/
protected class ConnectRunnable implements Runnable
{
+ private void sleep() throws InterruptedException
+ {
+ long now = System.currentTimeMillis();
+ if (connectAttempt != 0)
+ {
+ long passed = now - connectAttempt;
+ long timeout = getTimeout();
+ long sleep = Math.max(timeout - passed, timeout);
+ Thread.sleep(sleep);
+ }
+
+ connectAttempt = now;
+ }
+
public void run()
{
try
{
+ sleep();
+
int pos = url.indexOf(URL_SEPARATOR);
String type = url.substring(0, pos);
String description = url.substring(pos + URL_SEPARATOR.length());
@@ -254,7 +262,11 @@ public class CDOAdminClientImpl extends AbstractCDOAdmin implements CDOAdminClie
{
setConnected(false);
protocol = null;
- connect();
+
+ if (isActive())
+ {
+ connect();
+ }
}
});
@@ -266,20 +278,30 @@ public class CDOAdminClientImpl extends AbstractCDOAdmin implements CDOAdminClie
setConnected(true);
}
- catch (Exception ex)
+ catch (InterruptedException ex)
+ {
+ OM.LOG.error(ex);
+ return;
+ }
+ catch (Throwable ex)
{
if (protocol != null)
{
LifecycleUtil.deactivate(protocol.getChannel());
protocol = null;
- ConcurrencyUtil.sleep(getTimeout());
}
connect();
}
- finally
- {
- }
}
}
+
+ /**
+ * A separate class for better monitor debugging.
+ *
+ * @author Eike Stepper
+ */
+ private static final class ConnectLock
+ {
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClientManagerImpl.java b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClientManagerImpl.java
index 1771ffda3b..70c01fc2a4 100644
--- a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClientManagerImpl.java
+++ b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClientManagerImpl.java
@@ -95,7 +95,7 @@ public class CDOAdminClientManagerImpl extends SetContainer<CDOAdminClient> impl
public boolean addConnection(String url)
{
- CDOAdminClient connection = new CDOAdminClientImpl(url, ISignalProtocol.DEFAULT_TIMEOUT, this);
+ CDOAdminClient connection = new CDOAdminClientImpl(url, ISignalProtocol.DEFAULT_TIMEOUT, container);
return addElement(connection);
}

Back to the top