use of com.biglybt.core.logging.LogAlert in project BiglyBT by BiglySoftware.
the class PlatformManagerImpl method showInFinder.
/**
* <p>Shows the given file or directory in Finder</p>
* @param path Absolute path to the file or directory
*/
public void showInFinder(File path) {
try {
Class<?> claFileManager = getFileManagerClass();
if (claFileManager != null && getFileBrowserName().equals("Finder")) {
Method methRevealInFinder = claFileManager.getMethod("revealInFinder", new Class[] { File.class });
if (methRevealInFinder != null) {
Object result = methRevealInFinder.invoke(null, new Object[] { path });
if (result instanceof Boolean) {
if (((Boolean) result).booleanValue()) {
return;
}
}
}
}
} catch (Throwable e) {
}
boolean useOSA = !NativeInvocationBridge.sharedInstance().isEnabled() || !NativeInvocationBridge.sharedInstance().showInFinder(path, fileBrowserName);
if (useOSA) {
StringBuffer sb = new StringBuffer();
sb.append("tell application \"");
sb.append(getFileBrowserName());
sb.append("\"\n");
sb.append("reveal (posix file \"");
sb.append(path);
sb.append("\" as alias)\n");
sb.append("activate\n");
sb.append("end tell\n");
try {
performOSAScript(sb);
} catch (IOException e) {
Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogAlert.AT_ERROR, e.getMessage()));
}
}
}
use of com.biglybt.core.logging.LogAlert in project BiglyBT by BiglySoftware.
the class CocoaJavaBridge method logWarning.
/**
* Logs a warning message to Logger. The class monitor is used.
* @param message A warning message
*/
private void logWarning(String message) {
try {
classMon.enter();
Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogAlert.AT_WARNING, message));
} finally {
classMon.exit();
}
}
use of com.biglybt.core.logging.LogAlert in project BiglyBT by BiglySoftware.
the class DirectByteBufferPoolReal method allocateNewBuffer.
/**
* Allocate and return a new direct ByteBuffer.
*/
private ByteBuffer allocateNewBuffer(final int _size) {
try {
return ByteBuffer.allocateDirect(_size);
} catch (OutOfMemoryError e) {
// Debug.out("Running garbage collector...");
clearBufferPools();
runGarbageCollection();
try {
return ByteBuffer.allocateDirect(_size);
} catch (OutOfMemoryError ex) {
String msg = "Memory allocation failed: Out of direct memory space.\n" + "To fix: Use the -XX:MaxDirectMemorySize=512m command line option,\n" + "or upgrade your Java JRE to version 1.4.2_05 or 1.5 series or newer.";
Debug.out(msg);
Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogAlert.AT_ERROR, msg));
printInUse(true);
throw (ex);
}
}
}
use of com.biglybt.core.logging.LogAlert in project BiglyBT by BiglySoftware.
the class PluginInstallerImpl method uninstall.
@Override
public UpdateCheckInstance uninstall(final PluginInterface[] pis, final PluginInstallationListener listener_maybe_null, final Map<Integer, Object> properties) throws PluginException {
properties.put(UpdateCheckInstance.PT_UNINSTALL_RESTART_REQUIRED, false);
for (int i = 0; i < pis.length; i++) {
PluginInterface pi = pis[i];
if (pi.getPluginState().isMandatory()) {
throw (new PluginException("Plugin '" + pi.getPluginID() + "' is mandatory, can't uninstall"));
}
if (pi.getPluginState().isBuiltIn()) {
throw (new PluginException("Plugin '" + pi.getPluginID() + "' is built-in, can't uninstall"));
}
String plugin_dir = pi.getPluginDirectoryName();
if (plugin_dir == null || !new File(plugin_dir).exists()) {
throw (new PluginException("Plugin '" + pi.getPluginID() + "' is not loaded from the file system, can't uninstall"));
}
}
try {
UpdateManager uman = manager.getDefaultPluginInterface().getUpdateManager();
UpdateCheckInstance inst = uman.createEmptyUpdateCheckInstance(UpdateCheckInstance.UCI_UNINSTALL, "update.instance.uninstall");
final int[] rds_added = { 0 };
final AESemaphore rd_waiter_sem = new AESemaphore("uninst:rd:wait");
for (int i = 0; i < pis.length; i++) {
final PluginInterface pi = pis[i];
final String plugin_dir = pi.getPluginDirectoryName();
inst.addUpdatableComponent(new UpdatableComponent() {
@Override
public String getName() {
return (pi.getPluginName());
}
@Override
public int getMaximumCheckTime() {
return (0);
}
@Override
public void checkForUpdate(final UpdateChecker checker) {
try {
ResourceDownloader rd = manager.getDefaultPluginInterface().getUtilities().getResourceDownloaderFactory().create(new File(plugin_dir));
// the plugin may have > 1 plugin interfaces, make the name up appropriately
String update_name = "";
PluginInterface[] ifs = manager.getPluginInterfaces();
Arrays.sort(ifs, new Comparator() {
@Override
public int compare(Object o1, Object o2) {
return (((PluginInterface) o1).getPluginName().compareTo(((PluginInterface) o2).getPluginName()));
}
});
for (int i = 0; i < ifs.length; i++) {
if (ifs[i].getPluginID().equals(pi.getPluginID())) {
update_name += (update_name.length() == 0 ? "" : ",") + ifs[i].getPluginName();
}
}
boolean unloadable = pi.getPluginState().isUnloadable();
if (!unloadable) {
properties.put(UpdateCheckInstance.PT_UNINSTALL_RESTART_REQUIRED, true);
}
final Update update = checker.addUpdate(update_name, new String[] { "Uninstall: " + plugin_dir }, pi.getPluginVersion(), pi.getPluginVersion(), rd, unloadable ? Update.RESTART_REQUIRED_NO : Update.RESTART_REQUIRED_YES);
synchronized (rds_added) {
rds_added[0]++;
}
rd.addListener(new ResourceDownloaderAdapter() {
@Override
public boolean completed(ResourceDownloader downloader, InputStream data) {
try {
try {
if (pi.getPluginState().isUnloadable()) {
pi.getPluginState().unload();
if (!FileUtil.recursiveDelete(new File(plugin_dir))) {
update.setRestartRequired(Update.RESTART_REQUIRED_YES);
properties.put(UpdateCheckInstance.PT_UNINSTALL_RESTART_REQUIRED, true);
checker.reportProgress("Failed to remove plugin, restart will be required");
}
}
UpdateInstaller installer = checker.createInstaller();
installer.addRemoveAction(new File(plugin_dir).getCanonicalPath());
update.complete(true);
try {
PluginInitializer.fireEvent(PluginEvent.PEV_PLUGIN_UNINSTALLED, pi.getPluginID());
} catch (Throwable e) {
Debug.out(e);
}
} catch (Throwable e) {
update.complete(false);
Debug.printStackTrace(e);
Logger.log(new LogAlert(LogAlert.REPEATABLE, "Plugin uninstall failed", e));
}
return (true);
} finally {
rd_waiter_sem.release();
}
}
@Override
public void failed(ResourceDownloader downloader, ResourceDownloaderException e) {
try {
update.complete(false);
if (!downloader.isCancelled()) {
Logger.log(new LogAlert(LogAlert.REPEATABLE, "Plugin uninstall failed", e));
}
} finally {
rd_waiter_sem.release();
}
}
});
} finally {
checker.completed();
}
}
}, false);
}
if (listener_maybe_null != null) {
inst.addListener(new UpdateCheckInstanceListener() {
@Override
public void cancelled(UpdateCheckInstance instance) {
listener_maybe_null.cancelled();
}
@Override
public void complete(UpdateCheckInstance instance) {
// needs to be async in the case of the caller of the uninstall needing access to the
// updatecheckinstance and this is a sync callback
new AEThread2("Uninstall:async") {
@Override
public void run() {
int wait_count;
synchronized (rds_added) {
wait_count = rds_added[0];
}
for (int i = 0; i < wait_count; i++) {
rd_waiter_sem.reserve();
}
listener_maybe_null.completed();
}
}.start();
}
});
}
inst.start();
return (inst);
} catch (Throwable e) {
PluginException pe;
if (e instanceof PluginException) {
pe = (PluginException) e;
} else {
pe = new PluginException("Uninstall failed", e);
}
if (listener_maybe_null != null) {
listener_maybe_null.failed(pe);
}
throw (pe);
}
}
use of com.biglybt.core.logging.LogAlert in project BiglyBT by BiglySoftware.
the class PluginInitializer method initialisePlugin.
private void initialisePlugin(List l) throws PluginException {
PluginException last_load_failure = null;
for (int i = 0; i < l.size(); i++) {
final PluginInterfaceImpl plugin_interface = (PluginInterfaceImpl) l.get(i);
if (plugin_interface.getPluginState().isDisabled()) {
synchronized (s_plugin_interfaces) {
s_plugin_interfaces.add(plugin_interface);
}
continue;
}
if (plugin_interface.getPluginState().isOperational()) {
continue;
}
Throwable load_failure = null;
final Plugin plugin = plugin_interface.getPlugin();
try {
UtilitiesImpl.callWithPluginThreadContext(plugin_interface, new runnableWithException<PluginException>() {
@Override
public void run() throws PluginException {
fireCreated(plugin_interface);
plugin.initialize(plugin_interface);
if (!(plugin instanceof FailedPlugin)) {
plugin_interface.getPluginStateImpl().setOperational(true, false);
}
}
});
} catch (Throwable e) {
load_failure = e;
}
synchronized (s_plugin_interfaces) {
s_plugins.add(plugin);
s_plugin_interfaces.add(plugin_interface);
}
if (load_failure != null) {
Debug.printStackTrace(load_failure);
String msg = "Error initializing plugin '" + plugin_interface.getPluginName() + "'";
Logger.log(new LogAlert(LogAlert.UNREPEATABLE, msg, load_failure));
System.out.println(msg + " : " + load_failure);
last_load_failure = new PluginException(msg, load_failure);
}
}
if (last_load_failure != null) {
throw (last_load_failure);
}
}
Aggregations