Search in sources :

Example 6 with DelayedTask

use of com.biglybt.pif.utils.DelayedTask in project BiglyBT by BiglySoftware.

the class UPnPPlugin method initialize.

@Override
public void initialize(PluginInterface _plugin_interface) {
    plugin_interface = _plugin_interface;
    log = plugin_interface.getLogger().getTimeStampedChannel("UPnP");
    log.setDiagnostic();
    log.setForce(true);
    UIManager ui_manager = plugin_interface.getUIManager();
    final BasicPluginViewModel model = ui_manager.createBasicPluginViewModel("UPnP");
    model.setConfigSectionID(UPNP_PLUGIN_CONFIGSECTION_ID);
    BasicPluginConfigModel upnp_config = ui_manager.createBasicPluginConfigModel(ConfigSection.SECTION_PLUGINS, UPNP_PLUGIN_CONFIGSECTION_ID);
    // NATPMP
    BasicPluginConfigModel natpmp_config = ui_manager.createBasicPluginConfigModel(UPNP_PLUGIN_CONFIGSECTION_ID, NATPMP_PLUGIN_CONFIGSECTION_ID);
    natpmp_config.addLabelParameter2("natpmp.info");
    ActionParameter natpmp_wiki = natpmp_config.addActionParameter2("Utils.link.visit", "MainWindow.about.internet.wiki");
    natpmp_wiki.setStyle(ActionParameter.STYLE_LINK);
    natpmp_wiki.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            try {
                plugin_interface.getUIManager().openURL(new URL(Constants.URL_WIKI + "w/NATPMP"));
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    });
    natpmp_enable_param = natpmp_config.addBooleanParameter2("natpmp.enable", "natpmp.enable", false);
    nat_pmp_router = natpmp_config.addStringParameter2("natpmp.routeraddress", "natpmp.routeraddress", "");
    natpmp_enable_param.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            setNATPMPEnableState();
        }
    });
    natpmp_enable_param.addEnabledOnSelection(nat_pmp_router);
    // UPNP
    upnp_config.addLabelParameter2("upnp.info");
    upnp_config.addHyperlinkParameter2("upnp.wiki_link", Constants.URL_WIKI + "w/UPnP");
    upnp_enable_param = upnp_config.addBooleanParameter2("upnp.enable", "upnp.enable", true);
    grab_ports_param = upnp_config.addBooleanParameter2("upnp.grabports", "upnp.grabports", false);
    release_mappings_param = upnp_config.addBooleanParameter2("upnp.releasemappings", "upnp.releasemappings", true);
    ActionParameter refresh_param = upnp_config.addActionParameter2("upnp.refresh.label", "upnp.refresh.button");
    refresh_param.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            UPnPPlugin.this.refreshMappings();
        }
    });
    // Auto-refresh mappings every minute when enabled.
    final BooleanParameter auto_refresh_on_bad_nat_param = upnp_config.addBooleanParameter2("upnp.refresh_on_bad_nat", "upnp.refresh_mappings_on_bad_nat", false);
    plugin_interface.getUtilities().createTimer("upnp mapping auto-refresh", true).addPeriodicEvent(1 * 60 * 1000, new UTTimerEventPerformer() {

        private long last_bad_nat = 0;

        @Override
        public void perform(UTTimerEvent event) {
            if (upnp == null) {
                return;
            }
            if (!auto_refresh_on_bad_nat_param.getValue()) {
                return;
            }
            if (!upnp_enable_param.getValue()) {
                return;
            }
            int status = plugin_interface.getConnectionManager().getNATStatus();
            if (status == ConnectionManager.NAT_BAD) {
                // Only try to refresh the mappings if this is the first bad NAT
                // message we've been given in the last 15 minutes - we don't want
                // to endlessly retry performing the mappings
                long now = plugin_interface.getUtilities().getCurrentSystemTime();
                if (last_bad_nat + (15 * 60 * 1000) < now) {
                    last_bad_nat = now;
                    log.log(LoggerChannel.LT_WARNING, "NAT status is firewalled - trying to refresh UPnP mappings");
                    refreshMappings(true);
                }
            }
        }
    });
    upnp_config.addLabelParameter2("blank.resource");
    alert_success_param = upnp_config.addBooleanParameter2("upnp.alertsuccess", "upnp.alertsuccess", false);
    alert_other_port_param = upnp_config.addBooleanParameter2("upnp.alertothermappings", "upnp.alertothermappings", true);
    alert_device_probs_param = upnp_config.addBooleanParameter2("upnp.alertdeviceproblems", "upnp.alertdeviceproblems", true);
    selected_interfaces_param = upnp_config.addStringParameter2("upnp.selectedinterfaces", "upnp.selectedinterfaces", "");
    selected_interfaces_param.setGenerateIntermediateEvents(false);
    selected_addresses_param = upnp_config.addStringParameter2("upnp.selectedaddresses", "upnp.selectedaddresses", "");
    selected_addresses_param.setGenerateIntermediateEvents(false);
    desc_prefix_param = upnp_config.addStringParameter2("upnp.descprefix", "upnp.descprefix", Constants.APP_NAME + " UPnP");
    desc_prefix_param.setGenerateIntermediateEvents(false);
    ignore_bad_devices = upnp_config.addBooleanParameter2("upnp.ignorebaddevices", "upnp.ignorebaddevices", true);
    ignored_devices_list = upnp_config.addLabelParameter2("upnp.ignorebaddevices.info");
    ActionParameter reset_param = upnp_config.addActionParameter2("upnp.ignorebaddevices.reset", "upnp.ignorebaddevices.reset.action");
    reset_param.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            PluginConfig pc = plugin_interface.getPluginconfig();
            for (int i = 0; i < STATS_KEYS.length; i++) {
                String key = "upnp.device.stats." + STATS_KEYS[i];
                pc.setPluginMapParameter(key, new HashMap());
            }
            pc.setPluginMapParameter("upnp.device.ignorelist", new HashMap());
            updateIgnoreList();
        }
    });
    trace_to_log = upnp_config.addBooleanParameter2("upnp.trace_to_log", "upnp.trace_to_log", false);
    final boolean enabled = upnp_enable_param.getValue();
    upnp_enable_param.addEnabledOnSelection(alert_success_param);
    upnp_enable_param.addEnabledOnSelection(grab_ports_param);
    upnp_enable_param.addEnabledOnSelection(refresh_param);
    auto_refresh_on_bad_nat_param.addEnabledOnSelection(refresh_param);
    upnp_enable_param.addEnabledOnSelection(alert_other_port_param);
    upnp_enable_param.addEnabledOnSelection(alert_device_probs_param);
    upnp_enable_param.addEnabledOnSelection(release_mappings_param);
    upnp_enable_param.addEnabledOnSelection(selected_interfaces_param);
    upnp_enable_param.addEnabledOnSelection(selected_addresses_param);
    upnp_enable_param.addEnabledOnSelection(desc_prefix_param);
    upnp_enable_param.addEnabledOnSelection(ignore_bad_devices);
    upnp_enable_param.addEnabledOnSelection(ignored_devices_list);
    upnp_enable_param.addEnabledOnSelection(reset_param);
    upnp_enable_param.addEnabledOnSelection(trace_to_log);
    natpmp_enable_param.setEnabled(enabled);
    model.getStatus().setText(enabled ? "Running" : "Disabled");
    upnp_enable_param.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter p) {
            boolean e = upnp_enable_param.getValue();
            natpmp_enable_param.setEnabled(e);
            model.getStatus().setText(e ? "Running" : "Disabled");
            if (e) {
                startUp();
            } else {
                closeDown(true);
            }
            setNATPMPEnableState();
        }
    });
    model.getActivity().setVisible(false);
    model.getProgress().setVisible(false);
    log.addListener(new LoggerChannelListener() {

        @Override
        public void messageLogged(int type, String message) {
            model.getLogArea().appendText(message + "\n");
        }

        @Override
        public void messageLogged(String str, Throwable error) {
            model.getLogArea().appendText(error.toString() + "\n");
        }
    });
    // startup() used to be called on initializationComplete()
    // Moved to delayed task because rootDeviceFound can take
    // a lot of CPU cycle.  Let's hope nothing breaks
    DelayedTask dt = plugin_interface.getUtilities().createDelayedTask(new Runnable() {

        @Override
        public void run() {
            if (enabled) {
                updateIgnoreList();
                startUp();
            }
        }
    });
    dt.queue();
    plugin_interface.addListener(new PluginListener() {

        @Override
        public void initializationComplete() {
        }

        @Override
        public void closedownInitiated() {
            if (services.size() == 0) {
                plugin_interface.getPluginconfig().setPluginParameter("plugin.info", "");
            }
        }

        @Override
        public void closedownComplete() {
            closeDown(true);
        }
    });
}
Also used : LoggerChannelListener(com.biglybt.pif.logging.LoggerChannelListener) UTTimerEvent(com.biglybt.pif.utils.UTTimerEvent) UIManager(com.biglybt.pif.ui.UIManager) BasicPluginViewModel(com.biglybt.pif.ui.model.BasicPluginViewModel) URL(java.net.URL) PluginListener(com.biglybt.pif.PluginListener) PluginConfig(com.biglybt.pif.PluginConfig) DelayedTask(com.biglybt.pif.utils.DelayedTask) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel) UTTimerEventPerformer(com.biglybt.pif.utils.UTTimerEventPerformer)

Example 7 with DelayedTask

use of com.biglybt.pif.utils.DelayedTask in project BiglyBT by BiglySoftware.

the class CoreImpl method start.

@Override
public void start() throws CoreException {
    if (!canStart()) {
        throw (new CoreException("Core: already started (alternative process)"));
    }
    AEThread2.setOurThread();
    try {
        this_mon.enter();
        if (started) {
            throw (new CoreException("Core: already started"));
        }
        if (stopped) {
            throw (new CoreException("Core: already stopped"));
        }
        started = true;
    } finally {
        this_mon.exit();
    }
    // If a user sets this property, it is an alias for the following settings.
    if ("1".equals(System.getProperty(SystemProperties.SYSPROP_SAFEMODE))) {
        if (Logger.isEnabled())
            Logger.log(new LogEvent(LOGID, "Safe mode enabled"));
        Constants.isSafeMode = true;
        System.setProperty(SystemProperties.SYSPROP_LOADPLUGINS, "0");
        System.setProperty(SystemProperties.SYSPROP_DISABLEDOWNLOADS, "1");
        System.setProperty(SystemProperties.SYSPROP_SKIP_SWTCHECK, "1");
        // Not using localised text - not sure it's safe to this early.
        Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogEvent.LT_WARNING, "You are running " + Constants.APP_NAME + " in safe mode - you " + "can change your configuration, but any downloads added will " + "not be remembered when you close " + Constants.APP_NAME + "."));
    }
    /**
     * test to see if UI plays nicely with a really slow initialization
     */
    String sDelayCore = System.getProperty("delay.core", null);
    if (sDelayCore != null) {
        try {
            long delayCore = Long.parseLong(sDelayCore);
            Thread.sleep(delayCore);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    // run plugin loading in parallel to the global manager loading
    AEThread2 pluginload = new AEThread2("PluginLoader", true) {

        @Override
        public void run() {
            if (Logger.isEnabled())
                Logger.log(new LogEvent(LOGID, "Loading of Plugins starts"));
            pi.loadPlugins(CoreImpl.this, false, !"0".equals(System.getProperty(SystemProperties.SYSPROP_LOADPLUGINS)), true, true);
            if (Logger.isEnabled())
                Logger.log(new LogEvent(LOGID, "Loading of Plugins complete"));
        }
    };
    if (LOAD_PLUGINS_IN_OTHER_THREAD) {
        pluginload.start();
    } else {
        pluginload.run();
    }
    // Disable async loading of existing torrents, because there are many things
    // (like hosting) that require all the torrents to be loaded.  While we
    // can write code for each of these cases to wait until the torrents are
    // loaded, it's a pretty big job to find them all and fix all their quirks.
    // Too big of a job for this late in the release stage.
    // Other example is the tracker plugin that is coded in a way where it must
    // always publish a complete rss feed
    global_manager = GlobalManagerFactory.create(this, null, 0);
    if (stopped) {
        System.err.println("Core stopped while starting");
        return;
    }
    // wait until plugin loading is done
    if (LOAD_PLUGINS_IN_OTHER_THREAD) {
        pluginload.join();
    }
    if (stopped) {
        System.err.println("Core stopped while starting");
        return;
    }
    VuzeFileHandler.getSingleton().addProcessor(new VuzeFileProcessor() {

        @Override
        public void process(VuzeFile[] files, int expected_types) {
            for (int i = 0; i < files.length; i++) {
                VuzeFile vf = files[i];
                VuzeFileComponent[] comps = vf.getComponents();
                for (int j = 0; j < comps.length; j++) {
                    VuzeFileComponent comp = comps[j];
                    int comp_type = comp.getType();
                    if (comp_type == VuzeFileComponent.COMP_TYPE_ADD_TORRENT) {
                        PluginInterface default_pi = getPluginManager().getDefaultPluginInterface();
                        Map map = comp.getContent();
                        try {
                            Torrent torrent;
                            String url = MapUtils.getMapString(map, "torrent_url", null);
                            if (url != null) {
                                TorrentDownloader dl = default_pi.getTorrentManager().getURLDownloader(new URL(url));
                                torrent = dl.download();
                            } else {
                                String tf = MapUtils.getMapString(map, "torrent_file", null);
                                if (tf != null) {
                                    File file = new File(tf);
                                    if (!file.canRead() || file.isDirectory()) {
                                        throw (new Exception("torrent_file '" + tf + "' is invalid"));
                                    }
                                    torrent = default_pi.getTorrentManager().createFromBEncodedFile(file);
                                } else {
                                    throw (new Exception("torrent_url or torrent_file must be specified"));
                                }
                            }
                            File dest = null;
                            String save_folder = MapUtils.getMapString(map, "save_folder", null);
                            if (save_folder != null) {
                                dest = new File(save_folder, torrent.getName());
                            } else {
                                String save_file = MapUtils.getMapString(map, "save_file", null);
                                if (save_file != null) {
                                    dest = new File(save_file);
                                }
                            }
                            if (dest != null) {
                                dest.getParentFile().mkdirs();
                            }
                            default_pi.getDownloadManager().addDownload(torrent, null, dest);
                        } catch (Throwable e) {
                            Debug.out(e);
                        }
                        comp.setProcessed();
                    }
                }
            }
        }
    });
    triggerLifeCycleComponentCreated(global_manager);
    pi.initialisePlugins();
    if (stopped) {
        System.err.println("Core stopped while starting");
        return;
    }
    if (Logger.isEnabled())
        Logger.log(new LogEvent(LOGID, "Initializing Plugins complete"));
    try {
        PluginInterface dht_pi = getPluginManager().getPluginInterfaceByClass(DHTPlugin.class);
        if (dht_pi != null) {
            dht_pi.addEventListener(new PluginEventListener() {

                private boolean first_dht = true;

                @Override
                public void handleEvent(PluginEvent ev) {
                    if (ev.getType() == DHTPlugin.EVENT_DHT_AVAILABLE) {
                        if (first_dht) {
                            first_dht = false;
                            DHT dht = (DHT) ev.getValue();
                            dht.addListener(new DHTListener() {

                                @Override
                                public void speedTesterAvailable(DHTSpeedTester tester) {
                                    if (speed_manager != null) {
                                        speed_manager.setSpeedTester(tester);
                                    }
                                }
                            });
                            global_manager.addListener(new GlobalManagerAdapter() {

                                @Override
                                public void seedingStatusChanged(boolean seeding_only_mode, boolean b) {
                                    checkConfig();
                                }
                            });
                            COConfigurationManager.addAndFireParameterListeners(new String[] { TransferSpeedValidator.AUTO_UPLOAD_ENABLED_CONFIGKEY, TransferSpeedValidator.AUTO_UPLOAD_SEEDING_ENABLED_CONFIGKEY }, new ParameterListener() {

                                @Override
                                public void parameterChanged(String parameterName) {
                                    checkConfig();
                                }
                            });
                        }
                    }
                }

                protected void checkConfig() {
                    if (speed_manager != null) {
                        speed_manager.setEnabled(TransferSpeedValidator.isAutoSpeedActive(global_manager));
                    }
                }
            });
        }
    } catch (Throwable e) {
    }
    if (COConfigurationManager.getBooleanParameter("Resume Downloads On Start")) {
        global_manager.resumeDownloads();
    }
    VersionCheckClient.getSingleton().initialise();
    instance_manager.initialize();
    NetworkManager.getSingleton().initialize(this);
    SpeedLimitHandler.getSingleton(this);
    Runtime.getRuntime().addShutdownHook(new AEThread("Shutdown Hook") {

        @Override
        public void runSupport() {
            Logger.log(new LogEvent(LOGID, "Shutdown hook triggered"));
            CoreImpl.this.stop();
        }
    });
    DelayedTask delayed_task = UtilitiesImpl.addDelayedTask("Core", new Runnable() {

        @Override
        public void run() {
            new AEThread2("core:delayTask", true) {

                @Override
                public void run() {
                    AEDiagnostics.checkDumpsAndNatives();
                    COConfigurationManager.setParameter("diags.enable.pending.writes", true);
                    AEDiagnostics.flushPendingLogs();
                    NetworkAdmin na = NetworkAdmin.getSingleton();
                    na.runInitialChecks(CoreImpl.this);
                    na.addPropertyChangeListener(new NetworkAdminPropertyChangeListener() {

                        private String last_as;

                        @Override
                        public void propertyChanged(String property) {
                            NetworkAdmin na = NetworkAdmin.getSingleton();
                            if (property.equals(NetworkAdmin.PR_NETWORK_INTERFACES)) {
                                boolean found_usable = false;
                                NetworkAdminNetworkInterface[] intf = na.getInterfaces();
                                for (int i = 0; i < intf.length; i++) {
                                    NetworkAdminNetworkInterfaceAddress[] addresses = intf[i].getAddresses();
                                    for (int j = 0; j < addresses.length; j++) {
                                        if (!addresses[j].isLoopback()) {
                                            found_usable = true;
                                        }
                                    }
                                }
                                if (!found_usable) {
                                    return;
                                }
                                Logger.log(new LogEvent(LOGID, "Network interfaces have changed (new=" + na.getNetworkInterfacesAsString() + ")"));
                                announceAll(false);
                            } else if (property.equals(NetworkAdmin.PR_AS)) {
                                String as = na.getCurrentASN().getAS();
                                if (last_as == null) {
                                    last_as = as;
                                } else if (!as.equals(last_as)) {
                                    Logger.log(new LogEvent(LOGID, "AS has changed (new=" + as + ")"));
                                    last_as = as;
                                    announceAll(false);
                                }
                            }
                        }
                    });
                    setupSleepAndCloseActions();
                }
            }.start();
        }
    });
    delayed_task.queue();
    if (stopped) {
        System.err.println("Core stopped while starting");
        return;
    }
    PairingManagerFactory.getSingleton();
    CoreRunningListener[] runningListeners;
    mon_coreRunningListeners.enter();
    try {
        if (coreRunningListeners == null) {
            runningListeners = new CoreRunningListener[0];
        } else {
            runningListeners = coreRunningListeners.toArray(new CoreRunningListener[0]);
            coreRunningListeners = null;
        }
    } finally {
        mon_coreRunningListeners.exit();
    }
    // Trigger Listeners now that core is started
    new AEThread2("Plugin Init Complete", false) {

        @Override
        public void run() {
            try {
                PlatformManagerFactory.getPlatformManager().startup(CoreImpl.this);
            } catch (Throwable e) {
                Debug.out("PlatformManager: init failed", e);
            }
            Iterator it = lifecycle_listeners.iterator();
            while (it.hasNext()) {
                try {
                    CoreLifecycleListener listener = (CoreLifecycleListener) it.next();
                    if (!listener.requiresPluginInitCompleteBeforeStartedEvent()) {
                        listener.started(CoreImpl.this);
                    }
                } catch (Throwable e) {
                    Debug.printStackTrace(e);
                }
            }
            pi.initialisationComplete();
            it = lifecycle_listeners.iterator();
            while (it.hasNext()) {
                try {
                    CoreLifecycleListener listener = (CoreLifecycleListener) it.next();
                    if (listener.requiresPluginInitCompleteBeforeStartedEvent()) {
                        listener.started(CoreImpl.this);
                    }
                } catch (Throwable e) {
                    Debug.printStackTrace(e);
                }
            }
        }
    }.start();
    // Typically there are many runningListeners, most with quick execution, and
    // a few longer ones.  Let 3 run at a time, queue the rest.  Without
    // a ThreadPool, the slow ones would delay the startup processes that run
    // after this start() method
    ThreadPool tp = new ThreadPool("Trigger CoreRunning Listeners", 3);
    for (final CoreRunningListener l : runningListeners) {
        try {
            tp.run(new AERunnable() {

                @Override
                public void runSupport() {
                    l.coreRunning(CoreImpl.this);
                }
            });
        } catch (Throwable t) {
            Debug.out(t);
        }
    }
// Debug.out("Core Start Complete");
}
Also used : Torrent(com.biglybt.pif.torrent.Torrent) TOTorrent(com.biglybt.core.torrent.TOTorrent) DHTSpeedTester(com.biglybt.core.dht.speed.DHTSpeedTester) VuzeFileComponent(com.biglybt.core.vuzefile.VuzeFileComponent) URL(java.net.URL) DHT(com.biglybt.core.dht.DHT) NetworkAdmin(com.biglybt.core.networkmanager.admin.NetworkAdmin) DHTListener(com.biglybt.core.dht.DHTListener) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) DelayedTask(com.biglybt.pif.utils.DelayedTask) LogEvent(com.biglybt.core.logging.LogEvent) LogAlert(com.biglybt.core.logging.LogAlert) VuzeFileProcessor(com.biglybt.core.vuzefile.VuzeFileProcessor) NetworkAdminPropertyChangeListener(com.biglybt.core.networkmanager.admin.NetworkAdminPropertyChangeListener) GlobalManagerAdapter(com.biglybt.core.global.GlobalManagerAdapter) ParameterListener(com.biglybt.core.config.ParameterListener) TorrentDownloader(com.biglybt.pif.torrent.TorrentDownloader) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) VuzeFile(com.biglybt.core.vuzefile.VuzeFile)

Example 8 with DelayedTask

use of com.biglybt.pif.utils.DelayedTask in project BiglyBT by BiglySoftware.

the class DHTPlugin method initComplete.

protected void initComplete(final UITextField status_area, final boolean logging, final String override_ip) {
    AEThread2 t = new AEThread2("DHTPlugin.init", true) {

        @Override
        public void run() {
            boolean went_async = false;
            try {
                enabled = VersionCheckClient.getSingleton().DHTEnableAllowed();
                if (enabled) {
                    status_area.setText("Initialising");
                    final DelayedTask dt = plugin_interface.getUtilities().createDelayedTask(new Runnable() {

                        @Override
                        public void run() {
                            // go async again as don't want to block other tasks
                            new AEThread2("DHTPlugin.init2", true) {

                                @Override
                                public void run() {
                                    try {
                                        List plugins = new ArrayList();
                                        // adapter only added to first DHTPluginImpl we create
                                        DHTPluginImplAdapter adapter = new DHTPluginImplAdapter() {

                                            @Override
                                            public void localContactChanged(DHTPluginContact local_contact) {
                                                for (int i = 0; i < listeners.size(); i++) {
                                                    ((DHTPluginListener) listeners.get(i)).localAddressChanged(local_contact);
                                                }
                                            }
                                        };
                                        if (AZ_MAIN_DHT_ENABLE) {
                                            main_dht = new DHTPluginImpl(plugin_interface, CoreFactory.getSingleton().getNATTraverser(), adapter, DHTTransportUDP.PROTOCOL_VERSION_AZ_MAIN, DHT.NW_AZ_MAIN, false, override_ip, dht_data_port, reseed, warn_user, logging, log, dht_log);
                                            plugins.add(main_dht);
                                            adapter = null;
                                        }
                                        if (AZ_MAIN_DHT_V6_ENABLE) {
                                            if (NetworkAdmin.getSingleton().hasDHTIPV6()) {
                                                main_v6_dht = new DHTPluginImpl(plugin_interface, CoreFactory.getSingleton().getNATTraverser(), adapter, DHTTransportUDP.PROTOCOL_VERSION_AZ_MAIN, DHT.NW_AZ_MAIN_V6, true, null, dht_data_port, reseed, warn_user, logging, log, dht_log);
                                                plugins.add(main_v6_dht);
                                                adapter = null;
                                            }
                                        }
                                        if (Constants.isCVSVersion() && AZ_CVS_DHT_ENABLE) {
                                            cvs_dht = new DHTPluginImpl(plugin_interface, CoreFactory.getSingleton().getNATTraverser(), adapter, DHTTransportUDP.PROTOCOL_VERSION_AZ_CVS, DHT.NW_AZ_CVS, false, override_ip, dht_data_port, reseed, warn_user, logging, log, dht_log);
                                            plugins.add(cvs_dht);
                                            adapter = null;
                                        }
                                        if (BIGLYBT_MAIN_DHT_ENABLE) {
                                            biglybt_dht = new DHTPluginImpl(plugin_interface, CoreFactory.getSingleton().getNATTraverser(), adapter, DHTTransportUDP.PROTOCOL_VERSION_BIGLYBT, DHT.NW_BIGLYBT_MAIN, false, override_ip, dht_data_port, reseed, warn_user, logging, log, dht_log);
                                            plugins.add(biglybt_dht);
                                            adapter = null;
                                        }
                                        DHTPluginImpl[] _dhts = new DHTPluginImpl[plugins.size()];
                                        plugins.toArray(_dhts);
                                        dhts = _dhts;
                                        status = dhts[0].getStatus();
                                        status_area.setText(dhts[0].getStatusText());
                                    } catch (Throwable e) {
                                        enabled = false;
                                        status = STATUS_DISABLED;
                                        status_area.setText("Disabled due to error during initialisation");
                                        log.log(e);
                                        Debug.printStackTrace(e);
                                    } finally {
                                        init_sem.releaseForever();
                                    }
                                    if (status == STATUS_RUNNING) {
                                        changePort(dht_data_port);
                                    }
                                }
                            }.start();
                        }
                    });
                    dt.queue();
                    went_async = true;
                } else {
                    status = STATUS_DISABLED;
                    status_area.setText("Disabled administratively due to network problems");
                }
            } catch (Throwable e) {
                enabled = false;
                status = STATUS_DISABLED;
                status_area.setText("Disabled due to error during initialisation");
                log.log(e);
                Debug.printStackTrace(e);
            } finally {
                if (!went_async) {
                    init_sem.releaseForever();
                }
            }
        }
    };
    t.start();
}
Also used : DHTPluginImplAdapter(com.biglybt.plugin.dht.impl.DHTPluginImplAdapter) DHTPluginImpl(com.biglybt.plugin.dht.impl.DHTPluginImpl) DelayedTask(com.biglybt.pif.utils.DelayedTask)

Example 9 with DelayedTask

use of com.biglybt.pif.utils.DelayedTask in project BiglyBT by BiglySoftware.

the class VersionCheckClient method initialise.

public void initialise() {
    DelayedTask delayed_task = UtilitiesImpl.addDelayedTask("VersionCheck", new Runnable() {

        @Override
        public void run() {
            final AESemaphore sem = new AESemaphore("VCC:init");
            new AEThread2("VCC:init", true) {

                @Override
                public void run() {
                    try {
                        getVersionCheckInfo(REASON_UPDATE_CHECK_START);
                    } finally {
                        sem.release();
                    }
                }
            }.start();
            if (!sem.reserve(5000)) {
                Debug.out("Timeout waiting for version check to complete");
            }
        }
    });
    delayed_task.queue();
}
Also used : DelayedTask(com.biglybt.pif.utils.DelayedTask)

Example 10 with DelayedTask

use of com.biglybt.pif.utils.DelayedTask in project BiglyBT by BiglySoftware.

the class ShareHosterPlugin method initializationComplete.

@Override
public void initializationComplete() {
    final DelayedTask dt = plugin_interface.getUtilities().createDelayedTask(new Runnable() {

        @Override
        public void run() {
            initialise();
        }
    });
    dt.queue();
}
Also used : DelayedTask(com.biglybt.pif.utils.DelayedTask)

Aggregations

DelayedTask (com.biglybt.pif.utils.DelayedTask)11 PluginInterface (com.biglybt.pif.PluginInterface)4 ParameterListener (com.biglybt.core.config.ParameterListener)3 LoggerChannelListener (com.biglybt.pif.logging.LoggerChannelListener)3 UIManager (com.biglybt.pif.ui.UIManager)3 BasicPluginConfigModel (com.biglybt.pif.ui.model.BasicPluginConfigModel)3 URL (java.net.URL)3 TOTorrent (com.biglybt.core.torrent.TOTorrent)2 PluginException (com.biglybt.pif.PluginException)2 PluginListener (com.biglybt.pif.PluginListener)2 Torrent (com.biglybt.pif.torrent.Torrent)2 BasicPluginViewModel (com.biglybt.pif.ui.model.BasicPluginViewModel)2 DHT (com.biglybt.core.dht.DHT)1 DHTListener (com.biglybt.core.dht.DHTListener)1 DHTSpeedTester (com.biglybt.core.dht.speed.DHTSpeedTester)1 GlobalManager (com.biglybt.core.global.GlobalManager)1 GlobalManagerAdapter (com.biglybt.core.global.GlobalManagerAdapter)1 LogAlert (com.biglybt.core.logging.LogAlert)1 LogEvent (com.biglybt.core.logging.LogEvent)1 NetworkAdmin (com.biglybt.core.networkmanager.admin.NetworkAdmin)1