Skip to main content
summaryrefslogtreecommitdiffstats
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
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')
-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
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/CompositeMetadataRepository.java7
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/LocalMetadataRepository.java11
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/IUMap.java31
-rw-r--r--bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/IMetadataRepository.java16
-rw-r--r--bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/spi/AbstractMetadataRepository.java13
-rw-r--r--bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/metadata/UpdateSiteMetadataRepository.java10
10 files changed, 206 insertions, 11 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;
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/CompositeMetadataRepository.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/CompositeMetadataRepository.java
index f10a0a088..8ad7d0273 100644
--- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/CompositeMetadataRepository.java
+++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/CompositeMetadataRepository.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 IBM Corporation and others.
+ * Copyright (c) 2008, 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
@@ -21,8 +21,7 @@ import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.p2.persistence.CompositeRepositoryIO;
import org.eclipse.equinox.internal.p2.persistence.CompositeRepositoryState;
-import org.eclipse.equinox.p2.core.IProvisioningAgent;
-import org.eclipse.equinox.p2.core.ProvisionException;
+import org.eclipse.equinox.p2.core.*;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.index.IIndex;
import org.eclipse.equinox.p2.metadata.index.IIndexProvider;
@@ -47,6 +46,7 @@ public class CompositeMetadataRepository extends AbstractMetadataRepository impl
// keep a list of the repositories that we have successfully loaded
private List<IMetadataRepository> loadedRepos = new ArrayList<IMetadataRepository>();
private IMetadataRepositoryManager manager;
+ private IPool<IInstallableUnit> iuPool = new WeakPool<IInstallableUnit>();
/**
* Create a Composite repository in memory.
@@ -157,6 +157,7 @@ public class CompositeMetadataRepository extends AbstractMetadataRepository impl
//set repository to system to hide from users
getManager().setRepositoryProperty(absolute, IRepository.PROP_SYSTEM, String.valueOf(true));
}
+ currentRepo.compress(iuPool); // Share IUs across this CompositeMetadataRepository
// we successfully loaded the repo so remember it
loadedRepos.add(currentRepo);
} catch (ProvisionException e) {
diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/LocalMetadataRepository.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/LocalMetadataRepository.java
index 6f848b152..69ef5d5a7 100644
--- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/LocalMetadataRepository.java
+++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/LocalMetadataRepository.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 IBM Corporation and others.
+ * Copyright (c) 2007, 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
@@ -23,8 +23,7 @@ import org.eclipse.equinox.internal.p2.metadata.*;
import org.eclipse.equinox.internal.p2.metadata.index.*;
import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus;
import org.eclipse.equinox.internal.provisional.p2.repository.RepositoryEvent;
-import org.eclipse.equinox.p2.core.IProvisioningAgent;
-import org.eclipse.equinox.p2.core.ProvisionException;
+import org.eclipse.equinox.p2.core.*;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.KeyWithLocale;
import org.eclipse.equinox.p2.metadata.index.IIndex;
@@ -356,4 +355,10 @@ public class LocalMetadataRepository extends AbstractMetadataRepository implemen
return result;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.equinox.p2.repository.metadata.IMetadataRepository#compress(IPool<IInstallableUnit> iuPool)
+ */
+ public void compress(IPool<IInstallableUnit> iuPool) {
+ units.compress(iuPool);
+ }
}
diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/IUMap.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/IUMap.java
index 99d7b7531..674387912 100644
--- a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/IUMap.java
+++ b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/IUMap.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 IBM Corporation and others.
+ * Copyright (c) 2009, 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
@@ -12,7 +12,9 @@
package org.eclipse.equinox.internal.p2.metadata;
import java.util.*;
+import java.util.Map.Entry;
import org.eclipse.equinox.internal.p2.core.helpers.CollectionUtils;
+import org.eclipse.equinox.p2.core.IPool;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.query.*;
@@ -224,4 +226,31 @@ public class IUMap implements Cloneable {
for (IInstallableUnit iu : toRemove)
remove(iu);
}
+
+ /**
+ * Replace all instances of the IInstallableUnits in the receiver
+ * with the shared IInstallableUnits from the provided iuPool.
+ * This operation is a no-op if iuPool is null.
+ *
+ * @param iuPool an IPool containing the shared IInstallableUnits
+ */
+ public void compress(IPool<IInstallableUnit> iuPool) {
+ if (iuPool == null) {
+ return;
+ }
+
+ Iterator<Entry<String, Object>> entries = units.entrySet().iterator();
+ while (entries.hasNext()) {
+ Entry<String, Object> entry = entries.next();
+ Object value = entry.getValue();
+ if (value.getClass().isArray()) {
+ IInstallableUnit[] array = (IInstallableUnit[]) value;
+ for (int i = 0; i < array.length; i++) {
+ array[i] = iuPool.add(array[i]);
+ }
+ } else {
+ entry.setValue(iuPool.add((IInstallableUnit) value));
+ }
+ }
+ }
}
diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/IMetadataRepository.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/IMetadataRepository.java
index e6633c37f..54654f75e 100644
--- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/IMetadataRepository.java
+++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/IMetadataRepository.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 IBM Corporation and others.
+ * Copyright (c) 2007, 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
@@ -13,6 +13,7 @@ package org.eclipse.equinox.p2.repository.metadata;
import java.util.Collection;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.equinox.p2.core.IPool;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.repository.*;
import org.eclipse.equinox.p2.repository.metadata.spi.AbstractMetadataRepository;
@@ -81,4 +82,17 @@ public interface IMetadataRepository extends IRepository<IInstallableUnit> {
* the execution will be returned in the status.
*/
public IStatus executeBatch(IRunnableWithProgress runnable, IProgressMonitor monitor);
+
+ /**
+ * Cause semantically equivalent IInstallableUnits in the receiver to be
+ * replaced with a shared object from the provided {@link IPool}. New objects are
+ * added to the {@link IPool} as required.
+ * <p>
+ * While the {@link IPool} should be retained to increase the scope of sharing when
+ * calling {@link #compress(IPool)} on subsequent repositories, the {@link IPool} can
+ * be discarded without adversely effecting the receiver.
+ * </p>
+ * @since 2.1
+ */
+ public void compress(IPool<IInstallableUnit> iuPool);
}
diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/spi/AbstractMetadataRepository.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/spi/AbstractMetadataRepository.java
index b526bb874..92cae1740 100644
--- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/spi/AbstractMetadataRepository.java
+++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/p2/repository/metadata/spi/AbstractMetadataRepository.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 IBM Corporation and others.
+ * Copyright (c) 2007, 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
@@ -15,6 +15,7 @@ import java.util.Collection;
import java.util.Map;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.repository.Activator;
+import org.eclipse.equinox.p2.core.IPool;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.Version;
@@ -151,4 +152,14 @@ public abstract class AbstractMetadataRepository extends AbstractRepository<IIns
return Status.OK_STATUS;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.equinox.p2.repository.metadata.IMetadataRepository#compress(IPool<IInstallableUnit> iuPool)
+ */
+ /**
+ * @since 2.1
+ */
+ public void compress(IPool<IInstallableUnit> iuPool) {
+ // Default no-op. Subclasses should override as appropriate
+ }
+
}
diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/metadata/UpdateSiteMetadataRepository.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/metadata/UpdateSiteMetadataRepository.java
index 3dcdc6b49..84c8a3214 100644
--- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/metadata/UpdateSiteMetadataRepository.java
+++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/metadata/UpdateSiteMetadataRepository.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 IBM Corporation and others.
+ * Copyright (c) 2008, 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
@@ -15,6 +15,7 @@ import java.util.Collection;
import java.util.Map;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.equinox.p2.core.IPool;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.query.IQuery;
@@ -194,4 +195,11 @@ public class UpdateSiteMetadataRepository implements IMetadataRepository {
public IStatus executeBatch(IRunnableWithProgress runnable, IProgressMonitor monitor) {
return delegate.executeBatch(runnable, monitor);
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.equinox.p2.repository.metadata.IMetadataRepository#compress(IPool<IInstallableUnit> iuPool)
+ */
+ public void compress(IPool<IInstallableUnit> iuPool) {
+ delegate.compress(iuPool);
+ }
} \ No newline at end of file

Back to the top