Search in sources :

Example 6 with AESemaphore

use of com.biglybt.core.util.AESemaphore in project BiglyBT by BiglySoftware.

the class InstallablePluginImpl method install.

@Override
public void install(boolean shared, boolean low_noise, final boolean wait_until_done, Map<Integer, Object> properties) throws PluginException {
    final AESemaphore sem = new AESemaphore("FPI");
    final PluginException[] error = { null };
    installer.install(new InstallablePlugin[] { this }, shared, low_noise, properties, new PluginInstallationListener() {

        public boolean cancelled;

        @Override
        public void completed() {
            sem.release();
        }

        @Override
        public void cancelled() {
            cancelled = true;
            error[0] = new PluginException("Install cancelled");
            sem.release();
        }

        @Override
        public void failed(PluginException e) {
            error[0] = e;
            sem.release();
            if (!wait_until_done && !cancelled) {
                Debug.out("Install failed", e);
            }
        }
    });
    if (wait_until_done) {
        sem.reserve();
        if (error[0] != null) {
            throw (error[0]);
        }
    }
}
Also used : PluginInstallationListener(com.biglybt.pif.installer.PluginInstallationListener) PluginException(com.biglybt.pif.PluginException) AESemaphore(com.biglybt.core.util.AESemaphore)

Example 7 with AESemaphore

use of com.biglybt.core.util.AESemaphore in project BiglyBT by BiglySoftware.

the class StaticUtilities method getUIManager.

/**
 * gets the default UI manager and also waits for up to a specified time for a UI instance to
 * attach. useful when doing things during initialisation
 * @param millis_to_wait_for_attach
 * @return
 */
public static UIManager getUIManager(long millis_to_wait_for_attach) {
    final UIManager ui_manager = PluginInitializer.getDefaultInterface().getUIManager();
    if (ui_manager.getUIInstances().length == 0) {
        final AESemaphore sem = new AESemaphore("waitforui");
        ui_manager.addUIListener(new UIManagerListener() {

            @Override
            public void UIAttached(UIInstance instance) {
                ui_manager.removeUIListener(this);
                sem.releaseForever();
            }

            @Override
            public void UIDetached(UIInstance instance) {
            }
        });
        // UIAttached is only fired once initialisation is complete. However, the instance
        // can be made available prior to this and there is a case where this event is blocking
        // the firing of the completion event. therefore pick it up if present directly
        long time_to_go = millis_to_wait_for_attach;
        while (ui_manager.getUIInstances().length == 0) {
            if (sem.reserve(1000)) {
                break;
            }
            time_to_go -= 1000;
            if (time_to_go <= 0) {
                Debug.out("Timeout waiting for UI to attach");
                break;
            }
        }
    }
    return (ui_manager);
}
Also used : UIManager(com.biglybt.pif.ui.UIManager) AESemaphore(com.biglybt.core.util.AESemaphore) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) UIInstance(com.biglybt.pif.ui.UIInstance)

Example 8 with AESemaphore

use of com.biglybt.core.util.AESemaphore in project BiglyBT by BiglySoftware.

the class PlayerInstaller method install.

public boolean install() {
    try {
        installer = CoreFactory.getSingleton().getPluginManager().getPluginInstaller();
        StandardPlugin sp = installer.getStandardPlugin("azemp");
        Map<Integer, Object> properties = new HashMap<>();
        properties.put(UpdateCheckInstance.PT_UI_STYLE, UpdateCheckInstance.PT_UI_STYLE_NONE);
        properties.put(UpdateCheckInstance.PT_UI_DISABLE_ON_SUCCESS_SLIDEY, true);
        final AESemaphore sem = new AESemaphore("emp install");
        final boolean[] result = new boolean[1];
        instance = installer.install(new InstallablePlugin[] { sp }, false, properties, new PluginInstallationListener() {

            @Override
            public void completed() {
                result[0] = true;
                if (listener != null) {
                    listener.finished();
                }
                sem.release();
            }

            @Override
            public void cancelled() {
                result[0] = false;
                if (listener != null) {
                    listener.finished();
                }
                sem.release();
            }

            @Override
            public void failed(PluginException e) {
                result[0] = false;
                if (listener != null) {
                    listener.finished();
                }
                sem.release();
            }
        });
        boolean kill_it;
        synchronized (this) {
            kill_it = cancelled;
        }
        if (kill_it) {
            instance.cancel();
            return (false);
        }
        instance.addListener(new UpdateCheckInstanceListener() {

            @Override
            public void cancelled(UpdateCheckInstance instance) {
            }

            @Override
            public void complete(UpdateCheckInstance instance) {
                Update[] updates = instance.getUpdates();
                for (final Update update : updates) {
                    ResourceDownloader[] rds = update.getDownloaders();
                    for (ResourceDownloader rd : rds) {
                        rd.addListener(new ResourceDownloaderAdapter() {

                            @Override
                            public void reportActivity(ResourceDownloader downloader, String activity) {
                            }

                            @Override
                            public void reportPercentComplete(ResourceDownloader downloader, int percentage) {
                                if (listener != null) {
                                    listener.progress(percentage);
                                }
                            }
                        });
                    }
                }
            }
        });
        sem.reserve();
        return result[0];
    } catch (Throwable e) {
    }
    return false;
}
Also used : UpdateCheckInstance(com.biglybt.pif.update.UpdateCheckInstance) UpdateCheckInstanceListener(com.biglybt.pif.update.UpdateCheckInstanceListener) HashMap(java.util.HashMap) PluginException(com.biglybt.pif.PluginException) StandardPlugin(com.biglybt.pif.installer.StandardPlugin) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) AESemaphore(com.biglybt.core.util.AESemaphore) Update(com.biglybt.pif.update.Update) InstallablePlugin(com.biglybt.pif.installer.InstallablePlugin) ResourceDownloaderAdapter(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderAdapter) PluginInstallationListener(com.biglybt.pif.installer.PluginInstallationListener)

Example 9 with AESemaphore

use of com.biglybt.core.util.AESemaphore in project BiglyBT by BiglySoftware.

the class SWTNetworkSelection method selectNetworks.

@Override
public String[] selectNetworks(final String description, final String[] tracker_networks) {
    final Display display = Utils.getDisplay();
    if (display.isDisposed()) {
        return (null);
    }
    final AESemaphore sem = new AESemaphore("NetworkClassifier");
    final classifierDialog[] dialog = new classifierDialog[1];
    try {
        Utils.execSWTThread(new AERunnable() {

            @Override
            public void runSupport() {
                dialog[0] = new classifierDialog(sem, display, description, tracker_networks);
            }
        });
    } catch (Throwable e) {
        Debug.printStackTrace(e);
        return (null);
    }
    sem.reserve();
    return (dialog[0].getSelection());
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) AESemaphore(com.biglybt.core.util.AESemaphore) Display(org.eclipse.swt.widgets.Display)

Example 10 with AESemaphore

use of com.biglybt.core.util.AESemaphore in project BiglyBT by BiglySoftware.

the class PlatformMessengerConfig method syncInvoke.

protected Map syncInvoke(String operationID, Map parameters, boolean forceProxy) throws PlatformMessengerException {
    PlatformMessage message = new PlatformMessage("AZMSG", listener_id, operationID, parameters, 0);
    if (!send_azid) {
        message.setSendAZID(false);
    }
    message.setForceProxy(forceProxy);
    final AESemaphore sem = new AESemaphore("PlatformMessengerConfig:syncInvoke");
    final Object[] result = { null };
    PlatformMessenger.queueMessage(message, new PlatformMessengerListener() {

        @Override
        public void messageSent(PlatformMessage message) {
        }

        @Override
        public void replyReceived(PlatformMessage message, String replyType, Map reply) {
            try {
                if (replyType.equals(PlatformMessenger.REPLY_EXCEPTION)) {
                    String e_message = (String) reply.get("message");
                    if (e_message != null) {
                        result[0] = new PlatformMessengerException(e_message);
                    } else {
                        String text = (String) reply.get("text");
                        Throwable e = (Throwable) reply.get("Throwable");
                        if (text == null && e == null) {
                            result[0] = new PlatformMessengerException("Unknown error");
                        } else if (text == null) {
                            result[0] = new PlatformMessengerException("Failed to send RPC", e);
                        } else if (e == null) {
                            result[0] = new PlatformMessengerException(text);
                        } else {
                            result[0] = new PlatformMessengerException(text, e);
                        }
                    }
                } else {
                    result[0] = reply;
                }
            } finally {
                sem.release();
            }
        }
    });
    sem.reserve();
    if (result[0] instanceof PlatformMessengerException) {
        throw ((PlatformMessengerException) result[0]);
    }
    return ((Map) result[0]);
}
Also used : PlatformMessengerException(com.biglybt.core.messenger.PlatformMessengerException) AESemaphore(com.biglybt.core.util.AESemaphore) PlatformMessengerListener(com.biglybt.core.messenger.PlatformMessengerListener) Map(java.util.Map) PlatformMessage(com.biglybt.core.messenger.PlatformMessage)

Aggregations

AESemaphore (com.biglybt.core.util.AESemaphore)14 PluginException (com.biglybt.pif.PluginException)4 PluginInstallationListener (com.biglybt.pif.installer.PluginInstallationListener)4 HashMap (java.util.HashMap)4 InstallablePlugin (com.biglybt.pif.installer.InstallablePlugin)3 StandardPlugin (com.biglybt.pif.installer.StandardPlugin)3 Update (com.biglybt.pif.update.Update)3 UpdateCheckInstance (com.biglybt.pif.update.UpdateCheckInstance)3 UpdateCheckInstanceListener (com.biglybt.pif.update.UpdateCheckInstanceListener)3 ResourceDownloader (com.biglybt.pif.utils.resourcedownloader.ResourceDownloader)3 ResourceDownloaderAdapter (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderAdapter)3 InetSocketAddress (java.net.InetSocketAddress)3 Map (java.util.Map)3 ProtocolEndpoint (com.biglybt.core.networkmanager.ProtocolEndpoint)2 NetworkAdminException (com.biglybt.core.networkmanager.admin.NetworkAdminException)2 AEThread2 (com.biglybt.core.util.AEThread2)2 SocketChannel (java.nio.channels.SocketChannel)2 DiskManagerFileInfoImpl (com.biglybt.core.disk.impl.DiskManagerFileInfoImpl)1 DiskManagerRecheckInstance (com.biglybt.core.disk.impl.DiskManagerRecheckInstance)1 DMPieceList (com.biglybt.core.disk.impl.piecemapper.DMPieceList)1