use of com.biglybt.core.util.AEThread in project BiglyBT by BiglySoftware.
the class ResourceDownloaderTimeoutImpl method asyncDownload.
@Override
public void asyncDownload() {
try {
this_mon.enter();
if (!cancelled) {
current_downloader = delegate.getClone(this);
informActivity(getLogIndent() + "Downloading: " + getName());
current_downloader.addListener(this);
current_downloader.asyncDownload();
Thread t = new AEThread("ResourceDownloaderTimeout") {
@Override
public void runSupport() {
try {
Thread.sleep(timeout_millis);
cancel(new ResourceDownloaderException(ResourceDownloaderTimeoutImpl.this, "Download timeout"));
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
};
t.setDaemon(true);
t.start();
}
} finally {
this_mon.exit();
}
}
use of com.biglybt.core.util.AEThread in project BiglyBT by BiglySoftware.
the class CocoaJavaBridge method executeScriptWithNewThread.
/**
* <p>Executes a new instance of NSAppleScript in a forked AEThread</p>
* <p>This method always returns a "true" event descriptor. Callbacks are currently unsupported
* , so in the event of an error, the logger is autuomatically notified.</p>
* <p>The thread's runSupport method is wrapped in an autorelease pool. If there are
* no format parameters, MessageFormat is not used to parse the format string, and
* the format string will be treated as the source itself.</p>
* @see com.biglybt.core.util.AEThread#runSupport()
* @see MessageFormat#format(String, Object...)
* @see NSAppleScript#execute(com.apple.cocoa.foundation.NSMutableDictionary)
* @return NSAppleEventDescriptor.descriptorWithBoolean(true)
* @throws InvocationTargetException
* @throws IllegalAccessException
* @throws IllegalArgumentException
*/
protected final Object executeScriptWithNewThread(final String scriptFormat, final Object[] params) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
Thread worker = new AEThread("ScriptObject", true) {
@Override
public void runSupport() {
try {
int pool = NSAutoreleasePool_push();
long start = System.currentTimeMillis();
String src;
if (params == null || params.length == 0) {
src = scriptFormat;
} else {
src = MessageFormat.format(scriptFormat, params);
}
Debug.outNoStack("Executing: \n" + src);
Object /*NSMutableDictionary*/
errorInfo = new_NSMutableDictionary();
if (NSAppleScript_execute(new_NSAppleScript(src), errorInfo) == null) {
Debug.out(String.valueOf(NSMutableDictionary_objectForKey(errorInfo, NSAppleScript_AppleScriptErrorMessage)));
// logWarning(String.valueOf(errorInfo.objectForKey(NSAppleScript.AppleScriptErrorBriefMessage)));
}
Debug.outNoStack(MessageFormat.format("Elapsed time: {0}ms\n", new Object[] { new Long(System.currentTimeMillis() - start) }));
NSAutoreleasePool_pop(pool);
} catch (Throwable e) {
Debug.out(e);
}
}
};
worker.setPriority(Thread.NORM_PRIORITY - 1);
worker.start();
return methNSAppleEventDescriptor_descriptorWithBoolean.invoke(null, true);
// return NSAppleEventDescriptor.descriptorWithBoolean(true);
}
use of com.biglybt.core.util.AEThread in project BiglyBT by BiglySoftware.
the class CocoaJavaBridge method executeScriptWithAsync.
/**
* <p>Asynchronously executes a new instance of NSAppleScript</p>
* <p>This method always returns a "true" event descriptor. Callbacks are currently unsupported
* , so in the event of an error, the logger is autuomatically notified.</p>
* <p>The thread's runSupport method is wrapped in an autorelease pool. If there are
* no format parameters, MessageFormat is not used to parse the format string, and
* the format string will be treated as the source itself.</p>
* @see com.biglybt.core.util.AEThread#runSupport()
* @see MessageFormat#format(String, Object...)
* @see NSAppleScript#execute(com.apple.cocoa.foundation.NSMutableDictionary)
* @return NSAppleEventDescriptor.descriptorWithBoolean(true)
* @throws InvocationTargetException
* @throws IllegalAccessException
* @throws IllegalArgumentException
*/
protected final Object executeScriptWithAsync(final String scriptFormat, final Object[] params) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
final AERunnable worker = new AERunnable() {
@Override
public void runSupport() {
try {
int pool = NSAutoreleasePool_push();
long start = System.currentTimeMillis();
String src;
if (params == null || params.length == 0) {
src = scriptFormat;
} else {
src = MessageFormat.format(scriptFormat, params);
}
Debug.outNoStack("Executing: \n" + src);
Object /*NSMutableDictionary*/
errorInfo = new_NSMutableDictionary();
if (NSAppleScript_execute(new_NSAppleScript(src), errorInfo) == null) {
Debug.out(String.valueOf(NSMutableDictionary_objectForKey(errorInfo, NSAppleScript_AppleScriptErrorMessage)));
// logWarning(String.valueOf(errorInfo.objectForKey(NSAppleScript.AppleScriptErrorBriefMessage)));
}
Debug.outNoStack(MessageFormat.format("Elapsed time: {0}ms\n", new Object[] { new Long(System.currentTimeMillis() - start) }));
NSAutoreleasePool_pop(pool);
} catch (Throwable t) {
Debug.out(t);
}
}
};
AEThread t = new AEThread("ScriptObject", true) {
@Override
public void runSupport() {
scriptDispatcher.exec(worker);
}
};
t.setPriority(Thread.NORM_PRIORITY - 1);
t.start();
return methNSAppleEventDescriptor_descriptorWithBoolean.invoke(null, true);
// return NSAppleEventDescriptor.descriptorWithBoolean(true);
}
use of com.biglybt.core.util.AEThread in project BiglyBT by BiglySoftware.
the class UpdateAutoDownloader method completed.
// @see com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderListener#completed(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader, java.io.InputStream)
@Override
public boolean completed(ResourceDownloader downloader, InputStream data) {
downloader.removeListener(this);
if (!nextUpdate()) {
// fire in another thread so completed function can exit
AEThread thread = new AEThread("AllDownloadsComplete", true) {
@Override
public void runSupport() {
allDownloadsComplete();
}
};
thread.start();
}
return true;
}
Aggregations