try{
stats_writer = new GlobalManagerStatsWriter( core );
}catch( Throwable e ){
Logger.log(new LogEvent(LOGID, "Stats unavailable", e ));
}
// Wait at least a few seconds before loading existing torrents.
// typically the UI will call loadExistingTorrents before this runs
// This is here in case the UI is stupid or forgets
if (existingTorrentLoadDelay > 0) {
loadTorrentsDelay = new DelayedEvent("GM:tld", existingTorrentLoadDelay,
new AERunnable() {
public void runSupport() {
loadExistingTorrentsNow(false); // already async
}
});
} else {
// run sync
loadDownloads();
}
if (progress_listener != null){
progress_listener.reportCurrentTask(MessageText.getString("splash.initializeGM"));
}
// Initialize scraper after loadDownloads so that we can merge scrapes
// into one request per tracker
trackerScraper = TRTrackerScraperFactory.getSingleton();
trackerScraper.setClientResolver(
new TRTrackerScraperClientResolver()
{
public int
getStatus(
HashWrapper torrent_hash )
{
DownloadManager dm = getDownloadManager(torrent_hash);
if ( dm == null ){
return( TRTrackerScraperClientResolver.ST_NOT_FOUND );
}
int dm_state = dm.getState();
if ( dm_state == DownloadManager.STATE_QUEUED ){
return( TRTrackerScraperClientResolver.ST_QUEUED );
}else if ( dm_state == DownloadManager.STATE_DOWNLOADING ||
dm_state == DownloadManager.STATE_SEEDING ){
return( TRTrackerScraperClientResolver.ST_RUNNING );
}
return( TRTrackerScraperClientResolver.ST_OTHER );
}
public boolean
isNetworkEnabled(
HashWrapper hash,
URL url )
{
DownloadManager dm = getDownloadManager(hash);
if ( dm == null ){
return( false );
}
String nw = AENetworkClassifier.categoriseAddress( url.getHost());
String[] networks = dm.getDownloadState().getNetworks();
for (int i=0;i<networks.length;i++){
if ( networks[i] == nw ){
return( true );
}
}
return( false );
}
public int[]
getCachedScrape(
HashWrapper hash )
{
DownloadManager dm = getDownloadManager(hash);
if ( dm == null ){
return( null );
}
long cache = dm.getDownloadState().getLongAttribute( DownloadManagerState.AT_SCRAPE_CACHE );
if ( cache == -1 ){
return( null );
}else{
int seeds = (int)((cache>>32)&0x00ffffff);
int leechers = (int)(cache&0x00ffffff);
return( new int[]{ seeds, leechers });
}
}
public Object[]
getExtensions(
HashWrapper hash )
{
DownloadManager dm = getDownloadManager(hash);
Character state;
String ext;
if ( dm == null ){
ext = "";
state = TRTrackerScraperClientResolver.FL_NONE;
}else{
ext = dm.getDownloadState().getTrackerClientExtensions();
if ( ext == null ){
ext = "";
}
boolean comp = dm.isDownloadComplete( false );
int dm_state = dm.getState();
// treat anything not stopped or running as queued as we need to be "optimistic"
// for torrents at the start-of-day
if ( dm_state == DownloadManager.STATE_ERROR ||
dm_state == DownloadManager.STATE_STOPPED ||
( dm_state == DownloadManager.STATE_STOPPING && dm.getSubState() != DownloadManager.STATE_QUEUED )){
state = comp?TRTrackerScraperClientResolver.FL_COMPLETE_STOPPED:TRTrackerScraperClientResolver.FL_INCOMPLETE_STOPPED;
}else if ( dm_state == DownloadManager.STATE_DOWNLOADING ||
dm_state == DownloadManager.STATE_SEEDING ){
state = comp?TRTrackerScraperClientResolver.FL_COMPLETE_RUNNING:TRTrackerScraperClientResolver.FL_INCOMPLETE_RUNNING;
}else{
state = comp?TRTrackerScraperClientResolver.FL_COMPLETE_QUEUED:TRTrackerScraperClientResolver.FL_INCOMPLETE_QUEUED;
}
}
return( new Object[]{ ext, state });
}
public boolean
redirectTrackerUrl(
HashWrapper hash,
URL old_url,
URL new_url )
{
DownloadManager dm = getDownloadManager(hash);
if ( dm == null || dm.getTorrent() == null ){
return( false );
}
return( TorrentUtils.replaceAnnounceURL( dm.getTorrent(), old_url, new_url ));
}
});
trackerScraper.addListener(
new TRTrackerScraperListener() {
public void scrapeReceived(TRTrackerScraperResponse response) {
HashWrapper hash = response.getHash();
DownloadManager manager = (DownloadManager)manager_map.get( hash );
if ( manager != null ) {
manager.setTrackerScrapeResponse( response );
}
}
});
try{
host_support = new GlobalManagerHostSupport( this );
}catch( Throwable e ){
Logger.log(new LogEvent(LOGID, "Hosting unavailable", e));
}
checker = new Checker();
checker.start();
torrent_folder_watcher = new TorrentFolderWatcher( this );
TRTrackerUtils.addListener(
new TRTrackerUtilsListener()
{
public void
announceDetailsChanged()
{
Logger.log( new LogEvent(LOGID, "Announce details have changed, updating trackers" ));
List managers = managers_cow;
for (int i=0;i<managers.size();i++){