Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rapicault2011-05-05 20:42:55 +0000
committerPascal Rapicault2011-05-05 20:42:55 +0000
commit388a6d0b41f52f400d95883462d6b13bb6168b89 (patch)
tree6b27f2a3ae4c45560c64049372c2430a4db89e35
parent16e01eaf0a00b539d9521641ba4fa42351d6c0d3 (diff)
downloadrt.equinox.p2-388a6d0b41f52f400d95883462d6b13bb6168b89.tar.gz
rt.equinox.p2-388a6d0b41f52f400d95883462d6b13bb6168b89.tar.xz
rt.equinox.p2-388a6d0b41f52f400d95883462d6b13bb6168b89.zip
Bug 340352 - [performance] [scalability] copying local artifacts has an unnecessary overhead of 0.1s
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Messages.java2
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/messages.properties3
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java41
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryFactory.java2
4 files changed, 45 insertions, 3 deletions
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Messages.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Messages.java
index a3db07bff..da8c1f788 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Messages.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Messages.java
@@ -59,6 +59,8 @@ public class Messages extends NLS {
public static String retryRequest;
+ public static String error_copying_local_file;
+
static {
// initialize resource bundles
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/messages.properties b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/messages.properties
index 0225f0178..9622be281 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/messages.properties
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/messages.properties
@@ -51,4 +51,5 @@ exception_unsupportedRemoveFromComposite = Cannot remove descriptors from a comp
exception_unableToCreateParentDir = Unable to create parent directory.
folder_artifact_not_file_repo=Artifact {0} is a folder but the repository is an archive or remote location.
-retryRequest=Download of {0} failed on repository {1}. Retrying. \ No newline at end of file
+retryRequest=Download of {0} failed on repository {1}. Retrying.
+error_copying_local_file=An error occurred copying file {0}. \ No newline at end of file
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 e0d96bfdc..3d7c46757 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
@@ -582,8 +582,47 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme
return status.getCode() == CODE_RETRY ? status : result;
}
+ /**
+ * Copy a file to an output stream.
+ * Optionally close the streams when done.
+ * Notify the monitor about progress we make
+ *
+ * @return the number of bytes written.
+ */
+ private IStatus copyFileToStream(File in, OutputStream out, IProgressMonitor monitor) {
+ // Buffer filled with contents from the stream at a time
+ int bufferSize = 16 * 1024;
+ byte[] buffer = new byte[bufferSize];
+ // Number of passes in the below loop, convert to integer which is needed in monitor conversion below
+ int expected_loops = new Double(in.length() / bufferSize).intValue() + 1; // +1: also count the initial run
+ SubMonitor sub = SubMonitor.convert(monitor, Messages.downloading + in.getName(), expected_loops);
+ // Be optimistic about the outcome of this...
+ IStatus status = Status.OK_STATUS;
+ try {
+ FileInputStream stream = new FileInputStream(in);
+ try {
+ int len;
+ while ((len = stream.read(buffer)) != -1) {
+ out.write(buffer, 0, len);
+ sub.worked(1);
+ }
+ } finally {
+ stream.close();
+ }
+ } catch (IOException ioe) {
+ status = new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.error_copying_local_file, in.getAbsolutePath()), ioe);
+ }
+ sub.done();
+ return status;
+ }
+
private IStatus downloadArtifact(IArtifactDescriptor descriptor, URI mirrorLocation, OutputStream destination, IProgressMonitor monitor) {
- IStatus result = getTransport().download(mirrorLocation, destination, monitor);
+ //Bug 340352: transport has performance overhead of 100ms and more, bypass it for local copies
+ IStatus result = Status.OK_STATUS;
+ if (mirrorLocation.getScheme().equals(SimpleArtifactRepositoryFactory.PROTOCOL_FILE))
+ result = copyFileToStream(new File(mirrorLocation), destination, monitor);
+ else
+ result = getTransport().download(mirrorLocation, destination, monitor);
if (mirrors != null)
mirrors.reportResult(mirrorLocation.toString(), result);
if (result.isOK() || result.getSeverity() == IStatus.CANCEL)
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryFactory.java
index 6c79d0a18..041e9f6d7 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryFactory.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryFactory.java
@@ -29,7 +29,7 @@ import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactRepositoryFactory;
import org.eclipse.osgi.util.NLS;
public class SimpleArtifactRepositoryFactory extends ArtifactRepositoryFactory {
- private static final String PROTOCOL_FILE = "file"; //$NON-NLS-1$
+ public static final String PROTOCOL_FILE = "file"; //$NON-NLS-1$
private static final String JAR_EXTENSION = ".jar"; //$NON-NLS-1$
private static final String XML_EXTENSION = ".xml"; //$NON-NLS-1$

Back to the top