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]);
}
}
}
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);
}
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;
}
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());
}
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]);
}
Aggregations