use of com.biglybt.core.util.AEThread in project BiglyBT by BiglySoftware.
the class ExternalIPCheckerServiceImpl method initiateCheckSupport.
protected void initiateCheckSupport(final long timeout) {
Thread t = new AEThread("IPChecker") {
@Override
public void runSupport() {
try {
initiateCheckSupport();
} finally {
setComplete();
}
}
};
t.setDaemon(true);
t.start();
if (timeout > 0) {
Thread t2 = new AEThread("IPChecker2") {
@Override
public void runSupport() {
try {
if (!timeout_sem.reserve(timeout)) {
if (!completed) {
informFailure("timeout");
setComplete();
}
}
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
};
t2.setDaemon(true);
t2.start();
}
}
use of com.biglybt.core.util.AEThread in project BiglyBT by BiglySoftware.
the class VirtualBlockingServerChannelSelector method start.
/**
* Start the server and begin accepting incoming connections.
*/
@Override
public void start() {
try {
this_mon.enter();
if (!isRunning()) {
try {
server_channel = ServerSocketChannel.open();
server_channel.socket().setReuseAddress(true);
if (receive_buffer_size > 0)
server_channel.socket().setReceiveBufferSize(receive_buffer_size);
server_channel.socket().bind(bind_address, 1024);
if (Logger.isEnabled())
Logger.log(new LogEvent(LOGID, "TCP incoming server socket " + bind_address));
AEThread accept_thread = new AEThread("VServerSelector:port" + bind_address.getPort()) {
@Override
public void runSupport() {
accept_loop();
}
};
accept_thread.setDaemon(true);
accept_thread.start();
} catch (Throwable t) {
Debug.out(t);
Logger.log(new LogAlert(LogAlert.UNREPEATABLE, "ERROR, unable to bind TCP incoming server socket to " + bind_address.getPort(), t));
}
// init to now
last_accept_time = SystemTime.getCurrentTime();
}
} finally {
this_mon.exit();
}
}
use of com.biglybt.core.util.AEThread in project BiglyBT by BiglySoftware.
the class ResourceDownloaderTimeoutImpl method asyncGetSize.
public void asyncGetSize() {
try {
this_mon.enter();
if (!cancelled) {
current_downloader = delegate.getClone(this);
Thread size_thread = new AEThread("ResourceDownloader:size getter") {
@Override
public void runSupport() {
try {
long res = current_downloader.getSize();
result = new Long(res);
setProperties(current_downloader);
done_sem.release();
} catch (ResourceDownloaderException e) {
failed(current_downloader, e);
}
}
};
size_thread.setDaemon(true);
size_thread.start();
Thread t = new AEThread("ResourceDownloaderTimeout") {
@Override
public void runSupport() {
try {
Thread.sleep(timeout_millis);
cancel(new ResourceDownloaderException(ResourceDownloaderTimeoutImpl.this, "getSize 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 Share method execute.
@Override
public void execute(String commandName, final ConsoleInput ci, List args) {
if (args.isEmpty()) {
printHelp(ci.out, args);
return;
}
final ShareManager share_manager;
try {
share_manager = ci.core.getPluginManager().getDefaultPluginInterface().getShareManager();
} catch (ShareException e) {
ci.out.println("ERROR: " + e.getMessage() + " ::");
Debug.printStackTrace(e);
return;
}
final String arg = (String) args.remove(0);
if (args.isEmpty() && ("list".equalsIgnoreCase(arg))) {
ShareResource[] shares = share_manager.getShares();
if (shares.length == 0) {
ci.out.println("> No shares found");
} else {
HashSet share_map = new HashSet();
int share_num = 0;
for (int i = 0; i < shares.length; i++) {
ShareResource share = shares[i];
if (share instanceof ShareResourceDirContents) {
share_map.add(share);
} else if (share.getParent() != null) {
} else {
ci.out.println("> " + share_num++ + ": " + shares[i].getName());
}
}
Iterator it = share_map.iterator();
TorrentManager tm = ci.core.getPluginManager().getDefaultPluginInterface().getTorrentManager();
TorrentAttribute category_attribute = tm.getAttribute(TorrentAttribute.TA_CATEGORY);
TorrentAttribute props_attribute = tm.getAttribute(TorrentAttribute.TA_SHARE_PROPERTIES);
while (it.hasNext()) {
ShareResourceDirContents root = (ShareResourceDirContents) it.next();
String cat = root.getAttribute(category_attribute);
String props = root.getAttribute(props_attribute);
String extra = cat == null ? "" : (",cat=" + cat);
extra += props == null ? "" : (",props=" + props);
ci.out.println("> " + share_num++ + ": " + root.getName() + extra);
outputChildren(ci, " ", root);
}
}
return;
}
String first_arg = (String) args.get(0);
if (first_arg.equals("hash") && args.size() > 1) {
byte[] hash = ByteFormatter.decodeString((String) args.get(1));
boolean force = false;
if (args.size() > 2) {
force = ((String) args.get(2)).equalsIgnoreCase("true");
}
if (("remove".equalsIgnoreCase(arg))) {
ShareResource[] shares = share_manager.getShares();
boolean done = false;
for (int i = 0; i < shares.length; i++) {
ShareResource share = shares[i];
ShareItem item = null;
if (share instanceof ShareResourceFile) {
item = ((ShareResourceFile) share).getItem();
} else if (share instanceof ShareResourceDir) {
item = ((ShareResourceDir) share).getItem();
}
if (item != null) {
try {
byte[] item_hash = item.getTorrent().getHash();
if (Arrays.equals(hash, item_hash)) {
share.delete(force);
ci.out.println("> Share " + share.getName() + " removed");
done = true;
break;
}
} catch (Throwable e) {
ci.out.println("ERROR: " + e.getMessage() + " ::");
Debug.printStackTrace(e);
}
}
}
if (!done) {
ci.out.println("> Share with hash " + ByteFormatter.encodeString(hash) + " not found");
}
} else {
ci.out.println("ERROR: Unsupported hash based command '" + arg + "'");
}
return;
}
final File path = new File(first_arg);
if (!path.exists()) {
ci.out.println("ERROR: path [" + path + "] does not exist.");
return;
}
if (("remove".equalsIgnoreCase(arg))) {
ShareResource[] shares = share_manager.getShares();
boolean done = false;
for (int i = 0; i < shares.length; i++) {
if (shares[i].getName().equals(path.toString())) {
try {
shares[i].delete();
ci.out.println("> Share " + path.toString() + " removed");
done = true;
} catch (Throwable e) {
ci.out.println("ERROR: " + e.getMessage() + " ::");
Debug.printStackTrace(e);
}
break;
}
}
if (!done) {
ci.out.println("> Share " + path.toString() + " not found");
}
return;
}
String category = null;
String props = null;
if (args.size() == 2) {
String properties = (String) args.get(1);
StringTokenizer tok = new StringTokenizer(properties, ";");
while (tok.hasMoreTokens()) {
String token = tok.nextToken();
int pos = token.indexOf('=');
if (pos == -1) {
ci.out.println("ERROR: invalid properties string '" + properties + "'");
return;
} else {
String lhs = token.substring(0, pos).trim().toLowerCase();
String rhs = token.substring(pos + 1).trim();
if (lhs.equals("category")) {
category = rhs;
} else {
if (lhs.equals("private") || lhs.equals("dht_backup") || lhs.equals("comment")) {
if (props == null) {
props = "";
}
if (lhs.equals("comment")) {
rhs = rhs.replace('_', ' ');
}
if (rhs.length() > 0) {
props += (props.length() == 0 ? "" : ";") + lhs + "=" + rhs;
}
} else {
ci.out.println("ERROR: invalid properties string '" + properties + "'");
return;
}
}
}
}
}
final String f_category = category;
final String f_props = props;
new AEThread("shareFile") {
@Override
public void runSupport() {
try {
ShareResource resource = share_manager.getShare(path);
if ("file".equalsIgnoreCase(arg)) {
ci.out.println("File [" + path + "] share being processed in background...");
if (resource == null) {
resource = share_manager.addFile(path);
}
} else if ("folder".equalsIgnoreCase(arg)) {
ci.out.println("Folder [" + path + "] share being processed in background...");
if (resource == null) {
resource = share_manager.addDir(path);
}
} else if ("contents".equalsIgnoreCase(arg)) {
ci.out.println("Folder contents [" + path + "] share being processed in background...");
if (resource == null) {
resource = share_manager.addDirContents(path, false);
}
} else if ("rcontents".equalsIgnoreCase(arg)) {
ci.out.println("Folder contents recursive [" + path + "] share being processed in background...");
if (resource == null) {
resource = share_manager.addDirContents(path, true);
}
} else {
ci.out.println("ERROR: type '" + arg + "' unknown.");
}
if (resource != null) {
TorrentManager tm = ci.core.getPluginManager().getDefaultPluginInterface().getTorrentManager();
String cat = f_category;
if (cat != null) {
if (cat.length() == 0) {
cat = null;
}
resource.setAttribute(tm.getAttribute(TorrentAttribute.TA_CATEGORY), cat);
}
String pro = f_props;
if (pro != null) {
if (pro.length() == 0) {
pro = null;
}
resource.setAttribute(tm.getAttribute(TorrentAttribute.TA_SHARE_PROPERTIES), pro);
}
}
if (resource != null) {
ci.out.println("... processing complete");
}
} catch (Throwable e) {
ci.out.println("ERROR: " + e.getMessage() + " ::");
Debug.printStackTrace(e);
}
}
}.start();
}
use of com.biglybt.core.util.AEThread in project BiglyBT by BiglySoftware.
the class SpeedTestPanel method finish.
@Override
public void finish() {
test_running = true;
clListener = new WizardListener() {
@Override
public void closed() {
cancel();
}
};
wizard.addListener(clListener);
wizard.setFinishEnabled(false);
// convert to mode
final int test_mode = NetworkAdminSpeedTester.TEST_TYPES[testCombo.getSelectionIndex()];
final boolean encState = encryptToggle.getSelection();
Thread t = new AEThread("SpeedTest Performer") {
@Override
public void runSupport() {
runTest(test_mode, encState);
}
};
t.setPriority(Thread.MIN_PRIORITY);
t.setDaemon(true);
t.start();
}
Aggregations