diff options
author | Simon Rettberg | 2022-03-22 11:21:54 +0100 |
---|---|---|
committer | Simon Rettberg | 2022-03-22 11:21:54 +0100 |
commit | 499d11c1718ebc5807c0a054fa99ad1027a2baea (patch) | |
tree | afb2b741acaf906e5f53e6a0ff9cc82dade54dfe /dozentenmodul | |
parent | [client] Fix closing upload activity panel (diff) | |
download | tutor-module-499d11c1718ebc5807c0a054fa99ad1027a2baea.tar.gz tutor-module-499d11c1718ebc5807c0a054fa99ad1027a2baea.tar.xz tutor-module-499d11c1718ebc5807c0a054fa99ad1027a2baea.zip |
[client] Show local unhashed vs. hashed chunks in detailed progress view
Diffstat (limited to 'dozentenmodul')
7 files changed, 46 insertions, 8 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/AsyncHashGenerator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/AsyncHashGenerator.java index 8ef12e12..07efc449 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/AsyncHashGenerator.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/AsyncHashGenerator.java @@ -57,6 +57,8 @@ public class AsyncHashGenerator extends Thread { private AtomicInteger pendingHashes = new AtomicInteger(); private volatile boolean isCanceled = false; + + private AtomicInteger completeCount = new AtomicInteger(); static { LOGGER.info("Using " + HASH_WORK_POOL.getMaximumPoolSize() + " hash workers."); @@ -225,6 +227,7 @@ public class AsyncHashGenerator extends Thread { wasLastChunk = true; } } + completeCount.set(finishedChunks); } if (chunkIndex + 1 == chunkList.size()) { LOGGER.debug("Hashed last chunk #" + chunkIndex + ", total=" + chunkList.size() + ", finished=" + finishedChunks); @@ -320,4 +323,8 @@ public class AsyncHashGenerator extends Thread { return true; } + public AtomicInteger getCompleteCounter() { + return completeCount; + } + } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/TransferEvent.java b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/TransferEvent.java index bc75cad8..3ce33e48 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/TransferEvent.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/TransferEvent.java @@ -42,9 +42,14 @@ public class TransferEvent { * An optional error message */ public final String errorMessage; + + /** + * How many blocks have been hashed locally + */ + public final int locallyHashedCount; public TransferEvent(TransferState state, byte[] progress, long speedRaw, long virtualSpeedRaw, long remainingRaw, - String errorMessage) { + String errorMessage, int hashCompleteCount) { this.state = state; this.progress = progress; this.speedRaw = speedRaw; @@ -58,6 +63,12 @@ public class TransferEvent { this.remaining = FormatHelper.formatMilliseconds(remainingRaw + 30000, false); } this.errorMessage = errorMessage; + this.locallyHashedCount = hashCompleteCount; + } + + public TransferEvent(TransferState state, byte[] progress, long speedRaw, long virtualSpeedRaw, long remainingRaw, + String errorMessage) { + this(state, progress, speedRaw, virtualSpeedRaw, remainingRaw, errorMessage, progress.length); } } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/UploadTask.java b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/UploadTask.java index 84b9b47a..fc13f113 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/UploadTask.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/filetransfer/UploadTask.java @@ -157,6 +157,8 @@ public class UploadTask extends TransferTask { private long virtualSpeed = 0; private long nextQueryDebug; + private AtomicInteger hashCompleteCounter; + @Override protected TransferEvent getTransferEvent() { final long now = System.currentTimeMillis(); @@ -206,7 +208,8 @@ public class UploadTask extends TransferTask { if (transferConnectionError != null && (error == null || transferConnectionError.equals("Out of disk space"))) { error = transferConnectionError; } - TransferEvent event = new TransferEvent(state, blocks, speed, virtualSpeed, timeRemaining, error); + TransferEvent event = new TransferEvent(state, blocks, speed, virtualSpeed, timeRemaining, error, + hashCompleteCounter.get()); return event; } @@ -214,4 +217,8 @@ public class UploadTask extends TransferTask { protected TransferThread createNewThread() { return new UploadThread(); } + + public void setHashCounter(AtomicInteger completeCounter) { + this.hashCompleteCounter = completeCounter; + } } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/TransferPanel.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/TransferPanel.java index 95464f24..80f5d529 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/TransferPanel.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/TransferPanel.java @@ -162,7 +162,7 @@ public abstract class TransferPanel extends ActivityPanel implements TransferEve } // Progress bar if (event.progress != null) { - progress.setStatus(event.progress); + progress.setStatus(event); } panel.validate(); } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/BlockProgressBar.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/BlockProgressBar.java index 22089f70..c7e0172f 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/BlockProgressBar.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/BlockProgressBar.java @@ -10,6 +10,7 @@ import java.awt.geom.Rectangle2D; import javax.swing.JPanel; +import org.openslx.dozmod.filetransfer.TransferEvent; import org.openslx.dozmod.gui.Gui; import org.openslx.thrifthelper.TransferStatusWrapper; @@ -31,6 +32,8 @@ public class BlockProgressBar extends JPanel { private boolean simpleMode = true; private boolean showEstimatedComplete = false; + + private int locallyHashedBlockCount; public BlockProgressBar(byte[] blocks) { super(); @@ -46,8 +49,9 @@ public class BlockProgressBar extends JPanel { this.blocks.setBlocks(blocks); } - public void setStatus(byte[] blocks) { - this.blocks.setBlocks(blocks); + public void setStatus(TransferEvent event) { + this.blocks.setBlocks(event.progress); + this.locallyHashedBlockCount = event.locallyHashedCount; this.repaint(100); } @@ -142,13 +146,19 @@ public class BlockProgressBar extends JPanel { g.setColor(Color.WHITE); g.fillRect(0, 0, getWidth(), getHeight()); float x = 0, y = 0; - for (byte block : blocks.getBlocks()) { + byte[] ba = blocks.getBlocks(); + for (int i = 0; i < ba.length; ++i) { + byte block = ba[i]; float toX = x + blockWidth; if (block >= 0 && block < blockColors.length) { g.setColor(blockColors[block]); final int boxWidth = ((int) toX) - ((int) x) - 1; final int boxHeight = (int) (y + blockHeightVisible) - (int) y; - g.fillRect((int) x, (int) y, boxWidth > 1 ? boxWidth : 1, boxHeight > 1 ? boxHeight : 1); + if (i < locallyHashedBlockCount) { + g.fillRect((int) x, (int) y, boxWidth > 1 ? boxWidth : 1, boxHeight > 1 ? boxHeight : 1); + } else { + g.drawRect((int) x, (int) y, boxWidth > 1 ? boxWidth : 1, boxHeight > 1 ? boxHeight : 1); + } } x = toX; if (x + 0.5 > width) { diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadSummaryPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadSummaryPage.java index 400ee6c6..add3a4f4 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadSummaryPage.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageUploadSummaryPage.java @@ -41,7 +41,7 @@ public class ImageUploadSummaryPage extends ImageUploadSummaryPageLayout { if (!pageIsVisible) return; if (event.progress != null) { - ctlUploadProgressBar.setStatus(event.progress); + ctlUploadProgressBar.setStatus(event); } if (event.state == TransferState.FINISHED) { updateInfoText(null); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/UploadInitiator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/UploadInitiator.java index 811eb447..78e41d05 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/UploadInitiator.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/UploadInitiator.java @@ -174,6 +174,9 @@ public class UploadInitiator { return; } uploadTask.setMinConnections(Config.getTransferConnectionCount()); + if (hashGen != null) { + uploadTask.setHashCounter(hashGen.getCompleteCounter()); + } Thread uploadThread = new Thread(uploadTask, "UploadTask"); uploadThread.setDaemon(true); uploadThread.start(); |