-Trying to fix GUI freezing.
This commit is contained in:
tonikelope 2019-07-04 14:37:48 +02:00
parent 4de7ed638b
commit 70d3daaf18
11 changed files with 66 additions and 66 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.tonikelope</groupId> <groupId>com.tonikelope</groupId>
<artifactId>MegaBasterd</artifactId> <artifactId>MegaBasterd</artifactId>
<version>6.19</version> <version>6.20</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<dependencies> <dependencies>
<dependency> <dependency>

View File

@ -27,6 +27,7 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
private final Object _secure_notify_lock; private final Object _secure_notify_lock;
private volatile boolean _error_wait; private volatile boolean _error_wait;
private boolean _notified; private boolean _notified;
private boolean _force_smartproxy;
private String _current_smart_proxy; private String _current_smart_proxy;
public ChunkDownloader(int id, Download download) { public ChunkDownloader(int id, Download download) {
@ -37,6 +38,7 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
_download = download; _download = download;
_current_smart_proxy = null; _current_smart_proxy = null;
_error_wait = false; _error_wait = false;
_force_smartproxy = true;
} }
@ -115,6 +117,13 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
SmartMegaProxyManager proxy_manager = MainPanel.getProxy_manager(); SmartMegaProxyManager proxy_manager = MainPanel.getProxy_manager();
if (_force_smartproxy) {
_current_smart_proxy = proxy_manager.getFastestProxy();
getDownload().enableProxyTurboMode();
}
while (!_exit && !_download.isStopped()) { while (!_exit && !_download.isStopped()) {
if (worker_url == null || http_error == 403) { if (worker_url == null || http_error == 403) {
@ -132,18 +141,18 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
String chunk_url = ChunkManager.genChunkUrl(worker_url, _download.getFile_size(), chunk_offset, chunk_size); String chunk_url = ChunkManager.genChunkUrl(worker_url, _download.getFile_size(), chunk_offset, chunk_size);
if ((http_error == 509 || slow_proxy || (chunk_error && _current_smart_proxy != null)) && MainPanel.isUse_smart_proxy() && !MainPanel.isUse_proxy()) { if ((_current_smart_proxy != null || http_error == 509) && MainPanel.isUse_smart_proxy() && !MainPanel.isUse_proxy()) {
if (_current_smart_proxy != null) { if (slow_proxy || chunk_error) {
proxy_manager.blockProxy(_current_smart_proxy); proxy_manager.blockProxy(_current_smart_proxy);
_current_smart_proxy = proxy_manager.getFastestProxy();
Logger.getLogger(MiscTools.class.getName()).log(Level.WARNING, "{0}: worker {1} excluding proxy -> {2}", new Object[]{Thread.currentThread().getName(), _id, _current_smart_proxy}); Logger.getLogger(MiscTools.class.getName()).log(Level.WARNING, "{0}: worker {1} excluding proxy -> {2}", new Object[]{Thread.currentThread().getName(), _id, _current_smart_proxy});
} }
_current_smart_proxy = proxy_manager.getFastestProxy();
if (_current_smart_proxy != null) { if (_current_smart_proxy != null) {
String[] proxy_info = _current_smart_proxy.split(":"); String[] proxy_info = _current_smart_proxy.split(":");
@ -154,10 +163,10 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
con = (HttpURLConnection) url.openConnection(proxy); con = (HttpURLConnection) url.openConnection(proxy);
getDownload().enableProxyTurboMode();
} else { } else {
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Worker [{1}] SmartProxy getFastestProxy returned NULL!", new Object[]{Thread.currentThread().getName(), _id});
URL url = new URL(chunk_url); URL url = new URL(chunk_url);
con = (HttpURLConnection) url.openConnection(); con = (HttpURLConnection) url.openConnection();
@ -180,19 +189,8 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
} else { } else {
if (_current_smart_proxy != null) {
String[] proxy_info = _current_smart_proxy.split(":");
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxy_info[0], Integer.parseInt(proxy_info[1])));
con = (HttpURLConnection) url.openConnection(proxy);
} else {
con = (HttpURLConnection) url.openConnection(); con = (HttpURLConnection) url.openConnection();
} }
}
} }
if (_current_smart_proxy != null) { if (_current_smart_proxy != null) {
@ -308,7 +306,7 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
http_error = 0; http_error = 0;
if (_current_smart_proxy != null) { if (_current_smart_proxy != null && finish_chunk_time != -1) {
//Update average chunk download speed using SmartProxy //Update average chunk download speed using SmartProxy
long chunk_speed = Math.round(chunk_size / (((double) (finish_chunk_time - init_chunk_time - paused)) / 1000)); long chunk_speed = Math.round(chunk_size / (((double) (finish_chunk_time - init_chunk_time - paused)) / 1000));
@ -339,7 +337,7 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
timeout = true; timeout = true;
} }
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex.getMessage());
} finally { } finally {

View File

@ -113,6 +113,7 @@ public class ChunkDownloaderMono extends ChunkDownloader {
try { try {
Thread.sleep(1000); Thread.sleep(1000);
} catch (InterruptedException excep) { } catch (InterruptedException excep) {
} }
setError_wait(false); setError_wait(false);

View File

@ -1,7 +1,6 @@
package com.tonikelope.megabasterd; package com.tonikelope.megabasterd;
import static com.tonikelope.megabasterd.CryptTools.*; import static com.tonikelope.megabasterd.CryptTools.*;
import static com.tonikelope.megabasterd.MiscTools.*;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -239,7 +238,7 @@ public class ChunkUploader implements Runnable, SecureSingleThreadNotifiable {
} catch (IOException ex) { } catch (IOException ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex.getMessage());
} finally { } finally {
@ -270,7 +269,11 @@ public class ChunkUploader implements Runnable, SecureSingleThreadNotifiable {
_upload.getView().updateSlotsStatus(); _upload.getView().updateSlotsStatus();
Thread.sleep(getWaitTimeExpBackOff(conta_error) * 1000); try {
Thread.sleep(1000);
} catch (InterruptedException excep) {
}
_error_wait = false; _error_wait = false;

View File

@ -93,6 +93,7 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
private long _last_chunk_id_dispatched; private long _last_chunk_id_dispatched;
private final MegaAPI _ma; private final MegaAPI _ma;
private volatile boolean _canceled; private volatile boolean _canceled;
private volatile boolean _turbo;
public Download(MainPanel main_panel, MegaAPI ma, String url, String download_path, String file_name, String file_key, Long file_size, String file_pass, String file_noexpire, boolean use_slots, boolean restart, String custom_chunks_dir) { public Download(MainPanel main_panel, MegaAPI ma, String url, String download_path, String file_name, String file_key, Long file_size, String file_pass, String file_noexpire, boolean use_slots, boolean restart, String custom_chunks_dir) {
@ -133,6 +134,7 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
_view = new DownloadView(this); _view = new DownloadView(this);
_progress_meter = new ProgressMeter(this); _progress_meter = new ProgressMeter(this);
_custom_chunks_dir = custom_chunks_dir; _custom_chunks_dir = custom_chunks_dir;
_turbo = false;
} }
public Download(Download download) { public Download(Download download) {
@ -174,6 +176,7 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
_view = new DownloadView(this); _view = new DownloadView(this);
_progress_meter = new ProgressMeter(this); _progress_meter = new ProgressMeter(this);
_custom_chunks_dir = download.getCustom_chunks_dir(); _custom_chunks_dir = download.getCustom_chunks_dir();
_turbo = false;
} }
@ -204,7 +207,9 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
synchronized (_turbo_proxy_lock) { synchronized (_turbo_proxy_lock) {
if (getChunkworkers().size() < Transference.MAX_WORKERS) { if (!_turbo) {
_turbo = true;
Download tthis = this; Download tthis = this;
@ -213,11 +218,13 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
@Override @Override
public void run() { public void run() {
synchronized (_workers_lock) {
getView().getSpeed_label().setForeground(Color.BLACK); getView().getSpeed_label().setForeground(Color.BLACK);
getView().getSlots_spinner().setEnabled(false); getView().getSlots_spinner().setEnabled(false);
}
});
synchronized (_workers_lock) {
for (int t = getChunkworkers().size(); t <= Transference.MAX_WORKERS; t++) { for (int t = getChunkworkers().size(); t <= Transference.MAX_WORKERS; t++) {
@ -228,14 +235,23 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
_thread_pool.execute(c); _thread_pool.execute(c);
} }
}
swingInvoke(
new Runnable() {
@Override
public void run() {
getView().getSlots_spinner().setValue(Transference.MAX_WORKERS); getView().getSlots_spinner().setValue(Transference.MAX_WORKERS);
getView().getSlots_spinner().setEnabled(true); getView().getSlots_spinner().setEnabled(true);
} }
}
}); });
} }
} }
} }
public ConcurrentLinkedQueue<Long> getRejectedChunkIds() { public ConcurrentLinkedQueue<Long> getRejectedChunkIds() {

View File

@ -28,13 +28,11 @@ public final class DownloadManager extends TransferenceManager {
for (final Transference d : downloads) { for (final Transference d : downloads) {
swingInvokeAndWait( swingInvoke(
new Runnable() { new Runnable() {
@Override @Override
public void run() { public void run() {
getScroll_panel().remove(((Download) d).getView()); getScroll_panel().remove(((Download) d).getView());
((Download) d).getView().revalidate();
((Download) d).getView().repaint();
} }
}); });
@ -63,13 +61,11 @@ public final class DownloadManager extends TransferenceManager {
@Override @Override
public void provision(final Transference download) { public void provision(final Transference download) {
swingInvokeAndWait( swingInvoke(
new Runnable() { new Runnable() {
@Override @Override
public void run() { public void run() {
getScroll_panel().add(((Download) download).getView()); getScroll_panel().add(((Download) download).getView());
((Download) download).getView().revalidate();
((Download) download).getView().repaint();
} }
}); });
@ -129,16 +125,12 @@ public final class DownloadManager extends TransferenceManager {
getScroll_panel().remove((Component) down.getView()); getScroll_panel().remove((Component) down.getView());
getScroll_panel().add((Component) down.getView()); getScroll_panel().add((Component) down.getView());
((Download) down).getView().revalidate();
((Download) down).getView().repaint();
} }
for (final Transference down : getTransference_finished_queue()) { for (final Transference down : getTransference_finished_queue()) {
getScroll_panel().remove((Component) down.getView()); getScroll_panel().remove((Component) down.getView());
getScroll_panel().add((Component) down.getView()); getScroll_panel().add((Component) down.getView());
((Download) down).getView().revalidate();
((Download) down).getView().repaint();
} }
} }

View File

@ -50,7 +50,7 @@ import javax.swing.UIManager;
*/ */
public final class MainPanel { public final class MainPanel {
public static final String VERSION = "6.19"; public static final String VERSION = "6.20";
public static final int THROTTLE_SLICE_SIZE = 16 * 1024; public static final int THROTTLE_SLICE_SIZE = 16 * 1024;
public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024; public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024;
public static final int STREAMER_PORT = 1337; public static final int STREAMER_PORT = 1337;

View File

@ -18,7 +18,7 @@ import org.apache.commons.collections4.queue.CircularFifoQueue;
public final class SpeedMeter implements Runnable { public final class SpeedMeter implements Runnable {
public static final int SLEEP = 3000; public static final int SLEEP = 3000;
public static final int CHUNK_SPEED_QUEUE_MAX_SIZE = 5; public static final int CHUNK_SPEED_QUEUE_MAX_SIZE = 10;
private final JLabel _speed_label; private final JLabel _speed_label;
private final JLabel _rem_label; private final JLabel _rem_label;
private final TransferenceManager _trans_manager; private final TransferenceManager _trans_manager;

View File

@ -297,13 +297,11 @@ abstract public class TransferenceManager implements Runnable, SecureSingleThrea
_transference_running_list.add(transference); _transference_running_list.add(transference);
swingInvokeAndWait( swingInvoke(
new Runnable() { new Runnable() {
@Override @Override
public void run() { public void run() {
getScroll_panel().add((Component) transference.getView(), 0); getScroll_panel().add((Component) transference.getView(), 0);
_main_panel.getView().revalidate();
_main_panel.getView().repaint();
} }
}); });

View File

@ -41,8 +41,6 @@ public final class UploadManager extends TransferenceManager {
@Override @Override
public void run() { public void run() {
getScroll_panel().add(((Upload) upload).getView()); getScroll_panel().add(((Upload) upload).getView());
((Upload) upload).getView().revalidate();
((Upload) upload).getView().repaint();
} }
}); });
@ -69,16 +67,12 @@ public final class UploadManager extends TransferenceManager {
getScroll_panel().remove((Component) up.getView()); getScroll_panel().remove((Component) up.getView());
getScroll_panel().add((Component) up.getView()); getScroll_panel().add((Component) up.getView());
((Upload) up).getView().revalidate();
((Upload) up).getView().repaint();
} }
for (Transference up : getTransference_finished_queue()) { for (Transference up : getTransference_finished_queue()) {
getScroll_panel().remove((Component) up.getView()); getScroll_panel().remove((Component) up.getView());
getScroll_panel().add((Component) up.getView()); getScroll_panel().add((Component) up.getView());
((Upload) up).getView().revalidate();
((Upload) up).getView().repaint();
} }
} }
}); });
@ -107,8 +101,6 @@ public final class UploadManager extends TransferenceManager {
@Override @Override
public void run() { public void run() {
getScroll_panel().remove(((Upload) u).getView()); getScroll_panel().remove(((Upload) u).getView());
((Upload) u).getView().revalidate();
((Upload) u).getView().repaint();
} }
}); });

Binary file not shown.

Before

Width:  |  Height:  |  Size: 194 KiB

After

Width:  |  Height:  |  Size: 218 KiB