use of com.biglybt.core.CoreOperationTask.ProgressCallbackAdapter in project BiglyBT by BiglySoftware.
the class Initializer method stopIt.
@Override
public void stopIt(boolean isForRestart) throws CoreException {
if (core != null) {
if (isForRestart) {
core.checkRestartSupported();
}
}
try {
if (core != null) {
try {
long lStopStarted = System.currentTimeMillis();
System.out.println("core.stop");
AESemaphore stop_sem = new AESemaphore("stop");
ProgressCallback prog = new ProgressCallbackAdapter() {
@Override
public int getStyle() {
return (STYLE_NO_CLOSE | STYLE_MODAL);
}
@Override
public int getDelay() {
return (3 * 1000);
}
public int getSupportedTaskStates() {
return (ProgressCallback.ST_SUBTASKS);
}
};
boolean show_progress = COConfigurationManager.getBooleanParameter("Tidy Close With Progress");
if (show_progress) {
if (Utils.isSWTThread()) {
Debug.out("Can't run closedown progress window as already on SWT thread");
} else {
Utils.execSWTThread(() -> {
FileUtil.runAsTask(CoreOperation.OP_PROGRESS, new CoreOperationTask() {
@Override
public String getName() {
return (MessageText.getString(isForRestart ? "label.restarting.app" : "label.closing.app"));
}
@Override
public DownloadManager getDownload() {
return (null);
}
@Override
public void run(CoreOperation operation) {
try {
stop_sem.reserve();
} catch (Throwable e) {
throw (new RuntimeException(e));
}
}
@Override
public ProgressCallback getProgressCallback() {
return (prog);
}
});
});
}
}
try {
if (isForRestart) {
core.restart(prog);
} else {
core.stop(prog);
}
} finally {
stop_sem.release();
}
System.out.println("core.stop done in " + (System.currentTimeMillis() - lStopStarted));
} catch (Throwable e) {
// don't let any failure here cause the stop operation to fail
Debug.out(e);
}
}
} finally {
// do this later than before so we get UI updates during closedown and can see progress of stats etc
UIUpdaterSWT.destroyInstance();
if (startServer != null) {
startServer.stopIt();
}
}
SWTThread instance = SWTThread.getInstance();
if (instance != null) {
instance.terminate();
}
}
Aggregations