Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-09-24 08:11:55 +0000
committerEike Stepper2012-09-24 08:11:55 +0000
commit5099a29f7a689840273b7c75102ed404a278c6ac (patch)
treefd99a222b2608e29c814897cef76632a289d09f3
parent29e1e2337294bbdae52221cb72b12567caac81f5 (diff)
downloadcdo-5099a29f7a689840273b7c75102ed404a278c6ac.tar.gz
cdo-5099a29f7a689840273b7c75102ed404a278c6ac.tar.xz
cdo-5099a29f7a689840273b7c75102ed404a278c6ac.zip
[390169] Provide a central registry for open CDOViews
https://bugs.eclipse.org/bugs/show_bug.cgi?id=390169
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOViewRegistry.java50
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOViewContainerImpl.java1
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java4
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewRegistryImpl.java147
4 files changed, 202 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOViewRegistry.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOViewRegistry.java
new file mode 100644
index 0000000000..017650e910
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOViewRegistry.java
@@ -0,0 +1,50 @@
+/*
+ * 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.view;
+
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.view.CDOViewRegistry.Registration;
+
+import org.eclipse.net4j.util.container.IContainer;
+
+/**
+ * A global registry of all open {@link CDOView views} and {@link CDOTransaction transactions}.
+ *
+ * @author Eike Stepper
+ * @since 4.2
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
+ * @apiviz.composedOf {@link org.eclipse.emf.cdo.view.CDOView}
+ */
+public interface CDOViewRegistry extends IContainer<Registration>
+{
+ public static final CDOViewRegistry INSTANCE = org.eclipse.emf.internal.cdo.view.CDOViewRegistryImpl.INSTANCE;
+
+ public static final int NOT_REGISTERED = 0;
+
+ public int[] getIDs();
+
+ public CDOView[] getViews();
+
+ public int getID(CDOView view);
+
+ public CDOView getView(int id);
+
+ /**
+ * @author Eike Stepper
+ */
+ public interface Registration
+ {
+ public int getID();
+
+ public CDOView getView();
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOViewContainerImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOViewContainerImpl.java
index 6d8cb6165d..5fccdb3748 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOViewContainerImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/session/CDOViewContainerImpl.java
@@ -245,6 +245,7 @@ public abstract class CDOViewContainerImpl extends Container<CDOView> implements
}
viewSet.remove(view);
+ view.deactivate();
throw ex;
}
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
index a66fb3716d..61c4701b8f 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
@@ -1119,6 +1119,8 @@ public class CDOViewImpl extends AbstractCDOView
{
sessionProtocol.openView(viewID, isReadOnly(), this);
}
+
+ CDOViewRegistryImpl.INSTANCE.register(this);
}
/**
@@ -1127,6 +1129,8 @@ public class CDOViewImpl extends AbstractCDOView
@Override
protected void doDeactivate() throws Exception
{
+ CDOViewRegistryImpl.INSTANCE.deregister(this);
+
if (invalidationRunner != null)
{
LifecycleUtil.deactivate(invalidationRunner, OMLogger.Level.WARN);
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewRegistryImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewRegistryImpl.java
new file mode 100644
index 0000000000..4fcde5f869
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewRegistryImpl.java
@@ -0,0 +1,147 @@
+/*
+ * 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.internal.cdo.view;
+
+import org.eclipse.emf.cdo.view.CDOView;
+import org.eclipse.emf.cdo.view.CDOViewRegistry;
+import org.eclipse.emf.cdo.view.CDOViewRegistry.Registration;
+
+import org.eclipse.net4j.util.container.Container;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ * @since 4.2
+ * @see CDOView
+ */
+public class CDOViewRegistryImpl extends Container<Registration> implements CDOViewRegistry
+{
+ public static final CDOViewRegistryImpl INSTANCE = new CDOViewRegistryImpl();
+
+ private final Map<Integer, Registration> ids = new HashMap<Integer, Registration>();
+
+ private final Map<CDOView, Registration> views = new HashMap<CDOView, Registration>();
+
+ private int lastID;
+
+ public CDOViewRegistryImpl()
+ {
+ }
+
+ public synchronized Registration[] getElements()
+ {
+ return ids.values().toArray(new Registration[ids.size()]);
+ }
+
+ public synchronized int[] getIDs()
+ {
+ int[] result = new int[ids.size()];
+
+ int i = 0;
+ for (Integer id : ids.keySet())
+ {
+ result[i++] = id;
+ }
+
+ return result;
+ }
+
+ public synchronized CDOView[] getViews()
+ {
+ return views.keySet().toArray(new CDOView[views.size()]);
+ }
+
+ public synchronized int getID(CDOView view)
+ {
+ Registration registration = views.get(view);
+ if (registration != null)
+ {
+ return registration.getID();
+ }
+
+ return NOT_REGISTERED;
+ }
+
+ public synchronized CDOView getView(int id)
+ {
+ Registration registration = ids.get(id);
+ if (registration != null)
+ {
+ return registration.getView();
+ }
+
+ return null;
+ }
+
+ void register(CDOView view)
+ {
+ Registration registration;
+ synchronized (this)
+ {
+ if (views.containsKey(view))
+ {
+ return;
+ }
+
+ int id = ++lastID;
+ registration = new RegistrationImpl(id, view);
+
+ ids.put(id, registration);
+ views.put(view, registration);
+ }
+
+ fireElementAddedEvent(registration);
+ }
+
+ void deregister(CDOView view)
+ {
+ Registration registration;
+ synchronized (this)
+ {
+ registration = views.remove(view);
+ if (registration != null)
+ {
+ int id = registration.getID();
+ ids.remove(id);
+ }
+ }
+
+ fireElementRemovedEvent(registration);
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private static final class RegistrationImpl implements Registration
+ {
+ private final int id;
+
+ private final CDOView view;
+
+ public RegistrationImpl(int id, CDOView view)
+ {
+ this.id = id;
+ this.view = view;
+ }
+
+ public int getID()
+ {
+ return id;
+ }
+
+ public CDOView getView()
+ {
+ return view;
+ }
+ }
+}

Back to the top