Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-06-03 08:08:27 +0000
committerEike Stepper2012-06-03 08:08:27 +0000
commit16393578f04212585befb46905d135839f54f557 (patch)
tree6b25a66b5b34b9e5fc754ad6fea677ad4eba5ca2 /plugins
parent67f3b30c6f26881dad8ce4a36e7a50c14bf5c9b3 (diff)
downloadcdo-16393578f04212585befb46905d135839f54f557.tar.gz
cdo-16393578f04212585befb46905d135839f54f557.tar.xz
cdo-16393578f04212585befb46905d135839f54f557.zip
[381472] Design a repository administration API
https://bugs.eclipse.org/bugs/show_bug.cgi?id=381472
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.admin/.options1
-rw-r--r--plugins/org.eclipse.emf.cdo.admin/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClient.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClientRepository.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/bundle/OM.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/CDOAdminClientProtocol.java (renamed from plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClientProtocol.java)3
-rw-r--r--plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/CreateRepositoryRequest.java (renamed from plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CreateRepositoryRequest.java)2
-rw-r--r--plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/DeleteRepositoryRequest.java (renamed from plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/DeleteRepositoryRequest.java)2
-rw-r--r--plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/QueryRepositoriesRequest.java (renamed from plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/QueryRepositoriesRequest.java)17
-rw-r--r--plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/RepositoryAddedIndication.java (renamed from plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/RepositoryAddedIndication.java)4
-rw-r--r--plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/RepositoryRemovedIndication.java (renamed from plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/RepositoryRemovedIndication.java)3
-rw-r--r--plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/RepositoryStateChangedIndication.java (renamed from plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/RepositoryStateChangedIndication.java)3
-rw-r--r--plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/RepositoryTypeChangedIndication.java (renamed from plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/RepositoryTypeChangedIndication.java)3
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/admin/CDOAdmin.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/admin/AbstractCDOAdmin.java47
-rw-r--r--plugins/org.eclipse.emf.cdo.server.admin/.options1
-rw-r--r--plugins/org.eclipse.emf.cdo.server.admin/META-INF/MANIFEST.MF4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.admin/plugin.xml2
-rw-r--r--plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/admin/CDOAdminServerUtil.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/CDOAdminServer.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/bundle/OM.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/protocol/CDOAdminServerProtocol.java (renamed from plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/CDOAdminServerProtocol.java)8
-rw-r--r--plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/protocol/CreateRepositoryIndication.java (renamed from plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/CreateRepositoryIndication.java)3
-rw-r--r--plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/protocol/DeleteRepositoryIndication.java (renamed from plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/DeleteRepositoryIndication.java)4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/protocol/QueryRepositoriesIndication.java (renamed from plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/QueryRepositoriesIndication.java)27
-rw-r--r--plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/protocol/RepositoryAddedRequest.java (renamed from plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/RepositoryAddedRequest.java)3
-rw-r--r--plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/protocol/RepositoryRemovedRequest.java (renamed from plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/RepositoryRemovedRequest.java)4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/protocol/RepositoryStateChangedRequest.java (renamed from plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/RepositoryStateChangedRequest.java)2
-rw-r--r--plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/protocol/RepositoryTypeChangedRequest.java (renamed from plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/RepositoryTypeChangedRequest.java)2
-rw-r--r--plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/spi/admin/CDOAdminHandler.java (renamed from plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/admin/CDOAdminHandler.java)2
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/CDOServerUtil.java612
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_381472_Test.java565
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/IRepositoryConfig.java107
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java7
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/SessionConfig.java1142
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/ManagedContainer.java1336
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/SetContainer.java19
37 files changed, 2306 insertions, 1652 deletions
diff --git a/plugins/org.eclipse.emf.cdo.admin/.options b/plugins/org.eclipse.emf.cdo.admin/.options
index b94e99b109..a8d4aa029a 100644
--- a/plugins/org.eclipse.emf.cdo.admin/.options
+++ b/plugins/org.eclipse.emf.cdo.admin/.options
@@ -1,3 +1,4 @@
# Debugging and tracing options
org.eclipse.emf.cdo.admin/debug = true
+org.eclipse.emf.cdo.admin/debug.protocol = true
diff --git a/plugins/org.eclipse.emf.cdo.admin/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.admin/META-INF/MANIFEST.MF
index 1da02bfcd1..caefc6c6aa 100644
--- a/plugins/org.eclipse.emf.cdo.admin/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.admin/META-INF/MANIFEST.MF
@@ -17,5 +17,6 @@ Export-Package: org.eclipse.emf.cdo.admin;version="4.1.0",
org.eclipse.emf.cdo.defs,
org.eclipse.emf.cdo.ui,
org.eclipse.emf.cdo.examples",
- org.eclipse.emf.cdo.internal.admin.bundle;version="4.1.0";x-friends:="org.eclipse.emf.cdo.tests"
+ org.eclipse.emf.cdo.internal.admin.bundle;version="4.1.0";x-friends:="org.eclipse.emf.cdo.tests",
+ org.eclipse.emf.cdo.internal.admin.protocol;version="4.1.0";x-internal:=true
Bundle-ActivationPolicy: lazy
diff --git a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClient.java b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClient.java
index dc14b2c137..9e52167ef4 100644
--- a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClient.java
+++ b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClient.java
@@ -12,6 +12,7 @@ package org.eclipse.emf.cdo.internal.admin;
import org.eclipse.emf.cdo.common.CDOCommonRepository.State;
import org.eclipse.emf.cdo.common.CDOCommonRepository.Type;
+import org.eclipse.emf.cdo.internal.admin.protocol.CDOAdminClientProtocol;
import org.eclipse.emf.cdo.spi.common.admin.AbstractCDOAdmin;
import org.eclipse.net4j.connector.IConnector;
diff --git a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClientRepository.java b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClientRepository.java
index b00694e944..211fd30d90 100644
--- a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClientRepository.java
+++ b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClientRepository.java
@@ -160,6 +160,12 @@ public class CDOAdminClientRepository extends Notifier implements CDOAdminReposi
return admin.deleteRepository(this, type);
}
+ @Override
+ public String toString()
+ {
+ return name;
+ }
+
public void typeChanged(Type oldType, Type newType)
{
type = newType;
diff --git a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/bundle/OM.java b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/bundle/OM.java
index 54a3476607..3d254b9f95 100644
--- a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/bundle/OM.java
+++ b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/bundle/OM.java
@@ -29,6 +29,8 @@ public abstract class OM
public static final OMTracer DEBUG = BUNDLE.tracer("debug"); //$NON-NLS-1$
+ public static final OMTracer DEBUG_PROTOCOL = DEBUG.tracer("protocol"); //$NON-NLS-1$
+
public static final OMLogger LOG = BUNDLE.logger();
/**
diff --git a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClientProtocol.java b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/CDOAdminClientProtocol.java
index 853242b40a..ccbed1981d 100644
--- a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CDOAdminClientProtocol.java
+++ b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/CDOAdminClientProtocol.java
@@ -8,10 +8,11 @@
* Contributors:
* Eike Stepper - initial API and implementation
*/
-package org.eclipse.emf.cdo.internal.admin;
+package org.eclipse.emf.cdo.internal.admin.protocol;
import org.eclipse.emf.cdo.common.admin.CDOAdminRepository;
import org.eclipse.emf.cdo.common.util.TransportException;
+import org.eclipse.emf.cdo.internal.admin.CDOAdminClient;
import org.eclipse.emf.cdo.spi.common.admin.CDOAdminProtocolConstants;
import org.eclipse.net4j.signal.RequestWithConfirmation;
diff --git a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CreateRepositoryRequest.java b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/CreateRepositoryRequest.java
index 16ea3c8f95..224bb80c84 100644
--- a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/CreateRepositoryRequest.java
+++ b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/CreateRepositoryRequest.java
@@ -8,7 +8,7 @@
* Contributors:
* Eike Stepper - initial API and implementation
*/
-package org.eclipse.emf.cdo.internal.admin;
+package org.eclipse.emf.cdo.internal.admin.protocol;
import org.eclipse.emf.cdo.spi.common.admin.CDOAdminProtocolConstants;
diff --git a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/DeleteRepositoryRequest.java b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/DeleteRepositoryRequest.java
index 9be9369060..8474aede23 100644
--- a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/DeleteRepositoryRequest.java
+++ b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/DeleteRepositoryRequest.java
@@ -8,7 +8,7 @@
* Contributors:
* Eike Stepper - initial API and implementation
*/
-package org.eclipse.emf.cdo.internal.admin;
+package org.eclipse.emf.cdo.internal.admin.protocol;
import org.eclipse.emf.cdo.spi.common.admin.CDOAdminProtocolConstants;
diff --git a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/QueryRepositoriesRequest.java b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/QueryRepositoriesRequest.java
index 60d06aeaac..ed521a323f 100644
--- a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/QueryRepositoriesRequest.java
+++ b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/QueryRepositoriesRequest.java
@@ -8,14 +8,18 @@
* Contributors:
* Eike Stepper - initial API and implementation
*/
-package org.eclipse.emf.cdo.internal.admin;
+package org.eclipse.emf.cdo.internal.admin.protocol;
import org.eclipse.emf.cdo.common.admin.CDOAdminRepository;
+import org.eclipse.emf.cdo.internal.admin.CDOAdminClient;
+import org.eclipse.emf.cdo.internal.admin.CDOAdminClientRepository;
+import org.eclipse.emf.cdo.internal.admin.bundle.OM;
import org.eclipse.emf.cdo.spi.common.admin.CDOAdminProtocolConstants;
import org.eclipse.net4j.signal.RequestWithConfirmation;
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.Set;
@@ -24,6 +28,8 @@ import java.util.Set;
*/
public class QueryRepositoriesRequest extends RequestWithConfirmation<Object>
{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_PROTOCOL, QueryRepositoriesRequest.class);
+
private Set<CDOAdminRepository> result;
public QueryRepositoriesRequest(CDOAdminClientProtocol protocol, Set<CDOAdminRepository> result)
@@ -45,10 +51,19 @@ public class QueryRepositoriesRequest extends RequestWithConfirmation<Object>
CDOAdminClient admin = protocol.getInfraStructure();
int size = in.readInt();
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Reading {0} repository infos...", size); //$NON-NLS-1$
+ }
+
for (int i = 0; i < size; i++)
{
CDOAdminClientRepository repository = new CDOAdminClientRepository(admin, in);
result.add(repository);
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Read repository info for {0}", repository.getName()); //$NON-NLS-1$
+ }
}
return null;
diff --git a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/RepositoryAddedIndication.java b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/RepositoryAddedIndication.java
index 6a02f8cf66..4e0b8f373e 100644
--- a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/RepositoryAddedIndication.java
+++ b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/RepositoryAddedIndication.java
@@ -8,8 +8,10 @@
* Contributors:
* Eike Stepper - initial API and implementation
*/
-package org.eclipse.emf.cdo.internal.admin;
+package org.eclipse.emf.cdo.internal.admin.protocol;
+import org.eclipse.emf.cdo.internal.admin.CDOAdminClient;
+import org.eclipse.emf.cdo.internal.admin.CDOAdminClientRepository;
import org.eclipse.emf.cdo.spi.common.admin.CDOAdminProtocolConstants;
import org.eclipse.net4j.signal.Indication;
diff --git a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/RepositoryRemovedIndication.java b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/RepositoryRemovedIndication.java
index 7febee7509..cbf91dcda3 100644
--- a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/RepositoryRemovedIndication.java
+++ b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/RepositoryRemovedIndication.java
@@ -8,9 +8,10 @@
* Contributors:
* Eike Stepper - initial API and implementation
*/
-package org.eclipse.emf.cdo.internal.admin;
+package org.eclipse.emf.cdo.internal.admin.protocol;
import org.eclipse.emf.cdo.common.admin.CDOAdminRepository;
+import org.eclipse.emf.cdo.internal.admin.CDOAdminClient;
import org.eclipse.emf.cdo.spi.common.admin.CDOAdminProtocolConstants;
import org.eclipse.net4j.signal.Indication;
diff --git a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/RepositoryStateChangedIndication.java b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/RepositoryStateChangedIndication.java
index 92cba22826..64d4bc64c5 100644
--- a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/RepositoryStateChangedIndication.java
+++ b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/RepositoryStateChangedIndication.java
@@ -8,9 +8,10 @@
* Contributors:
* Eike Stepper - initial API and implementation
*/
-package org.eclipse.emf.cdo.internal.admin;
+package org.eclipse.emf.cdo.internal.admin.protocol;
import org.eclipse.emf.cdo.common.CDOCommonRepository.State;
+import org.eclipse.emf.cdo.internal.admin.CDOAdminClient;
import org.eclipse.emf.cdo.spi.common.admin.CDOAdminProtocolConstants;
import org.eclipse.net4j.signal.Indication;
diff --git a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/RepositoryTypeChangedIndication.java b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/RepositoryTypeChangedIndication.java
index 356ccebce8..0315712b60 100644
--- a/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/RepositoryTypeChangedIndication.java
+++ b/plugins/org.eclipse.emf.cdo.admin/src/org/eclipse/emf/cdo/internal/admin/protocol/RepositoryTypeChangedIndication.java
@@ -8,9 +8,10 @@
* Contributors:
* Eike Stepper - initial API and implementation
*/
-package org.eclipse.emf.cdo.internal.admin;
+package org.eclipse.emf.cdo.internal.admin.protocol;
import org.eclipse.emf.cdo.common.CDOCommonRepository.Type;
+import org.eclipse.emf.cdo.internal.admin.CDOAdminClient;
import org.eclipse.emf.cdo.spi.common.admin.CDOAdminProtocolConstants;
import org.eclipse.net4j.signal.Indication;
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/admin/CDOAdmin.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/admin/CDOAdmin.java
index cfcad78191..a24deecfdd 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/admin/CDOAdmin.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/admin/CDOAdmin.java
@@ -28,4 +28,6 @@ public interface CDOAdmin extends IContainer<CDOAdminRepository>, Closeable
public CDOAdminRepository getRepository(String name);
public CDOAdminRepository createRepository(String name, String type, Map<String, Object> properties);
+
+ public CDOAdminRepository waitForRepository(String name);
}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/admin/AbstractCDOAdmin.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/admin/AbstractCDOAdmin.java
index 57facbd418..dc0be20195 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/admin/AbstractCDOAdmin.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/admin/AbstractCDOAdmin.java
@@ -14,9 +14,12 @@ import org.eclipse.emf.cdo.common.admin.CDOAdmin;
import org.eclipse.emf.cdo.common.admin.CDOAdminRepository;
import org.eclipse.net4j.util.ObjectUtil;
+import org.eclipse.net4j.util.WrappedException;
import org.eclipse.net4j.util.concurrent.TimeoutRuntimeException;
import org.eclipse.net4j.util.container.SetContainer;
+import java.util.Arrays;
+import java.util.Comparator;
import java.util.Map;
/**
@@ -66,17 +69,11 @@ public abstract class AbstractCDOAdmin extends SetContainer<CDOAdminRepository>
return null;
}
- public CDOAdminRepository createRepository(String name, String type, Map<String, Object> properties)
+ public CDOAdminRepository waitForRepository(String name)
{
checkActive();
-
synchronized (this)
{
- if (!doCreateRepository(name, type, properties))
- {
- return null;
- }
-
long end = System.currentTimeMillis() + timeout;
while (System.currentTimeMillis() < end)
{
@@ -92,7 +89,7 @@ public abstract class AbstractCDOAdmin extends SetContainer<CDOAdminRepository>
}
catch (InterruptedException ex)
{
- return null;
+ throw WrappedException.wrap(ex);
}
}
@@ -100,6 +97,20 @@ public abstract class AbstractCDOAdmin extends SetContainer<CDOAdminRepository>
}
}
+ public CDOAdminRepository createRepository(String name, String type, Map<String, Object> properties)
+ {
+ checkActive();
+ synchronized (this)
+ {
+ if (!doCreateRepository(name, type, properties))
+ {
+ return null;
+ }
+
+ return waitForRepository(name);
+ }
+ }
+
public boolean deleteRepository(CDOAdminRepository repository, String type)
{
checkActive();
@@ -134,6 +145,26 @@ public abstract class AbstractCDOAdmin extends SetContainer<CDOAdminRepository>
}
}
+ @Override
+ protected CDOAdminRepository[] sortElements(CDOAdminRepository[] array)
+ {
+ Arrays.sort(array, new Comparator<CDOAdminRepository>()
+ {
+ public int compare(CDOAdminRepository r1, CDOAdminRepository r2)
+ {
+ return r1.getName().compareTo(r2.getName());
+ }
+ });
+
+ return array;
+ }
+
+ @Override
+ protected boolean validateElement(CDOAdminRepository repository)
+ {
+ return getRepository(repository.getName()) == null;
+ }
+
protected abstract boolean doCreateRepository(String name, String type, Map<String, Object> properties);
protected abstract boolean doDeleteRepository(String name, String type);
diff --git a/plugins/org.eclipse.emf.cdo.server.admin/.options b/plugins/org.eclipse.emf.cdo.server.admin/.options
index ecd4dd90e6..1f4b543a10 100644
--- a/plugins/org.eclipse.emf.cdo.server.admin/.options
+++ b/plugins/org.eclipse.emf.cdo.server.admin/.options
@@ -1,3 +1,4 @@
# Debugging and tracing options
org.eclipse.emf.cdo.server.admin/debug = true
+org.eclipse.emf.cdo.server.admin/debug.protocol = true
diff --git a/plugins/org.eclipse.emf.cdo.server.admin/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.server.admin/META-INF/MANIFEST.MF
index f3342cd6ef..031def5f7c 100644
--- a/plugins/org.eclipse.emf.cdo.server.admin/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.server.admin/META-INF/MANIFEST.MF
@@ -14,4 +14,6 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)";resoluti
org.eclipse.net4j;bundle-version="[4.0.0,5.0.0)";visibility:=reexport
Export-Package: org.eclipse.emf.cdo.server.admin;version="4.1.0",
org.eclipse.emf.cdo.server.internal.admin;version="4.1.0";x-internal:=true,
- org.eclipse.emf.cdo.server.internal.admin.bundle;version="4.1.0";x-internal:=true
+ org.eclipse.emf.cdo.server.internal.admin.bundle;version="4.1.0";x-internal:=true,
+ org.eclipse.emf.cdo.server.internal.admin.protocol;version="4.1.0";x-internal:=true,
+ org.eclipse.emf.cdo.server.spi.admin;version="4.1.0"
diff --git a/plugins/org.eclipse.emf.cdo.server.admin/plugin.xml b/plugins/org.eclipse.emf.cdo.server.admin/plugin.xml
index 71c05fceee..b98a3aa1a1 100644
--- a/plugins/org.eclipse.emf.cdo.server.admin/plugin.xml
+++ b/plugins/org.eclipse.emf.cdo.server.admin/plugin.xml
@@ -17,7 +17,7 @@
<factory
productGroup="org.eclipse.net4j.serverProtocols"
type="cdo-admin"
- class="org.eclipse.emf.cdo.server.internal.admin.CDOAdminServerProtocol$Factory$Plugin"/>
+ class="org.eclipse.emf.cdo.server.internal.admin.protocol.CDOAdminServerProtocol$Factory$Plugin"/>
<factory
productGroup="org.eclipse.emf.cdo.server.admin.adminServers"
type="default"
diff --git a/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/admin/CDOAdminServerUtil.java b/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/admin/CDOAdminServerUtil.java
index a9d96a6802..0c5d86938d 100644
--- a/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/admin/CDOAdminServerUtil.java
+++ b/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/admin/CDOAdminServerUtil.java
@@ -10,7 +10,8 @@
*/
package org.eclipse.emf.cdo.server.admin;
-import org.eclipse.emf.cdo.server.internal.admin.CDOAdminServerProtocol;
+import org.eclipse.emf.cdo.server.internal.admin.CDOAdminServer;
+import org.eclipse.emf.cdo.server.internal.admin.protocol.CDOAdminServerProtocol;
import org.eclipse.net4j.util.container.IManagedContainer;
@@ -27,6 +28,7 @@ public final class CDOAdminServerUtil
public static void prepareContainer(IManagedContainer container, IManagedContainer repositoriesContainer)
{
+ container.registerFactory(new CDOAdminServer.Factory(repositoriesContainer));
container.registerFactory(new CDOAdminServerProtocol.Factory(repositoriesContainer));
}
diff --git a/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/CDOAdminServer.java b/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/CDOAdminServer.java
index cae3e82cda..4d7eb6562f 100644
--- a/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/CDOAdminServer.java
+++ b/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/CDOAdminServer.java
@@ -14,8 +14,9 @@ import org.eclipse.emf.cdo.common.CDOCommonRepository.State;
import org.eclipse.emf.cdo.common.CDOCommonRepository.Type;
import org.eclipse.emf.cdo.server.CDOServerUtil;
import org.eclipse.emf.cdo.server.IRepository;
-import org.eclipse.emf.cdo.server.admin.CDOAdminHandler;
import org.eclipse.emf.cdo.server.internal.admin.bundle.OM;
+import org.eclipse.emf.cdo.server.internal.admin.protocol.CDOAdminServerProtocol;
+import org.eclipse.emf.cdo.server.spi.admin.CDOAdminHandler;
import org.eclipse.emf.cdo.spi.common.admin.AbstractCDOAdmin;
import org.eclipse.emf.cdo.spi.server.RepositoryFactory;
diff --git a/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/bundle/OM.java b/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/bundle/OM.java
index 2e964bfb17..c3c8710fcb 100644
--- a/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/bundle/OM.java
+++ b/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/bundle/OM.java
@@ -29,6 +29,8 @@ public abstract class OM
public static final OMTracer DEBUG = BUNDLE.tracer("debug"); //$NON-NLS-1$
+ public static final OMTracer DEBUG_PROTOCOL = DEBUG.tracer("protocol"); //$NON-NLS-1$
+
public static final OMLogger LOG = BUNDLE.logger();
/**
diff --git a/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/CDOAdminServerProtocol.java b/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/protocol/CDOAdminServerProtocol.java
index 5fb7a3d2ff..a479852740 100644
--- a/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/CDOAdminServerProtocol.java
+++ b/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/protocol/CDOAdminServerProtocol.java
@@ -8,10 +8,12 @@
* Contributors:
* Eike Stepper - initial API and implementation
*/
-package org.eclipse.emf.cdo.server.internal.admin;
+package org.eclipse.emf.cdo.server.internal.admin.protocol;
import org.eclipse.emf.cdo.common.CDOCommonRepository.State;
import org.eclipse.emf.cdo.common.CDOCommonRepository.Type;
+import org.eclipse.emf.cdo.server.internal.admin.CDOAdminServer;
+import org.eclipse.emf.cdo.server.internal.admin.CDOAdminServerRepository;
import org.eclipse.emf.cdo.spi.common.admin.CDOAdminProtocolConstants;
import org.eclipse.net4j.signal.SignalProtocol;
@@ -83,10 +85,10 @@ public class CDOAdminServerProtocol extends SignalProtocol<CDOAdminServer>
return new QueryRepositoriesIndication(this);
case CDOAdminProtocolConstants.SIGNAL_CREATE_REPOSITORY:
- return new QueryRepositoriesIndication(this);
+ return new CreateRepositoryIndication(this);
case CDOAdminProtocolConstants.SIGNAL_DELETE_REPOSITORY:
- return new QueryRepositoriesIndication(this);
+ return new DeleteRepositoryIndication(this);
default:
return super.createSignalReactor(signalID);
diff --git a/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/CreateRepositoryIndication.java b/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/protocol/CreateRepositoryIndication.java
index e30edb22d8..69dd58c5b8 100644
--- a/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/CreateRepositoryIndication.java
+++ b/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/protocol/CreateRepositoryIndication.java
@@ -8,9 +8,10 @@
* Contributors:
* Eike Stepper - initial API and implementation
*/
-package org.eclipse.emf.cdo.server.internal.admin;
+package org.eclipse.emf.cdo.server.internal.admin.protocol;
import org.eclipse.emf.cdo.common.admin.CDOAdminRepository;
+import org.eclipse.emf.cdo.server.internal.admin.CDOAdminServer;
import org.eclipse.emf.cdo.spi.common.admin.CDOAdminProtocolConstants;
import org.eclipse.net4j.signal.IndicationWithResponse;
diff --git a/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/DeleteRepositoryIndication.java b/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/protocol/DeleteRepositoryIndication.java
index c5d82b3bc4..9696749acb 100644
--- a/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/DeleteRepositoryIndication.java
+++ b/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/protocol/DeleteRepositoryIndication.java
@@ -8,8 +8,10 @@
* Contributors:
* Eike Stepper - initial API and implementation
*/
-package org.eclipse.emf.cdo.server.internal.admin;
+package org.eclipse.emf.cdo.server.internal.admin.protocol;
+import org.eclipse.emf.cdo.server.internal.admin.CDOAdminServer;
+import org.eclipse.emf.cdo.server.internal.admin.CDOAdminServerRepository;
import org.eclipse.emf.cdo.spi.common.admin.CDOAdminProtocolConstants;
import org.eclipse.net4j.signal.IndicationWithResponse;
diff --git a/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/QueryRepositoriesIndication.java b/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/protocol/QueryRepositoriesIndication.java
index f6fdf31e64..9e5aa8d94b 100644
--- a/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/QueryRepositoriesIndication.java
+++ b/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/protocol/QueryRepositoriesIndication.java
@@ -8,19 +8,26 @@
* Contributors:
* Eike Stepper - initial API and implementation
*/
-package org.eclipse.emf.cdo.server.internal.admin;
+package org.eclipse.emf.cdo.server.internal.admin.protocol;
+import org.eclipse.emf.cdo.common.admin.CDOAdminRepository;
+import org.eclipse.emf.cdo.server.internal.admin.CDOAdminServer;
+import org.eclipse.emf.cdo.server.internal.admin.CDOAdminServerRepository;
+import org.eclipse.emf.cdo.server.internal.admin.bundle.OM;
import org.eclipse.emf.cdo.spi.common.admin.CDOAdminProtocolConstants;
import org.eclipse.net4j.signal.IndicationWithResponse;
import org.eclipse.net4j.util.io.ExtendedDataInputStream;
import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
/**
* @author Eike Stepper
*/
public class QueryRepositoriesIndication extends IndicationWithResponse
{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_PROTOCOL, QueryRepositoriesIndication.class);
+
public QueryRepositoriesIndication(CDOAdminServerProtocol protocol)
{
super(protocol, CDOAdminProtocolConstants.SIGNAL_QUERY_REPOSITORIES);
@@ -38,12 +45,22 @@ public class QueryRepositoriesIndication extends IndicationWithResponse
CDOAdminServerProtocol protocol = (CDOAdminServerProtocol)getProtocol();
CDOAdminServer admin = protocol.getInfraStructure();
- CDOAdminServerRepository[] repositories = (CDOAdminServerRepository[])admin.getRepositories();
- out.writeInt(repositories.length);
+ CDOAdminRepository[] repositories = admin.getRepositories();
+ int size = repositories.length;
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Writing {0} repository infos...", size); //$NON-NLS-1$
+ }
- for (int i = 0; i < repositories.length; i++)
+ out.writeInt(size);
+ for (int i = 0; i < size; i++)
{
- CDOAdminServerRepository repository = repositories[i];
+ CDOAdminServerRepository repository = (CDOAdminServerRepository)repositories[i];
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Writing repository info for {0}", repository.getName()); //$NON-NLS-1$
+ }
+
repository.write(out);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/RepositoryAddedRequest.java b/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/protocol/RepositoryAddedRequest.java
index 56c464af0d..a1c4903f26 100644
--- a/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/RepositoryAddedRequest.java
+++ b/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/protocol/RepositoryAddedRequest.java
@@ -8,8 +8,9 @@
* Contributors:
* Eike Stepper - initial API and implementation
*/
-package org.eclipse.emf.cdo.server.internal.admin;
+package org.eclipse.emf.cdo.server.internal.admin.protocol;
+import org.eclipse.emf.cdo.server.internal.admin.CDOAdminServerRepository;
import org.eclipse.emf.cdo.spi.common.admin.CDOAdminProtocolConstants;
import org.eclipse.net4j.signal.Request;
diff --git a/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/RepositoryRemovedRequest.java b/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/protocol/RepositoryRemovedRequest.java
index f1ed00311e..0980811d24 100644
--- a/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/RepositoryRemovedRequest.java
+++ b/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/protocol/RepositoryRemovedRequest.java
@@ -8,7 +8,7 @@
* Contributors:
* Eike Stepper - initial API and implementation
*/
-package org.eclipse.emf.cdo.server.internal.admin;
+package org.eclipse.emf.cdo.server.internal.admin.protocol;
import org.eclipse.emf.cdo.spi.common.admin.CDOAdminProtocolConstants;
@@ -24,7 +24,7 @@ public class RepositoryRemovedRequest extends Request
public RepositoryRemovedRequest(CDOAdminServerProtocol serverProtocol, String name)
{
- super(serverProtocol, CDOAdminProtocolConstants.SIGNAL_REPOSITORY_ADDED);
+ super(serverProtocol, CDOAdminProtocolConstants.SIGNAL_REPOSITORY_REMOVED);
this.name = name;
}
diff --git a/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/RepositoryStateChangedRequest.java b/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/protocol/RepositoryStateChangedRequest.java
index ea81e0e0d7..6c7fd0f7b8 100644
--- a/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/RepositoryStateChangedRequest.java
+++ b/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/protocol/RepositoryStateChangedRequest.java
@@ -8,7 +8,7 @@
* Contributors:
* Eike Stepper - initial API and implementation
*/
-package org.eclipse.emf.cdo.server.internal.admin;
+package org.eclipse.emf.cdo.server.internal.admin.protocol;
import org.eclipse.emf.cdo.common.CDOCommonRepository.State;
import org.eclipse.emf.cdo.spi.common.admin.CDOAdminProtocolConstants;
diff --git a/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/RepositoryTypeChangedRequest.java b/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/protocol/RepositoryTypeChangedRequest.java
index 3577716722..641a2eab34 100644
--- a/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/RepositoryTypeChangedRequest.java
+++ b/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/internal/admin/protocol/RepositoryTypeChangedRequest.java
@@ -8,7 +8,7 @@
* Contributors:
* Eike Stepper - initial API and implementation
*/
-package org.eclipse.emf.cdo.server.internal.admin;
+package org.eclipse.emf.cdo.server.internal.admin.protocol;
import org.eclipse.emf.cdo.common.CDOCommonRepository.Type;
import org.eclipse.emf.cdo.spi.common.admin.CDOAdminProtocolConstants;
diff --git a/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/admin/CDOAdminHandler.java b/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/spi/admin/CDOAdminHandler.java
index 3e8be068dc..e8dbdcb5db 100644
--- a/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/admin/CDOAdminHandler.java
+++ b/plugins/org.eclipse.emf.cdo.server.admin/src/org/eclipse/emf/cdo/server/spi/admin/CDOAdminHandler.java
@@ -8,7 +8,7 @@
* Contributors:
* Eike Stepper - initial API and implementation
*/
-package org.eclipse.emf.cdo.server.admin;
+package org.eclipse.emf.cdo.server.spi.admin;
import org.eclipse.emf.cdo.server.IRepository;
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/CDOServerUtil.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/CDOServerUtil.java
index 91c7afb88a..fb92a4825f 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/CDOServerUtil.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/CDOServerUtil.java
@@ -1,304 +1,308 @@
-/*
- * 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.server;
-
-import org.eclipse.emf.cdo.common.CDOCommonRepository;
-import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
-import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.common.revision.CDORevisionManager;
-import org.eclipse.emf.cdo.common.revision.CDORevisionProvider;
-import org.eclipse.emf.cdo.internal.server.Repository;
-import org.eclipse.emf.cdo.internal.server.ServerCDOView;
-import org.eclipse.emf.cdo.internal.server.SessionManager;
-import org.eclipse.emf.cdo.internal.server.bundle.OM;
-import org.eclipse.emf.cdo.internal.server.syncing.FailoverParticipant;
-import org.eclipse.emf.cdo.internal.server.syncing.OfflineClone;
-import org.eclipse.emf.cdo.internal.server.syncing.RepositorySynchronizer;
-import org.eclipse.emf.cdo.session.CDOSessionConfigurationFactory;
-import org.eclipse.emf.cdo.spi.common.branch.CDOBranchUtil;
-import org.eclipse.emf.cdo.spi.common.revision.ManagedRevisionProvider;
-import org.eclipse.emf.cdo.spi.server.InternalRepositorySynchronizer;
-import org.eclipse.emf.cdo.spi.server.InternalSession;
-import org.eclipse.emf.cdo.spi.server.InternalStore;
-import org.eclipse.emf.cdo.spi.server.RepositoryFactory;
-import org.eclipse.emf.cdo.view.CDOView;
-
-import org.eclipse.net4j.util.ObjectUtil;
-import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.om.OMPlatform;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Various static methods that may help with CDO {@link IRepository repositories} and server-side {@link CDOView views}.
- *
- * @author Eike Stepper
- * @apiviz.exclude
- */
-public final class CDOServerUtil
-{
- private CDOServerUtil()
- {
- }
-
- /**
- * @since 4.0
- */
- public static CDOView openView(ISession session, CDOBranchPoint branchPoint, boolean legacyModeEnabled,
- CDORevisionProvider revisionProvider)
- {
- return new ServerCDOView((InternalSession)session, branchPoint, legacyModeEnabled, revisionProvider);
- }
-
- /**
- * @since 4.0
- */
- public static CDOView openView(ISession session, CDOBranchPoint branchPoint, boolean legacyModeEnabled)
- {
- CDORevisionManager revisionManager = session.getManager().getRepository().getRevisionManager();
- CDORevisionProvider revisionProvider = new ManagedRevisionProvider(revisionManager, branchPoint);
- return new ServerCDOView((InternalSession)session, branchPoint, legacyModeEnabled, revisionProvider);
- }
-
- /**
- * @since 4.0
- */
- public static CDOView openView(IView view, boolean legacyModeEnabled)
- {
- ISession session = view.getSession();
- CDOBranchPoint branchPoint = CDOBranchUtil.copyBranchPoint(view);
- return openView(session, branchPoint, legacyModeEnabled, view);
- }
-
- /**
- * @since 4.0
- */
- public static CDOView openView(IStoreAccessor.CommitContext commitContext, boolean legacyModeEnabled)
- {
- ISession session = commitContext.getTransaction().getSession();
- CDOBranchPoint branchPoint = commitContext.getBranchPoint();
- return openView(session, branchPoint, legacyModeEnabled, commitContext);
- }
-
- /**
- * @since 3.0
- * @deprecated Not yet supported.
- */
- @Deprecated
- public static org.eclipse.emf.cdo.server.embedded.CDOSessionConfiguration createSessionConfiguration()
- {
- return new org.eclipse.emf.cdo.internal.server.embedded.EmbeddedClientSessionConfiguration();
- }
-
- /**
- * @since 3.0
- */
- public static ISessionManager createSessionManager()
- {
- return new SessionManager();
- }
-
- public static IRepository createRepository(String name, IStore store, Map<String, String> props)
- {
- Repository repository = new Repository.Default();
- initRepository(repository, name, store, props);
- return repository;
- }
-
- /**
- * @since 3.0
- */
- public static IRepositorySynchronizer createRepositorySynchronizer(
- CDOSessionConfigurationFactory remoteSessionConfigurationFactory)
- {
- RepositorySynchronizer synchronizer = new RepositorySynchronizer();
- synchronizer.setRemoteSessionConfigurationFactory(remoteSessionConfigurationFactory);
- return synchronizer;
- }
-
- /**
- * @since 3.0
- */
- public static ISynchronizableRepository createOfflineClone(String name, IStore store, Map<String, String> props,
- IRepositorySynchronizer synchronizer)
- {
- OfflineClone repository = new OfflineClone();
- initRepository(repository, name, store, props);
- repository.setSynchronizer((InternalRepositorySynchronizer)synchronizer);
- return repository;
- }
-
- /**
- * @since 4.0
- */
- public static ISynchronizableRepository createFailoverParticipant(String name, IStore store,
- Map<String, String> props, IRepositorySynchronizer synchronizer, boolean master, boolean allowBackupCommits)
- {
- FailoverParticipant repository = new FailoverParticipant();
- initRepository(repository, name, store, props);
- repository.setSynchronizer((InternalRepositorySynchronizer)synchronizer);
- repository.setType(master ? CDOCommonRepository.Type.MASTER : CDOCommonRepository.Type.BACKUP);
- return repository;
- }
-
- /**
- * @since 3.0
- */
- public static ISynchronizableRepository createFailoverParticipant(String name, IStore store,
- Map<String, String> props, IRepositorySynchronizer synchronizer, boolean master)
- {
- return createFailoverParticipant(name, store, props, synchronizer, master, false);
- }
-
- /**
- * @since 4.0
- */
- public static ISynchronizableRepository createFailoverParticipant(String name, IStore store,
- Map<String, String> props, IRepositorySynchronizer synchronizer)
- {
- return createFailoverParticipant(name, store, props, synchronizer, false);
- }
-
- /**
- * @since 4.0
- */
- public static ISynchronizableRepository createFailoverParticipant(String name, IStore store, Map<String, String> props)
- {
- return createFailoverParticipant(name, store, props, null);
- }
-
- private static void initRepository(Repository repository, String name, IStore store, Map<String, String> props)
- {
- repository.setName(name);
- repository.setStore((InternalStore)store);
- repository.setProperties(props);
- }
-
- public static void addRepository(IManagedContainer container, IRepository repository)
- {
- container.putElement(RepositoryFactory.PRODUCT_GROUP, RepositoryFactory.TYPE, repository.getName(), repository);
- LifecycleUtil.activate(repository);
- }
-
- public static IRepository getRepository(IManagedContainer container, String name)
- {
- return RepositoryFactory.get(container, name);
- }
-
- public static Element getRepositoryConfig(String repositoryName) throws ParserConfigurationException, SAXException,
- IOException
- {
- File configFile = OMPlatform.INSTANCE.getConfigFile("cdo-server.xml"); //$NON-NLS-1$
-
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document document = builder.parse(configFile);
- NodeList elements = document.getElementsByTagName("repository"); //$NON-NLS-1$
- for (int i = 0; i < elements.getLength(); i++)
- {
- Node node = elements.item(i);
- if (node instanceof Element)
- {
- Element element = (Element)node;
- String name = element.getAttribute("name"); //$NON-NLS-1$
- if (ObjectUtil.equals(name, repositoryName))
- {
- return element;
- }
- }
- }
-
- throw new IllegalStateException("Repository config not found: " + repositoryName); //$NON-NLS-1$
- }
-
- /**
- * An abstract {@link IRepository.ReadAccessHandler read-access handler} that grants or denies access to single
- * {@link CDORevision revisions}.
- *
- * @author Eike Stepper
- * @since 2.0
- * @apiviz.exclude
- */
- public static abstract class RepositoryReadAccessValidator implements IRepository.ReadAccessHandler
- {
- public RepositoryReadAccessValidator()
- {
- }
-
- public void handleRevisionsBeforeSending(ISession session, CDORevision[] revisions,
- List<CDORevision> additionalRevisions) throws RuntimeException
- {
- List<String> violations = new ArrayList<String>();
- for (CDORevision revision : revisions)
- {
- String violation = validate(session, revision);
- if (violation != null)
- {
- violations.add(violation);
- }
- }
-
- if (!violations.isEmpty())
- {
- throwException(session, violations);
- }
-
- for (Iterator<CDORevision> it = additionalRevisions.iterator(); it.hasNext();)
- {
- CDORevision revision = it.next();
- String violation = validate(session, revision);
- if (violation != null)
- {
- OM.LOG.info("Revision can not be delivered to " + session + ": " + violation); //$NON-NLS-1$ //$NON-NLS-2$
- it.remove();
- }
- }
- }
-
- protected void throwException(ISession session, List<String> violations) throws RuntimeException
- {
- StringBuilder builder = new StringBuilder();
- builder.append("Revisions can not be delivered to "); //$NON-NLS-1$
- builder.append(session);
- builder.append(":"); //$NON-NLS-1$
- for (String violation : violations)
- {
- builder.append("\n- "); //$NON-NLS-1$
- builder.append(violation);
- }
-
- throwException(builder.toString());
- }
-
- protected void throwException(String message) throws RuntimeException
- {
- throw new IllegalStateException(message);
- }
-
- protected abstract String validate(ISession session, CDORevision revision);
- }
-}
+/*
+ * 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.server;
+
+import org.eclipse.emf.cdo.common.CDOCommonRepository;
+import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.common.revision.CDORevisionManager;
+import org.eclipse.emf.cdo.common.revision.CDORevisionProvider;
+import org.eclipse.emf.cdo.internal.server.Repository;
+import org.eclipse.emf.cdo.internal.server.ServerCDOView;
+import org.eclipse.emf.cdo.internal.server.SessionManager;
+import org.eclipse.emf.cdo.internal.server.bundle.OM;
+import org.eclipse.emf.cdo.internal.server.syncing.FailoverParticipant;
+import org.eclipse.emf.cdo.internal.server.syncing.OfflineClone;
+import org.eclipse.emf.cdo.internal.server.syncing.RepositorySynchronizer;
+import org.eclipse.emf.cdo.session.CDOSessionConfigurationFactory;
+import org.eclipse.emf.cdo.spi.common.branch.CDOBranchUtil;
+import org.eclipse.emf.cdo.spi.common.revision.ManagedRevisionProvider;
+import org.eclipse.emf.cdo.spi.server.InternalRepositorySynchronizer;
+import org.eclipse.emf.cdo.spi.server.InternalSession;
+import org.eclipse.emf.cdo.spi.server.InternalStore;
+import org.eclipse.emf.cdo.spi.server.RepositoryFactory;
+import org.eclipse.emf.cdo.view.CDOView;
+
+import org.eclipse.net4j.util.ObjectUtil;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.om.OMPlatform;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Various static methods that may help with CDO {@link IRepository repositories} and server-side {@link CDOView views}.
+ *
+ * @author Eike Stepper
+ * @apiviz.exclude
+ */
+public final class CDOServerUtil
+{
+ private CDOServerUtil()
+ {
+ }
+
+ /**
+ * @since 4.0
+ */
+ public static CDOView openView(ISession session, CDOBranchPoint branchPoint, boolean legacyModeEnabled,
+ CDORevisionProvider revisionProvider)
+ {
+ return new ServerCDOView((InternalSession)session, branchPoint, legacyModeEnabled, revisionProvider);
+ }
+
+ /**
+ * @since 4.0
+ */
+ public static CDOView openView(ISession session, CDOBranchPoint branchPoint, boolean legacyModeEnabled)
+ {
+ CDORevisionManager revisionManager = session.getManager().getRepository().getRevisionManager();
+ CDORevisionProvider revisionProvider = new ManagedRevisionProvider(revisionManager, branchPoint);
+ return new ServerCDOView((InternalSession)session, branchPoint, legacyModeEnabled, revisionProvider);
+ }
+
+ /**
+ * @since 4.0
+ */
+ public static CDOView openView(IView view, boolean legacyModeEnabled)
+ {
+ ISession session = view.getSession();
+ CDOBranchPoint branchPoint = CDOBranchUtil.copyBranchPoint(view);
+ return openView(session, branchPoint, legacyModeEnabled, view);
+ }
+
+ /**
+ * @since 4.0
+ */
+ public static CDOView openView(IStoreAccessor.CommitContext commitContext, boolean legacyModeEnabled)
+ {
+ ISession session = commitContext.getTransaction().getSession();
+ CDOBranchPoint branchPoint = commitContext.getBranchPoint();
+ return openView(session, branchPoint, legacyModeEnabled, commitContext);
+ }
+
+ /**
+ * @since 3.0
+ * @deprecated Not yet supported.
+ */
+ @Deprecated
+ public static org.eclipse.emf.cdo.server.embedded.CDOSessionConfiguration createSessionConfiguration()
+ {
+ return new org.eclipse.emf.cdo.internal.server.embedded.EmbeddedClientSessionConfiguration();
+ }
+
+ /**
+ * @since 3.0
+ */
+ public static ISessionManager createSessionManager()
+ {
+ return new SessionManager();
+ }
+
+ public static IRepository createRepository(String name, IStore store, Map<String, String> props)
+ {
+ Repository repository = new Repository.Default();
+ initRepository(repository, name, store, props);
+ return repository;
+ }
+
+ /**
+ * @since 3.0
+ */
+ public static IRepositorySynchronizer createRepositorySynchronizer(
+ CDOSessionConfigurationFactory remoteSessionConfigurationFactory)
+ {
+ RepositorySynchronizer synchronizer = new RepositorySynchronizer();
+ synchronizer.setRemoteSessionConfigurationFactory(remoteSessionConfigurationFactory);
+ return synchronizer;
+ }
+
+ /**
+ * @since 3.0
+ */
+ public static ISynchronizableRepository createOfflineClone(String name, IStore store, Map<String, String> props,
+ IRepositorySynchronizer synchronizer)
+ {
+ OfflineClone repository = new OfflineClone();
+ initRepository(repository, name, store, props);
+ repository.setSynchronizer((InternalRepositorySynchronizer)synchronizer);
+ return repository;
+ }
+
+ /**
+ * @since 4.0
+ */
+ public static ISynchronizableRepository createFailoverParticipant(String name, IStore store,
+ Map<String, String> props, IRepositorySynchronizer synchronizer, boolean master, boolean allowBackupCommits)
+ {
+ FailoverParticipant repository = new FailoverParticipant();
+ initRepository(repository, name, store, props);
+ repository.setSynchronizer((InternalRepositorySynchronizer)synchronizer);
+ repository.setType(master ? CDOCommonRepository.Type.MASTER : CDOCommonRepository.Type.BACKUP);
+ return repository;
+ }
+
+ /**
+ * @since 3.0
+ */
+ public static ISynchronizableRepository createFailoverParticipant(String name, IStore store,
+ Map<String, String> props, IRepositorySynchronizer synchronizer, boolean master)
+ {
+ return createFailoverParticipant(name, store, props, synchronizer, master, false);
+ }
+
+ /**
+ * @since 4.0
+ */
+ public static ISynchronizableRepository createFailoverParticipant(String name, IStore store,
+ Map<String, String> props, IRepositorySynchronizer synchronizer)
+ {
+ return createFailoverParticipant(name, store, props, synchronizer, false);
+ }
+
+ /**
+ * @since 4.0
+ */
+ public static ISynchronizableRepository createFailoverParticipant(String name, IStore store, Map<String, String> props)
+ {
+ return createFailoverParticipant(name, store, props, null);
+ }
+
+ private static void initRepository(Repository repository, String name, IStore store, Map<String, String> props)
+ {
+ repository.setName(name);
+ repository.setStore((InternalStore)store);
+ repository.setProperties(props);
+ }
+
+ public static void addRepository(IManagedContainer container, IRepository repository)
+ {
+ String productGroup = RepositoryFactory.PRODUCT_GROUP;
+ String type = RepositoryFactory.TYPE;
+ String name = repository.getName();
+
+ container.putElement(productGroup, type, name, repository);
+ LifecycleUtil.activate(repository);
+ }
+
+ public static IRepository getRepository(IManagedContainer container, String name)
+ {
+ return RepositoryFactory.get(container, name);
+ }
+
+ public static Element getRepositoryConfig(String repositoryName) throws ParserConfigurationException, SAXException,
+ IOException
+ {
+ File configFile = OMPlatform.INSTANCE.getConfigFile("cdo-server.xml"); //$NON-NLS-1$
+
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document document = builder.parse(configFile);
+ NodeList elements = document.getElementsByTagName("repository"); //$NON-NLS-1$
+ for (int i = 0; i < elements.getLength(); i++)
+ {
+ Node node = elements.item(i);
+ if (node instanceof Element)
+ {
+ Element element = (Element)node;
+ String name = element.getAttribute("name"); //$NON-NLS-1$
+ if (ObjectUtil.equals(name, repositoryName))
+ {
+ return element;
+ }
+ }
+ }
+
+ throw new IllegalStateException("Repository config not found: " + repositoryName); //$NON-NLS-1$
+ }
+
+ /**
+ * An abstract {@link IRepository.ReadAccessHandler read-access handler} that grants or denies access to single
+ * {@link CDORevision revisions}.
+ *
+ * @author Eike Stepper
+ * @since 2.0
+ * @apiviz.exclude
+ */
+ public static abstract class RepositoryReadAccessValidator implements IRepository.ReadAccessHandler
+ {
+ public RepositoryReadAccessValidator()
+ {
+ }
+
+ public void handleRevisionsBeforeSending(ISession session, CDORevision[] revisions,
+ List<CDORevision> additionalRevisions) throws RuntimeException
+ {
+ List<String> violations = new ArrayList<String>();
+ for (CDORevision revision : revisions)
+ {
+ String violation = validate(session, revision);
+ if (violation != null)
+ {
+ violations.add(violation);
+ }
+ }
+
+ if (!violations.isEmpty())
+ {
+ throwException(session, violations);
+ }
+
+ for (Iterator<CDORevision> it = additionalRevisions.iterator(); it.hasNext();)
+ {
+ CDORevision revision = it.next();
+ String violation = validate(session, revision);
+ if (violation != null)
+ {
+ OM.LOG.info("Revision can not be delivered to " + session + ": " + violation); //$NON-NLS-1$ //$NON-NLS-2$
+ it.remove();
+ }
+ }
+ }
+
+ protected void throwException(ISession session, List<String> violations) throws RuntimeException
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append("Revisions can not be delivered to "); //$NON-NLS-1$
+ builder.append(session);
+ builder.append(":"); //$NON-NLS-1$
+ for (String violation : violations)
+ {
+ builder.append("\n- "); //$NON-NLS-1$
+ builder.append(violation);
+ }
+
+ throwException(builder.toString());
+ }
+
+ protected void throwException(String message) throws RuntimeException
+ {
+ throw new IllegalStateException(message);
+ }
+
+ protected abstract String validate(ISession session, CDORevision revision);
+ }
+}
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 dccb74ab0a..60cdde3abb 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
@@ -11,16 +11,35 @@
package org.eclipse.emf.cdo.tests.bugzilla;
import org.eclipse.emf.cdo.admin.CDOAdminUtil;
+import org.eclipse.emf.cdo.common.CDOCommonRepository.State;
+import org.eclipse.emf.cdo.common.CDOCommonRepository.Type;
import org.eclipse.emf.cdo.common.admin.CDOAdmin;
import org.eclipse.emf.cdo.common.admin.CDOAdminRepository;
+import org.eclipse.emf.cdo.common.id.CDOIDUtil;
+import org.eclipse.emf.cdo.common.util.RepositoryStateChangedEvent;
+import org.eclipse.emf.cdo.common.util.RepositoryTypeChangedEvent;
import org.eclipse.emf.cdo.server.IRepository;
-import org.eclipse.emf.cdo.server.admin.CDOAdminHandler;
+import org.eclipse.emf.cdo.server.spi.admin.CDOAdminHandler;
+import org.eclipse.emf.cdo.spi.server.InternalRepository;
import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.config.ISessionConfig;
+import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.CleanRepositoriesAfter;
+import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.Requires;
import org.eclipse.emf.cdo.tests.config.impl.SessionConfig;
+import org.eclipse.emf.cdo.tests.util.TestListener;
import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.util.container.IContainerDelta;
+import org.eclipse.net4j.util.container.IContainerEvent;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.event.IEvent;
import org.eclipse.net4j.util.factory.ProductCreationException;
+import org.eclipse.net4j.util.io.IOUtil;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
/**
@@ -30,24 +49,23 @@ import java.util.Map;
*
* @author Eike Stepper
*/
+@Requires(ISessionConfig.CAPABILITY_NET4J)
+@CleanRepositoriesAfter
public class Bugzilla_381472_Test extends AbstractCDOTest
{
private static final String ADMIN_HANDLER_TYPE = "test";
- private CDOAdmin admin;
-
- @Override
- protected void doSetUp() throws Exception
+ private CDOAdmin openAdmin(final Map<String, Object> expectedProperties)
{
- super.doSetUp();
-
- getContainerConfig().getServerContainer().registerFactory(new CDOAdminHandler.Factory(ADMIN_HANDLER_TYPE)
+ IManagedContainer serverContainer = getContainerConfig().getServerContainer();
+ serverContainer.registerFactory(new CDOAdminHandler.Factory(ADMIN_HANDLER_TYPE)
{
@Override
public CDOAdminHandler create(String description) throws ProductCreationException
{
return new CDOAdminHandler()
{
+
public String getType()
{
return ADMIN_HANDLER_TYPE;
@@ -55,6 +73,7 @@ public class Bugzilla_381472_Test extends AbstractCDOTest
public IRepository createRepository(String name, Map<String, Object> properties)
{
+ assertEquals(expectedProperties, properties);
return getRepository(name);
}
@@ -68,24 +87,534 @@ public class Bugzilla_381472_Test extends AbstractCDOTest
SessionConfig.Net4j sessionConfig = (SessionConfig.Net4j)getSessionConfig();
IConnector connector = sessionConfig.getConnector();
- admin = CDOAdminUtil.openAdmin(connector);
+ return CDOAdminUtil.openAdmin(connector);
+ }
+
+ public void testInitial() throws Exception
+ {
+ CDOAdmin admin = openAdmin(null);
+
+ try
+ {
+ CDOAdminRepository[] repositories = admin.getRepositories();
+ assertEquals(1, repositories.length);
+ assertEquals(getRepository().getName(), repositories[0].getName());
+ }
+ finally
+ {
+ IOUtil.closeSilent(admin);
+ }
+ }
+
+ public void testRepoAdded() throws Exception
+ {
+ CDOAdmin admin = openAdmin(null);
+
+ try
+ {
+ InternalRepository repo2 = getRepository("repo2");
+ admin.waitForRepository("repo2");
+
+ CDOAdminRepository[] repositories = admin.getRepositories();
+ assertEquals(2, repositories.length);
+ assertEquals(getRepository().getName(), repositories[0].getName());
+ assertEquals(repo2.getName(), repositories[1].getName());
+ }
+ finally
+ {
+ IOUtil.closeSilent(admin);
+ }
+ }
+
+ public void testRepoAddedRemoved() throws Exception
+ {
+ final CDOAdmin admin = openAdmin(null);
+
+ try
+ {
+ InternalRepository repo2 = getRepository("repo2");
+ admin.waitForRepository("repo2");
+
+ CDOAdminRepository[] repositories = admin.getRepositories();
+ assertEquals(2, repositories.length);
+ assertEquals(getRepository().getName(), repositories[0].getName());
+ assertEquals(repo2.getName(), repositories[1].getName());
+
+ LifecycleUtil.deactivate(repo2);
+
+ new PollingTimeOuter()
+ {
+ @Override
+ protected boolean successful()
+ {
+ CDOAdminRepository[] repositories = admin.getRepositories();
+ if (repositories.length != 1)
+ {
+ return false;
+ }
+
+ assertEquals(getRepository().getName(), repositories[0].getName());
+ return true;
+ }
+ }.assertNoTimeOut();
+ }
+ finally
+ {
+ IOUtil.closeSilent(admin);
+ }
+ }
+
+ public void testRepoAddedRemovedAdded() throws Exception
+ {
+ final CDOAdmin admin = openAdmin(null);
+
+ try
+ {
+ InternalRepository repo2 = getRepository("repo2");
+ admin.waitForRepository("repo2");
+
+ CDOAdminRepository[] repositories = admin.getRepositories();
+ assertEquals(2, repositories.length);
+ assertEquals(getRepository().getName(), repositories[0].getName());
+ assertEquals(repo2.getName(), repositories[1].getName());
+
+ LifecycleUtil.deactivate(repo2);
+
+ new PollingTimeOuter()
+ {
+ @Override
+ protected boolean successful()
+ {
+ CDOAdminRepository[] repositories = admin.getRepositories();
+ if (repositories.length != 1)
+ {
+ return false;
+ }
+
+ assertEquals(getRepository().getName(), repositories[0].getName());
+ return true;
+ }
+ }.assertNoTimeOut();
+
+ repo2 = getRepository("repo2");
+ admin.waitForRepository("repo2");
+
+ repositories = admin.getRepositories();
+ assertEquals(2, repositories.length);
+ assertEquals(getRepository().getName(), repositories[0].getName());
+ assertEquals(repo2.getName(), repositories[1].getName());
+ }
+ finally
+ {
+ IOUtil.closeSilent(admin);
+ }
+ }
+
+ public void testRepoAddedRemovedAddedOther() throws Exception
+ {
+ final CDOAdmin admin = openAdmin(null);
+
+ try
+ {
+ InternalRepository repo2 = getRepository("repo2");
+ admin.waitForRepository("repo2");
+
+ CDOAdminRepository[] repositories = admin.getRepositories();
+ assertEquals(2, repositories.length);
+ assertEquals(getRepository().getName(), repositories[0].getName());
+ assertEquals(repo2.getName(), repositories[1].getName());
+
+ LifecycleUtil.deactivate(repo2);
+
+ new PollingTimeOuter()
+ {
+ @Override
+ protected boolean successful()
+ {
+ CDOAdminRepository[] repositories = admin.getRepositories();
+ if (repositories.length != 1)
+ {
+ return false;
+ }
+
+ assertEquals(getRepository().getName(), repositories[0].getName());
+ return true;
+ }
+ }.assertNoTimeOut();
+
+ InternalRepository repo3 = getRepository("repo3");
+ admin.waitForRepository("repo3");
+
+ repositories = admin.getRepositories();
+ assertEquals(2, repositories.length);
+ assertEquals(getRepository().getName(), repositories[0].getName());
+ assertEquals(repo3.getName(), repositories[1].getName());
+ }
+ finally
+ {
+ IOUtil.closeSilent(admin);
+ }
+ }
+
+ public void testRepoAddedAdded() throws Exception
+ {
+ CDOAdmin admin = openAdmin(null);
+
+ try
+ {
+ InternalRepository repo2 = getRepository("repo2");
+ admin.waitForRepository("repo2");
+
+ CDOAdminRepository[] repositories = admin.getRepositories();
+ assertEquals(2, repositories.length);
+ assertEquals(getRepository().getName(), repositories[0].getName());
+ assertEquals(repo2.getName(), repositories[1].getName());
+
+ InternalRepository repo3 = getRepository("repo3");
+ admin.waitForRepository("repo3");
+
+ repositories = admin.getRepositories();
+ assertEquals(3, repositories.length);
+ assertEquals(getRepository().getName(), repositories[0].getName());
+ assertEquals(repo2.getName(), repositories[1].getName());
+ assertEquals(repo3.getName(), repositories[2].getName());
+ }
+ finally
+ {
+ IOUtil.closeSilent(admin);
+ }
+ }
+
+ public void testRepoAddedEvent() throws Exception
+ {
+ CDOAdmin admin = openAdmin(null);
+
+ TestListener listener = new TestListener();
+ admin.addListener(listener);
+
+ try
+ {
+ getRepository("repo2");
+ admin.waitForRepository("repo2");
+
+ IEvent[] events = listener.getEvents();
+ assertEquals(1, events.length);
+
+ @SuppressWarnings("unchecked")
+ IContainerEvent<CDOAdminRepository> event = (IContainerEvent<CDOAdminRepository>)events[0];
+ assertEquals(IContainerDelta.Kind.ADDED, event.getDeltaKind());
+ assertEquals("repo2", event.getDeltaElement().getName());
+ }
+ finally
+ {
+ IOUtil.closeSilent(admin);
+ }
+ }
+
+ public void testRepoRemovedEvent() throws Exception
+ {
+ final CDOAdmin admin = openAdmin(null);
+
+ TestListener listener = new TestListener();
+ admin.addListener(listener);
+
+ try
+ {
+ InternalRepository repo1 = getRepository();
+ LifecycleUtil.deactivate(repo1);
+
+ new PollingTimeOuter()
+ {
+ @Override
+ protected boolean successful()
+ {
+ CDOAdminRepository[] repositories = admin.getRepositories();
+ return repositories.length == 0;
+ }
+ }.assertNoTimeOut();
+
+ IEvent[] events = listener.getEvents();
+ assertEquals(1, events.length);
+
+ @SuppressWarnings("unchecked")
+ IContainerEvent<CDOAdminRepository> event = (IContainerEvent<CDOAdminRepository>)events[0];
+ assertEquals(IContainerDelta.Kind.REMOVED, event.getDeltaKind());
+ assertEquals("repo1", event.getDeltaElement().getName());
+ }
+ finally
+ {
+ IOUtil.closeSilent(admin);
+ }
+ }
+
+ public void testRepoTypeChangedEvent() throws Exception
+ {
+ CDOAdmin admin = openAdmin(null);
+
+ try
+ {
+ CDOAdminRepository repo1 = admin.getRepository("repo1");
+
+ final TestListener listener = new TestListener();
+ repo1.addListener(listener);
+
+ getRepository().setType(Type.BACKUP);
+
+ new PollingTimeOuter()
+ {
+ @Override
+ protected boolean successful()
+ {
+ IEvent[] events = listener.getEvents();
+ if (events.length != 1)
+ {
+ return false;
+ }
+
+ RepositoryTypeChangedEvent event = (RepositoryTypeChangedEvent)events[0];
+ assertEquals(Type.MASTER, event.getOldType());
+ assertEquals(Type.BACKUP, event.getNewType());
+ return true;
+ }
+ }.assertNoTimeOut();
+ }
+ finally
+ {
+ IOUtil.closeSilent(admin);
+ }
+ }
+
+ public void testRepoStateChangedEvent() throws Exception
+ {
+ CDOAdmin admin = openAdmin(null);
+
+ try
+ {
+ CDOAdminRepository repo1 = admin.getRepository("repo1");
+
+ final TestListener listener = new TestListener();
+ repo1.addListener(listener);
+
+ getRepository().setState(State.OFFLINE);
+
+ new PollingTimeOuter()
+ {
+ @Override
+ protected boolean successful()
+ {
+ IEvent[] events = listener.getEvents();
+ if (events.length != 1)
+ {
+ return false;
+ }
+
+ RepositoryStateChangedEvent event = (RepositoryStateChangedEvent)events[0];
+ assertEquals(State.ONLINE, event.getOldState());
+ assertEquals(State.OFFLINE, event.getNewState());
+ return true;
+ }
+ }.assertNoTimeOut();
+ }
+ finally
+ {
+ IOUtil.closeSilent(admin);
+ }
+ }
+
+ public void testCreateRepo() throws Exception
+ {
+ CDOAdmin admin = openAdmin(null);
+
+ TestListener listener = new TestListener();
+ admin.addListener(listener);
+
+ try
+ {
+ CDOAdminRepository repo2 = admin.createRepository("repo2", ADMIN_HANDLER_TYPE, null);
+ assertEquals("repo2", repo2.getName());
+
+ CDOAdminRepository[] repositories = admin.getRepositories();
+ assertEquals(2, repositories.length);
+ assertEquals(getRepository().getName(), repositories[0].getName());
+ assertEquals(repo2.getName(), repositories[1].getName());
+
+ IEvent[] events = listener.getEvents();
+ assertEquals(Arrays.asList(events).toString(), 1, events.length);
+
+ @SuppressWarnings("unchecked")
+ IContainerEvent<CDOAdminRepository> event = (IContainerEvent<CDOAdminRepository>)events[0];
+ assertEquals(IContainerDelta.Kind.ADDED, event.getDeltaKind());
+ assertEquals("repo2", event.getDeltaElement().getName());
+ }
+ finally
+ {
+ IOUtil.closeSilent(admin);
+ }
+ }
+
+ public void testCreateRepoWithPropertiesEmpty() throws Exception
+ {
+ Map<String, Object> properties = Collections.emptyMap();
+ CDOAdmin admin = openAdmin(properties);
+
+ TestListener listener = new TestListener();
+ admin.addListener(listener);
+
+ try
+ {
+ CDOAdminRepository repo2 = admin.createRepository("repo2", ADMIN_HANDLER_TYPE, properties);
+ assertEquals("repo2", repo2.getName());
+
+ CDOAdminRepository[] repositories = admin.getRepositories();
+ assertEquals(2, repositories.length);
+ assertEquals(getRepository().getName(), repositories[0].getName());
+ assertEquals(repo2.getName(), repositories[1].getName());
+
+ IEvent[] events = listener.getEvents();
+ assertEquals(Arrays.asList(events).toString(), 1, events.length);
+
+ @SuppressWarnings("unchecked")
+ IContainerEvent<CDOAdminRepository> event = (IContainerEvent<CDOAdminRepository>)events[0];
+ assertEquals(IContainerDelta.Kind.ADDED, event.getDeltaKind());
+ assertEquals("repo2", event.getDeltaElement().getName());
+ }
+ finally
+ {
+ IOUtil.closeSilent(admin);
+ }
+ }
+
+ public void testCreateRepoWithPropertiesPrimitive() throws Exception
+ {
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put("key", 4711);
+
+ CDOAdmin admin = openAdmin(properties);
+
+ TestListener listener = new TestListener();
+ admin.addListener(listener);
+
+ try
+ {
+ CDOAdminRepository repo2 = admin.createRepository("repo2", ADMIN_HANDLER_TYPE, properties);
+ assertEquals("repo2", repo2.getName());
+
+ CDOAdminRepository[] repositories = admin.getRepositories();
+ assertEquals(2, repositories.length);
+ assertEquals(getRepository().getName(), repositories[0].getName());
+ assertEquals(repo2.getName(), repositories[1].getName());
+
+ IEvent[] events = listener.getEvents();
+ assertEquals(Arrays.asList(events).toString(), 1, events.length);
+
+ @SuppressWarnings("unchecked")
+ IContainerEvent<CDOAdminRepository> event = (IContainerEvent<CDOAdminRepository>)events[0];
+ assertEquals(IContainerDelta.Kind.ADDED, event.getDeltaKind());
+ assertEquals("repo2", event.getDeltaElement().getName());
+ }
+ finally
+ {
+ IOUtil.closeSilent(admin);
+ }
+ }
+
+ public void testCreateRepoWithPropertiesCDOID() throws Exception
+ {
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put("key", CDOIDUtil.createLong(4711));
+
+ CDOAdmin admin = openAdmin(properties);
+
+ TestListener listener = new TestListener();
+ admin.addListener(listener);
+
+ try
+ {
+ CDOAdminRepository repo2 = admin.createRepository("repo2", ADMIN_HANDLER_TYPE, properties);
+ assertEquals("repo2", repo2.getName());
+
+ CDOAdminRepository[] repositories = admin.getRepositories();
+ assertEquals(2, repositories.length);
+ assertEquals(getRepository().getName(), repositories[0].getName());
+ assertEquals(repo2.getName(), repositories[1].getName());
+
+ IEvent[] events = listener.getEvents();
+ assertEquals(Arrays.asList(events).toString(), 1, events.length);
+
+ @SuppressWarnings("unchecked")
+ IContainerEvent<CDOAdminRepository> event = (IContainerEvent<CDOAdminRepository>)events[0];
+ assertEquals(IContainerDelta.Kind.ADDED, event.getDeltaKind());
+ assertEquals("repo2", event.getDeltaElement().getName());
+ }
+ finally
+ {
+ IOUtil.closeSilent(admin);
+ }
}
- @Override
- protected void doTearDown() throws Exception
+ public void testCreateRepoWrongHandlerType() throws Exception
{
- admin.close();
- super.doTearDown();
+ CDOAdmin admin = openAdmin(null);
+
+ try
+ {
+ admin.createRepository("repo2", "WRONG", null);
+ fail("Exception expected");
+ }
+ catch (Exception expected)
+ {
+ // Success
+ }
+ finally
+ {
+ IOUtil.closeSilent(admin);
+ }
}
- @Deprecated
- public void testDummy() throws Exception
+ public void testDeleteRepo() throws Exception
{
+ CDOAdmin admin = openAdmin(null);
+
+ TestListener listener = new TestListener();
+ admin.addListener(listener);
+
+ try
+ {
+ CDOAdminRepository repo1 = admin.getRepository("repo1");
+ repo1.delete(ADMIN_HANDLER_TYPE);
+ assertEquals(null, admin.getRepository("repo1"));
+
+ IEvent[] events = listener.getEvents();
+ assertEquals(Arrays.asList(events).toString(), 1, events.length);
+
+ @SuppressWarnings("unchecked")
+ IContainerEvent<CDOAdminRepository> event = (IContainerEvent<CDOAdminRepository>)events[0];
+ assertEquals(IContainerDelta.Kind.REMOVED, event.getDeltaKind());
+ assertEquals("repo1", event.getDeltaElement().getName());
+ }
+ finally
+ {
+ IOUtil.closeSilent(admin);
+ }
}
- public void _testEmpty() throws Exception
+ public void testDeleteRepoWrongHandlerType() throws Exception
{
- CDOAdminRepository[] repositories = admin.getRepositories();
- System.out.println(repositories);
+ CDOAdmin admin = openAdmin(null);
+
+ try
+ {
+ CDOAdminRepository repo1 = admin.getRepository("repo1");
+ repo1.delete("WRONG");
+ fail("Exception expected");
+ }
+ catch (Exception expected)
+ {
+ // Success
+ }
+ finally
+ {
+ IOUtil.closeSilent(admin);
+ }
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/IRepositoryConfig.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/IRepositoryConfig.java
index 6011f89bb4..9102649a2f 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/IRepositoryConfig.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/IRepositoryConfig.java
@@ -1,53 +1,54 @@
-/*
- * 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.tests.config;
-
-import org.eclipse.emf.cdo.common.CDOCommonRepository.IDGenerationLocation;
-import org.eclipse.emf.cdo.server.IStore;
-import org.eclipse.emf.cdo.spi.server.InternalRepository;
-
-import java.util.Map;
-
-/**
- * @author Eike Stepper
- */
-public interface IRepositoryConfig extends IConfig
-{
- public static final String REPOSITORY_NAME = "repo1";
-
- public static final String CAPABILITY_AUDITING = "repository.auditing";
-
- public static final String CAPABILITY_BRANCHING = "repository.branching";
-
- public static final String CAPABILITY_UUIDS = "repository.uuids";
-
- public static final String CAPABILITY_OFFLINE = "repository.offline";
-
- public static final String CAPABILITY_RESTARTABLE = "repository.restartable";
-
- public boolean isSupportingAudits();
-
- public boolean isSupportingBranches();
-
- public IDGenerationLocation getIDGenerationLocation();
-
- public Map<String, String> getRepositoryProperties();
-
- public InternalRepository getRepository(String name, boolean activate);
-
- public InternalRepository getRepository(String name);
-
- public void registerRepository(InternalRepository repository);
-
- public void setRestarting(boolean b);
-
- public IStore createStore(String repoName);
-}
+/*
+ * 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.tests.config;
+
+import org.eclipse.emf.cdo.common.CDOCommonRepository.IDGenerationLocation;
+import org.eclipse.emf.cdo.server.IRepositoryProvider;
+import org.eclipse.emf.cdo.server.IStore;
+import org.eclipse.emf.cdo.spi.server.InternalRepository;
+
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IRepositoryConfig extends IConfig, IRepositoryProvider
+{
+ public static final String REPOSITORY_NAME = "repo1";
+
+ public static final String CAPABILITY_AUDITING = "repository.auditing";
+
+ public static final String CAPABILITY_BRANCHING = "repository.branching";
+
+ public static final String CAPABILITY_UUIDS = "repository.uuids";
+
+ public static final String CAPABILITY_OFFLINE = "repository.offline";
+
+ public static final String CAPABILITY_RESTARTABLE = "repository.restartable";
+
+ public boolean isSupportingAudits();
+
+ public boolean isSupportingBranches();
+
+ public IDGenerationLocation getIDGenerationLocation();
+
+ public Map<String, String> getRepositoryProperties();
+
+ public InternalRepository getRepository(String name, boolean activate);
+
+ public InternalRepository getRepository(String name);
+
+ public void registerRepository(InternalRepository repository);
+
+ public void setRestarting(boolean b);
+
+ public IStore createStore(String repoName);
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java
index fd2cc703bc..fa252f3771 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java
@@ -35,6 +35,7 @@ import org.eclipse.emf.cdo.server.IStore;
import org.eclipse.emf.cdo.server.IStoreAccessor.CommitContext;
import org.eclipse.emf.cdo.server.ITransaction;
import org.eclipse.emf.cdo.server.StoreThreadLocal;
+import org.eclipse.emf.cdo.server.admin.CDOAdminServerUtil;
import org.eclipse.emf.cdo.server.mem.MEMStoreUtil;
import org.eclipse.emf.cdo.server.net4j.CDONet4jServerUtil;
import org.eclipse.emf.cdo.server.ocl.OCLQueryHandler;
@@ -256,11 +257,14 @@ public abstract class RepositoryConfig extends Config implements IRepositoryConf
}
}
- repository.setQueryHandlerProvider(new ContainerQueryHandlerProvider(getCurrentTest().getServerContainer()));
+ IManagedContainer serverContainer = getCurrentTest().getServerContainer();
+
+ repository.setQueryHandlerProvider(new ContainerQueryHandlerProvider(serverContainer));
registerRepository(repository);
if (activate)
{
LifecycleUtil.activate(repository);
+ CDOServerUtil.addRepository(serverContainer, repository);
}
}
@@ -341,6 +345,7 @@ public abstract class RepositoryConfig extends Config implements IRepositoryConf
IManagedContainer serverContainer = getCurrentTest().getServerContainer();
OCLQueryHandler.prepareContainer(serverContainer);
+ CDOAdminServerUtil.prepareContainer(serverContainer);
CDONet4jServerUtil.prepareContainer(serverContainer, new IRepositoryProvider()
{
public IRepository getRepository(String name)
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/SessionConfig.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/SessionConfig.java
index 2d68484f9b..04a228e0f2 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/SessionConfig.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/SessionConfig.java
@@ -1,571 +1,571 @@
-/*
- * 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.tests.config.impl;
-
-import org.eclipse.emf.cdo.net4j.CDONet4jSessionConfiguration;
-import org.eclipse.emf.cdo.net4j.CDONet4jUtil;
-import org.eclipse.emf.cdo.net4j.CDONet4jViewProvider;
-import org.eclipse.emf.cdo.server.CDOServerUtil;
-import org.eclipse.emf.cdo.server.IRepository;
-import org.eclipse.emf.cdo.session.CDOSession;
-import org.eclipse.emf.cdo.session.CDOSessionConfiguration;
-import org.eclipse.emf.cdo.spi.common.CDOLobStoreImpl;
-import org.eclipse.emf.cdo.tests.config.IConfig;
-import org.eclipse.emf.cdo.tests.config.IRepositoryConfig;
-import org.eclipse.emf.cdo.tests.config.ISessionConfig;
-import org.eclipse.emf.cdo.tests.util.TestRevisionManager;
-import org.eclipse.emf.cdo.util.CDOUtil;
-import org.eclipse.emf.cdo.view.CDOFetchRuleManager;
-import org.eclipse.emf.cdo.view.CDOViewProvider;
-import org.eclipse.emf.cdo.view.CDOViewProviderRegistry;
-
-import org.eclipse.net4j.acceptor.IAcceptor;
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.jvm.JVMUtil;
-import org.eclipse.net4j.tcp.TCPUtil;
-import org.eclipse.net4j.tcp.ssl.SSLUtil;
-import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.event.IListener;
-import org.eclipse.net4j.util.io.IOUtil;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.security.IPasswordCredentialsProvider;
-
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.impl.EPackageImpl;
-
-import java.io.File;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * @author Eike Stepper
- */
-public abstract class SessionConfig extends Config implements ISessionConfig
-{
- public static final String PROP_TEST_SESSION_CONFIGURATION = "test.session.SessionConfiguration";
-
- public static final String PROP_TEST_CREDENTIALS_PROVIDER = "test.session.CredentialsProvider";
-
- public static final String PROP_TEST_FETCH_RULE_MANAGER = "test.session.FetchRuleManager";
-
- private static final long serialVersionUID = 1L;
-
- private transient Set<CDOSession> sessions;
-
- private transient IListener sessionListener;
-
- public SessionConfig(String name)
- {
- super(name);
- }
-
- public void startTransport() throws Exception
- {
- }
-
- public void stopTransport() throws Exception
- {
- }
-
- public CDOSession openSession()
- {
- return openSession(IRepositoryConfig.REPOSITORY_NAME);
- }
-
- public CDOSession openSession(String repositoryName)
- {
- CDOSessionConfiguration configuration = getTestSessionConfiguration();
- if (configuration == null)
- {
- configuration = createSessionConfiguration(repositoryName);
- }
-
- IPasswordCredentialsProvider credentialsProvider = getTestCredentialsProvider();
- if (credentialsProvider != null)
- {
- configuration.getAuthenticator().setCredentialsProvider(credentialsProvider);
- }
-
- CDOSession session = configuration.openSession();
- configureSession(session);
- session.addListener(sessionListener);
-
- synchronized (sessions)
- {
- sessions.add(session);
- }
-
- return session;
- }
-
- @Override
- public void setUp() throws Exception
- {
- super.setUp();
- sessions = new HashSet<CDOSession>();
- sessionListener = new LifecycleEventAdapter()
- {
- @Override
- protected void onDeactivated(ILifecycle session)
- {
- synchronized (sessions)
- {
- sessions.remove(session);
- }
- }
- };
- }
-
- @Override
- public void tearDown() throws Exception
- {
- try
- {
- if (sessions != null)
- {
- CDOSession[] array;
- synchronized (sessions)
- {
- array = sessions.toArray(new CDOSession[sessions.size()]);
- }
-
- for (CDOSession session : array)
- {
- session.removeListener(sessionListener);
- LifecycleUtil.deactivate(session);
- }
-
- synchronized (sessions)
- {
- sessions.clear();
- }
- }
-
- sessions = null;
- sessionListener = null;
- stopTransport();
- super.tearDown();
- }
- finally
- {
- removeDynamicPackagesFromGlobalRegistry();
- }
- }
-
- protected CDOSessionConfiguration getTestSessionConfiguration()
- {
- return (CDOSessionConfiguration)getTestProperty(PROP_TEST_SESSION_CONFIGURATION);
- }
-
- protected IPasswordCredentialsProvider getTestCredentialsProvider()
- {
- return (IPasswordCredentialsProvider)getTestProperty(PROP_TEST_CREDENTIALS_PROVIDER);
- }
-
- protected CDOFetchRuleManager getTestFetchRuleManager()
- {
- return (CDOFetchRuleManager)getTestProperty(PROP_TEST_FETCH_RULE_MANAGER);
- }
-
- protected abstract CDOSessionConfiguration createSessionConfiguration(String repositoryName);
-
- protected void configureSession(CDOSession session)
- {
- final File lobCache = getCurrentTest().createTempFolder("tmp_" + new Date().getTime());
- session.options().setLobCache(new CDOLobStoreImpl(lobCache));
- session.addListener(new LifecycleEventAdapter()
- {
- @Override
- protected void onDeactivated(ILifecycle lifecycle)
- {
- IOUtil.delete(lobCache);
- }
- });
-
- CDOUtil.setLegacyModeDefault(true);
- }
-
- private void removeDynamicPackagesFromGlobalRegistry()
- {
- EPackage.Registry registry = EPackage.Registry.INSTANCE;
- for (String uri : registry.keySet().toArray(new String[registry.size()]))
- {
- Object object = registry.get(uri);
- if (object != null && object.getClass() == EPackageImpl.class)
- {
- registry.remove(uri);
- }
- }
- }
-
- /**
- * @author Eike Stepper
- * @deprecated Not yet supported.
- */
- @Deprecated
- public static final class Embedded extends SessionConfig
- {
- public static final String NAME = "Embedded";
-
- public static final Embedded INSTANCE = new Embedded();
-
- private static final long serialVersionUID = 1L;
-
- public Embedded()
- {
- super(NAME);
- }
-
- public void initCapabilities(Set<String> capabilities)
- {
- capabilities.add(CAPABILITY_EMBEDDED);
- }
-
- public String getURIPrefix()
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected CDOSessionConfiguration createSessionConfiguration(String repositoryName)
- {
- IRepository repository = getCurrentTest().getRepository(repositoryName);
-
- org.eclipse.emf.cdo.server.embedded.CDOSessionConfiguration configuration = CDOServerUtil
- .createSessionConfiguration();
- configuration.setRepository(repository);
- return configuration;
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static abstract class Net4j extends SessionConfig
- {
- private static final long serialVersionUID = 1L;
-
- private transient CDOViewProvider viewProvider;
-
- public Net4j(String name)
- {
- super(name);
- }
-
- public void initCapabilities(Set<String> capabilities)
- {
- capabilities.add(CAPABILITY_NET4J);
- }
-
- @Override
- public void startTransport() throws Exception
- {
- IAcceptor acceptor = getAcceptor();
- LifecycleUtil.activate(acceptor);
-
- IConnector connector = getConnector();
- LifecycleUtil.activate(connector);
- }
-
- @Override
- public void stopTransport() throws Exception
- {
- ConfigTest currentTest = getCurrentTest();
-
- try
- {
- if (currentTest.hasClientContainer())
- {
- IConnector connector = getConnector();
- connector.close();
- }
- }
- catch (Exception ex)
- {
- IOUtil.print(ex);
- }
-
- try
- {
- if (currentTest.hasServerContainer())
- {
- IAcceptor acceptor = getAcceptor();
- acceptor.close();
- }
- }
- catch (Exception ex)
- {
- IOUtil.print(ex);
- }
- }
-
- @Override
- protected CDOSessionConfiguration createSessionConfiguration(String repositoryName)
- {
- CDONet4jSessionConfiguration configuration = CDONet4jUtil.createNet4jSessionConfiguration();
- configuration.setConnector(getConnector());
- configuration.setRepositoryName(repositoryName);
- configuration.setRevisionManager(new TestRevisionManager());
- return configuration;
- }
-
- @Override
- protected void configureSession(CDOSession session)
- {
- super.configureSession(session);
- ((org.eclipse.emf.cdo.net4j.CDONet4jSession)session).options().getNet4jProtocol().setTimeout(-1);
- }
-
- protected abstract CDOViewProvider createViewProvider(IManagedContainer container);
-
- @Override
- public void setUp() throws Exception
- {
- super.setUp();
-
- viewProvider = createViewProvider(getCurrentTest().getClientContainer());
- if (viewProvider != null)
- {
- CDOViewProviderRegistry.INSTANCE.addViewProvider(viewProvider);
- }
- }
-
- @Override
- public void tearDown() throws Exception
- {
- if (viewProvider != null)
- {
- CDOViewProviderRegistry.INSTANCE.removeViewProvider(viewProvider);
- }
-
- super.tearDown();
- }
-
- public abstract IAcceptor getAcceptor();
-
- public abstract IConnector getConnector();
-
- /**
- * @author Eike Stepper
- */
- public static final class TCP extends SessionConfig.Net4j
- {
- public static final String NAME = "TCP";
-
- public static final TCP INSTANCE = new TCP();
-
- public static final String CONNECTOR_HOST = "localhost";
-
- private static final long serialVersionUID = 1L;
-
- public TCP()
- {
- super(NAME);
- }
-
- @Override
- public void initCapabilities(Set<String> capabilities)
- {
- super.initCapabilities(capabilities);
- capabilities.add(CAPABILITY_NET4J_TCP);
- }
-
- public String getURIPrefix()
- {
- return "cdo.net4j.tcp://" + CONNECTOR_HOST;
- }
-
- @Override
- public IAcceptor getAcceptor()
- {
- return TCPUtil.getAcceptor(getCurrentTest().getServerContainer(), null);
- }
-
- @Override
- public IConnector getConnector()
- {
- return TCPUtil.getConnector(getCurrentTest().getClientContainer(), CONNECTOR_HOST);
- }
-
- @Override
- public void setUp() throws Exception
- {
- super.setUp();
-
- IManagedContainer clientContainer = getCurrentTest().getClientContainer();
- TCPUtil.prepareContainer(clientContainer);
-
- IManagedContainer serverContainer = getCurrentTest().getServerContainer();
- if (serverContainer != clientContainer)
- {
- TCPUtil.prepareContainer(serverContainer);
- }
- }
-
- @Override
- protected CDOViewProvider createViewProvider(final IManagedContainer container)
- {
- return new CDONet4jViewProvider.TCP()
- {
- @Override
- protected IManagedContainer getContainer()
- {
- return container;
- }
- };
- }
- }
-
- /**
- * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
- */
- public static final class SSL extends SessionConfig.Net4j
- {
- public static final String NAME = "SSL";
-
- public static final SSL INSTANCE = new SSL();
-
- public static final String CONNECTOR_HOST = "localhost";
-
- private static final long serialVersionUID = 1L;
-
- public SSL()
- {
- super(NAME);
- }
-
- @Override
- public void initCapabilities(Set<String> capabilities)
- {
- super.initCapabilities(capabilities);
- capabilities.add(CAPABILITY_NET4J_SSL);
- }
-
- public String getURIPrefix()
- {
- return "cdo.net4j.ssl://" + CONNECTOR_HOST;
- }
-
- @Override
- public IAcceptor getAcceptor()
- {
- return SSLUtil.getAcceptor(getCurrentTest().getServerContainer(), null);
- }
-
- @Override
- public IConnector getConnector()
- {
- return SSLUtil.getConnector(getCurrentTest().getClientContainer(), CONNECTOR_HOST);
- }
-
- @Override
- public void setUp() throws Exception
- {
- super.setUp();
-
- IManagedContainer clientContainer = getCurrentTest().getClientContainer();
- SSLUtil.prepareContainer(clientContainer);
-
- IManagedContainer serverContainer = getCurrentTest().getServerContainer();
- if (serverContainer != clientContainer)
- {
- SSLUtil.prepareContainer(serverContainer);
- }
- }
-
- @Override
- protected CDOViewProvider createViewProvider(final IManagedContainer container)
- {
- return new CDONet4jViewProvider.SSL()
- {
- @Override
- protected IManagedContainer getContainer()
- {
- return container;
- }
- };
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static final class JVM extends SessionConfig.Net4j
- {
- public static final String NAME = "JVM";
-
- public static final JVM INSTANCE = new JVM();
-
- public static final String ACCEPTOR_NAME = "default";
-
- private static final long serialVersionUID = 1L;
-
- public JVM()
- {
- super(NAME);
- }
-
- @Override
- public void initCapabilities(Set<String> capabilities)
- {
- super.initCapabilities(capabilities);
- capabilities.add(CAPABILITY_NET4J_JVM);
- }
-
- public String getURIPrefix()
- {
- return "cdo.net4j.jvm://" + ACCEPTOR_NAME;
- }
-
- @Override
- public IAcceptor getAcceptor()
- {
- return JVMUtil.getAcceptor(getCurrentTest().getServerContainer(), ACCEPTOR_NAME);
- }
-
- @Override
- public IConnector getConnector()
- {
- return JVMUtil.getConnector(getCurrentTest().getClientContainer(), ACCEPTOR_NAME);
- }
-
- @Override
- public void setUp() throws Exception
- {
- super.setUp();
- JVMUtil.prepareContainer(getCurrentTest().getClientContainer());
- JVMUtil.prepareContainer(getCurrentTest().getServerContainer());
- }
-
- @Override
- public boolean isValid(Set<IConfig> configs)
- {
- return !configs.contains(ContainerConfig.Separated.INSTANCE);
- }
-
- @Override
- protected CDOViewProvider createViewProvider(final IManagedContainer container)
- {
- return new CDONet4jViewProvider.JVM()
- {
- @Override
- protected IManagedContainer getContainer()
- {
- return container;
- }
- };
- }
- }
- }
-}
+/*
+ * 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.tests.config.impl;
+
+import org.eclipse.emf.cdo.net4j.CDONet4jSessionConfiguration;
+import org.eclipse.emf.cdo.net4j.CDONet4jUtil;
+import org.eclipse.emf.cdo.net4j.CDONet4jViewProvider;
+import org.eclipse.emf.cdo.server.CDOServerUtil;
+import org.eclipse.emf.cdo.server.IRepository;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.session.CDOSessionConfiguration;
+import org.eclipse.emf.cdo.spi.common.CDOLobStoreImpl;
+import org.eclipse.emf.cdo.tests.config.IConfig;
+import org.eclipse.emf.cdo.tests.config.IRepositoryConfig;
+import org.eclipse.emf.cdo.tests.config.ISessionConfig;
+import org.eclipse.emf.cdo.tests.util.TestRevisionManager;
+import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.view.CDOFetchRuleManager;
+import org.eclipse.emf.cdo.view.CDOViewProvider;
+import org.eclipse.emf.cdo.view.CDOViewProviderRegistry;
+
+import org.eclipse.net4j.acceptor.IAcceptor;
+import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.jvm.JVMUtil;
+import org.eclipse.net4j.tcp.TCPUtil;
+import org.eclipse.net4j.tcp.ssl.SSLUtil;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.io.IOUtil;
+import org.eclipse.net4j.util.lifecycle.ILifecycle;
+import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.security.IPasswordCredentialsProvider;
+
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.impl.EPackageImpl;
+
+import java.io.File;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class SessionConfig extends Config implements ISessionConfig
+{
+ public static final String PROP_TEST_SESSION_CONFIGURATION = "test.session.SessionConfiguration";
+
+ public static final String PROP_TEST_CREDENTIALS_PROVIDER = "test.session.CredentialsProvider";
+
+ public static final String PROP_TEST_FETCH_RULE_MANAGER = "test.session.FetchRuleManager";
+
+ private static final long serialVersionUID = 1L;
+
+ private transient Set<CDOSession> sessions;
+
+ private transient IListener sessionListener;
+
+ public SessionConfig(String name)
+ {
+ super(name);
+ }
+
+ public void startTransport() throws Exception
+ {
+ }
+
+ public void stopTransport() throws Exception
+ {
+ }
+
+ public CDOSession openSession()
+ {
+ return openSession(IRepositoryConfig.REPOSITORY_NAME);
+ }
+
+ public CDOSession openSession(String repositoryName)
+ {
+ CDOSessionConfiguration configuration = getTestSessionConfiguration();
+ if (configuration == null)
+ {
+ configuration = createSessionConfiguration(repositoryName);
+ }
+
+ IPasswordCredentialsProvider credentialsProvider = getTestCredentialsProvider();
+ if (credentialsProvider != null)
+ {
+ configuration.getAuthenticator().setCredentialsProvider(credentialsProvider);
+ }
+
+ CDOSession session = configuration.openSession();
+ configureSession(session);
+ session.addListener(sessionListener);
+
+ synchronized (sessions)
+ {
+ sessions.add(session);
+ }
+
+ return session;
+ }
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ sessions = new HashSet<CDOSession>();
+ sessionListener = new LifecycleEventAdapter()
+ {
+ @Override
+ protected void onDeactivated(ILifecycle session)
+ {
+ synchronized (sessions)
+ {
+ sessions.remove(session);
+ }
+ }
+ };
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ if (sessions != null)
+ {
+ CDOSession[] array;
+ synchronized (sessions)
+ {
+ array = sessions.toArray(new CDOSession[sessions.size()]);
+ }
+
+ for (CDOSession session : array)
+ {
+ session.removeListener(sessionListener);
+ LifecycleUtil.deactivate(session);
+ }
+
+ synchronized (sessions)
+ {
+ sessions.clear();
+ }
+ }
+
+ sessions = null;
+ sessionListener = null;
+ stopTransport();
+ super.tearDown();
+ }
+ finally
+ {
+ removeDynamicPackagesFromGlobalRegistry();
+ }
+ }
+
+ protected CDOSessionConfiguration getTestSessionConfiguration()
+ {
+ return (CDOSessionConfiguration)getTestProperty(PROP_TEST_SESSION_CONFIGURATION);
+ }
+
+ protected IPasswordCredentialsProvider getTestCredentialsProvider()
+ {
+ return (IPasswordCredentialsProvider)getTestProperty(PROP_TEST_CREDENTIALS_PROVIDER);
+ }
+
+ protected CDOFetchRuleManager getTestFetchRuleManager()
+ {
+ return (CDOFetchRuleManager)getTestProperty(PROP_TEST_FETCH_RULE_MANAGER);
+ }
+
+ protected abstract CDOSessionConfiguration createSessionConfiguration(String repositoryName);
+
+ protected void configureSession(CDOSession session)
+ {
+ final File lobCache = getCurrentTest().createTempFolder("tmp_" + new Date().getTime());
+ session.options().setLobCache(new CDOLobStoreImpl(lobCache));
+ session.addListener(new LifecycleEventAdapter()
+ {
+ @Override
+ protected void onDeactivated(ILifecycle lifecycle)
+ {
+ IOUtil.delete(lobCache);
+ }
+ });
+
+ CDOUtil.setLegacyModeDefault(true);
+ }
+
+ private void removeDynamicPackagesFromGlobalRegistry()
+ {
+ EPackage.Registry registry = EPackage.Registry.INSTANCE;
+ for (String uri : registry.keySet().toArray(new String[registry.size()]))
+ {
+ Object object = registry.get(uri);
+ if (object != null && object.getClass() == EPackageImpl.class)
+ {
+ registry.remove(uri);
+ }
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ * @deprecated Not yet supported.
+ */
+ @Deprecated
+ public static final class Embedded extends SessionConfig
+ {
+ public static final String NAME = "Embedded";
+
+ public static final Embedded INSTANCE = new Embedded();
+
+ private static final long serialVersionUID = 1L;
+
+ public Embedded()
+ {
+ super(NAME);
+ }
+
+ public void initCapabilities(Set<String> capabilities)
+ {
+ capabilities.add(CAPABILITY_EMBEDDED);
+ }
+
+ public String getURIPrefix()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected CDOSessionConfiguration createSessionConfiguration(String repositoryName)
+ {
+ IRepository repository = getCurrentTest().getRepository(repositoryName);
+
+ org.eclipse.emf.cdo.server.embedded.CDOSessionConfiguration configuration = CDOServerUtil
+ .createSessionConfiguration();
+ configuration.setRepository(repository);
+ return configuration;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static abstract class Net4j extends SessionConfig
+ {
+ private static final long serialVersionUID = 1L;
+
+ private transient CDOViewProvider viewProvider;
+
+ public Net4j(String name)
+ {
+ super(name);
+ }
+
+ public void initCapabilities(Set<String> capabilities)
+ {
+ capabilities.add(CAPABILITY_NET4J);
+ }
+
+ @Override
+ public void startTransport() throws Exception
+ {
+ IAcceptor acceptor = getAcceptor();
+ LifecycleUtil.activate(acceptor);
+
+ IConnector connector = getConnector();
+ LifecycleUtil.activate(connector);
+ }
+
+ @Override
+ public void stopTransport() throws Exception
+ {
+ ConfigTest currentTest = getCurrentTest();
+
+ try
+ {
+ if (currentTest.hasClientContainer())
+ {
+ IConnector connector = getConnector();
+ connector.close();
+ }
+ }
+ catch (Exception ex)
+ {
+ IOUtil.print(ex);
+ }
+
+ try
+ {
+ if (currentTest.hasServerContainer())
+ {
+ IAcceptor acceptor = getAcceptor();
+ acceptor.close();
+ }
+ }
+ catch (Exception ex)
+ {
+ IOUtil.print(ex);
+ }
+ }
+
+ @Override
+ protected CDOSessionConfiguration createSessionConfiguration(String repositoryName)
+ {
+ CDONet4jSessionConfiguration configuration = CDONet4jUtil.createNet4jSessionConfiguration();
+ configuration.setConnector(getConnector());
+ configuration.setRepositoryName(repositoryName);
+ configuration.setRevisionManager(new TestRevisionManager());
+ return configuration;
+ }
+
+ @Override
+ protected void configureSession(CDOSession session)
+ {
+ super.configureSession(session);
+ ((org.eclipse.emf.cdo.net4j.CDONet4jSession)session).options().getNet4jProtocol().setTimeout(-1);
+ }
+
+ protected abstract CDOViewProvider createViewProvider(IManagedContainer container);
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ viewProvider = createViewProvider(getCurrentTest().getClientContainer());
+ if (viewProvider != null)
+ {
+ CDOViewProviderRegistry.INSTANCE.addViewProvider(viewProvider);
+ }
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ if (viewProvider != null)
+ {
+ CDOViewProviderRegistry.INSTANCE.removeViewProvider(viewProvider);
+ }
+
+ super.tearDown();
+ }
+
+ public abstract IAcceptor getAcceptor();
+
+ public abstract IConnector getConnector();
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class TCP extends SessionConfig.Net4j
+ {
+ public static final String NAME = "TCP";
+
+ public static final TCP INSTANCE = new TCP();
+
+ public static final String CONNECTOR_HOST = "localhost";
+
+ private static final long serialVersionUID = 1L;
+
+ public TCP()
+ {
+ super(NAME);
+ }
+
+ @Override
+ public void initCapabilities(Set<String> capabilities)
+ {
+ super.initCapabilities(capabilities);
+ capabilities.add(CAPABILITY_NET4J_TCP);
+ }
+
+ public String getURIPrefix()
+ {
+ return "cdo.net4j.tcp://" + CONNECTOR_HOST;
+ }
+
+ @Override
+ public IAcceptor getAcceptor()
+ {
+ return TCPUtil.getAcceptor(getCurrentTest().getServerContainer(), null);
+ }
+
+ @Override
+ public IConnector getConnector()
+ {
+ return TCPUtil.getConnector(getCurrentTest().getClientContainer(), CONNECTOR_HOST);
+ }
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ IManagedContainer clientContainer = getCurrentTest().getClientContainer();
+ TCPUtil.prepareContainer(clientContainer);
+
+ IManagedContainer serverContainer = getCurrentTest().getServerContainer();
+ if (serverContainer != clientContainer)
+ {
+ TCPUtil.prepareContainer(serverContainer);
+ }
+ }
+
+ @Override
+ protected CDOViewProvider createViewProvider(final IManagedContainer container)
+ {
+ return new CDONet4jViewProvider.TCP()
+ {
+ @Override
+ protected IManagedContainer getContainer()
+ {
+ return container;
+ }
+ };
+ }
+ }
+
+ /**
+ * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
+ */
+ public static final class SSL extends SessionConfig.Net4j
+ {
+ public static final String NAME = "SSL";
+
+ public static final SSL INSTANCE = new SSL();
+
+ public static final String CONNECTOR_HOST = "localhost";
+
+ private static final long serialVersionUID = 1L;
+
+ public SSL()
+ {
+ super(NAME);
+ }
+
+ @Override
+ public void initCapabilities(Set<String> capabilities)
+ {
+ super.initCapabilities(capabilities);
+ capabilities.add(CAPABILITY_NET4J_SSL);
+ }
+
+ public String getURIPrefix()
+ {
+ return "cdo.net4j.ssl://" + CONNECTOR_HOST;
+ }
+
+ @Override
+ public IAcceptor getAcceptor()
+ {
+ return SSLUtil.getAcceptor(getCurrentTest().getServerContainer(), null);
+ }
+
+ @Override
+ public IConnector getConnector()
+ {
+ return SSLUtil.getConnector(getCurrentTest().getClientContainer(), CONNECTOR_HOST);
+ }
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ IManagedContainer clientContainer = getCurrentTest().getClientContainer();
+ SSLUtil.prepareContainer(clientContainer);
+
+ IManagedContainer serverContainer = getCurrentTest().getServerContainer();
+ if (serverContainer != clientContainer)
+ {
+ SSLUtil.prepareContainer(serverContainer);
+ }
+ }
+
+ @Override
+ protected CDOViewProvider createViewProvider(final IManagedContainer container)
+ {
+ return new CDONet4jViewProvider.SSL()
+ {
+ @Override
+ protected IManagedContainer getContainer()
+ {
+ return container;
+ }
+ };
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class JVM extends SessionConfig.Net4j
+ {
+ public static final String NAME = "JVM";
+
+ public static final JVM INSTANCE = new JVM();
+
+ public static final String ACCEPTOR_NAME = "default";
+
+ private static final long serialVersionUID = 1L;
+
+ public JVM()
+ {
+ super(NAME);
+ }
+
+ @Override
+ public void initCapabilities(Set<String> capabilities)
+ {
+ super.initCapabilities(capabilities);
+ capabilities.add(CAPABILITY_NET4J_JVM);
+ }
+
+ public String getURIPrefix()
+ {
+ return "cdo.net4j.jvm://" + ACCEPTOR_NAME;
+ }
+
+ @Override
+ public IAcceptor getAcceptor()
+ {
+ return JVMUtil.getAcceptor(getCurrentTest().getServerContainer(), ACCEPTOR_NAME);
+ }
+
+ @Override
+ public IConnector getConnector()
+ {
+ return JVMUtil.getConnector(getCurrentTest().getClientContainer(), ACCEPTOR_NAME);
+ }
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ JVMUtil.prepareContainer(getCurrentTest().getClientContainer());
+ JVMUtil.prepareContainer(getCurrentTest().getServerContainer());
+ }
+
+ @Override
+ public boolean isValid(Set<IConfig> configs)
+ {
+ return !configs.contains(ContainerConfig.Separated.INSTANCE);
+ }
+
+ @Override
+ protected CDOViewProvider createViewProvider(final IManagedContainer container)
+ {
+ return new CDONet4jViewProvider.JVM()
+ {
+ @Override
+ protected IManagedContainer getContainer()
+ {
+ return container;
+ }
+ };
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/ManagedContainer.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/ManagedContainer.java
index b5ed75dc9c..157e59e70e 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/ManagedContainer.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/ManagedContainer.java
@@ -1,666 +1,670 @@
-/*
- * 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.container;
-
-import org.eclipse.net4j.internal.util.bundle.OM;
-import org.eclipse.net4j.util.ObjectUtil;
-import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
-import org.eclipse.net4j.util.event.EventUtil;
-import org.eclipse.net4j.util.event.IEvent;
-import org.eclipse.net4j.util.event.IListener;
-import org.eclipse.net4j.util.factory.FactoryKey;
-import org.eclipse.net4j.util.factory.IFactory;
-import org.eclipse.net4j.util.factory.IFactoryKey;
-import org.eclipse.net4j.util.factory.ProductCreationException;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-import org.eclipse.net4j.util.lifecycle.Lifecycle;
-import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.registry.HashMapRegistry;
-import org.eclipse.net4j.util.registry.IRegistry;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
-import java.io.Serializable;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map.Entry;
-import java.util.Set;
-
-/**
- * A default implementation of a {@link IManagedContainer managed container}.
- *
- * @author Eike Stepper
- * @apiviz.exclude
- */
-public class ManagedContainer extends Lifecycle implements IManagedContainer
-{
- private IRegistry<IFactoryKey, IFactory> factoryRegistry;
-
- private List<IElementProcessor> postProcessors;
-
- private IRegistry<ElementKey, Object> elementRegistry = new HashMapRegistry<ElementKey, Object>();
-
- @ExcludeFromDump
- private transient long maxElementID;
-
- @ExcludeFromDump
- private transient IListener elementListener = new LifecycleEventAdapter()
- {
- @Override
- protected void onDeactivated(ILifecycle lifecycle)
- {
- for (Entry<ElementKey, Object> entry : getElementRegistryEntries())
- {
- if (lifecycle == entry.getValue())
- {
- removeElement(entry.getKey());
- return;
- }
- }
- }
- };
-
- public ManagedContainer()
- {
- }
-
- public synchronized IRegistry<IFactoryKey, IFactory> getFactoryRegistry()
- {
- if (factoryRegistry == null)
- {
- factoryRegistry = createFactoryRegistry();
- }
-
- return factoryRegistry;
- }
-
- public ManagedContainer registerFactory(IFactory factory)
- {
- getFactoryRegistry().put(factory.getKey(), factory);
- return this;
- }
-
- public synchronized List<IElementProcessor> getPostProcessors()
- {
- if (postProcessors == null)
- {
- postProcessors = createPostProcessors();
- }
-
- return postProcessors;
- }
-
- public synchronized void addPostProcessor(IElementProcessor postProcessor, boolean processExistingElements)
- {
- if (processExistingElements)
- {
- ContainerEvent<Object> event = new ContainerEvent<Object>(this);
- for (Entry<ElementKey, Object> entry : getElementRegistryEntries())
- {
- ElementKey key = entry.getKey();
- Object element = entry.getValue();
-
- String productGroup = key.getProductGroup();
- String factoryType = key.getFactoryType();
- String description = key.getDescription();
- Object newElement = postProcessor.process(this, productGroup, factoryType, description, element);
- if (newElement != element)
- {
- synchronized (elementRegistry)
- {
- elementRegistry.put(key, newElement);
- }
-
- event.addDelta(element, IContainerDelta.Kind.REMOVED);
- event.addDelta(newElement, IContainerDelta.Kind.ADDED);
- }
- }
-
- fireEvent(event);
- }
-
- getPostProcessors().add(postProcessor);
- }
-
- public void addPostProcessor(IElementProcessor postProcessor)
- {
- addPostProcessor(postProcessor, false);
- }
-
- public void removePostProcessor(IElementProcessor postProcessor)
- {
- getPostProcessors().remove(postProcessor);
- }
-
- public Set<String> getProductGroups()
- {
- checkActive();
- Set<String> result = new HashSet<String>();
- for (IFactoryKey key : factoryRegistry.keySet())
- {
- result.add(key.getProductGroup());
- }
-
- for (ElementKey key : getElementRegistryKeys())
- {
- result.add(key.getProductGroup());
- }
-
- return result;
- }
-
- public Set<String> getFactoryTypes(String productGroup)
- {
- checkActive();
- Set<String> result = new HashSet<String>();
- for (IFactoryKey key : factoryRegistry.keySet())
- {
- if (ObjectUtil.equals(key.getProductGroup(), productGroup))
- {
- result.add(key.getType());
- }
- }
-
- for (ElementKey key : getElementRegistryKeys())
- {
- if (ObjectUtil.equals(key.getProductGroup(), productGroup))
- {
- result.add(key.getFactoryType());
- }
- }
-
- return result;
- }
-
- public IFactory getFactory(String productGroup, String factoryType) throws FactoryNotFoundException
- {
- FactoryKey key = new FactoryKey(productGroup, factoryType);
- IFactory factory = getFactoryRegistry().get(key);
- if (factory == null)
- {
- throw new FactoryNotFoundException("Factory not found: " + key); //$NON-NLS-1$
- }
-
- return factory;
- }
-
- public boolean isEmpty()
- {
- checkActive();
- synchronized (elementRegistry)
- {
- return elementRegistry.isEmpty();
- }
- }
-
- public String[] getElementKey(Object element)
- {
- checkActive();
- for (Entry<ElementKey, Object> entry : getElementRegistryEntries())
- {
- if (entry.getValue() == element)
- {
- ElementKey key = entry.getKey();
- String[] result = { key.getProductGroup(), key.getFactoryType(), key.getDescription() };
- return result;
- }
- }
-
- return null;
- }
-
- public Object[] getElements()
- {
- checkActive();
- return getElementRegistryValues();
- }
-
- public Object[] getElements(String productGroup)
- {
- checkActive();
- List<Object> result = new ArrayList<Object>();
- for (Entry<ElementKey, Object> entry : getElementRegistryEntries())
- {
- ElementKey key = entry.getKey();
- if (ObjectUtil.equals(key.getProductGroup(), productGroup))
- {
- result.add(entry.getValue());
- }
- }
-
- return result.toArray();
- }
-
- public Object[] getElements(String productGroup, String factoryType)
- {
- checkActive();
- List<Object> result = new ArrayList<Object>();
- for (Entry<ElementKey, Object> entry : getElementRegistryEntries())
- {
- ElementKey key = entry.getKey();
- if (ObjectUtil.equals(key.getProductGroup(), productGroup)
- && ObjectUtil.equals(key.getFactoryType(), factoryType))
- {
- result.add(entry.getValue());
- }
- }
-
- return result.toArray();
- }
-
- public Object getElement(String productGroup, String factoryType, String description)
- throws FactoryNotFoundException, ProductCreationException
- {
- return getElement(productGroup, factoryType, description, true);
- }
-
- /**
- * @since 2.0
- */
- public Object getElement(String productGroup, String factoryType, String description, boolean activate)
- throws FactoryNotFoundException, ProductCreationException
- {
- checkActive();
- ElementKey key = new ElementKey(productGroup, factoryType, description);
- Object element;
- synchronized (elementRegistry)
- {
- element = elementRegistry.get(key);
- }
-
- if (element == null)
- {
- element = createElement(productGroup, factoryType, description);
- element = postProcessElement(productGroup, factoryType, description, element);
-
- if (activate)
- {
- LifecycleUtil.activate(element);
- }
-
- putElement(key, element);
- }
-
- return element;
- }
-
- public Object putElement(String productGroup, String factoryType, String description, Object element)
- {
- checkActive();
- element = postProcessElement(productGroup, factoryType, description, element);
-
- ElementKey key = new ElementKey(productGroup, factoryType, description);
- return putElement(key, element);
- }
-
- protected Object putElement(ElementKey key, Object element)
- {
- ContainerEvent<Object> event = new ContainerEvent<Object>(this);
- Object oldElement;
- synchronized (elementRegistry)
- {
- key.setID(++maxElementID);
- oldElement = elementRegistry.put(key, element);
- }
-
- if (oldElement != null)
- {
- EventUtil.removeListener(oldElement, elementListener);
- event.addDelta(oldElement, IContainerDelta.Kind.REMOVED);
- }
-
- event.addDelta(element, IContainerDelta.Kind.ADDED);
- fireEvent(event);
- EventUtil.addListener(element, elementListener);
- return oldElement;
- }
-
- public Object removeElement(String productGroup, String factoryType, String description)
- {
- checkActive();
- ElementKey key = new ElementKey(productGroup, factoryType, description);
- return removeElement(key);
- }
-
- protected Object removeElement(ElementKey key)
- {
- Object element;
- synchronized (elementRegistry)
- {
- element = elementRegistry.remove(key);
- }
-
- if (element != null)
- {
- EventUtil.removeListener(element, elementListener);
- fireEvent(new SingleDeltaContainerEvent<Object>(this, element, IContainerDelta.Kind.REMOVED));
- }
-
- return element;
- }
-
- public void clearElements()
- {
- checkActive();
- ContainerEvent<Object> event = null;
- synchronized (elementRegistry)
- {
- if (!elementRegistry.isEmpty())
- {
- event = new ContainerEvent<Object>(this);
- for (Object element : elementRegistry.values())
- {
- EventUtil.removeListener(element, elementListener);
- event.addDelta(element, IContainerDelta.Kind.REMOVED);
- }
-
- elementRegistry.clear();
- }
- }
-
- if (event != null)
- {
- fireEvent(event);
- }
- }
-
- public void loadElements(InputStream stream) throws IOException, FactoryNotFoundException, ProductCreationException
- {
- checkActive();
- synchronized (elementRegistry)
- {
- clearElements();
- ObjectInputStream ois = new ObjectInputStream(stream);
- int size = ois.readInt();
- for (int i = 0; i < size; i++)
- {
- try
- {
- ElementKey key = (ElementKey)ois.readObject();
- Object element = getElement(key.getProductGroup(), key.getFactoryType(), key.getDescription());
-
- boolean active = ois.readBoolean();
- if (active)
- {
- // TODO Reconsider activation
- LifecycleUtil.activate(element);
- }
- }
- catch (ClassNotFoundException cannotHappen)
- {
- }
- }
-
- initMaxElementID();
- }
- }
-
- public void saveElements(OutputStream stream) throws IOException
- {
- checkActive();
- synchronized (elementRegistry)
- {
- ObjectOutputStream oos = new ObjectOutputStream(stream);
- List<Entry<ElementKey, Object>> entries = new ArrayList<Entry<ElementKey, Object>>(elementRegistry.entrySet());
- Collections.sort(entries, new EntryComparator());
-
- oos.writeInt(entries.size());
- for (Entry<ElementKey, Object> entry : entries)
- {
- oos.writeObject(entry.getKey());
- oos.writeBoolean(LifecycleUtil.isActive(entry.getValue()));
- }
- }
- }
-
- @Override
- public void fireEvent(IEvent event)
- {
- if (event instanceof IContainerEvent<?>)
- {
- @SuppressWarnings("unchecked")
- IContainerEvent<Object> e = (IContainerEvent<Object>)event;
- if (e.isEmpty())
- {
- return;
- }
- }
-
- super.fireEvent(event);
- }
-
- @Override
- public String toString()
- {
- return "ManagedContainer"; //$NON-NLS-1$
- }
-
- protected IRegistry<IFactoryKey, IFactory> createFactoryRegistry()
- {
- return new HashMapRegistry<IFactoryKey, IFactory>();
- }
-
- protected List<IElementProcessor> createPostProcessors()
- {
- return new ArrayList<IElementProcessor>();
- }
-
- /**
- * @since 2.0
- */
- protected ElementKey[] getElementRegistryKeys()
- {
- synchronized (elementRegistry)
- {
- return elementRegistry.keySet().toArray(new ElementKey[elementRegistry.size()]);
- }
- }
-
- /**
- * @since 2.0
- */
- protected Object[] getElementRegistryValues()
- {
- synchronized (elementRegistry)
- {
- return elementRegistry.values().toArray(new Object[elementRegistry.size()]);
- }
- }
-
- /**
- * @since 2.0
- */
- @SuppressWarnings("unchecked")
- protected Entry<ElementKey, Object>[] getElementRegistryEntries()
- {
- synchronized (elementRegistry)
- {
- return elementRegistry.entrySet().toArray(new Entry[elementRegistry.size()]);
- }
- }
-
- protected Object createElement(String productGroup, String factoryType, String description)
- throws FactoryNotFoundException, ProductCreationException
- {
- IFactory factory = getFactory(productGroup, factoryType);
- return factory.create(description);
- }
-
- protected Object postProcessElement(String productGroup, String factoryType, String description, Object element)
- {
- for (IElementProcessor processor : getPostProcessors())
- {
- element = processor.process(this, productGroup, factoryType, description, element);
- }
-
- return element;
- }
-
- private void initMaxElementID()
- {
- maxElementID = 0L;
- for (ElementKey key : elementRegistry.keySet())
- {
- long id = key.getID();
- if (maxElementID < id)
- {
- maxElementID = id;
- }
- }
- }
-
- @Override
- protected void doActivate() throws Exception
- {
- super.doActivate();
- LifecycleUtil.activate(getFactoryRegistry());
- LifecycleUtil.activate(getPostProcessors());
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- for (Object element : getElementRegistryValues())
- {
- try
- {
- LifecycleUtil.deactivateNoisy(element);
- EventUtil.removeListener(element, elementListener);
- }
- catch (RuntimeException ex)
- {
- OM.LOG.warn(ex);
- }
- }
-
- LifecycleUtil.deactivate(factoryRegistry);
- factoryRegistry = null;
-
- LifecycleUtil.deactivate(postProcessors);
- postProcessors = null;
-
- elementRegistry.clear();
- elementRegistry = null;
- super.doDeactivate();
- }
-
- /**
- * @author Eike Stepper
- */
- private static final class ElementKey implements Serializable, Comparable<ElementKey>
- {
- private static final long serialVersionUID = 1L;
-
- private long id;
-
- private String productGroup;
-
- private String factoryType;
-
- private String description;
-
- public ElementKey(String productGroup, String factoryType, String description)
- {
- this.productGroup = productGroup;
- this.factoryType = factoryType;
- this.description = description;
- }
-
- public long getID()
- {
- return id;
- }
-
- public void setID(long id)
- {
- this.id = id;
- }
-
- public String getProductGroup()
- {
- return productGroup;
- }
-
- public String getFactoryType()
- {
- return factoryType;
- }
-
- public String getDescription()
- {
- return description;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (obj == this)
- {
- return true;
- }
-
- if (obj instanceof ElementKey)
- {
- ElementKey key = (ElementKey)obj;
- return ObjectUtil.equals(productGroup, key.productGroup) && ObjectUtil.equals(factoryType, key.factoryType)
- && ObjectUtil.equals(description, key.description);
- }
-
- return false;
- }
-
- @Override
- public int hashCode()
- {
- return ObjectUtil.hashCode(productGroup) ^ ObjectUtil.hashCode(factoryType) ^ ObjectUtil.hashCode(description);
- }
-
- @Override
- public String toString()
- {
- return MessageFormat.format("{0}[{1}, {2}]", productGroup, factoryType, description); //$NON-NLS-1$
- }
-
- public int compareTo(ElementKey key)
- {
- if (id < key.id)
- {
- return -1;
- }
-
- if (id > key.id)
- {
- return 1;
- }
-
- return 0;
- }
- }
-
- /**
- * @author Eike Stepper
- */
- private static final class EntryComparator implements Comparator<Entry<ElementKey, Object>>
- {
- public int compare(Entry<ElementKey, Object> entry1, Entry<ElementKey, Object> entry2)
- {
- return entry1.getKey().compareTo(entry2.getKey());
- }
- }
-}
+/*
+ * 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.container;
+
+import org.eclipse.net4j.internal.util.bundle.OM;
+import org.eclipse.net4j.util.ObjectUtil;
+import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
+import org.eclipse.net4j.util.event.EventUtil;
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.factory.FactoryKey;
+import org.eclipse.net4j.util.factory.IFactory;
+import org.eclipse.net4j.util.factory.IFactoryKey;
+import org.eclipse.net4j.util.factory.ProductCreationException;
+import org.eclipse.net4j.util.lifecycle.ILifecycle;
+import org.eclipse.net4j.util.lifecycle.Lifecycle;
+import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.registry.HashMapRegistry;
+import org.eclipse.net4j.util.registry.IRegistry;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.Set;
+
+/**
+ * A default implementation of a {@link IManagedContainer managed container}.
+ *
+ * @author Eike Stepper
+ * @apiviz.exclude
+ */
+public class ManagedContainer extends Lifecycle implements IManagedContainer
+{
+ private IRegistry<IFactoryKey, IFactory> factoryRegistry;
+
+ private List<IElementProcessor> postProcessors;
+
+ private IRegistry<ElementKey, Object> elementRegistry = new HashMapRegistry<ElementKey, Object>();
+
+ @ExcludeFromDump
+ private transient long maxElementID;
+
+ @ExcludeFromDump
+ private transient IListener elementListener = new LifecycleEventAdapter()
+ {
+ @Override
+ protected void onDeactivated(ILifecycle lifecycle)
+ {
+ for (Entry<ElementKey, Object> entry : getElementRegistryEntries())
+ {
+ if (lifecycle == entry.getValue())
+ {
+ removeElement(entry.getKey());
+ return;
+ }
+ }
+ }
+ };
+
+ public ManagedContainer()
+ {
+ }
+
+ public synchronized IRegistry<IFactoryKey, IFactory> getFactoryRegistry()
+ {
+ if (factoryRegistry == null)
+ {
+ factoryRegistry = createFactoryRegistry();
+ }
+
+ return factoryRegistry;
+ }
+
+ public ManagedContainer registerFactory(IFactory factory)
+ {
+ getFactoryRegistry().put(factory.getKey(), factory);
+ return this;
+ }
+
+ public synchronized List<IElementProcessor> getPostProcessors()
+ {
+ if (postProcessors == null)
+ {
+ postProcessors = createPostProcessors();
+ }
+
+ return postProcessors;
+ }
+
+ public synchronized void addPostProcessor(IElementProcessor postProcessor, boolean processExistingElements)
+ {
+ if (processExistingElements)
+ {
+ ContainerEvent<Object> event = new ContainerEvent<Object>(this);
+ for (Entry<ElementKey, Object> entry : getElementRegistryEntries())
+ {
+ ElementKey key = entry.getKey();
+ Object element = entry.getValue();
+
+ String productGroup = key.getProductGroup();
+ String factoryType = key.getFactoryType();
+ String description = key.getDescription();
+ Object newElement = postProcessor.process(this, productGroup, factoryType, description, element);
+ if (newElement != element)
+ {
+ synchronized (elementRegistry)
+ {
+ elementRegistry.put(key, newElement);
+ }
+
+ event.addDelta(element, IContainerDelta.Kind.REMOVED);
+ event.addDelta(newElement, IContainerDelta.Kind.ADDED);
+ }
+ }
+
+ fireEvent(event);
+ }
+
+ getPostProcessors().add(postProcessor);
+ }
+
+ public void addPostProcessor(IElementProcessor postProcessor)
+ {
+ addPostProcessor(postProcessor, false);
+ }
+
+ public void removePostProcessor(IElementProcessor postProcessor)
+ {
+ getPostProcessors().remove(postProcessor);
+ }
+
+ public Set<String> getProductGroups()
+ {
+ checkActive();
+ Set<String> result = new HashSet<String>();
+ for (IFactoryKey key : factoryRegistry.keySet())
+ {
+ result.add(key.getProductGroup());
+ }
+
+ for (ElementKey key : getElementRegistryKeys())
+ {
+ result.add(key.getProductGroup());
+ }
+
+ return result;
+ }
+
+ public Set<String> getFactoryTypes(String productGroup)
+ {
+ checkActive();
+ Set<String> result = new HashSet<String>();
+ for (IFactoryKey key : factoryRegistry.keySet())
+ {
+ if (ObjectUtil.equals(key.getProductGroup(), productGroup))
+ {
+ result.add(key.getType());
+ }
+ }
+
+ for (ElementKey key : getElementRegistryKeys())
+ {
+ if (ObjectUtil.equals(key.getProductGroup(), productGroup))
+ {
+ result.add(key.getFactoryType());
+ }
+ }
+
+ return result;
+ }
+
+ public IFactory getFactory(String productGroup, String factoryType) throws FactoryNotFoundException
+ {
+ FactoryKey key = new FactoryKey(productGroup, factoryType);
+ IFactory factory = getFactoryRegistry().get(key);
+ if (factory == null)
+ {
+ throw new FactoryNotFoundException("Factory not found: " + key); //$NON-NLS-1$
+ }
+
+ return factory;
+ }
+
+ public boolean isEmpty()
+ {
+ checkActive();
+ synchronized (elementRegistry)
+ {
+ return elementRegistry.isEmpty();
+ }
+ }
+
+ public String[] getElementKey(Object element)
+ {
+ checkActive();
+ for (Entry<ElementKey, Object> entry : getElementRegistryEntries())
+ {
+ if (entry.getValue() == element)
+ {
+ ElementKey key = entry.getKey();
+ String[] result = { key.getProductGroup(), key.getFactoryType(), key.getDescription() };
+ return result;
+ }
+ }
+
+ return null;
+ }
+
+ public Object[] getElements()
+ {
+ checkActive();
+ return getElementRegistryValues();
+ }
+
+ public Object[] getElements(String productGroup)
+ {
+ checkActive();
+ List<Object> result = new ArrayList<Object>();
+ for (Entry<ElementKey, Object> entry : getElementRegistryEntries())
+ {
+ ElementKey key = entry.getKey();
+ if (ObjectUtil.equals(key.getProductGroup(), productGroup))
+ {
+ result.add(entry.getValue());
+ }
+ }
+
+ return result.toArray();
+ }
+
+ public Object[] getElements(String productGroup, String factoryType)
+ {
+ checkActive();
+ List<Object> result = new ArrayList<Object>();
+ for (Entry<ElementKey, Object> entry : getElementRegistryEntries())
+ {
+ ElementKey key = entry.getKey();
+ if (ObjectUtil.equals(key.getProductGroup(), productGroup)
+ && ObjectUtil.equals(key.getFactoryType(), factoryType))
+ {
+ result.add(entry.getValue());
+ }
+ }
+
+ return result.toArray();
+ }
+
+ public Object getElement(String productGroup, String factoryType, String description)
+ throws FactoryNotFoundException, ProductCreationException
+ {
+ return getElement(productGroup, factoryType, description, true);
+ }
+
+ /**
+ * @since 2.0
+ */
+ public Object getElement(String productGroup, String factoryType, String description, boolean activate)
+ throws FactoryNotFoundException, ProductCreationException
+ {
+ checkActive();
+ ElementKey key = new ElementKey(productGroup, factoryType, description);
+ Object element;
+ synchronized (elementRegistry)
+ {
+ element = elementRegistry.get(key);
+ }
+
+ if (element == null)
+ {
+ element = createElement(productGroup, factoryType, description);
+ element = postProcessElement(productGroup, factoryType, description, element);
+
+ if (activate)
+ {
+ LifecycleUtil.activate(element);
+ }
+
+ putElement(key, element);
+ }
+
+ return element;
+ }
+
+ public Object putElement(String productGroup, String factoryType, String description, Object element)
+ {
+ checkActive();
+ element = postProcessElement(productGroup, factoryType, description, element);
+
+ ElementKey key = new ElementKey(productGroup, factoryType, description);
+ return putElement(key, element);
+ }
+
+ protected Object putElement(ElementKey key, Object element)
+ {
+ ContainerEvent<Object> event = new ContainerEvent<Object>(this);
+ Object oldElement;
+ synchronized (elementRegistry)
+ {
+ key.setID(++maxElementID);
+ oldElement = elementRegistry.put(key, element);
+ }
+
+ if (oldElement != element)
+ {
+ if (oldElement != null)
+ {
+ EventUtil.removeListener(oldElement, elementListener);
+ event.addDelta(oldElement, IContainerDelta.Kind.REMOVED);
+ }
+
+ event.addDelta(element, IContainerDelta.Kind.ADDED);
+ fireEvent(event);
+ EventUtil.addListener(element, elementListener);
+ }
+
+ return oldElement;
+ }
+
+ public Object removeElement(String productGroup, String factoryType, String description)
+ {
+ checkActive();
+ ElementKey key = new ElementKey(productGroup, factoryType, description);
+ return removeElement(key);
+ }
+
+ protected Object removeElement(ElementKey key)
+ {
+ Object element;
+ synchronized (elementRegistry)
+ {
+ element = elementRegistry.remove(key);
+ }
+
+ if (element != null)
+ {
+ EventUtil.removeListener(element, elementListener);
+ fireEvent(new SingleDeltaContainerEvent<Object>(this, element, IContainerDelta.Kind.REMOVED));
+ }
+
+ return element;
+ }
+
+ public void clearElements()
+ {
+ checkActive();
+ ContainerEvent<Object> event = null;
+ synchronized (elementRegistry)
+ {
+ if (!elementRegistry.isEmpty())
+ {
+ event = new ContainerEvent<Object>(this);
+ for (Object element : elementRegistry.values())
+ {
+ EventUtil.removeListener(element, elementListener);
+ event.addDelta(element, IContainerDelta.Kind.REMOVED);
+ }
+
+ elementRegistry.clear();
+ }
+ }
+
+ if (event != null)
+ {
+ fireEvent(event);
+ }
+ }
+
+ public void loadElements(InputStream stream) throws IOException, FactoryNotFoundException, ProductCreationException
+ {
+ checkActive();
+ synchronized (elementRegistry)
+ {
+ clearElements();
+ ObjectInputStream ois = new ObjectInputStream(stream);
+ int size = ois.readInt();
+ for (int i = 0; i < size; i++)
+ {
+ try
+ {
+ ElementKey key = (ElementKey)ois.readObject();
+ Object element = getElement(key.getProductGroup(), key.getFactoryType(), key.getDescription());
+
+ boolean active = ois.readBoolean();
+ if (active)
+ {
+ // TODO Reconsider activation
+ LifecycleUtil.activate(element);
+ }
+ }
+ catch (ClassNotFoundException cannotHappen)
+ {
+ }
+ }
+
+ initMaxElementID();
+ }
+ }
+
+ public void saveElements(OutputStream stream) throws IOException
+ {
+ checkActive();
+ synchronized (elementRegistry)
+ {
+ ObjectOutputStream oos = new ObjectOutputStream(stream);
+ List<Entry<ElementKey, Object>> entries = new ArrayList<Entry<ElementKey, Object>>(elementRegistry.entrySet());
+ Collections.sort(entries, new EntryComparator());
+
+ oos.writeInt(entries.size());
+ for (Entry<ElementKey, Object> entry : entries)
+ {
+ oos.writeObject(entry.getKey());
+ oos.writeBoolean(LifecycleUtil.isActive(entry.getValue()));
+ }
+ }
+ }
+
+ @Override
+ public void fireEvent(IEvent event)
+ {
+ if (event instanceof IContainerEvent<?>)
+ {
+ @SuppressWarnings("unchecked")
+ IContainerEvent<Object> e = (IContainerEvent<Object>)event;
+ if (e.isEmpty())
+ {
+ return;
+ }
+ }
+
+ super.fireEvent(event);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "ManagedContainer"; //$NON-NLS-1$
+ }
+
+ protected IRegistry<IFactoryKey, IFactory> createFactoryRegistry()
+ {
+ return new HashMapRegistry<IFactoryKey, IFactory>();
+ }
+
+ protected List<IElementProcessor> createPostProcessors()
+ {
+ return new ArrayList<IElementProcessor>();
+ }
+
+ /**
+ * @since 2.0
+ */
+ protected ElementKey[] getElementRegistryKeys()
+ {
+ synchronized (elementRegistry)
+ {
+ return elementRegistry.keySet().toArray(new ElementKey[elementRegistry.size()]);
+ }
+ }
+
+ /**
+ * @since 2.0
+ */
+ protected Object[] getElementRegistryValues()
+ {
+ synchronized (elementRegistry)
+ {
+ return elementRegistry.values().toArray(new Object[elementRegistry.size()]);
+ }
+ }
+
+ /**
+ * @since 2.0
+ */
+ @SuppressWarnings("unchecked")
+ protected Entry<ElementKey, Object>[] getElementRegistryEntries()
+ {
+ synchronized (elementRegistry)
+ {
+ return elementRegistry.entrySet().toArray(new Entry[elementRegistry.size()]);
+ }
+ }
+
+ protected Object createElement(String productGroup, String factoryType, String description)
+ throws FactoryNotFoundException, ProductCreationException
+ {
+ IFactory factory = getFactory(productGroup, factoryType);
+ return factory.create(description);
+ }
+
+ protected Object postProcessElement(String productGroup, String factoryType, String description, Object element)
+ {
+ for (IElementProcessor processor : getPostProcessors())
+ {
+ element = processor.process(this, productGroup, factoryType, description, element);
+ }
+
+ return element;
+ }
+
+ private void initMaxElementID()
+ {
+ maxElementID = 0L;
+ for (ElementKey key : elementRegistry.keySet())
+ {
+ long id = key.getID();
+ if (maxElementID < id)
+ {
+ maxElementID = id;
+ }
+ }
+ }
+
+ @Override
+ protected void doActivate() throws Exception
+ {
+ super.doActivate();
+ LifecycleUtil.activate(getFactoryRegistry());
+ LifecycleUtil.activate(getPostProcessors());
+ }
+
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ for (Object element : getElementRegistryValues())
+ {
+ try
+ {
+ LifecycleUtil.deactivateNoisy(element);
+ EventUtil.removeListener(element, elementListener);
+ }
+ catch (RuntimeException ex)
+ {
+ OM.LOG.warn(ex);
+ }
+ }
+
+ LifecycleUtil.deactivate(factoryRegistry);
+ factoryRegistry = null;
+
+ LifecycleUtil.deactivate(postProcessors);
+ postProcessors = null;
+
+ elementRegistry.clear();
+ elementRegistry = null;
+ super.doDeactivate();
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private static final class ElementKey implements Serializable, Comparable<ElementKey>
+ {
+ private static final long serialVersionUID = 1L;
+
+ private long id;
+
+ private String productGroup;
+
+ private String factoryType;
+
+ private String description;
+
+ public ElementKey(String productGroup, String factoryType, String description)
+ {
+ this.productGroup = productGroup;
+ this.factoryType = factoryType;
+ this.description = description;
+ }
+
+ public long getID()
+ {
+ return id;
+ }
+
+ public void setID(long id)
+ {
+ this.id = id;
+ }
+
+ public String getProductGroup()
+ {
+ return productGroup;
+ }
+
+ public String getFactoryType()
+ {
+ return factoryType;
+ }
+
+ public String getDescription()
+ {
+ return description;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ {
+ return true;
+ }
+
+ if (obj instanceof ElementKey)
+ {
+ ElementKey key = (ElementKey)obj;
+ return ObjectUtil.equals(productGroup, key.productGroup) && ObjectUtil.equals(factoryType, key.factoryType)
+ && ObjectUtil.equals(description, key.description);
+ }
+
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return ObjectUtil.hashCode(productGroup) ^ ObjectUtil.hashCode(factoryType) ^ ObjectUtil.hashCode(description);
+ }
+
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format("{0}[{1}, {2}]", productGroup, factoryType, description); //$NON-NLS-1$
+ }
+
+ public int compareTo(ElementKey key)
+ {
+ if (id < key.id)
+ {
+ return -1;
+ }
+
+ if (id > key.id)
+ {
+ return 1;
+ }
+
+ return 0;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private static final class EntryComparator implements Comparator<Entry<ElementKey, Object>>
+ {
+ public int compare(Entry<ElementKey, Object> entry1, Entry<ElementKey, Object> entry2)
+ {
+ return entry1.getKey().compareTo(entry2.getKey());
+ }
+ }
+}
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 496fccb6b2..b85b6d289b 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
@@ -56,7 +56,9 @@ public class SetContainer<E> extends Container<E>
{
@SuppressWarnings("unchecked")
E[] a = (E[])Array.newInstance(componentType, set.size());
+
array = set.toArray(a);
+ array = sortElements(array);
}
return array;
@@ -64,10 +66,14 @@ public class SetContainer<E> extends Container<E>
public boolean addElement(E element)
{
- checkActive();
boolean added;
synchronized (this)
{
+ if (!validateElement(element))
+ {
+ return false;
+ }
+
added = set.add(element);
if (added)
{
@@ -87,7 +93,6 @@ public class SetContainer<E> extends Container<E>
public boolean removeElement(E element)
{
- checkActive();
boolean removed;
synchronized (this)
{
@@ -112,4 +117,14 @@ public class SetContainer<E> extends Container<E>
{
return set;
}
+
+ protected E[] sortElements(E[] array)
+ {
+ return array;
+ }
+
+ protected boolean validateElement(E element)
+ {
+ return true;
+ }
}

Back to the top