From 82aeb8dee11f4114494fe3dd0ca1097312d2dfd5 Mon Sep 17 00:00:00 2001 From: Mengxin Zhu Date: Mon, 21 Nov 2011 11:39:34 +0800 Subject: Fix 351944 to avoid unnecessary loading artifact repository when doing query, getting artifact descriptors via artifact key. Without fixing though simple artifact repository always checks the last modify of artifacts.jar file, however it still cost some time, it will waste a lot of time especially the repository locates on a read-only NFS server. Signed-off-by: Mengxin Zhu --- .../repository/simple/SimpleArtifactRepository.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'bundles/org.eclipse.equinox.p2.artifact.repository') diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java index b365b0376..79970410d 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java @@ -84,6 +84,11 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme * Does this instance of the repository currently hold a lock */ private boolean holdsLock = false; + /** + * Does this instance of the repository can be locked. + * It will be initialized when initializing the location for repository + */ + private Boolean canLock = null; private long cacheTimestamp = 0l; @@ -327,7 +332,8 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme boolean lockAcquired = false; try { - if (canLock()) { + canLock = new Boolean(canLock()); + if (canLock.booleanValue()) { lockAcquired = lockAndLoad(true, new NullProgressMonitor()); if (!lockAcquired) throw new IllegalStateException("Cannot acquire the lock for " + location); //$NON-NLS-1$ @@ -973,6 +979,8 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme desc.setRepository(this); if (updateTimestamp) updateTimestamp(); + if (canLock == null) + canLock = new Boolean(canLock()); } private String getBlobStoreName(String defaultValue) { @@ -1425,11 +1433,11 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme } /** - * Returns true if this instance of SimpleArtifactRepository holds the lock, - * false otherwise. + * Returns true if this instance of SimpleArtifactRepository holds the lock or + * this repository can't be locked at all due to permission, false otherwise. */ private boolean holdsLock() { - return holdsLock; + return (canLock != null && !canLock.booleanValue()) || holdsLock; } /**URIUtil.toURI(location.toURI() -- cgit v1.2.3