Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

send chat message

  • Loading branch information...
commit b11db1e2e390dfaa18c5384ab0a4e3a46cbf752a 1 parent 20ec3b0
@tomamic tomamic authored
View
0  blogracy-vuze/mvn-install-vuze.sh 100755 → 100644
File mode changed
View
53 blogracy-vuze/src/main/java/net/blogracy/services/DownloadService.java
@@ -23,9 +23,12 @@
package net.blogracy.services;
import java.io.File;
+import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.logging.FileHandler;
+import java.util.logging.SimpleFormatter;
import javax.jms.Connection;
import javax.jms.DeliveryMode;
@@ -64,35 +67,59 @@
public class DownloadService implements MessageListener {
class CompletionListener implements DownloadCompletionListener {
private TextMessage request;
+ private long cron;
+ private long started;
- CompletionListener(TextMessage request) {
+ CompletionListener(TextMessage request, long cron) {
this.request = request;
+ this.cron = cron;
+ this.started = System.currentTimeMillis() - cron;
+ try {
+ long delay = System.currentTimeMillis() - cron;
+ log.info("download-started " + delay + " " + request.getText());
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
}
public void onCompletion(Download d) {
try {
- JSONObject record = new JSONObject(request.getText());
+ long completed = System.currentTimeMillis() - cron;
+ log.info("download-completed " + completed + " " + started + " " + request.getText());
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+ try {
TextMessage response = session.createTextMessage();
- response.setText(record.toString());
+ response.setText(request.getText());
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 PluginInterface vuze;
+ private java.util.logging.Logger log;
private Session session;
private Destination queue;
private MessageProducer producer;
private MessageConsumer consumer;
- public DownloadService(Connection connection, PluginInterface plugin) {
- this.plugin = plugin;
+ public DownloadService(Connection connection, PluginInterface vuze) {
+ try {
+ log = java.util.logging.Logger.getLogger("net.blogracy.services.download");
+ log.addHandler(new java.util.logging.FileHandler("download.log"));
+ log.getHandlers()[0].setFormatter(new SimpleFormatter());
+ } catch (SecurityException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ this.vuze = vuze;
try {
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
producer = session.createProducer(null);
@@ -111,6 +138,8 @@ public void onMessage(final Message request) {
public void run() {
try {
String text = ((TextMessage) request).getText();
+ final long cron = System.currentTimeMillis();
+ log.info("download-requested " + text);
Logger.info("download service:" + text + ";");
final JSONObject entry = new JSONObject(text);
try {
@@ -119,16 +148,16 @@ public void run() {
File folder = file.getParentFile();
Download download = null;
- ResourceDownloader rdl = plugin.getUtilities()
+ ResourceDownloader rdl = vuze.getUtilities()
.getResourceDownloaderFactory().create(magnetUri);
InputStream is = rdl.download();
- Torrent torrent = plugin.getTorrentManager()
+ Torrent torrent = vuze.getTorrentManager()
.createFromBEncodedInputStream(is);
- download = plugin.getDownloadManager().addDownload(torrent,
+ download = vuze.getDownloadManager().addDownload(torrent,
null, folder);
if (download != null && file != null) {
download.renameDownload(file.getName());
- download.addCompletionListener(new CompletionListener((TextMessage) request));
+ download.addCompletionListener(new CompletionListener((TextMessage) request, cron));
download.setForceStart(true);
Logger.info(magnetUri + " added to download list");
} else {
View
59 blogracy-vuze/src/main/java/net/blogracy/services/SeedService.java
@@ -26,6 +26,7 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.logging.SimpleFormatter;
import javax.jms.Connection;
import javax.jms.DeliveryMode;
@@ -39,10 +40,13 @@
import javax.jms.TextMessage;
import net.blogracy.logging.Logger;
+import net.blogracy.services.DownloadService.CompletionListener;
import org.gudy.azureus2.core3.util.Base32;
+import org.gudy.azureus2.core3.util.ByteFormatter;
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;
@@ -60,16 +64,52 @@
* ...
*/
public class SeedService implements MessageListener {
+ class CompletionListener implements DownloadCompletionListener {
+ private TextMessage request;
+ private long cron;
+ private long started;
- private PluginInterface plugin;
+ CompletionListener(TextMessage request, long cron) {
+ this.request = request;
+ this.cron = cron;
+ this.started = System.currentTimeMillis() - cron;
+ try {
+ log.info("seed-started " + started + " " + request.getText());
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void onCompletion(Download d) {
+ try {
+ long completed = System.currentTimeMillis() - cron;
+ log.info("seed-completed " + completed + " " + started + " " + request.getText());
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private PluginInterface vuze;
+ private java.util.logging.Logger log;
private Session session;
private Destination queue;
private MessageProducer producer;
private MessageConsumer consumer;
- public SeedService(Connection connection, PluginInterface plugin) {
- this.plugin = plugin;
+ public SeedService(Connection connection, PluginInterface vuze) {
+ try {
+ log = java.util.logging.Logger.getLogger("net.blogracy.services.seed");
+ log.addHandler(new java.util.logging.FileHandler("seed.log"));
+ log.getHandlers()[0].setFormatter(new SimpleFormatter());
+ } catch (SecurityException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ this.vuze = vuze;
try {
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
producer = session.createProducer(null);
@@ -86,15 +126,19 @@ public SeedService(Connection connection, PluginInterface plugin) {
public void onMessage(Message request) {
try {
String text = ((TextMessage) request).getText();
+ final long cron = System.currentTimeMillis();
+ log.info("seed-requested " + text);
Logger.info("seed service:" + text + ";");
JSONObject entry = new JSONObject(text);
try {
File file = new File(entry.getString("file"));
- Torrent torrent = plugin.getTorrentManager()
+ /*Torrent torrent = plugin.getTorrentManager()
.createFromDataFile(file,
- new URL("udp://tracker.openbittorrent.com:80"));
- torrent.setComplete(file.getParentFile());
+ new URL("udp://tracker.openbittorrent.com:80"));*/
+ Torrent torrent = vuze.getTorrentManager().createFromDataFile( file, new URL("dht:"));
+ torrent.setAnnounceURL(new URL("dht://" + ByteFormatter.encodeString(torrent.getHash()) + ".dht/announce"));
+ torrent.setComplete(file.getParentFile());
String name = Base32.encode(torrent.getHash());
int index = file.getName().lastIndexOf('.');
@@ -102,11 +146,12 @@ public void onMessage(Message request) {
name = name + file.getName().substring(index);
}
- Download download = plugin.getDownloadManager().addDownload(
+ Download download = vuze.getDownloadManager().addDownload(
torrent, null, // torrentFile,
file.getParentFile());
if (download != null) {
download.renameDownload(name);
+ download.addCompletionListener(new CompletionListener((TextMessage) request, cron));
download.setForceStart(true);
}
entry.put("uri", torrent.getMagnetURI().toExternalForm());
View
0  blogracy-web/src/main/config/genkey.sh 100755 → 100644
File mode changed
View
2  blogracy-web/src/main/java/net/blogracy/WebServer.java
@@ -43,7 +43,7 @@ public static void main(String[] args) throws Exception {
// context.setContextPath("/");
// context.setParentLoaderPriority(true);
- Server server = new Server(8080);
+ Server server = new Server(8181);
server.setHandler(context);
server.start();
// server.join();
View
96 blogracy-web/src/main/java/net/blogracy/controller/ChatController.java
@@ -19,52 +19,66 @@
public class ChatController {
- private ConnectionFactory connectionFactory;
- private Connection connection;
- private Session session;
- private Destination topic;
- private MessageProducer producer;
- private static final String TOPIC_NAME = "CHAT.DEMO";
+ private ConnectionFactory connectionFactory;
+ private Connection connection;
+ private Session session;
+ private Destination topic;
+ private MessageProducer producer;
+ private static final String TOPIC_NAME = "CHAT.DEMO";
- private String localUser;
- private String remoteUser;
+ private String localUser;
+ private String remoteUser;
- private static final ChatController theInstance = new ChatController();
+ private static final ChatController theInstance = new ChatController();
- public static ChatController getSingleton() {
- return theInstance;
- }
+ public static ChatController getSingleton() {
+ return theInstance;
+ }
- public ChatController() {
- try {
- connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_BROKER_URL);
- connection = connectionFactory.createConnection();
- connection.start();
+ public ChatController() {
+ try {
+ connectionFactory = new ActiveMQConnectionFactory(
+ ActiveMQConnection.DEFAULT_BROKER_URL);
+ connection = connectionFactory.createConnection();
+ connection.start();
- session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- topic = session.createTopic(TOPIC_NAME);
- producer = session.createProducer(topic);
- producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- } catch (Exception e) {
- System.out.println("JMS error: creating the text listener");
- }
- }
+ session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ topic = session.createTopic(TOPIC_NAME);
+ producer = session.createProducer(topic);
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ } catch (Exception e) {
+ System.out.println("JMS error: creating the text listener");
+ }
+ }
- public void joinChannel(String channel) {
- System.out.println("Creating chat channel: " + channel);
- try {
- TextMessage msg = session.createTextMessage();
- msg.setText("<message type=\"join\" from=\"" + localUser + "\" channel=\"" + channel + "\"/>");
- producer.send(topic, msg);
- } catch (JMSException e) {
- System.out.println("JMS error: sending messages");
- }
- }
+ public void joinChannel(String channel) {
+ System.out.println("Creating chat channel: " + channel);
+ try {
+ TextMessage msg = session.createTextMessage();
+ msg.setText("<message type=\"join\" from=\"" + localUser
+ + "\" channel=\"" + channel + "\"/>");
+ producer.send(topic, msg);
+ } catch (JMSException e) {
+ System.out.println("JMS error: join channel");
+ }
+ }
- public static String getPrivateChannel(String localUser, String remoteUser) {
- if (localUser.compareTo(remoteUser) <= 0) {
- return localUser + remoteUser;
- }
- return remoteUser + localUser;
- }
+ public void sendMessage(String channel, String text) {
+ System.out.println("Creating chat channel: " + channel);
+ try {
+ TextMessage msg = session.createTextMessage();
+ msg.setText("<message type=\"chat\" from=\"" + localUser
+ + "\" channel=\"" + channel + "\">" + text + "</message>");
+ producer.send(topic, msg);
+ } catch (JMSException e) {
+ System.out.println("JMS error: send message");
+ }
+ }
+
+ public static String getPrivateChannel(String localUser, String remoteUser) {
+ if (localUser.compareTo(remoteUser) <= 0) {
+ return localUser + remoteUser;
+ }
+ return remoteUser + localUser;
+ }
}
View
0  blogracy-web/src/main/webapp/chat.jsp 100755 → 100644
File mode changed
View
0  blogracy-web/src/main/webapp/js/amq_jquery_adapter.js 100755 → 100644
File mode changed
View
0  blogracy-web/src/main/webapp/js/chat.js 100755 → 100644
File mode changed
Please sign in to comment.
Something went wrong with that request. Please try again.