Search in sources :

Example 21 with TrackerPeerSource

use of com.biglybt.core.tracker.TrackerPeerSource in project BiglyBT by BiglySoftware.

the class TypeItem method refresh.

@Override
public void refresh(TableCell cell) {
    TrackerPeerSource ps = (TrackerPeerSource) cell.getDataSource();
    int value = (ps == null) ? TrackerPeerSource.TP_UNKNOWN : ps.getType();
    if (!cell.setSortValue(value) && cell.isValid()) {
        return;
    }
    cell.setText(js_resources[value]);
}
Also used : TrackerPeerSource(com.biglybt.core.tracker.TrackerPeerSource)

Example 22 with TrackerPeerSource

use of com.biglybt.core.tracker.TrackerPeerSource in project BiglyBT by BiglySoftware.

the class TRTrackerAnnouncerMuxer method getTrackerPeerSource.

@Override
public TrackerPeerSource getTrackerPeerSource(final TOTorrentAnnounceURLSet set) {
    URL[] urls = set.getAnnounceURLs();
    final String[] url_strs = new String[urls.length];
    for (int i = 0; i < urls.length; i++) {
        url_strs[i] = urls[i].toExternalForm();
    }
    return (new TrackerPeerSource() {

        private StatusSummary _summary;

        private boolean enabled;

        private long fixup_time;

        private StatusSummary fixup() {
            long now = SystemTime.getMonotonousTime();
            if (now - fixup_time > 1000) {
                long most_recent = 0;
                StatusSummary summary = null;
                synchronized (TRTrackerAnnouncerMuxer.this) {
                    for (String str : url_strs) {
                        StatusSummary s = recent_responses.get(str);
                        if (s != null) {
                            if (summary == null || s.getTime() > most_recent) {
                                summary = s;
                                most_recent = s.getTime();
                            }
                        }
                    }
                }
                if (provider != null) {
                    enabled = provider.isPeerSourceEnabled(PEPeerSource.PS_BT_TRACKER);
                }
                if (summary != null) {
                    _summary = summary;
                }
                fixup_time = now;
            }
            return (_summary);
        }

        @Override
        public int getType() {
            return (TrackerPeerSource.TP_TRACKER);
        }

        @Override
        public String getName() {
            StatusSummary summary = fixup();
            if (summary != null) {
                String str = summary.getURL().toExternalForm();
                int pos = str.indexOf('?');
                if (pos != -1) {
                    str = str.substring(0, pos);
                }
                return (str);
            }
            return (url_strs[0]);
        }

        @Override
        public String getDetails() {
            return (null);
        }

        @Override
        public URL getURL() {
            StatusSummary summary = fixup();
            if (summary != null) {
                return (summary.getURL());
            }
            return (urls[0]);
        }

        @Override
        public int getStatus() {
            StatusSummary summary = fixup();
            if (!enabled) {
                return (ST_DISABLED);
            }
            if (summary != null) {
                return (summary.getStatus());
            }
            return (ST_QUEUED);
        }

        @Override
        public String getStatusString() {
            StatusSummary summary = fixup();
            if (summary != null && enabled) {
                return (summary.getStatusString());
            }
            return (null);
        }

        @Override
        public int getSeedCount() {
            StatusSummary summary = fixup();
            if (summary != null) {
                return (summary.getSeedCount());
            }
            return (-1);
        }

        @Override
        public int getLeecherCount() {
            StatusSummary summary = fixup();
            if (summary != null) {
                return (summary.getLeecherCount());
            }
            return (-1);
        }

        @Override
        public int getCompletedCount() {
            StatusSummary summary = fixup();
            if (summary != null) {
                return (summary.getCompletedCount());
            }
            return (-1);
        }

        @Override
        public int getPeers() {
            StatusSummary summary = fixup();
            if (summary != null) {
                return (summary.getPeers());
            }
            return (-1);
        }

        @Override
        public int getLastUpdate() {
            StatusSummary summary = fixup();
            if (summary != null) {
                long time = summary.getTime();
                if (time == 0) {
                    return (0);
                }
                long elapsed = SystemTime.getMonotonousTime() - time;
                return ((int) ((SystemTime.getCurrentTime() - elapsed) / 1000));
            }
            return (0);
        }

        @Override
        public int getSecondsToUpdate() {
            StatusSummary summary = fixup();
            if (summary != null) {
                return (summary.getSecondsToUpdate());
            }
            return (Integer.MIN_VALUE);
        }

        @Override
        public int getInterval() {
            StatusSummary summary = fixup();
            if (summary != null) {
                return (summary.getInterval());
            }
            return (-1);
        }

        @Override
        public int getMinInterval() {
            StatusSummary summary = fixup();
            if (summary != null && enabled) {
                return (summary.getMinInterval());
            }
            return (-1);
        }

        @Override
        public boolean isUpdating() {
            StatusSummary summary = fixup();
            if (summary != null && enabled) {
                return (summary.isUpdating());
            }
            return (false);
        }

        @Override
        public boolean canManuallyUpdate() {
            StatusSummary summary = fixup();
            if (summary == null) {
                return (false);
            }
            return (summary.canManuallyUpdate());
        }

        @Override
        public void manualUpdate() {
            StatusSummary summary = fixup();
            if (summary != null) {
                summary.manualUpdate();
            }
        }

        @Override
        public long[] getReportedStats() {
            StatusSummary summary = fixup();
            if (summary != null && enabled) {
                return (summary.getReportedStats());
            }
            return (null);
        }

        @Override
        public boolean canDelete() {
            return (false);
        }

        @Override
        public void delete() {
            Debug.out("derp");
        }
    });
}
Also used : TrackerPeerSource(com.biglybt.core.tracker.TrackerPeerSource) URL(java.net.URL)

Aggregations

TrackerPeerSource (com.biglybt.core.tracker.TrackerPeerSource)22 URL (java.net.URL)3 TrackerPeerSourceAdapter (com.biglybt.core.tracker.TrackerPeerSourceAdapter)2 TRTrackerScraperResponse (com.biglybt.core.tracker.client.TRTrackerScraperResponse)2 TOTorrent (com.biglybt.core.torrent.TOTorrent)1 TRTrackerAnnouncer (com.biglybt.core.tracker.client.TRTrackerAnnouncer)1 AERunnable (com.biglybt.core.util.AERunnable)1 PluginInterface (com.biglybt.pif.PluginInterface)1 Download (com.biglybt.pif.download.Download)1 DownloadImpl (com.biglybt.pifimpl.local.download.DownloadImpl)1 DHTPluginContact (com.biglybt.plugin.dht.DHTPluginContact)1 DHTPluginOperationListener (com.biglybt.plugin.dht.DHTPluginOperationListener)1 DHTPluginValue (com.biglybt.plugin.dht.DHTPluginValue)1 ExternalSeedPlugin (com.biglybt.plugin.extseed.ExternalSeedPlugin)1 SelectedContent (com.biglybt.ui.selectedcontent.SelectedContent)1 MultiTrackerEditor (com.biglybt.ui.swt.maketorrent.MultiTrackerEditor)1 TrackerEditorListener (com.biglybt.ui.swt.maketorrent.TrackerEditorListener)1 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)1 TableSelectedRowsListener (com.biglybt.ui.swt.views.table.TableSelectedRowsListener)1 InetSocketAddress (java.net.InetSocketAddress)1