aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
authorGravatar Klaus Aehlig <aehlig@google.com>2017-02-28 16:30:56 +0000
committerGravatar Yue Gan <yueg@google.com>2017-02-28 17:03:13 +0000
commiteed1ea7cd72cf5895e2864146879b28b23d0ed93 (patch)
tree80b775292374b410ab4a324a0c44cb05f005f52f /src/main
parente4fbf4236fa1606accc24918aa95abc4fb3b4b8e (diff)
Add an event reporting about downloading progress
The ProgressInputStream provides unstructured information about progress of downloading files in the form of Progress events. Add a new event type, to be posted over the event bus, providing structured information about the download progress. -- Change-Id: Idbbaa4325ade356e65ef7ef1a40e66730216b6fe Reviewed-on: https://cr.bazel.build/9113 PiperOrigin-RevId: 148772585 MOS_MIGRATED_REVID=148772585
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/DownloadProgressEvent.java64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/DownloadProgressEvent.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/DownloadProgressEvent.java
new file mode 100644
index 0000000000..a8f0f15efc
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/DownloadProgressEvent.java
@@ -0,0 +1,64 @@
+// Copyright 2016 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.bazel.repository.downloader;
+
+import com.google.devtools.build.lib.events.ExtendedEventHandler;
+import java.net.URL;
+
+/**
+ * Postable event reporting on progress made downloading an URL. It can be used to report the URL
+ * being downloaded and the number of bytes read so far.
+ */
+public class DownloadProgressEvent implements ExtendedEventHandler.ProgressLike {
+ private final URL originalUrl;
+ private final URL actualUrl;
+ private final long bytesRead;
+ private final boolean downloadFinished;
+
+ public DownloadProgressEvent(URL originalUrl, URL actualUrl, long bytesRead, boolean finished) {
+ this.originalUrl = originalUrl;
+ this.actualUrl = actualUrl;
+ this.bytesRead = bytesRead;
+ this.downloadFinished = finished;
+ }
+
+ public DownloadProgressEvent(URL originalUrl, long bytesRead, boolean finished) {
+ this(originalUrl, null, bytesRead, finished);
+ }
+
+ public DownloadProgressEvent(URL url, long bytesRead) {
+ this(url, bytesRead, false);
+ }
+
+ public DownloadProgressEvent(URL url) {
+ this(url, 0);
+ }
+
+ public URL getOriginalUrl() {
+ return originalUrl;
+ }
+
+ public URL getActualUrl() {
+ return actualUrl;
+ }
+
+ public boolean isFinished() {
+ return downloadFinished;
+ }
+
+ public long getBytesRead() {
+ return bytesRead;
+ }
+}