use of com.frostwire.bittorrent.BTEngine in project frostwire by frostwire.
the class TorrentConnectionPaneItem method initOptions.
@Override
public void initOptions() {
final BTEngine btEngine = BTEngine.getInstance();
ENABLE_DISTRIBUTED_HASH_TABLE_CHECKBOX_FIELD.setSelected(SharingSettings.ENABLE_DISTRIBUTED_HASH_TABLE.getValue());
VPN_DROP_PROTECTION_CHECKBOX.setSelected(ConnectionSettings.VPN_DROP_PROTECTION.getValue());
MAX_GLOBAL_NUM_CONNECTIONS_FIELD.setValue(btEngine.maxConnections());
MAX_PEERS_FIELD.setValue(btEngine.maxPeers());
MAX_ACTIVE_DOWNLOADS_FIELD.setValue(btEngine.maxActiveDownloads());
MAX_ACTIVE_SEEDS_FIELD.setValue(btEngine.maxActiveSeeds());
}
use of com.frostwire.bittorrent.BTEngine in project frostwire by frostwire.
the class TransferManager method onPreferenceChanged.
private void onPreferenceChanged(String key) {
// LOG.info("onPreferenceChanged(key="+key+")");
Engine.instance().getThreadPool().execute(() -> {
BTEngine e = BTEngine.getInstance();
ConfigurationManager CM = ConfigurationManager.instance();
if (key.equals(Constants.PREF_KEY_TORRENT_MAX_DOWNLOAD_SPEED)) {
e.downloadRateLimit((int) CM.getLong(key));
} else if (key.equals(Constants.PREF_KEY_TORRENT_MAX_UPLOAD_SPEED)) {
e.uploadRateLimit((int) CM.getLong(key));
} else if (key.equals(Constants.PREF_KEY_TORRENT_MAX_DOWNLOADS)) {
e.maxActiveDownloads((int) CM.getLong(key));
} else if (key.equals(Constants.PREF_KEY_TORRENT_MAX_UPLOADS)) {
e.maxActiveSeeds((int) CM.getLong(key));
} else if (key.equals(Constants.PREF_KEY_TORRENT_MAX_TOTAL_CONNECTIONS)) {
e.maxConnections((int) CM.getLong(key));
} else if (key.equals(Constants.PREF_KEY_TORRENT_MAX_PEERS)) {
e.maxPeers((int) CM.getLong(key));
}
});
}
use of com.frostwire.bittorrent.BTEngine in project frostwire by frostwire.
the class DownloadManagerImpl method loadSavedDownloadsAndScheduleWriting.
public void loadSavedDownloadsAndScheduleWriting() {
try {
BTEngine engine = BTEngine.getInstance();
engine.setListener(new BTEngineAdapter() {
@Override
public void downloadAdded(BTEngine engine, BTDownload dl) {
if (engine == null || dl == null) {
return;
}
String name = dl.getName();
if (name == null || name.contains("fetch_magnet:")) {
return;
}
File savePath = dl.getSavePath();
if (savePath != null && savePath.toString().contains("fetch_magnet")) {
return;
}
// don't add frostwire update downloads to the download manager.
if (savePath != null) {
final File parentFile = savePath.getParentFile();
if (parentFile != null) {
if (parentFile.getAbsolutePath().equals(UpdateSettings.UPDATES_DIR.getAbsolutePath())) {
LOG.info("Update download, not adding to transfer manager: " + savePath);
return;
}
} else if (savePath.getAbsolutePath().equals(UpdateSettings.UPDATES_DIR.getAbsolutePath())) {
// save path must have been a root folder, like D:\, so no parent file.
LOG.info("Update download, not adding to transfer manager: " + savePath);
return;
}
}
addDownload(dl);
}
@Override
public void downloadUpdate(BTEngine engine, BTDownload dl) {
updateDownload(dl);
}
});
engine.restoreDownloads();
} catch (Throwable e) {
LOG.error("General error loading saved downloads", e);
}
}
use of com.frostwire.bittorrent.BTEngine in project frostwire by frostwire.
the class BTDownloadMediatorAdvancedMenuFactory method createAdvancedSubMenu.
public static SkinMenu createAdvancedSubMenu() {
final com.frostwire.bittorrent.BTDownload[] dms = getSingleSelectedDownloadManagers();
if (dms == null) {
return null;
}
boolean upSpeedDisabled = false;
long totalUpSpeed = 0;
boolean upSpeedUnlimited = false;
long upSpeedSetMax = 0;
boolean downSpeedDisabled = false;
long totalDownSpeed = 0;
boolean downSpeedUnlimited = false;
long downSpeedSetMax = 0;
for (int i = 0; i < dms.length; i++) {
com.frostwire.bittorrent.BTDownload dm = (com.frostwire.bittorrent.BTDownload) dms[i];
try {
int maxul = dm.getUploadRateLimit();
if (maxul == 0) {
upSpeedUnlimited = true;
} else {
if (maxul > upSpeedSetMax) {
upSpeedSetMax = maxul;
}
}
if (maxul == -1) {
maxul = 0;
upSpeedDisabled = true;
}
totalUpSpeed += maxul;
int maxdl = dm.getDownloadRateLimit();
if (maxdl == 0) {
downSpeedUnlimited = true;
} else {
if (maxdl > downSpeedSetMax) {
downSpeedSetMax = maxdl;
}
}
if (maxdl == -1) {
maxdl = 0;
downSpeedDisabled = true;
}
totalDownSpeed += maxdl;
} catch (Exception ex) {
Debug.printStackTrace(ex);
}
}
final SkinMenu menuAdvanced = new SkinMenu(I18n.tr("Advanced"));
// advanced > Download Speed Menu //
BTEngine engine = BTEngine.getInstance();
long maxDownload = engine.downloadRateLimit();
long maxUpload = engine.uploadRateLimit();
addSpeedMenu(menuAdvanced, true, true, downSpeedDisabled, downSpeedUnlimited, totalDownSpeed, downSpeedSetMax, maxDownload, upSpeedDisabled, upSpeedUnlimited, totalUpSpeed, upSpeedSetMax, maxUpload, dms.length, new SpeedAdapter() {
public void setDownSpeed(final int speed) {
for (int i = 0; i < dms.length; i++) {
dms[i].setDownloadRateLimit(speed);
}
}
public void setUpSpeed(final int speed) {
for (int i = 0; i < dms.length; i++) {
dms[i].setUploadRateLimit(speed);
}
}
});
SkinMenu menuTracker = createTrackerMenu();
if (menuTracker != null) {
menuAdvanced.add(menuTracker);
}
return menuAdvanced;
}
use of com.frostwire.bittorrent.BTEngine in project frostwire by frostwire.
the class BTDownloadMediator method getBandwidth.
/**
* Returns the aggregate amount of bandwidth being consumed by active downloads.
*
* @return the total amount of bandwidth being consumed by active downloads.
*/
private double getBandwidth(boolean download) {
BTEngine engine = BTEngine.getInstance();
double totalBandwidth = download ? engine.downloadRate() : engine.uploadRate();
if (download) {
double httpBandwidth = 0;
for (BTDownload btDownload : this.getDownloads()) {
if (btDownload instanceof HttpDownload || btDownload instanceof SoundcloudDownload || btDownload instanceof YouTubeDownload) {
httpBandwidth += btDownload.getDownloadSpeed();
}
}
httpBandwidth = httpBandwidth * 1000;
totalBandwidth += httpBandwidth;
}
return totalBandwidth;
}
Aggregations