Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMengxin Zhu2012-02-09 05:54:44 -0500
committerMengxin Zhu2012-02-09 05:54:44 -0500
commit91027ecca979ba174a9617241ff3999250490ae9 (patch)
tree1d8319216de7712aa9f073e53b6746647ab98a1e /bundles/org.eclipse.equinox.p2.repository
parent5d2d6401627c5851207411a25c44dd56c17958da (diff)
downloadrt.equinox.p2-91027ecca979ba174a9617241ff3999250490ae9.tar.gz
rt.equinox.p2-91027ecca979ba174a9617241ff3999250490ae9.tar.xz
rt.equinox.p2-91027ecca979ba174a9617241ff3999250490ae9.zip
Rework the download progress event reports in the scenario of multiple agents. Signed-off-by: Mengxin Zhu <kane.zhu@windriver.com>
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.repository')
-rw-r--r--bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/ProgressStatistics.java26
1 files changed, 11 insertions, 15 deletions
diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/ProgressStatistics.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/ProgressStatistics.java
index dd8c89a89..dd878fd67 100644
--- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/ProgressStatistics.java
+++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/ProgressStatistics.java
@@ -16,7 +16,6 @@ import java.net.URI;
import java.text.NumberFormat;
import java.util.SortedMap;
import java.util.TreeMap;
-import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.osgi.util.NLS;
@@ -24,7 +23,8 @@ import org.eclipse.osgi.util.NLS;
/**
* Converts progress of file download to average download speed and keeps track of
* when it is suitable to update a progress monitor. A suitably scaled and formatted string for use
- * in progress monitoring is provided.
+ * in progress monitoring is provided. It will publishes {@link DownloadProgressEvent} if {@link IProvisioningAgent}
+ * is given and {@link IProvisioningEventBus} is available.
*/
public class ProgressStatistics {
private static final int DEFAULT_REPORT_INTERVAL = 1000;
@@ -33,8 +33,6 @@ public class ProgressStatistics {
private static final int SPEED_RESOLUTION = 1000;
- private static IProvisioningAgent agent = null;
-
private static String convert(long amount) {
NumberFormat fmt = NumberFormat.getInstance();
if (amount < 1024)
@@ -47,17 +45,12 @@ public class ProgressStatistics {
return fmt.format(((double) amount) / (1024 * 1024)) + "MB"; //$NON-NLS-1$
}
- public static void setProvisioningAgent(IProvisioningAgent agent) {
- ProgressStatistics.agent = agent;
- }
-
private void publishEvent(DownloadProgressEvent event) {
- if (agent == null) {
- agent = ServiceHelper.getService(Activator.getContext(), IProvisioningAgent.class);
- }
- IProvisioningEventBus eventBus = (IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME);
- if (eventBus != null) {
- eventBus.publishEvent(event);
+ if (m_agent != null) {
+ IProvisioningEventBus eventBus = (IProvisioningEventBus) m_agent.getService(IProvisioningEventBus.SERVICE_NAME);
+ if (eventBus != null) {
+ eventBus.publishEvent(event);
+ }
}
}
@@ -79,7 +72,9 @@ public class ProgressStatistics {
URI m_uri;
- public ProgressStatistics(URI uri, String fileName, long total) {
+ IProvisioningAgent m_agent;
+
+ public ProgressStatistics(IProvisioningAgent agent, URI uri, String fileName, long total) {
m_startTime = System.currentTimeMillis();
m_fileName = fileName;
@@ -91,6 +86,7 @@ public class ProgressStatistics {
m_recentSpeedMap = new TreeMap<Long, Long>();
m_recentSpeedMapKey = 0L;
m_uri = uri;
+ m_agent = agent;
}
public long getAverageSpeed() {

Back to the top