Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-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
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_381472_Test.java33
-rw-r--r--plugins/org.eclipse.emf.cdo.ui.admin/src/org/eclipse/emf/cdo/ui/internal/admin/CDOAdminView.java189
-rw-r--r--plugins/org.eclipse.emf.cdo.ui.admin/src/org/eclipse/emf/cdo/ui/internal/admin/bundle/OM.java36
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/ControlChannel.java508
-rw-r--r--plugins/org.eclipse.net4j.ui/META-INF/MANIFEST.MF6
-rw-r--r--plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/views/AcceptorsView.java71
-rw-r--r--plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/views/ConnectorsView.java49
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/ParallelRunner.java67
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/Stoppable.java59
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/SetContainer.java42
17 files changed, 987 insertions, 494 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;
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_381472_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_381472_Test.java
index 86c05e226c..34c7e47770 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_381472_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_381472_Test.java
@@ -10,6 +10,7 @@
*/
package org.eclipse.emf.cdo.tests.bugzilla;
+import org.eclipse.emf.cdo.admin.CDOAdminClient;
import org.eclipse.emf.cdo.admin.CDOAdminUtil;
import org.eclipse.emf.cdo.common.CDOCommonRepository.State;
import org.eclipse.emf.cdo.common.CDOCommonRepository.Type;
@@ -58,7 +59,7 @@ public class Bugzilla_381472_Test extends AbstractCDOTest
{
private static final String ADMIN_HANDLER_TYPE = "test";
- private CDOAdmin openAdmin(final Map<String, Object> expectedProperties)
+ private CDOAdmin openAdmin(final Map<String, Object> expectedProperties) throws InterruptedException
{
IManagedContainer serverContainer = getContainerConfig().getServerContainer();
serverContainer.registerFactory(new CDOAdminHandler.Factory(ADMIN_HANDLER_TYPE)
@@ -88,9 +89,23 @@ public class Bugzilla_381472_Test extends AbstractCDOTest
}
});
+ IManagedContainer clientContainer = getClientContainer();
SessionConfig.Net4j sessionConfig = (SessionConfig.Net4j)getSessionConfig();
IConnector connector = sessionConfig.getConnector();
- return CDOAdminUtil.openAdmin(connector);
+ String url = connector.getURL();
+
+ final CDOAdminClient admin = CDOAdminUtil.openAdmin(url, DEFAULT_TIMEOUT, clientContainer);
+
+ new PollingTimeOuter()
+ {
+ @Override
+ protected boolean successful()
+ {
+ return admin.isConnected();
+ }
+ }.assertNoTimeOut();
+
+ return admin;
}
private void cleanup(CDOAdmin admin)
@@ -98,20 +113,6 @@ public class Bugzilla_381472_Test extends AbstractCDOTest
IOUtil.closeSilent(admin);
}
- // @Override
- // protected void doSetUp() throws Exception
- // {
- // getRepositoryConfig().setAddRepository(true);
- // super.doSetUp();
- // }
- //
- // @Override
- // protected void doTearDown() throws Exception
- // {
- // getRepositoryConfig().setAddRepository(false);
- // super.doTearDown();
- // }
-
public void testInitial() throws Exception
{
CDOAdmin admin = openAdmin(null);
diff --git a/plugins/org.eclipse.emf.cdo.ui.admin/src/org/eclipse/emf/cdo/ui/internal/admin/CDOAdminView.java b/plugins/org.eclipse.emf.cdo.ui.admin/src/org/eclipse/emf/cdo/ui/internal/admin/CDOAdminView.java
index 7ba99c6972..4e2e5b580a 100644
--- a/plugins/org.eclipse.emf.cdo.ui.admin/src/org/eclipse/emf/cdo/ui/internal/admin/CDOAdminView.java
+++ b/plugins/org.eclipse.emf.cdo.ui.admin/src/org/eclipse/emf/cdo/ui/internal/admin/CDOAdminView.java
@@ -11,33 +11,23 @@
package org.eclipse.emf.cdo.ui.internal.admin;
import org.eclipse.emf.cdo.admin.CDOAdminClient;
-import org.eclipse.emf.cdo.admin.CDOAdminUtil;
+import org.eclipse.emf.cdo.admin.CDOAdminClientManager;
import org.eclipse.emf.cdo.common.admin.CDOAdminRepository;
+import org.eclipse.emf.cdo.ui.internal.admin.bundle.OM;
import org.eclipse.emf.cdo.ui.shared.SharedIcons;
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.ui.Net4jItemProvider;
import org.eclipse.net4j.util.container.IContainer;
-import org.eclipse.net4j.util.container.IContainerEvent;
-import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.container.IPluginContainer;
-import org.eclipse.net4j.util.event.IEvent;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter;
-import org.eclipse.net4j.util.ui.container.ElementWizardAction;
import org.eclipse.net4j.util.ui.views.ContainerItemProvider;
import org.eclipse.net4j.util.ui.views.ContainerView;
-import org.eclipse.net4j.util.ui.views.IElementFilter;
+import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IToolBarManager;
-import org.eclipse.spi.net4j.ConnectorFactory;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-
-import java.util.HashMap;
-import java.util.Map;
/**
* @author Eike Stepper
@@ -46,146 +36,95 @@ public class CDOAdminView extends ContainerView
{
public final static String ID = "org.eclipse.emf.cdo.ui.admin.CDOAdminView"; //$NON-NLS-1$
- private final Map<IConnector, CDOAdminClient> admins = new HashMap<IConnector, CDOAdminClient>();
+ private final CDOAdminClientManager adminManager = OM.getAdminManager();
- private IAction newConnectorAction = new ElementWizardAction(getShell(), "New Connector", "Open a new connector",
- org.eclipse.net4j.ui.shared.SharedIcons
- .getDescriptor(org.eclipse.net4j.ui.shared.SharedIcons.ETOOL_ADD_CONNECTOR), ConnectorFactory.PRODUCT_GROUP,
- getContainer(), "tcp")
- {
- @Override
- public String getDefaultDescription(String factoryType)
- {
- if ("tcp".equals(factoryType))
- {
- return "localhost";
- }
+ private Image connectionImage = org.eclipse.net4j.ui.shared.SharedIcons
+ .getImage(org.eclipse.net4j.ui.shared.SharedIcons.OBJ_CONNECTOR);
- return null;
- }
- };
+ private Image repositoryImage = SharedIcons.getImage(SharedIcons.OBJ_REPO);
- public CDOAdminView()
- {
- }
+ private IAction addConnectionAction;
- @Override
- protected Control createUI(Composite parent)
+ public CDOAdminView()
{
- return super.createUI(parent);
}
@Override
- protected IManagedContainer getContainer()
+ protected IContainer<?> getContainer()
{
- return IPluginContainer.INSTANCE;
+ return adminManager;
}
@Override
protected ContainerItemProvider<IContainer<Object>> createContainerItemProvider()
{
- return new Net4jItemProvider(new IElementFilter()
- {
- public boolean filter(Object element)
- {
- return element instanceof IConnector;
- }
- })
+ return new ContainerItemProvider<IContainer<Object>>()
{
@Override
- public Object getParent(Object element)
+ public String getText(Object obj)
{
- if (element instanceof CDOAdminRepository)
+ if (obj instanceof CDOAdminClient)
{
- CDOAdminRepository repository = (CDOAdminRepository)element;
- CDOAdminClient admin = (CDOAdminClient)repository.getAdmin();
- return admin.getConnector();
+ CDOAdminClient connection = (CDOAdminClient)obj;
+ return connection.getURL();
}
- return super.getParent(element);
+ if (obj instanceof CDOAdminRepository)
+ {
+ CDOAdminRepository repository = (CDOAdminRepository)obj;
+ return repository.getName() + " [" + repository.getType() + ", " + repository.getState() + "]";
+ }
+
+ return super.getText(obj);
}
@Override
- public Object[] getChildren(Object element)
+ public Image getImage(Object obj)
{
- if (element instanceof IConnector)
+ if (obj instanceof CDOAdminClient)
{
- IConnector connector = (IConnector)element;
-
- CDOAdminClient admin;
- synchronized (admins)
- {
- admin = admins.get(connector);
- if (admin == null)
- {
- admin = CDOAdminUtil.openAdmin(connector);
- admin.addListener(new LifecycleEventAdapter()
- {
- @Override
- protected void onActivated(ILifecycle lifecycle)
- {
- refreshViewer(true);
- }
-
- @Override
- protected void onDeactivated(ILifecycle lifecycle)
- {
- IConnector key = ((CDOAdminClient)lifecycle).getConnector();
- synchronized (admins)
- {
- admins.remove(key);
- }
-
- refreshViewer(true);
- }
-
- @Override
- protected void notifyOtherEvent(IEvent event)
- {
- if (event instanceof IContainerEvent)
- {
- refreshViewer(false);
- }
- }
- });
-
- admins.put(connector, admin);
- }
- }
+ return connectionImage;
+ }
- return admin.getRepositories();
+ if (obj instanceof CDOAdminRepository)
+ {
+ return repositoryImage;
}
- return super.getChildren(element);
+ return super.getImage(obj);
}
@Override
- public String getText(Object obj)
+ public Font getFont(Object obj)
{
- if (obj instanceof IConnector)
+ if (isDisabled(obj))
{
- IConnector connector = (IConnector)obj;
- return connector.getURL();
+ return getItalicFont();
}
- if (obj instanceof CDOAdminRepository)
+ return super.getFont(obj);
+ }
+
+ @Override
+ public Color getForeground(Object obj)
+ {
+ if (isDisabled(obj))
{
- CDOAdminRepository repository = (CDOAdminRepository)obj;
- return repository.getName() + " [" + repository.getType() + ", " + repository.getState() + "]";
+ return getDisplay().getSystemColor(SWT.COLOR_GRAY);
}
- return super.getText(obj);
+ return super.getForeground(obj);
}
- @Override
- public Image getImage(Object obj)
+ private boolean isDisabled(Object obj)
{
- if (obj instanceof CDOAdminRepository)
+ if (obj instanceof CDOAdminClient)
{
- return SharedIcons.getImage(SharedIcons.OBJ_REPO);
+ CDOAdminClient admin = (CDOAdminClient)obj;
+ return !admin.isConnected();
}
- return super.getImage(obj);
+ return false;
}
};
}
@@ -193,7 +132,29 @@ public class CDOAdminView extends ContainerView
@Override
protected void fillLocalToolBar(IToolBarManager manager)
{
- manager.add(newConnectorAction);
+ if (addConnectionAction == null)
+ {
+ addConnectionAction = new Action()
+ {
+ @Override
+ public void run()
+ {
+ InputDialog dialog = new InputDialog(getShell(), getText(), "Enter the connection URL:", null, null);
+ if (dialog.open() == InputDialog.OK)
+ {
+ String url = dialog.getValue();
+ adminManager.addConnection(url);
+ }
+ }
+ };
+
+ addConnectionAction.setText("Add Connection");
+ addConnectionAction.setToolTipText("Add a new connection");
+ addConnectionAction.setImageDescriptor(org.eclipse.net4j.ui.shared.SharedIcons
+ .getDescriptor(org.eclipse.net4j.ui.shared.SharedIcons.ETOOL_ADD));
+ }
+
+ manager.add(addConnectionAction);
super.fillLocalToolBar(manager);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.ui.admin/src/org/eclipse/emf/cdo/ui/internal/admin/bundle/OM.java b/plugins/org.eclipse.emf.cdo.ui.admin/src/org/eclipse/emf/cdo/ui/internal/admin/bundle/OM.java
index d3ff2b90ce..12e36e6e6d 100644
--- a/plugins/org.eclipse.emf.cdo.ui.admin/src/org/eclipse/emf/cdo/ui/internal/admin/bundle/OM.java
+++ b/plugins/org.eclipse.emf.cdo.ui.admin/src/org/eclipse/emf/cdo/ui/internal/admin/bundle/OM.java
@@ -11,6 +11,10 @@
*/
package org.eclipse.emf.cdo.ui.internal.admin.bundle;
+import org.eclipse.emf.cdo.admin.CDOAdminClientManager;
+import org.eclipse.emf.cdo.admin.CDOAdminUtil;
+
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.net4j.util.om.OMBundle;
import org.eclipse.net4j.util.om.OMPlatform;
import org.eclipse.net4j.util.om.log.OMLogger;
@@ -19,6 +23,9 @@ import org.eclipse.net4j.util.ui.UIActivator;
import org.eclipse.jface.resource.ImageDescriptor;
+import java.util.Collection;
+import java.util.List;
+
/**
* The <em>Operations & Maintenance</em> class of this bundle.
*
@@ -34,6 +41,13 @@ public abstract class OM
public static final OMTracer DEBUG = BUNDLE.tracer("debug"); //$NON-NLS-1$
+ private static CDOAdminClientManager adminManager = CDOAdminUtil.createAdminManager();
+
+ public static CDOAdminClientManager getAdminManager()
+ {
+ return adminManager;
+ }
+
public static ImageDescriptor getImageDescriptor(String imageFilePath)
{
return Activator.imageDescriptorFromPlugin(BUNDLE_ID, imageFilePath);
@@ -42,11 +56,31 @@ public abstract class OM
/**
* @author Eike Stepper
*/
- public static final class Activator extends UIActivator
+ public static final class Activator extends UIActivator.WithState
{
public Activator()
{
super(BUNDLE);
}
+
+ @Override
+ protected void doStartWithState(Object state) throws Exception
+ {
+ LifecycleUtil.activate(adminManager);
+ if (state instanceof List<?>)
+ {
+ @SuppressWarnings("unchecked")
+ Collection<String> urls = (Collection<String>)state;
+ adminManager.addConnections(urls);
+ }
+ }
+
+ @Override
+ protected Object doStopWithState() throws Exception
+ {
+ List<String> urls = adminManager.getConnectionURLs();
+ LifecycleUtil.deactivate(adminManager);
+ return urls;
+ }
}
}
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/ControlChannel.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/ControlChannel.java
index d5fdf575ec..18ac3648ea 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/ControlChannel.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/ControlChannel.java
@@ -1,251 +1,257 @@
-/*
- * 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.net4j.internal.tcp;
-
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.connector.ConnectorException;
-import org.eclipse.net4j.internal.tcp.bundle.OM;
-import org.eclipse.net4j.internal.tcp.messages.Messages;
-import org.eclipse.net4j.protocol.IProtocol;
-import org.eclipse.net4j.util.ImplementationError;
-import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
-import org.eclipse.net4j.util.concurrent.ISynchronizer;
-import org.eclipse.net4j.util.concurrent.SynchronizingCorrelator;
-import org.eclipse.net4j.util.concurrent.TimeoutRuntimeException;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-import org.eclipse.net4j.util.security.INegotiationContext;
-import org.eclipse.net4j.util.security.INegotiationContext.Receiver;
-
-import org.eclipse.internal.net4j.buffer.BufferUtil;
-
-import org.eclipse.spi.net4j.Channel;
-import org.eclipse.spi.net4j.InternalChannel;
-import org.eclipse.spi.net4j.InternalChannelMultiplexer;
-
-import java.nio.ByteBuffer;
-import java.text.MessageFormat;
-
-/**
- * @author Eike Stepper
- */
-public class ControlChannel extends Channel
-{
- public static final short CONTROL_CHANNEL_INDEX = InternalChannelMultiplexer.RESERVED_CHANNEL;
-
- public static final byte OPCODE_NEGOTIATION = 1;
-
- public static final byte OPCODE_REGISTRATION = 2;
-
- public static final byte OPCODE_REGISTRATION_ACK = 3;
-
- public static final byte OPCODE_DEREGISTRATION = 4;
-
- public static final byte SUCCESS = 1;
-
- public static final byte FAILURE = 0;
-
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, ControlChannel.class);
-
- private SynchronizingCorrelator<Short, Boolean> acknowledgements = new SynchronizingCorrelator<Short, Boolean>();
-
- public ControlChannel(TCPConnector connector)
- {
- setID(CONTROL_CHANNEL_INDEX);
- setMultiplexer(connector);
- setReceiveExecutor(connector.getConfig().getReceiveExecutor());
- setUserID(connector.getUserID());
- }
-
- public TCPConnector getConnector()
- {
- return (TCPConnector)getMultiplexer();
- }
-
- public boolean registerChannel(short channelID, long timeout, IProtocol<?> protocol)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Registering channel {0} with protocol {1}", channelID, protocol); //$NON-NLS-1$
- }
-
- assertValidChannelID(channelID);
- ISynchronizer<Boolean> acknowledgement = acknowledgements.correlate(channelID);
-
- IBuffer buffer = provideBuffer();
- ByteBuffer byteBuffer = buffer.startPutting(CONTROL_CHANNEL_INDEX);
- byteBuffer.put(OPCODE_REGISTRATION);
- byteBuffer.putShort(channelID);
- BufferUtil.putUTF8(byteBuffer, protocol == null ? null : protocol.getType());
- handleBuffer(buffer);
-
- Boolean acknowledged = acknowledgement.get(timeout);
- if (acknowledged == null)
- {
- throw new TimeoutRuntimeException(MessageFormat.format(Messages.getString("ControlChannel_0"), timeout)); //$NON-NLS-1$
- }
-
- return acknowledged;
- }
-
- public void deregisterChannel(short channelID)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Deregistering channel {0}", channelID); //$NON-NLS-1$
- }
-
- assertValidChannelID(channelID);
- IBuffer buffer = provideBuffer();
- ByteBuffer byteBuffer = buffer.startPutting(CONTROL_CHANNEL_INDEX);
- byteBuffer.put(OPCODE_DEREGISTRATION);
- byteBuffer.putShort(channelID);
- handleBuffer(buffer);
- }
-
- @Override
- public void handleBufferFromMultiplexer(IBuffer buffer)
- {
- try
- {
- ByteBuffer byteBuffer = buffer.getByteBuffer();
- byte opcode = byteBuffer.get();
- switch (opcode)
- {
- case OPCODE_NEGOTIATION:
- {
- assertNegotiating();
- INegotiationContext negotiationContext = getConnector().getNegotiationContext();
- while (negotiationContext == null)
- {
- ConcurrencyUtil.sleep(20);
- negotiationContext = getConnector().getNegotiationContext();
- }
-
- Receiver receiver = negotiationContext.getReceiver();
- receiver.receiveBuffer(negotiationContext, byteBuffer);
- break;
- }
-
- case OPCODE_REGISTRATION:
- {
- assertConnected();
- short channelID = byteBuffer.getShort();
- assertValidChannelID(channelID);
- boolean success = true;
-
- try
- {
- byte[] handlerFactoryUTF8 = BufferUtil.getByteArray(byteBuffer);
- String protocolID = BufferUtil.fromUTF8(handlerFactoryUTF8);
- InternalChannel channel = getConnector().inverseOpenChannel(channelID, protocolID);
- if (channel == null)
- {
- throw new ConnectorException(Messages.getString("ControlChannel_4")); //$NON-NLS-1$
- }
- }
- catch (Exception ex)
- {
- OM.LOG.error(ex);
- success = false;
- }
-
- sendStatus(OPCODE_REGISTRATION_ACK, channelID, success);
- break;
- }
-
- case OPCODE_DEREGISTRATION:
- {
- assertConnected();
- short channelID = byteBuffer.getShort();
- if (channelID == CONTROL_CHANNEL_INDEX)
- {
- throw new ImplementationError();
- }
-
- try
- {
- getConnector().inverseCloseChannel(channelID);
- }
- catch (Exception ex)
- {
- OM.LOG.error(ex);
- }
-
- break;
- }
-
- case OPCODE_REGISTRATION_ACK:
- {
- assertConnected();
- short channelID = byteBuffer.getShort();
- boolean success = byteBuffer.get() == SUCCESS;
- acknowledgements.put(channelID, success);
- break;
- }
-
- default:
- OM.LOG.error("Invalid opcode: " + opcode); //$NON-NLS-1$
- getConnector().deactivate();
- }
- }
- finally
- {
- buffer.release();
- }
- }
-
- @Override
- public String toString()
- {
- return MessageFormat.format("Channel[Control, {0}]", getLocation()); //$NON-NLS-1$
- }
-
- @Override
- protected void unregisterFromMultiplexer()
- {
- // Do nothing
- }
-
- private void sendStatus(byte opcode, short channelID, boolean status)
- {
- IBuffer buffer = provideBuffer();
- ByteBuffer byteBuffer = buffer.startPutting(CONTROL_CHANNEL_INDEX);
- byteBuffer.put(opcode);
- byteBuffer.putShort(channelID);
- byteBuffer.put(status ? SUCCESS : FAILURE);
- handleBuffer(buffer);
- }
-
- private void assertNegotiating()
- {
- if (!getConnector().isNegotiating())
- {
- getConnector().deactivate();
- throw new IllegalStateException("Connector is not negotiating"); //$NON-NLS-1$
- }
- }
-
- private void assertConnected()
- {
- if (!getConnector().isConnected())
- {
- throw new IllegalStateException("Connector is not connected"); //$NON-NLS-1$
- }
- }
-
- private void assertValidChannelID(short channelID)
- {
- if (channelID == CONTROL_CHANNEL_INDEX)
- {
- throw new IllegalArgumentException("Bad channelID"); //$NON-NLS-1$
- }
- }
-}
+/*
+ * 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.net4j.internal.tcp;
+
+import org.eclipse.net4j.buffer.IBuffer;
+import org.eclipse.net4j.connector.ConnectorException;
+import org.eclipse.net4j.internal.tcp.bundle.OM;
+import org.eclipse.net4j.internal.tcp.messages.Messages;
+import org.eclipse.net4j.protocol.IProtocol;
+import org.eclipse.net4j.util.ImplementationError;
+import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
+import org.eclipse.net4j.util.concurrent.ISynchronizer;
+import org.eclipse.net4j.util.concurrent.SynchronizingCorrelator;
+import org.eclipse.net4j.util.concurrent.TimeoutRuntimeException;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+import org.eclipse.net4j.util.security.INegotiationContext;
+import org.eclipse.net4j.util.security.INegotiationContext.Receiver;
+
+import org.eclipse.internal.net4j.buffer.BufferUtil;
+
+import org.eclipse.spi.net4j.Channel;
+import org.eclipse.spi.net4j.InternalChannel;
+import org.eclipse.spi.net4j.InternalChannelMultiplexer;
+
+import java.nio.ByteBuffer;
+import java.text.MessageFormat;
+
+/**
+ * @author Eike Stepper
+ */
+public class ControlChannel extends Channel
+{
+ public static final short CONTROL_CHANNEL_INDEX = InternalChannelMultiplexer.RESERVED_CHANNEL;
+
+ public static final byte OPCODE_NEGOTIATION = 1;
+
+ public static final byte OPCODE_REGISTRATION = 2;
+
+ public static final byte OPCODE_REGISTRATION_ACK = 3;
+
+ public static final byte OPCODE_DEREGISTRATION = 4;
+
+ public static final byte SUCCESS = 1;
+
+ public static final byte FAILURE = 0;
+
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, ControlChannel.class);
+
+ private SynchronizingCorrelator<Short, Boolean> acknowledgements = new SynchronizingCorrelator<Short, Boolean>();
+
+ public ControlChannel(TCPConnector connector)
+ {
+ setID(CONTROL_CHANNEL_INDEX);
+ setMultiplexer(connector);
+ setReceiveExecutor(connector.getConfig().getReceiveExecutor());
+ setUserID(connector.getUserID());
+ }
+
+ public TCPConnector getConnector()
+ {
+ return (TCPConnector)getMultiplexer();
+ }
+
+ public boolean registerChannel(short channelID, long timeout, IProtocol<?> protocol)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Registering channel {0} with protocol {1}", channelID, protocol); //$NON-NLS-1$
+ }
+
+ assertValidChannelID(channelID);
+ ISynchronizer<Boolean> acknowledgement = acknowledgements.correlate(channelID);
+
+ IBuffer buffer = provideBuffer();
+ ByteBuffer byteBuffer = buffer.startPutting(CONTROL_CHANNEL_INDEX);
+ byteBuffer.put(OPCODE_REGISTRATION);
+ byteBuffer.putShort(channelID);
+ BufferUtil.putUTF8(byteBuffer, protocol == null ? null : protocol.getType());
+ handleBuffer(buffer);
+
+ Boolean acknowledged = acknowledgement.get(timeout);
+ if (acknowledged == null)
+ {
+ throw new TimeoutRuntimeException(MessageFormat.format(Messages.getString("ControlChannel_0"), timeout)); //$NON-NLS-1$
+ }
+
+ return acknowledged;
+ }
+
+ public void deregisterChannel(short channelID)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Deregistering channel {0}", channelID); //$NON-NLS-1$
+ }
+
+ assertValidChannelID(channelID);
+ IBuffer buffer = provideBuffer();
+ ByteBuffer byteBuffer = buffer.startPutting(CONTROL_CHANNEL_INDEX);
+ byteBuffer.put(OPCODE_DEREGISTRATION);
+ byteBuffer.putShort(channelID);
+ handleBuffer(buffer);
+ }
+
+ @Override
+ public void handleBufferFromMultiplexer(IBuffer buffer)
+ {
+ try
+ {
+ ByteBuffer byteBuffer = buffer.getByteBuffer();
+ byte opcode = byteBuffer.get();
+ switch (opcode)
+ {
+ case OPCODE_NEGOTIATION:
+ {
+ assertNegotiating();
+ INegotiationContext negotiationContext = getConnector().getNegotiationContext();
+ while (negotiationContext == null)
+ {
+ ConcurrencyUtil.sleep(20);
+ negotiationContext = getConnector().getNegotiationContext();
+ }
+
+ Receiver receiver = negotiationContext.getReceiver();
+ receiver.receiveBuffer(negotiationContext, byteBuffer);
+ break;
+ }
+
+ case OPCODE_REGISTRATION:
+ {
+ assertConnected();
+ short channelID = byteBuffer.getShort();
+ assertValidChannelID(channelID);
+ boolean success = true;
+
+ try
+ {
+ byte[] handlerFactoryUTF8 = BufferUtil.getByteArray(byteBuffer);
+ String protocolID = BufferUtil.fromUTF8(handlerFactoryUTF8);
+ InternalChannel channel = getConnector().inverseOpenChannel(channelID, protocolID);
+ if (channel == null)
+ {
+ throw new ConnectorException(Messages.getString("ControlChannel_4")); //$NON-NLS-1$
+ }
+ }
+ catch (Exception ex)
+ {
+ success = false;
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Problem during channel registration", ex); //$NON-NLS-1$
+ }
+ }
+
+ sendStatus(OPCODE_REGISTRATION_ACK, channelID, success);
+ break;
+ }
+
+ case OPCODE_DEREGISTRATION:
+ {
+ assertConnected();
+ short channelID = byteBuffer.getShort();
+ if (channelID == CONTROL_CHANNEL_INDEX)
+ {
+ throw new ImplementationError();
+ }
+
+ try
+ {
+ getConnector().inverseCloseChannel(channelID);
+ }
+ catch (Exception ex)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Problem during channel deregistration", ex); //$NON-NLS-1$
+ }
+ }
+
+ break;
+ }
+
+ case OPCODE_REGISTRATION_ACK:
+ {
+ assertConnected();
+ short channelID = byteBuffer.getShort();
+ boolean success = byteBuffer.get() == SUCCESS;
+ acknowledgements.put(channelID, success);
+ break;
+ }
+
+ default:
+ OM.LOG.error("Invalid opcode: " + opcode); //$NON-NLS-1$
+ getConnector().deactivate();
+ }
+ }
+ finally
+ {
+ buffer.release();
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format("Channel[Control, {0}]", getLocation()); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void unregisterFromMultiplexer()
+ {
+ // Do nothing
+ }
+
+ private void sendStatus(byte opcode, short channelID, boolean status)
+ {
+ IBuffer buffer = provideBuffer();
+ ByteBuffer byteBuffer = buffer.startPutting(CONTROL_CHANNEL_INDEX);
+ byteBuffer.put(opcode);
+ byteBuffer.putShort(channelID);
+ byteBuffer.put(status ? SUCCESS : FAILURE);
+ handleBuffer(buffer);
+ }
+
+ private void assertNegotiating()
+ {
+ if (!getConnector().isNegotiating())
+ {
+ getConnector().deactivate();
+ throw new IllegalStateException("Connector is not negotiating"); //$NON-NLS-1$
+ }
+ }
+
+ private void assertConnected()
+ {
+ if (!getConnector().isConnected())
+ {
+ throw new IllegalStateException("Connector is not connected"); //$NON-NLS-1$
+ }
+ }
+
+ private void assertValidChannelID(short channelID)
+ {
+ if (channelID == CONTROL_CHANNEL_INDEX)
+ {
+ throw new IllegalArgumentException("Bad channelID"); //$NON-NLS-1$
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.ui/META-INF/MANIFEST.MF
index 4b069b2d7a..62cb25c11d 100644
--- a/plugins/org.eclipse.net4j.ui/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.net4j.ui/META-INF/MANIFEST.MF
@@ -15,8 +15,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)",
org.eclipse.net4j.ui.shared;bundle-version="[4.0.0,5.0.0)",
org.eclipse.net4j.jvm;bundle-version="[4.0.0,5.0.0)";resolution:=optional,
org.eclipse.net4j.tcp;bundle-version="[4.0.0,5.0.0)";resolution:=optional
-Export-Package: org.eclipse.net4j.ui;version="4.1.0",
- org.eclipse.net4j.internal.ui.bundle;version="4.1.0";x-internal:=true,
+Export-Package: org.eclipse.net4j.internal.ui.bundle;version="4.1.0";x-internal:=true,
org.eclipse.net4j.internal.ui.container;version="4.1.0";x-internal:=true,
org.eclipse.net4j.internal.ui.messages;version="4.1.0";x-internal:=true,
- org.eclipse.net4j.internal.ui.views;version="4.1.0";x-friends:="org.eclipse.net4j.ui.defs"
+ org.eclipse.net4j.internal.ui.views;version="4.1.0";x-friends:="org.eclipse.net4j.ui.defs,org.eclipse.emf.cdo.ui.admin",
+ org.eclipse.net4j.ui;version="4.1.0"
diff --git a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/views/AcceptorsView.java b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/views/AcceptorsView.java
index 759cad3a73..45e9aabee2 100644
--- a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/views/AcceptorsView.java
+++ b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/views/AcceptorsView.java
@@ -24,6 +24,7 @@ import org.eclipse.net4j.util.ui.views.IElementFilter;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.spi.net4j.AcceptorFactory;
+import org.eclipse.swt.widgets.Shell;
/**
* @author Eike Stepper
@@ -32,47 +33,7 @@ public class AcceptorsView extends ContainerView
{
public final static String ID = "org.eclipse.net4j.AcceptorsView"; //$NON-NLS-1$
- private IAction newAcceptorAction = new ElementWizardAction(getShell(), "New Acceptor", "Open a new acceptor",
- SharedIcons.getDescriptor(SharedIcons.ETOOL_ADD_ACCEPTOR), AcceptorFactory.PRODUCT_GROUP, getContainer(), "tcp")
- {
- @Override
- public String getDefaultDescription(String factoryType)
- {
- if ("jvm".equals(factoryType))
- {
- return "default";
- }
-
- if ("tcp".equals(factoryType))
- {
- return "0.0.0.0:2036";
- }
-
- return null;
- }
- };
-
- // private Action addAcceptorAction2036 = new SafeAction(Messages.getString("AcceptorsView_0"), //$NON-NLS-1$
- // Messages.getString("AcceptorsView_1"), //$NON-NLS-1$
- // getAddImageDescriptor())
- // {
- // @Override
- // protected void safeRun() throws Exception
- // {
- // Net4jUtil.getAcceptor(IPluginContainer.INSTANCE, "tcp", "0.0.0.0:2036"); //$NON-NLS-1$ //$NON-NLS-2$
- // }
- // };
- //
- // private Action addAcceptorAction2037 = new SafeAction(Messages.getString("AcceptorsView_4"),
- // Messages.getString("AcceptorsView_5"), //$NON-NLS-1$
- // getAddImageDescriptor())
- // {
- // @Override
- // protected void safeRun() throws Exception
- // {
- // Net4jUtil.getAcceptor(IPluginContainer.INSTANCE, "tcp", "0.0.0.0:2037"); //$NON-NLS-1$ //$NON-NLS-2$
- // }
- // };
+ private IAction newAcceptorAction;
public AcceptorsView()
{
@@ -99,7 +60,35 @@ public class AcceptorsView extends ContainerView
@Override
protected void fillLocalToolBar(IToolBarManager manager)
{
+ if (newAcceptorAction == null)
+ {
+ newAcceptorAction = createNewAcceptorAction(getShell(), getContainer());
+ }
+
manager.add(newAcceptorAction);
super.fillLocalToolBar(manager);
}
+
+ public static ElementWizardAction createNewAcceptorAction(Shell shell, IManagedContainer container)
+ {
+ return new ElementWizardAction(shell, "New Acceptor", "Open a new acceptor",
+ SharedIcons.getDescriptor(SharedIcons.ETOOL_ADD_ACCEPTOR), AcceptorFactory.PRODUCT_GROUP, container, "tcp")
+ {
+ @Override
+ public String getDefaultDescription(String factoryType)
+ {
+ if ("jvm".equals(factoryType))
+ {
+ return "default";
+ }
+
+ if ("tcp".equals(factoryType))
+ {
+ return "0.0.0.0:2036";
+ }
+
+ return null;
+ }
+ };
+ }
}
diff --git a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/views/ConnectorsView.java b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/views/ConnectorsView.java
index 699e7251bb..078269a37f 100644
--- a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/views/ConnectorsView.java
+++ b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/internal/ui/views/ConnectorsView.java
@@ -24,6 +24,7 @@ import org.eclipse.net4j.util.ui.views.IElementFilter;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.spi.net4j.ConnectorFactory;
+import org.eclipse.swt.widgets.Shell;
/**
* @author Eike Stepper
@@ -32,25 +33,7 @@ public class ConnectorsView extends ContainerView
{
public final static String ID = "org.eclipse.net4j.ConnectorsView"; //$NON-NLS-1$
- private IAction newConnectorAction = new ElementWizardAction(getShell(), "New Connector", "Open a new connector",
- SharedIcons.getDescriptor(SharedIcons.ETOOL_ADD_CONNECTOR), ConnectorFactory.PRODUCT_GROUP, getContainer(), "tcp")
- {
- @Override
- public String getDefaultDescription(String factoryType)
- {
- if ("jvm".equals(factoryType))
- {
- return "default";
- }
-
- if ("tcp".equals(factoryType))
- {
- return "localhost";
- }
-
- return null;
- }
- };
+ private IAction newConnectorAction;
public ConnectorsView()
{
@@ -77,7 +60,35 @@ public class ConnectorsView extends ContainerView
@Override
protected void fillLocalToolBar(IToolBarManager manager)
{
+ if (newConnectorAction == null)
+ {
+ newConnectorAction = createNewConnectorAction(getShell(), getContainer());
+ }
+
manager.add(newConnectorAction);
super.fillLocalToolBar(manager);
}
+
+ public static ElementWizardAction createNewConnectorAction(Shell shell, IManagedContainer container)
+ {
+ return new ElementWizardAction(shell, "New Connector", "Open a new connector",
+ SharedIcons.getDescriptor(SharedIcons.ETOOL_ADD_CONNECTOR), ConnectorFactory.PRODUCT_GROUP, container, "tcp")
+ {
+ @Override
+ public String getDefaultDescription(String factoryType)
+ {
+ if ("jvm".equals(factoryType))
+ {
+ return "default";
+ }
+
+ if ("tcp".equals(factoryType))
+ {
+ return "localhost";
+ }
+
+ return null;
+ }
+ };
+ }
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/ParallelRunner.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/ParallelRunner.java
new file mode 100644
index 0000000000..0c3769f5a3
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/ParallelRunner.java
@@ -0,0 +1,67 @@
+/*
+ * 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.net4j.util.concurrent;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * A {@link ArrayList list} of {@link Runnable runnables} that can be run in parallel.
+ *
+ * @since 3.2
+ * @author Eike Stepper
+ */
+public class ParallelRunner extends ArrayList<Runnable>
+{
+ private static final long serialVersionUID = 1L;
+
+ public ParallelRunner()
+ {
+ }
+
+ public ParallelRunner(Collection<? extends Runnable> c)
+ {
+ super(c);
+ }
+
+ public ParallelRunner(int initialCapacity)
+ {
+ super(initialCapacity);
+ }
+
+ public void run(ExecutorService executorService, long timeout) throws InterruptedException
+ {
+ final CountDownLatch latch = new CountDownLatch(size());
+
+ for (final Runnable runnable : this)
+ {
+ executorService.submit(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ runnable.run();
+ }
+ finally
+ {
+ latch.countDown();
+ }
+ }
+ });
+ }
+
+ latch.await(timeout, TimeUnit.MILLISECONDS);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/Stoppable.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/Stoppable.java
new file mode 100644
index 0000000000..1a8896f786
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/Stoppable.java
@@ -0,0 +1,59 @@
+/*
+ * 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.net4j.util.concurrent;
+
+import org.eclipse.net4j.internal.util.bundle.OM;
+
+/**
+ * A {@link Runnable runnable} that can be {@link #stop() stopped}.
+ *
+ * @since 3.2
+ * @author Eike Stepper
+ */
+public abstract class Stoppable implements Runnable
+{
+ private boolean stopped;
+
+ public Stoppable()
+ {
+ }
+
+ public final boolean isStopped()
+ {
+ return stopped;
+ }
+
+ public final void stop()
+ {
+ stopped = true;
+ }
+
+ public final void run()
+ {
+ while (!isStopped())
+ {
+ try
+ {
+ doRun();
+ }
+ catch (InterruptedException ex)
+ {
+ stop();
+ }
+ catch (Throwable t)
+ {
+ OM.LOG.error(t);
+ }
+ }
+ }
+
+ protected abstract void doRun() throws InterruptedException;
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/SetContainer.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/SetContainer.java
index a7a3833c5a..34ba925531 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/SetContainer.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/SetContainer.java
@@ -10,6 +10,7 @@
*/
package org.eclipse.net4j.util.container;
+import org.eclipse.net4j.util.container.IContainerDelta.Kind;
import org.eclipse.net4j.util.container.delegate.IContainerSet;
import org.eclipse.net4j.util.container.delegate.IContainerSortedSet;
@@ -31,8 +32,6 @@ public class SetContainer<E> extends Container<E>
private final Set<E> set;
- private E[] array;
-
public SetContainer(Class<E> componentType)
{
this(componentType, new HashSet<E>());
@@ -59,16 +58,33 @@ public class SetContainer<E> extends Container<E>
public synchronized E[] getElements()
{
checkActive();
- if (array == null)
+
+ @SuppressWarnings("unchecked")
+ E[] a = (E[])Array.newInstance(componentType, set.size());
+
+ E[] array = set.toArray(a);
+ array = sortElements(array);
+
+ return array;
+ }
+
+ public void clear()
+ {
+ ContainerEvent<E> event = new ContainerEvent<E>(this);
+ synchronized (this)
{
- @SuppressWarnings("unchecked")
- E[] a = (E[])Array.newInstance(componentType, set.size());
+ for (E element : set)
+ {
+ if (set.remove(element))
+ {
+ event.addDelta(element, Kind.REMOVED);
+ }
+ }
- array = set.toArray(a);
- array = sortElements(array);
+ notifyAll();
}
- return array;
+ fireEvent(event);
}
public boolean addElement(E element)
@@ -82,11 +98,6 @@ public class SetContainer<E> extends Container<E>
}
added = set.add(element);
- if (added)
- {
- array = null;
- }
-
notifyAll();
}
@@ -104,11 +115,6 @@ public class SetContainer<E> extends Container<E>
synchronized (this)
{
removed = set.remove(element);
- if (removed)
- {
- array = null;
- }
-
notifyAll();
}

Back to the top