Search in sources :

Example 31 with GlobalManager

use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.

the class CoreImpl method saveState.

@Override
public void saveState() {
    GlobalManager gm = global_manager;
    if (gm != null) {
        gm.saveState();
    }
    COConfigurationManager.save();
}
Also used : GlobalManager(com.biglybt.core.global.GlobalManager)

Example 32 with GlobalManager

use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.

the class DownloadManagerEnhancer method prepareForProgressiveMode.

protected void prepareForProgressiveMode(DownloadManager dm, boolean active) {
    if (active) {
        GlobalManager gm = core.getGlobalManager();
        List<DownloadManager> dms = (List<DownloadManager>) gm.getDownloadManagers();
        for (DownloadManager this_dm : dms) {
            if (this_dm == dm) {
                continue;
            }
            if (!this_dm.isDownloadComplete(false)) {
                int state = this_dm.getState();
                if (state == DownloadManager.STATE_DOWNLOADING || state == DownloadManager.STATE_QUEUED) {
                    pause(this_dm);
                }
            }
        }
        if (dm.isPaused()) {
            dm.resume();
        }
    } else {
        resume();
    }
}
Also used : GlobalManager(com.biglybt.core.global.GlobalManager)

Example 33 with GlobalManager

use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.

the class SpeedLimitHandler method checkSchedule.

private void checkSchedule(int tick_count) {
    GlobalManager gm = core.getGlobalManager();
    ScheduleRule current_rule;
    synchronized (this) {
        current_rule = active_rule;
        ScheduleRule latest_match = getActiveRule(new Date());
        if (latest_match == null) {
            active_rule = null;
            if (current_rule != null) {
                resetRules();
            }
        } else {
            String profile_name = latest_match.profile_name;
            boolean is_rule_pause_all = false;
            if (active_rule == null || !active_rule.sameAs(latest_match)) {
                String lc_profile_name = profile_name.toLowerCase();
                if (predefined_profile_names.contains(lc_profile_name)) {
                    if (lc_profile_name.equals("pause_all")) {
                        active_rule = latest_match;
                        is_rule_pause_all = true;
                        setRulePauseAllActive(true);
                    } else if (lc_profile_name.equals("resume_all")) {
                        active_rule = latest_match;
                        setRulePauseAllActive(false);
                    } else if (lc_profile_name.equals("null")) {
                        active_rule = latest_match;
                    } else {
                        Debug.out("Unknown pre-def name '" + profile_name + "'");
                    }
                } else if (profileExists(profile_name)) {
                    active_rule = latest_match;
                    loadProfile(profile_name);
                } else if (active_rule != null) {
                    active_rule = null;
                    resetRules();
                }
            } else {
                // must update because might have reloaded and the old rule may reference old stuff (e.g. old net limit)
                active_rule = latest_match;
                // same rule as before
                is_rule_pause_all = rule_pause_all_active;
            }
            if (rule_pause_all_active) {
                if (!is_rule_pause_all) {
                    setRulePauseAllActive(false);
                } else {
                    if (gm.canPauseDownloads()) {
                        gm.pauseDownloads();
                    }
                }
            }
        }
    }
    synchronized (extensions_lock) {
        prioritiser_enabled = true;
        for (List<NetLimit> l : net_limits.values()) {
            for (NetLimit n : l) {
                n.setEnabled(true);
            }
        }
        if (active_rule != null) {
            active_rule.checkExtensions();
        }
    }
    if (net_limits.size() > 0) {
        checkTagNetLimits(tick_count);
    }
    if ((current_rule != active_rule && net_limits.size() > 0) || net_limit_pause_all_active) {
        // net_limits can depend on the active rule, recalc
        // also have to periodically recheck stats if everything's paused as the stats won't in general
        // naturally update and trigger an update that way...
        updated(StatsFactory.getLongTermStats());
    }
    if (net_limit_pause_all_active) {
        if (gm.canPauseDownloads()) {
            gm.pauseDownloads();
        }
    }
}
Also used : GlobalManager(com.biglybt.core.global.GlobalManager)

Example 34 with GlobalManager

use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.

the class SubscriptionHistoryImpl method reconcileResults.

protected SubscriptionResultImpl[] reconcileResults(Engine engine, SubscriptionResultImpl[] latest_results) {
    auto_dl_supported = engine.getAutoDownloadSupported() == Engine.AUTO_DL_SUPPORTED_YES;
    int new_unread = 0;
    int new_read = 0;
    if (last_scan == 0) {
        // first download feed -> mark all existing as read
        GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
        for (int i = 0; i < latest_results.length; i++) {
            SubscriptionResultImpl result = latest_results[i];
            result.setReadInternal(true);
            try {
                String hash_str = result.getAssetHash();
                if (hash_str != null) {
                    byte[] hash = Base32.decode(hash_str);
                    DownloadManager dm = gm.getDownloadManager(new HashWrapper(hash));
                    if (dm != null) {
                        log("Adding existing association on first read for '" + dm.getDisplayName());
                        subs.addAssociation(hash);
                    }
                }
            } catch (Throwable e) {
                Debug.printStackTrace(e);
            }
        }
    }
    long now = SystemTime.getCurrentTime();
    SubscriptionResultImpl[] result;
    int max_results = getMaxNonDeletedResults();
    if (max_results < 0) {
        max_results = manager.getMaxNonDeletedResults();
    }
    SubscriptionResultImpl first_new_result = null;
    synchronized (this) {
        boolean got_new_or_changed_result = false;
        LinkedHashMap<String, SubscriptionResultImpl> results_map = manager.loadResults(subs);
        SubscriptionResultImpl[] existing_results = results_map.values().toArray(new SubscriptionResultImpl[results_map.size()]);
        ByteArrayHashMap result_key_map = new ByteArrayHashMap();
        ByteArrayHashMap result_key2_map = new ByteArrayHashMap();
        List new_results = new ArrayList();
        for (int i = 0; i < existing_results.length; i++) {
            SubscriptionResultImpl r = existing_results[i];
            result_key_map.put(r.getKey1(), r);
            byte[] key2 = r.getKey2();
            if (key2 != null) {
                result_key2_map.put(key2, r);
            }
            new_results.add(r);
            if (!r.isDeleted()) {
                if (r.getRead()) {
                    new_read++;
                } else {
                    new_unread++;
                }
            }
        }
        for (int i = 0; i < latest_results.length; i++) {
            SubscriptionResultImpl r = latest_results[i];
            // we first of all insist on names uniqueness
            SubscriptionResultImpl existing = (SubscriptionResultImpl) result_key_map.get(r.getKey1());
            if (existing == null) {
                // only if non-unique name do we fall back and use UID to remove duplicate
                // entries where the name has changed
                byte[] key2 = r.getKey2();
                if (key2 != null) {
                    existing = (SubscriptionResultImpl) result_key2_map.get(key2);
                }
            }
            if (existing == null) {
                last_new_result = now;
                new_results.add(r);
                result_key_map.put(r.getKey1(), r);
                byte[] key2 = r.getKey2();
                if (key2 != null) {
                    result_key2_map.put(key2, r);
                }
                got_new_or_changed_result = true;
                if (r.getRead()) {
                    new_read++;
                } else {
                    new_unread++;
                    if (first_new_result == null) {
                        first_new_result = r;
                    }
                }
            } else {
                if (existing.updateFrom(r)) {
                    got_new_or_changed_result = true;
                }
            }
        }
        if (max_results > 0 && (new_unread + new_read) > max_results) {
            for (int i = 0; i < new_results.size(); i++) {
                SubscriptionResultImpl r = (SubscriptionResultImpl) new_results.get(i);
                if (!r.isDeleted()) {
                    if (r.getRead()) {
                        new_read--;
                    } else {
                        new_unread--;
                    }
                    r.deleteInternal();
                    got_new_or_changed_result = true;
                    if ((new_unread + new_read) <= max_results) {
                        break;
                    }
                }
            }
        }
        if (got_new_or_changed_result) {
            result = (SubscriptionResultImpl[]) new_results.toArray(new SubscriptionResultImpl[new_results.size()]);
            manager.saveResults(subs, result);
        } else {
            result = existing_results;
        }
        last_scan = now;
        num_unread = new_unread;
        num_read = new_read;
    }
    // always save config as we have a new scan time
    saveConfig(SubscriptionListener.CR_RESULTS);
    if (post_notifications && first_new_result != null) {
        dispatcher.dispatch(new AERunnable() {

            @Override
            public void runSupport() {
                Map<String, String> cb_data = new HashMap<>();
                cb_data.put("subname", subs.getName());
                cb_data.put("subid", subs.getID());
                cb_data.put("allowReAdd", "true");
                String date_str = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date(SystemTime.getCurrentTime()));
                LocalActivityManager.addLocalActivity("NewResults:" + subs.getID(), "rss", MessageText.getString("subs.activity.new.results", new String[] { subs.getName(), String.valueOf(num_unread) }) + ": " + date_str, new String[] { MessageText.getString("label.view") }, ActivityCallback.class, cb_data);
            }
        });
    }
    return (result);
}
Also used : DownloadManager(com.biglybt.core.download.DownloadManager) GlobalManager(com.biglybt.core.global.GlobalManager) SimpleDateFormat(java.text.SimpleDateFormat)

Example 35 with GlobalManager

use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.

the class StatsWriterImpl method writeSupport.

protected void writeSupport() {
    writeLineRaw("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    boolean export_peer_stats = COConfigurationManager.getBooleanParameter("Stats Export Peer Details");
    boolean export_file_stats = COConfigurationManager.getBooleanParameter("Stats Export File Details");
    String xsl = COConfigurationManager.getStringParameter("Stats XSL File");
    if (xsl.length() > 0) {
        writeLineRaw("<?xml-stylesheet type=\"text/xsl\" href=\"" + xsl + "\"?>");
    }
    writeLineRaw("<STATS>");
    GlobalManager global = core.getGlobalManager();
    try {
        indent();
        writeTag("AZUREUS_VERSION", Constants.AZUREUS_VERSION);
        writeLineRaw("<GLOBAL>");
        try {
            indent();
            GlobalManagerStats gm_stats = global.getStats();
            writeRawCookedAverageTag("DOWNLOAD_SPEED", gm_stats.getDataReceiveRate() + gm_stats.getProtocolReceiveRate());
            writeRawCookedAverageTag("UPLOAD_SPEED", gm_stats.getDataSendRate() + gm_stats.getProtocolSendRate());
        } finally {
            exdent();
        }
        writeLineRaw("</GLOBAL>");
        writeLineRaw("<DOWNLOADS>");
        try {
            indent();
            List _dms = global.getDownloadManagers();
            DownloadManager[] dms = new DownloadManager[_dms.size()];
            // sort by position, downloads then seeders
            _dms.toArray(dms);
            Arrays.sort(dms, new Comparator() {

                @Override
                public int compare(Object o1, Object o2) {
                    DownloadManager d1 = (DownloadManager) o1;
                    DownloadManager d2 = (DownloadManager) o2;
                    int d1_index = d1.getPosition();
                    int d2_index = d2.getPosition();
                    if (d1.isDownloadComplete(false)) {
                        d1_index += 1000000;
                    }
                    if (d2.isDownloadComplete(false)) {
                        d2_index += 1000000;
                    }
                    return (d1_index - d2_index);
                }
            });
            for (int i = 0; i < dms.length; i++) {
                DownloadManager dm = (DownloadManager) dms[i];
                DownloadManagerStats dm_stats = dm.getStats();
                writeLineRaw("<DOWNLOAD>");
                try {
                    indent();
                    writeLineRaw("<TORRENT>");
                    // torrent can be null if broken torrent!
                    TOTorrent torrent = dm.getTorrent();
                    try {
                        indent();
                        writeTag("NAME", dm.getDisplayName());
                        writeTag("TORRENT_FILE", dm.getTorrentFileName());
                        if (torrent != null) {
                            writeTag("HASH", TorrentUtils.nicePrintTorrentHash(torrent, true));
                            writeRawCookedTag("SIZE", torrent.getSize());
                            writeTag("PIECE_LENGTH", torrent.getPieceLength());
                            writeTag("PIECE_COUNT", torrent.getNumberOfPieces());
                            writeTag("FILE_COUNT", torrent.getFiles().length);
                            writeTag("COMMENT", dm.getTorrentComment());
                            writeTag("CREATED_BY", dm.getTorrentCreatedBy());
                            writeTag("CREATION_DATE", torrent.getCreationDate());
                        }
                    } finally {
                        exdent();
                    }
                    writeLineRaw("</TORRENT>");
                    writeTag("DOWNLOAD_STATUS", DisplayFormatters.formatDownloadStatusDefaultLocale(dm));
                    writeTag("DOWNLOAD_DIR", dm.getSaveLocation().toString());
                    if (torrent != null) {
                        if (torrent.isSimpleTorrent()) {
                            writeTag("TARGET_FILE", dm.getSaveLocation().toString());
                        } else {
                            writeTag("TARGET_DIR", dm.getSaveLocation().toString());
                        }
                    }
                    writeTag("TRACKER_STATUS", dm.getTrackerStatus());
                    writeTag("COMPLETED", dm_stats.getCompleted());
                    writeTag("NON_DND_COMPLETED", dm.isDownloadComplete(false));
                    writeRawCookedTag("DOWNLOADED", dm_stats.getTotalDataBytesReceived());
                    writeRawCookedTag("UPLOADED", dm_stats.getTotalDataBytesSent());
                    writeRawCookedTag("DISCARDED", dm_stats.getDiscarded());
                    writeRawCookedAverageTag("DOWNLOAD_SPEED", dm_stats.getDataReceiveRate());
                    writeRawCookedAverageTag("UPLOAD_SPEED", dm_stats.getDataSendRate());
                    writeRawCookedAverageTag("TOTAL_SPEED", dm_stats.getTotalAverage());
                    writeRawCookedAverageTag("DOWNLOAD_SPEED_SMOOTH", dm_stats.getSmoothedDataReceiveRate());
                    writeRawCookedAverageTag("UPLOAD_SPEED_SMOOTH", dm_stats.getSmoothedDataSendRate());
                    writeTag("ELAPSED", dm_stats.getElapsedTime());
                    writeTag("ETA", DisplayFormatters.formatETA(dm_stats.getSmoothedETA()));
                    writeTag("HASH_FAILS", dm_stats.getHashFailCount());
                    writeTag("SHARE_RATIO", dm_stats.getShareRatio());
                    writeTag("TOTAL_SEEDS", dm.getNbSeeds());
                    writeTag("TOTAL_LEECHERS", dm.getNbPeers());
                    if (export_file_stats) {
                        try {
                            writeLineRaw("<FILES>");
                            indent();
                            DiskManagerFileInfo[] files = dm.getDiskManagerFileInfo();
                            for (int j = 0; j < files.length; j++) {
                                DiskManagerFileInfo file = files[j];
                                try {
                                    writeLineRaw("<FILE>");
                                    indent();
                                    writeTag("NAME", file.getTorrentFile().getRelativePath());
                                    writeTag("DND", file.isSkipped());
                                    writeRawCookedTag("SIZE", file.getLength());
                                    writeRawCookedTag("DOWNLOADED", file.getDownloaded());
                                } finally {
                                    exdent();
                                    writeLineRaw("</FILE>");
                                }
                            }
                        } finally {
                            exdent();
                            writeLineRaw("</FILES>");
                        }
                    }
                    if (export_peer_stats) {
                        try {
                            writeLineRaw("<PEERS>");
                            indent();
                            PEPeerManager pm = dm.getPeerManager();
                            if (pm != null) {
                                List peers = pm.getPeers();
                                for (int j = 0; j < peers.size(); j++) {
                                    PEPeer peer = (PEPeer) peers.get(j);
                                    PEPeerStats peer_stats = peer.getStats();
                                    byte[] id = peer.getId();
                                    if (id == null) {
                                        continue;
                                    }
                                    try {
                                        String peer_id = PeerClassifier.getPrintablePeerID(id);
                                        peer_id = escapeXML(peer_id);
                                        String type = escapeXML(peer.getClient());
                                        writeLineRaw("<PEER hex_id=\"" + ByteFormatter.encodeString(id) + "\" printable_id=\"" + peer_id + "\" type=\"" + type + "\">");
                                        indent();
                                        writeTag("IP", peer.getIp());
                                        writeTag("IS_SEED", peer.isSeed());
                                        writeRawCookedTag("DOWNLOADED", peer_stats.getTotalDataBytesReceived());
                                        writeRawCookedTag("UPLOADED", peer_stats.getTotalDataBytesSent());
                                        writeRawCookedAverageTag("DOWNLOAD_SPEED", peer_stats.getDataReceiveRate());
                                        writeRawCookedAverageTag("UPLOAD_SPEED", peer_stats.getDataSendRate());
                                    } catch (Throwable e) {
                                        Debug.printStackTrace(e);
                                    } finally {
                                        exdent();
                                        writeLineRaw("</PEER>");
                                    }
                                }
                            }
                        } finally {
                            exdent();
                            writeLineRaw("</PEERS>");
                        }
                    }
                } finally {
                    exdent();
                }
                writeLineRaw("</DOWNLOAD>");
            }
        } finally {
            exdent();
        }
        writeLineRaw("</DOWNLOADS>");
    } finally {
        exdent();
    }
    writeLineRaw("</STATS>");
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) PEPeer(com.biglybt.core.peer.PEPeer) GlobalManagerStats(com.biglybt.core.global.GlobalManagerStats) PEPeerStats(com.biglybt.core.peer.PEPeerStats) DownloadManager(com.biglybt.core.download.DownloadManager) Comparator(java.util.Comparator) GlobalManager(com.biglybt.core.global.GlobalManager) TOTorrent(com.biglybt.core.torrent.TOTorrent) List(java.util.List) PEPeerManager(com.biglybt.core.peer.PEPeerManager) DownloadManagerStats(com.biglybt.core.download.DownloadManagerStats)

Aggregations

GlobalManager (com.biglybt.core.global.GlobalManager)48 DownloadManager (com.biglybt.core.download.DownloadManager)33 Core (com.biglybt.core.Core)10 TOTorrent (com.biglybt.core.torrent.TOTorrent)10 List (java.util.List)7 CoreRunningListener (com.biglybt.core.CoreRunningListener)6 File (java.io.File)6 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)5 UIFunctions (com.biglybt.ui.UIFunctions)5 GlobalManagerStats (com.biglybt.core.global.GlobalManagerStats)4 PEPeerManager (com.biglybt.core.peer.PEPeerManager)4 HashWrapper (com.biglybt.core.util.HashWrapper)4 PluginInterface (com.biglybt.pif.PluginInterface)4 Menu (org.eclipse.swt.widgets.Menu)4 DiskManagerFileInfoSet (com.biglybt.core.disk.DiskManagerFileInfoSet)3 DownloadManagerInitialisationAdapter (com.biglybt.core.download.DownloadManagerInitialisationAdapter)3 PEPeer (com.biglybt.core.peer.PEPeer)3 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)3 PluginException (com.biglybt.pif.PluginException)3 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)3