Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDJ Houghton2011-01-19 21:42:03 +0000
committerDJ Houghton2011-01-19 21:42:03 +0000
commit399a463c78ff025543a7c04b35394fe5f9777430 (patch)
tree91f58ef4ea88b049dbb6ac7ee1ce4484ce5990ea /bundles/org.eclipse.equinox.p2.core
parenta21e9016630cd6d7ac5d0fd38a35b3e520686280 (diff)
downloadrt.equinox.p2-399a463c78ff025543a7c04b35394fe5f9777430.tar.gz
rt.equinox.p2-399a463c78ff025543a7c04b35394fe5f9777430.tar.xz
rt.equinox.p2-399a463c78ff025543a7c04b35394fe5f9777430.zip
Bug 324873 - [repository] Share IUs for Composite Repositories
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.core')
-rw-r--r--bundles/org.eclipse.equinox.p2.core/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/IPool.java36
-rw-r--r--bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/StrongPool.java44
-rw-r--r--bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/WeakPool.java47
4 files changed, 128 insertions, 1 deletions
diff --git a/bundles/org.eclipse.equinox.p2.core/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.core/META-INF/MANIFEST.MF
index f2bcbce96..dcc34fa39 100644
--- a/bundles/org.eclipse.equinox.p2.core/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.core/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.equinox.p2.core;singleton:=true
-Bundle-Version: 2.0.100.qualifier
+Bundle-Version: 2.1.0.qualifier
Bundle-ClassPath: .
Bundle-Activator: org.eclipse.equinox.internal.p2.core.Activator
Bundle-Vendor: %providerName
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/IPool.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/IPool.java
new file mode 100644
index 000000000..f1b2f0f71
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/IPool.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2011 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.core;
+
+/**
+ * A Pool allows semantically equivalent objects to be shared. To be useful, objects added to the pool should implement
+ * a meaningful equals() method.
+ * <p>
+ * Care must be taken by users that object sharing is appropriate for their application. It is easy
+ * to "over share" objects leading to unexpected and difficult to debug behaviour.
+ * </p><p>
+ * This interface is not intended to be implemented by clients.
+ * </p>
+ * @noimplement This interface is not intended to be implemented by clients.
+ * @since 2.1
+ */
+public interface IPool<T> {
+
+ /**
+ * Returns the first object from this pool which is {@link #equals(Object)} to the given object. If the pool
+ * contains no such object then the object is added to the pool and returned. If the object is <code>null</code>,
+ * <code>null</code> is returned.
+ *
+ * @param newObject the object to add
+ * @return a shared object that is equal to the given object or <code>null</code>
+ */
+ public abstract T add(T newObject);
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/StrongPool.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/StrongPool.java
new file mode 100644
index 000000000..d1780388b
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/StrongPool.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2011 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.core;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * An object pool backed by strong references. Objects stored in this pool
+ * will not be garbage collected as they refer to themselves. The client is responsible for
+ * nulling all references to the pool instance when it is no longer needed so that
+ * the contained objects can be garbage collected.
+ * <p>
+ * If a long lived, memory managed pool is required use {@link org.eclipse.equinox.p2.core.WeakPool}.
+ * </p>
+ * @since 2.1
+ */
+public class StrongPool<T> implements IPool<T> {
+ private Map<T, T> pool = new HashMap<T, T>();
+
+ /* (non-Javadoc)
+ * @see org.eclipse.equinox.p2.core.IPool#add(T)
+ */
+ public T add(T newObject) {
+ if (newObject == null) {
+ return null;
+ }
+
+ T reference = pool.get(newObject);
+ if (reference == null) {
+ pool.put(newObject, newObject);
+ return newObject;
+ }
+ return reference;
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/WeakPool.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/WeakPool.java
new file mode 100644
index 000000000..3f389fc75
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/WeakPool.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2011 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.core;
+
+import java.lang.ref.WeakReference;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+/**
+ * An object pool backed by weak references. Objects stored in this pool
+ * will be garbage collected once all strong references to the objects are broken.
+ * <p>
+ * Since {@link WeakReference} are not particularly light-weight, a client could use a {@link StrongPool}
+ * if the pool will be short lived and explicitly nulled by the client.
+ * </p>
+ * @since 2.1
+ */
+public class WeakPool<T> implements IPool<T> {
+ private Map<T, WeakReference<T>> pool = new WeakHashMap<T, WeakReference<T>>();
+
+ /* (non-Javadoc)
+ * @see org.eclipse.equinox.p2.core.IPool#add(T)
+ */
+ public T add(T newObject) {
+ if (newObject == null) {
+ return null;
+ }
+
+ WeakReference<T> weakReference = pool.get(newObject);
+ if (weakReference != null) {
+ T reference = weakReference.get();
+ if (reference != null) {
+ return reference;
+ }
+ }
+ pool.put(newObject, new WeakReference<T>(newObject));
+ return newObject;
+ }
+}

Back to the top