Search in sources :

Example 71 with DownloadManager

use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.

the class CoreImpl method checkRestartAction.

protected boolean checkRestartAction() {
    if (ra_restarting) {
        return (true);
    }
    int restart_after = COConfigurationManager.getIntParameter("Auto Restart When Idle");
    if (restart_after > 0) {
        List<DownloadManager> managers = getGlobalManager().getDownloadManagers();
        boolean active = false;
        for (DownloadManager manager : managers) {
            int state = manager.getState();
            if (state == DownloadManager.STATE_DOWNLOADING || state == DownloadManager.STATE_SEEDING) {
                active = true;
                break;
            }
        }
        if (active) {
            GlobalManagerStats stats = global_manager.getStats();
            long totals = stats.getTotalDataBytesReceived() + stats.getTotalDataBytesSent();
            long now = SystemTime.getMonotonousTime();
            if (totals == ra_last_total_data) {
                if (now - ra_last_data_time >= 60 * 1000 * restart_after) {
                    ra_restarting = true;
                    String message = MessageText.getString("core.restart.alert", new String[] { String.valueOf(restart_after) });
                    UIFunctions ui_functions = UIFunctionsManager.getUIFunctions();
                    if (ui_functions != null) {
                        ui_functions.forceNotify(UIFunctions.STATUSICON_NONE, null, message, null, new Object[0], -1);
                    }
                    Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogEvent.LT_INFORMATION, message));
                    new DelayedEvent("CoreRestart", 10 * 1000, new AERunnable() {

                        @Override
                        public void runSupport() {
                            requestRestart();
                        }
                    });
                    return (true);
                }
            } else {
                ra_last_total_data = totals;
                ra_last_data_time = now;
            }
        } else {
            ra_last_total_data = -1;
        }
    } else {
        ra_last_total_data = -1;
    }
    return (false);
}
Also used : UIFunctions(com.biglybt.ui.UIFunctions) GlobalManagerStats(com.biglybt.core.global.GlobalManagerStats) DownloadManager(com.biglybt.core.download.DownloadManager) LogAlert(com.biglybt.core.logging.LogAlert)

Example 72 with DownloadManager

use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.

the class GlobalManagerFileMerger method syncFileSets.

void syncFileSets() {
    List<DownloadManager> dms = gm.getDownloadManagers();
    synchronized (dm_map) {
        boolean changed = false;
        Set<HashWrapper> existing_dm_hashes = new HashSet<>(dm_map.keySet());
        if (enabled) {
            for (DownloadManager dm : dms) {
                /* 
					 * not sure why we were ignoring shares, one might share a local file in order to help
					 * out a 'normal' download
					 * 
					if ( !dm.isPersistent()){

						continue;
					}
					*/
                DownloadManagerState state = dm.getDownloadState();
                if (state.getFlag(DownloadManagerState.FLAG_LOW_NOISE) || state.getFlag(DownloadManagerState.FLAG_METADATA_DOWNLOAD)) {
                    continue;
                }
                if (enabled_extended || !dm.isDownloadComplete(false)) {
                    TOTorrent torrent = dm.getTorrent();
                    if (torrent != null) {
                        try {
                            HashWrapper hw = torrent.getHashWrapper();
                            if (dm_map.containsKey(hw)) {
                                existing_dm_hashes.remove(hw);
                            } else {
                                dm_map.put(hw, dm);
                                changed = true;
                            }
                        } catch (Throwable e) {
                        }
                    }
                }
            }
        }
        if (existing_dm_hashes.size() > 0) {
            changed = true;
            for (HashWrapper hw : existing_dm_hashes) {
                dm_map.remove(hw);
            }
        }
        if (changed) {
            List<Set<DiskManagerFileInfo>> interesting = new LinkedList<>();
            Map<Long, Set<DiskManagerFileInfo>> size_map = new HashMap<>();
            for (DownloadManager dm : dm_map.values()) {
                TOTorrent torrent = dm.getTorrent();
                if (torrent == null) {
                    continue;
                }
                DiskManagerFileInfo[] files = dm.getDiskManagerFileInfoSet().getFiles();
                for (DiskManagerFileInfo file : files) {
                    if (file.getNbPieces() < MIN_PIECES) {
                        continue;
                    }
                    long len = file.getLength();
                    Set<DiskManagerFileInfo> set = size_map.get(len);
                    if (set == null) {
                        set = new HashSet<>();
                        size_map.put(len, set);
                    }
                    boolean same_dm = false;
                    for (DiskManagerFileInfo existing : set) {
                        if (existing.getDownloadManager() == dm) {
                            same_dm = true;
                            break;
                        }
                    }
                    if (!same_dm) {
                        set.add(file);
                        if (set.size() == 2) {
                            interesting.add(set);
                        }
                    }
                }
            }
            // remove sets consisting of only completed files
            Iterator<Set<DiskManagerFileInfo>> interesting_it = interesting.iterator();
            while (interesting_it.hasNext()) {
                Set<DiskManagerFileInfo> set = interesting_it.next();
                boolean all_done = true;
                for (DiskManagerFileInfo file : set) {
                    if (file.getDownloaded() != file.getLength()) {
                        all_done = false;
                        break;
                    }
                }
                if (all_done) {
                    interesting_it.remove();
                }
            }
            List<SameSizeFiles> sames_copy = new LinkedList<>(sames);
            for (Set<DiskManagerFileInfo> set : interesting) {
                boolean found = false;
                Iterator<SameSizeFiles> sames_it = sames_copy.iterator();
                while (sames_it.hasNext()) {
                    SameSizeFiles same = sames_it.next();
                    if (same.sameAs(set)) {
                        found = true;
                        sames_it.remove();
                        break;
                    }
                }
                if (!found) {
                    sames.add(new SameSizeFiles(set));
                }
            }
            for (SameSizeFiles dead : sames_copy) {
                dead.destroy();
                sames.remove(dead);
            }
            if (sames.size() > 0) {
                if (timer_event == null) {
                    timer_event = SimpleTimer.addPeriodicEvent("GMFM:sync", TIMER_PERIOD, new TimerEventPerformer() {

                        private int tick_count = 0;

                        @Override
                        public void perform(TimerEvent event) {
                            tick_count++;
                            synchronized (dm_map) {
                                for (SameSizeFiles s : sames) {
                                    s.sync(tick_count);
                                }
                            }
                        }
                    });
                }
            } else {
                if (timer_event != null) {
                    timer_event.cancel();
                    timer_event = null;
                }
            }
        }
    }
}
Also used : DownloadManager(com.biglybt.core.download.DownloadManager) DownloadManagerState(com.biglybt.core.download.DownloadManagerState) DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) TOTorrent(com.biglybt.core.torrent.TOTorrent)

Example 73 with DownloadManager

use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.

the class GlobalManagerHostSupport method lookupTorrent.

@Override
public TOTorrent lookupTorrent(byte[] hash) {
    DownloadManager dm = gm.getDownloadManager(new HashWrapper(hash));
    if (dm != null) {
        TOTorrent torrent = dm.getTorrent();
        if (torrent != null) {
            return (torrent);
        }
    }
    TOTorrent torrent = DownloadManagerImpl.getStubTorrent(hash);
    return (torrent);
}
Also used : HashWrapper(com.biglybt.core.util.HashWrapper) TOTorrent(com.biglybt.core.torrent.TOTorrent) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 74 with DownloadManager

use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.

the class TagDownloadWithState method performOperation.

private void performOperation(int op, Set<DownloadManager> dms) {
    for (final DownloadManager dm : dms) {
        int dm_state = dm.getState();
        if (op == TagFeatureRunState.RSC_START) {
            if (dm_state == DownloadManager.STATE_STOPPED || dm_state == DownloadManager.STATE_ERROR) {
                rs_async.dispatch(new AERunnable() {

                    @Override
                    public void runSupport() {
                        dm.setStateQueued();
                    }
                });
            }
        } else if (op == TagFeatureRunState.RSC_STOP) {
            if (dm_state != DownloadManager.STATE_STOPPED && dm_state != DownloadManager.STATE_STOPPING && dm_state != DownloadManager.STATE_ERROR) {
                rs_async.dispatch(new AERunnable() {

                    @Override
                    public void runSupport() {
                        dm.stopIt(DownloadManager.STATE_STOPPED, false, false);
                        // recheck here in case it is an 'archive' action that requires
                        // download to be stopped
                        checkMaximumTaggables();
                    }
                });
            }
        } else if (op == TagFeatureRunState.RSC_PAUSE) {
            if (dm_state != DownloadManager.STATE_STOPPED && dm_state != DownloadManager.STATE_STOPPING && dm_state != DownloadManager.STATE_ERROR) {
                rs_async.dispatch(new AERunnable() {

                    @Override
                    public void runSupport() {
                        dm.pause();
                    }
                });
            }
        } else if (op == TagFeatureRunState.RSC_RESUME) {
            if (dm.isPaused()) {
                rs_async.dispatch(new AERunnable() {

                    @Override
                    public void runSupport() {
                        dm.resume();
                    }
                });
            }
        }
    }
}
Also used : DownloadManager(com.biglybt.core.download.DownloadManager)

Example 75 with DownloadManager

use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.

the class TagDownloadWithState method setTagMinShareRatio.

@Override
public void setTagMinShareRatio(int sr) {
    if (sr < 0) {
        sr = 0;
    }
    if (sr == min_share_ratio) {
        return;
    }
    min_share_ratio = sr;
    writeLongAttribute(AT_RATELIMIT_MIN_SR, sr);
    Set<DownloadManager> dms = getTaggedDownloads();
    for (DownloadManager dm : dms) {
        List<Tag> dm_tags = getTagType().getTagsForTaggable(dm);
        for (Tag t : dm_tags) {
            if (t == this) {
                continue;
            }
            if (t instanceof TagFeatureRateLimit) {
                int o_sr = ((TagFeatureRateLimit) t).getTagMinShareRatio();
                if (o_sr > sr) {
                    sr = o_sr;
                }
            }
        }
        dm.getDownloadState().setIntParameter(DownloadManagerState.PARAM_MIN_SHARE_RATIO, sr);
    }
    getTagType().fireChanged(this);
}
Also used : DownloadManager(com.biglybt.core.download.DownloadManager)

Aggregations

DownloadManager (com.biglybt.core.download.DownloadManager)307 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)54 TOTorrent (com.biglybt.core.torrent.TOTorrent)35 GlobalManager (com.biglybt.core.global.GlobalManager)33 PEPeerManager (com.biglybt.core.peer.PEPeerManager)29 File (java.io.File)29 List (java.util.List)21 Core (com.biglybt.core.Core)17 Download (com.biglybt.pif.download.Download)17 Point (org.eclipse.swt.graphics.Point)17 UIFunctions (com.biglybt.ui.UIFunctions)16 Tag (com.biglybt.core.tag.Tag)15 UIInputReceiverListener (com.biglybt.pif.ui.UIInputReceiverListener)14 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)13 ArrayList (java.util.ArrayList)13 DiskManager (com.biglybt.core.disk.DiskManager)12 DownloadManagerStats (com.biglybt.core.download.DownloadManagerStats)12 CoreRunningListener (com.biglybt.core.CoreRunningListener)11 DownloadManagerState (com.biglybt.core.download.DownloadManagerState)11 PEPeer (com.biglybt.core.peer.PEPeer)11