Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-06-09 06:25:01 +0000
committerEike Stepper2012-06-09 06:25:01 +0000
commitf8aaeebdc8d20dd68e9a0087e1cede40d2e1d38b (patch)
treec8a6e7a5849d5ce84f874678dd35a531c073d0b6 /plugins/org.eclipse.emf.cdo.admin
parenta64c90c2035bae5c504e15d66213beb78b93a66d (diff)
downloadcdo-f8aaeebdc8d20dd68e9a0087e1cede40d2e1d38b.tar.gz
cdo-f8aaeebdc8d20dd68e9a0087e1cede40d2e1d38b.tar.xz
cdo-f8aaeebdc8d20dd68e9a0087e1cede40d2e1d38b.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/admin/CDOAdminClient.java26
-rw-r--r--plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/admin/CDOAdminClientManager.java39
-rw-r--r--plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/admin/CDOAdminUtil.java27
-rw-r--r--plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClientImpl.java205
-rw-r--r--plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClientManagerImpl.java106
-rw-r--r--plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/CDOAdminClientProtocol.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/QueryRepositoriesRequest.java13
7 files changed, 390 insertions, 31 deletions
diff --git a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/admin/CDOAdminClient.java b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/admin/CDOAdminClient.java
index 1a24765290..b44afd1600 100644
--- a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/admin/CDOAdminClient.java
+++ b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/admin/CDOAdminClient.java
@@ -12,14 +12,36 @@ package org.eclipse.emf.cdo.admin;
import org.eclipse.emf.cdo.common.admin.CDOAdmin;
-import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.util.event.IEvent;
/**
* A client-side {@link CDOAdmin administrative interface}.
+ * <p>
+ * It can fire the following events:
+ * <ul>
+ * <li> {@link ConnectionStateChangedEvent} after the connection {@link #isConnected() state} has changed.
+ * </ul>
*
* @author Eike Stepper
*/
public interface CDOAdminClient extends CDOAdmin
{
- public IConnector getConnector();
+ public String getURL();
+
+ public boolean isConnected();
+
+ /**
+ * An {@link IEvent event} fired from a client-side {@link CDOAdminClient administrative interface}
+ * after the connection {@link CDOAdminClient#isConnected() state} has changed.
+ *
+ * @author Eike Stepper
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
+ */
+ public interface ConnectionStateChangedEvent extends IEvent
+ {
+ public CDOAdminClient getSource();
+
+ public boolean isConnected();
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/admin/CDOAdminClientManager.java b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/admin/CDOAdminClientManager.java
new file mode 100644
index 0000000000..766ef7a2e8
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/admin/CDOAdminClientManager.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.admin;
+
+import org.eclipse.net4j.util.container.IContainer;
+import org.eclipse.net4j.util.container.IManagedContainer;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Manages multiple {@link CDOAdminClient remote administration connections}.
+ *
+ * @author Eike Stepper
+ */
+public interface CDOAdminClientManager extends IContainer<CDOAdminClient>
+{
+ public IManagedContainer getContainer();
+
+ public CDOAdminClient[] getConnections();
+
+ public List<String> getConnectionURLs();
+
+ public CDOAdminClient getConnection(String url);
+
+ public int addConnections(Collection<String> urls);
+
+ public boolean addConnection(String url);
+
+ public boolean removeConnection(CDOAdminClient connection);
+}
diff --git a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/admin/CDOAdminUtil.java b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/admin/CDOAdminUtil.java
index 4db8d115e7..d42060a66b 100644
--- a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/admin/CDOAdminUtil.java
+++ b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/admin/CDOAdminUtil.java
@@ -11,9 +11,11 @@
package org.eclipse.emf.cdo.admin;
import org.eclipse.emf.cdo.internal.admin.CDOAdminClientImpl;
+import org.eclipse.emf.cdo.internal.admin.CDOAdminClientManagerImpl;
-import org.eclipse.net4j.connector.IConnector;
import org.eclipse.net4j.signal.ISignalProtocol;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.container.IPluginContainer;
/**
* Various static methods that may help with CDO remote administration.
@@ -28,13 +30,28 @@ public final class CDOAdminUtil
{
}
- public static CDOAdminClient openAdmin(IConnector connector)
+ public static CDOAdminClient openAdmin(String url)
{
- return openAdmin(connector, DEFAULT_TIMEOUT);
+ return openAdmin(url, DEFAULT_TIMEOUT);
}
- public static CDOAdminClient openAdmin(IConnector connector, long timeout)
+ public static CDOAdminClient openAdmin(String url, long timeout)
{
- return new CDOAdminClientImpl(connector, timeout);
+ return openAdmin(url, timeout, IPluginContainer.INSTANCE);
+ }
+
+ public static CDOAdminClient openAdmin(String url, long timeout, IManagedContainer container)
+ {
+ return new CDOAdminClientImpl(url, timeout, container);
+ }
+
+ public static CDOAdminClientManager createAdminManager()
+ {
+ return createAdminManager(IPluginContainer.INSTANCE);
+ }
+
+ public static CDOAdminClientManager createAdminManager(IManagedContainer container)
+ {
+ return new CDOAdminClientManagerImpl(container);
}
}
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 ef91162447..cc4496614e 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
@@ -13,34 +13,82 @@ package org.eclipse.emf.cdo.internal.admin;
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.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;
import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+
+import org.eclipse.spi.net4j.ConnectorFactory;
import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutorService;
/**
* @author Eike Stepper
*/
public class CDOAdminClientImpl extends AbstractCDOAdmin implements CDOAdminClient
{
- private final IConnector connector;
+ private static final String URL_SEPARATOR = "://";
+
+ private final CDOAdminClientManagerImpl manager;
+
+ private final String url;
+
+ private final IManagedContainer container;
+
+ private final ExecutorService executorService;
+
+ private boolean connected;
private CDOAdminClientProtocol protocol;
- public CDOAdminClientImpl(IConnector connector, long timeout)
+ public CDOAdminClientImpl(String url, long timeout, IManagedContainer container)
+ {
+ this(url, timeout, container, null);
+ }
+
+ protected CDOAdminClientImpl(String url, long timeout, CDOAdminClientManagerImpl manager)
+ {
+ this(url, timeout, manager.getContainer(), manager);
+ }
+
+ protected CDOAdminClientImpl(String url, long timeout, IManagedContainer container, CDOAdminClientManagerImpl manager)
{
super(timeout);
- this.connector = connector;
+ this.url = url;
+ this.container = container;
+ this.manager = manager;
+
+ executorService = ExecutorServiceFactory.get(container);
activate();
}
- public final IConnector getConnector()
+ public final String getURL()
+ {
+ return url;
+ }
+
+ public final IManagedContainer getContainer()
{
- return connector;
+ return container;
+ }
+
+ public CDOAdminClientManagerImpl getManager()
+ {
+ return manager;
+ }
+
+ public boolean isConnected()
+ {
+ return connected;
}
public void repositoryTypeChanged(String name, Type oldType, Type newType)
@@ -71,6 +119,55 @@ public class CDOAdminClientImpl extends AbstractCDOAdmin implements CDOAdminClie
}
@Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (url == null ? 0 : url.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+
+ if (obj == null)
+ {
+ return false;
+ }
+
+ if (!(obj instanceof CDOAdminClient))
+ {
+ return false;
+ }
+
+ CDOAdminClient other = (CDOAdminClient)obj;
+ if (url == null)
+ {
+ if (other.getURL() != null)
+ {
+ return false;
+ }
+ }
+ else if (!url.equals(other.getURL()))
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public String toString()
+ {
+ return url;
+ }
+
+ @Override
protected boolean doCreateRepository(String name, String type, Map<String, Object> properties)
{
return protocol.createRepository(name, type, properties);
@@ -86,23 +183,103 @@ public class CDOAdminClientImpl extends AbstractCDOAdmin implements CDOAdminClie
protected void doActivate() throws Exception
{
super.doActivate();
+ connect();
+ }
+
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ setConnected(false);
+
+ protocol.close();
+ protocol = null;
- protocol = new CDOAdminClientProtocol(this);
- protocol.queryRepositories(getSet());
- protocol.addListener(new LifecycleEventAdapter()
+ super.doDeactivate();
+ }
+
+ protected void connect()
+ {
+ executorService.submit(new ConnectRunnable());
+ }
+
+ protected void setConnected(final boolean on)
+ {
+ connected = on;
+ if (!on)
{
+ clear();
+ }
+
+ fireEvent(new ConnectionStateChangedEvent()
+ {
+ public CDOAdminClient getSource()
+ {
+ return CDOAdminClientImpl.this;
+ }
+
+ public boolean isConnected()
+ {
+ return on;
+ }
+
@Override
- protected void onDeactivated(ILifecycle lifecycle)
+ public String toString()
{
- deactivate();
+ return "ConnectionStateChangedEvent[connected=" + on + "]";
}
});
}
- @Override
- protected void doDeactivate() throws Exception
+ /**
+ * @author Eike Stepper
+ */
+ protected class ConnectRunnable implements Runnable
{
- protocol.close();
- super.doDeactivate();
+ public void run()
+ {
+ try
+ {
+ int pos = url.indexOf(URL_SEPARATOR);
+ String type = url.substring(0, pos);
+ String description = url.substring(pos + URL_SEPARATOR.length());
+
+ IConnector connector = (IConnector)container.getElement(ConnectorFactory.PRODUCT_GROUP, type, description);
+
+ protocol = new CDOAdminClientProtocol(CDOAdminClientImpl.this);
+ protocol.open(connector);
+ protocol.addListener(new LifecycleEventAdapter()
+ {
+ @Override
+ protected void onDeactivated(ILifecycle lifecycle)
+ {
+ setConnected(false);
+ protocol = null;
+ connect();
+ }
+ });
+
+ Set<CDOAdminRepository> repositories = protocol.queryRepositories();
+ for (CDOAdminRepository repository : repositories)
+ {
+ addElement(repository);
+ }
+
+ setConnected(true);
+ }
+ catch (Exception ex)
+ {
+ if (protocol != null)
+ {
+ LifecycleUtil.deactivate(protocol.getChannel());
+ protocol = null;
+ ConcurrencyUtil.sleep(getTimeout());
+ }
+
+ connect();
+ }
+ finally
+ {
+ }
+ }
}
}
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
new file mode 100644
index 0000000000..1771ffda3b
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClientManagerImpl.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.internal.admin;
+
+import org.eclipse.emf.cdo.admin.CDOAdminClient;
+import org.eclipse.emf.cdo.admin.CDOAdminClientManager;
+
+import org.eclipse.net4j.signal.ISignalProtocol;
+import org.eclipse.net4j.util.ObjectUtil;
+import org.eclipse.net4j.util.concurrent.ExecutorServiceFactory;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.container.SetContainer;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+
+/**
+ * @author Eike Stepper
+ */
+public class CDOAdminClientManagerImpl extends SetContainer<CDOAdminClient> implements CDOAdminClientManager
+{
+ private final IManagedContainer container;
+
+ private final ExecutorService executorService;
+
+ public CDOAdminClientManagerImpl(IManagedContainer container)
+ {
+ super(CDOAdminClient.class);
+ this.container = container;
+ executorService = ExecutorServiceFactory.get(container);
+ }
+
+ public final IManagedContainer getContainer()
+ {
+ return container;
+ }
+
+ public final ExecutorService getExecutorService()
+ {
+ return executorService;
+ }
+
+ public CDOAdminClient[] getConnections()
+ {
+ return getElements();
+ }
+
+ public List<String> getConnectionURLs()
+ {
+ List<String> urls = new ArrayList<String>();
+ for (CDOAdminClient connection : getConnections())
+ {
+ urls.add(connection.getURL());
+ }
+
+ return urls;
+ }
+
+ public CDOAdminClient getConnection(String url)
+ {
+ for (CDOAdminClient connection : getConnections())
+ {
+ if (ObjectUtil.equals(connection.getURL(), url))
+ {
+ return connection;
+ }
+ }
+
+ return null;
+ }
+
+ public int addConnections(Collection<String> urls)
+ {
+ int count = 0;
+ for (String url : urls)
+ {
+ if (addConnection(url))
+ {
+ ++count;
+ }
+ }
+
+ return count;
+ }
+
+ public boolean addConnection(String url)
+ {
+ CDOAdminClient connection = new CDOAdminClientImpl(url, ISignalProtocol.DEFAULT_TIMEOUT, this);
+ return addElement(connection);
+ }
+
+ public boolean removeConnection(CDOAdminClient connection)
+ {
+ return removeElement(connection);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/CDOAdminClientProtocol.java b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/CDOAdminClientProtocol.java
index c1687d4e96..94b6ed427e 100644
--- a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/CDOAdminClientProtocol.java
+++ b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/CDOAdminClientProtocol.java
@@ -31,12 +31,11 @@ public class CDOAdminClientProtocol extends SignalProtocol<CDOAdminClientImpl>
{
super(CDOAdminProtocolConstants.PROTOCOL_NAME);
setInfraStructure(admin);
- open(admin.getConnector());
}
- public void queryRepositories(Set<CDOAdminRepository> result)
+ public Set<CDOAdminRepository> queryRepositories()
{
- send(new QueryRepositoriesRequest(this, result));
+ return send(new QueryRepositoriesRequest(this));
}
public boolean createRepository(String name, String type, Map<String, Object> properties)
diff --git a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/QueryRepositoriesRequest.java b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/QueryRepositoriesRequest.java
index 5933dd3ab2..3cebca8b6c 100644
--- a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/QueryRepositoriesRequest.java
+++ b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/QueryRepositoriesRequest.java
@@ -21,21 +21,19 @@ import org.eclipse.net4j.util.io.ExtendedDataInputStream;
import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
import org.eclipse.net4j.util.om.trace.ContextTracer;
+import java.util.HashSet;
import java.util.Set;
/**
* @author Eike Stepper
*/
-public class QueryRepositoriesRequest extends RequestWithConfirmation<Object>
+public class QueryRepositoriesRequest extends RequestWithConfirmation<Set<CDOAdminRepository>>
{
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_PROTOCOL, QueryRepositoriesRequest.class);
- private Set<CDOAdminRepository> result;
-
- public QueryRepositoriesRequest(CDOAdminClientProtocol protocol, Set<CDOAdminRepository> result)
+ public QueryRepositoriesRequest(CDOAdminClientProtocol protocol)
{
super(protocol, CDOAdminProtocolConstants.SIGNAL_QUERY_REPOSITORIES);
- this.result = result;
}
@Override
@@ -45,7 +43,7 @@ public class QueryRepositoriesRequest extends RequestWithConfirmation<Object>
}
@Override
- protected Object confirming(ExtendedDataInputStream in) throws Exception
+ protected Set<CDOAdminRepository> confirming(ExtendedDataInputStream in) throws Exception
{
CDOAdminClientProtocol protocol = (CDOAdminClientProtocol)getProtocol();
CDOAdminClientImpl admin = protocol.getInfraStructure();
@@ -56,6 +54,7 @@ public class QueryRepositoriesRequest extends RequestWithConfirmation<Object>
TRACER.format("Reading {0} repository infos...", size); //$NON-NLS-1$
}
+ Set<CDOAdminRepository> result = new HashSet<CDOAdminRepository>();
for (int i = 0; i < size; i++)
{
CDOAdminClientRepository repository = new CDOAdminClientRepository(admin, in);
@@ -66,6 +65,6 @@ public class QueryRepositoriesRequest extends RequestWithConfirmation<Object>
}
}
- return null;
+ return result;
}
}

Back to the top