Permalink
Browse files

Merge pull request #36 from tomamic/master

periodical lookup
  • Loading branch information...
2 parents 54f258d + 69868f8 commit 9b2d182eb689610c85ae0f86cc842a300f2577ee @rik0 committed Feb 25, 2013
@@ -42,6 +42,7 @@
import org.gudy.azureus2.plugins.PluginInterface;
import org.gudy.azureus2.plugins.download.Download;
+import org.gudy.azureus2.plugins.download.DownloadCompletionListener;
import org.gudy.azureus2.plugins.download.DownloadException;
import org.gudy.azureus2.plugins.torrent.Torrent;
import org.gudy.azureus2.plugins.torrent.TorrentException;
@@ -61,6 +62,28 @@
* ...
*/
public class DownloadService implements MessageListener {
+ class CompletionListener implements DownloadCompletionListener {
+ private TextMessage request;
+
+ CompletionListener(TextMessage request) {
+ this.request = request;
+ }
+
+ public void onCompletion(Download d) {
+ try {
+ JSONObject record = new JSONObject(request.getText());
+ TextMessage response = session.createTextMessage();
+ response.setText(record.toString());
+ response.setJMSCorrelationID(request.getJMSCorrelationID());
+ producer.send(request.getJMSReplyTo(), response);
+ } catch (JMSException e) {
+ Logger.error("JMS error: download completion");
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
private PluginInterface plugin;
private Session session;
@@ -101,8 +124,10 @@ public void onMessage(Message request) {
.createFromBEncodedInputStream(is);
download = plugin.getDownloadManager().addDownload(torrent,
null, folder);
- if (download != null && file != null)
+ if (download != null && file != null) {
download.renameDownload(file.getName());
+ download.addCompletionListener(new CompletionListener((TextMessage) request));
+ }
Logger.info(magnetUri + " added to download list");
} catch (ResourceDownloaderException e) {
Logger.error("Torrent download error: download service: "
@@ -122,7 +122,7 @@ public void onMessage(final Message request) {
final long TIMEOUT = 5 * 60 * 1000; // 5 mins
DistributedDatabase ddb = plugin.getDistributedDatabase();
ddb.read(new DhtListener(textRequest),
- ddb.createKey(record.getString("key")), TIMEOUT,
+ ddb.createKey(record.getString("id")), TIMEOUT,
DistributedDatabase.OP_EXHAUSTIVE_READ);
} catch (DistributedDatabaseException e) {
Logger.error("DDB error: lookup service: " + text);
View

Large diffs are not rendered by default.

Oops, something went wrong.
Binary file not shown.
@@ -1,6 +1,7 @@
package net.blogracy;
import net.blogracy.model.users.User;
+import net.blogracy.controller.DistributedHashTable;
import net.blogracy.controller.FileSharing;
import net.blogracy.config.Configurations;
import java.util.List;
@@ -28,12 +29,17 @@ public static void main(String[] args) throws Exception
int TOTAL_WAIT = 5 * 60 * 1000; // 5 minutes
while (true) {
- List<User> friends = Configurations.getUserConfig().getFriends();
- int wait = TOTAL_WAIT / friends.size();
- for (User friend : friends) {
- FileSharing.getFeed(friend.getHash().toString());
- Thread.currentThread().sleep(wait);
- }
+ FileSharing sharing = FileSharing.getSingleton();
+ String id = Configurations.getUserConfig().getUser().getHash().toString();
+ sharing.addFeedEntry(id, "" + new java.util.Date(), null);
+
+ List<User> friends = Configurations.getUserConfig().getFriends();
+ int wait = TOTAL_WAIT / friends.size();
+ for (User friend : friends) {
+ DistributedHashTable.getSingleton().lookup(friend.getHash().toString());
+ FileSharing.getFeed(friend.getHash().toString());
+ Thread.currentThread().sleep(wait);
+ }
}
}
}
@@ -24,6 +24,7 @@
import java.io.File;
import java.io.IOException;
+import java.io.FileInputStream;
import java.io.InputStream;
import java.security.Key;
import java.security.KeyPair;
@@ -63,8 +64,14 @@
static private Properties loadProperties(String file) throws IOException {
// ClassLoader loader = ClassLoader.getSystemClassLoader();
// InputStream is = loader.getResourceAsStream(file);
- InputStream is = Configurations.class.getClassLoader()
+ InputStream is = null;
+ File f = new File(file);
+ if (f.exists()) {
+ is = new FileInputStream(f);
+ } else {
+ is = Configurations.class.getClassLoader()
.getResourceAsStream(file);
+ }
if (is != null) {
Properties properties = new Properties();
@@ -92,8 +99,9 @@ public String getCachedFilesDirectoryPath() {
String cachedFilesDirectoryPath = pathProperties
.getProperty(BLOGRACY_PATHS_CACHED);
// "Lazy" creation of cached files folder if non-existent
- this.createDirIfMissing(new File(cachedFilesDirectoryPath));
- return cachedFilesDirectoryPath;
+ File f = new File(cachedFilesDirectoryPath);
+ this.createDirIfMissing(f);
+ return f.getAbsolutePath();
}
@Override
Oops, something went wrong.

0 comments on commit 9b2d182

Please sign in to comment.