Browse files

simplified chat code, now using a single topic

  • Loading branch information...
1 parent 639b886 commit 9fbed92f0362125adb558db6d27539c909ab5173 mic committed Mar 2, 2013
View
121 blogracy-vuze/src/main/java/com/aelitis/azureus/plugins/chat/ChatPlugin.java
@@ -1,5 +1,5 @@
/*
- * Created on 28 fevr. 2005
+ * Created on 28 feb. 2005
* Created by Olivier Chalouhi
*
* Copyright (C) 2004 Aelitis SARL, All rights Reserved
@@ -60,7 +60,7 @@
private static final String COLUMN_ID_CHAT_ACTIVITY = "ChatActivityColumn";
private PluginInterface plugin_interface;
-// private UISWTInstance swtui;
+ private UISWTInstance swtui;
private PeerController controller;
// private LoggerChannel logger;
@@ -74,10 +74,10 @@
// private String resInactive = "com/aelitis/azureus/plugins/chat/ui/icons/red.png";
// public Image imgInactive;
-
+//
// private String resActive = "com/aelitis/azureus/plugins/chat/ui/icons/dgreen.png";
// public Image imgActive;
-
+//
// private String resActivity = "com/aelitis/azureus/plugins/chat/ui/icons/lgreen.png";
// public Image imgActivity;
@@ -87,6 +87,7 @@
private static Formatters formatters = null;
+
public void
initialize(
PluginInterface _pi )
@@ -116,37 +117,36 @@
controller.initialize();
controller.startPeerProcessing();
-/* plugin_interface.getUIManager().addUIListener(
- new UIManagerListener()
- {
- public void
- UIAttached(
- UIInstance instance )
- {
- if ( instance instanceof UISWTInstance ){
-
- swtui = (UISWTInstance)instance;
-
- imgInactive = loadImage(resInactive);
- imgActive = loadImage(resActive);
- imgActivity = loadImage(resActivity);
-
- ChatPanelsManager cpm = new ChatPanelsManager(ChatPlugin.this);
- swtui.addView(UISWTInstance.VIEW_MYTORRENTS, "Chat", cpm);
- swtui.addView(UISWTInstance.VIEW_MAIN, "CreateChat", cpm);
-
- addMyTorrentsColumn();
- }
- }
-
- public void
- UIDetached(
- UIInstance instance )
- {
-
- }
- });
- */
+// plugin_interface.getUIManager().addUIListener(
+// new UIManagerListener()
+// {
+// public void
+// UIAttached(
+// UIInstance instance )
+// {
+// if ( instance instanceof UISWTInstance ){
+//
+// swtui = (UISWTInstance)instance;
+//
+// imgInactive = loadImage(resInactive);
+// imgActive = loadImage(resActive);
+// imgActivity = loadImage(resActivity);
+//
+// ChatPanelsManager cpm = new ChatPanelsManager(ChatPlugin.this);
+// swtui.addView(UISWTInstance.VIEW_MYTORRENTS, "Chat", cpm);
+// swtui.addView(UISWTInstance.VIEW_MAIN, "CreateChat", cpm);
+//
+// addMyTorrentsColumn();
+// }
+// }
+//
+// public void
+// UIDetached(
+// UIInstance instance )
+// {
+//
+// }
+// });
}
}
@@ -291,29 +291,28 @@ private Torrent loadTorrent(String res) {
return null;
}
-/* private void addMyTorrentsColumn() {
-
- MyTorrentsActivityIndicator activityIndicator = new MyTorrentsActivityIndicator(this, controller, swtui);
-
- addIndicatorToTable(TableManager.TABLE_MYTORRENTS_INCOMPLETE,activityIndicator);
- addIndicatorToTable(TableManager.TABLE_MYTORRENTS_COMPLETE,activityIndicator);
- }
-
- private void addIndicatorToTable(String tableID,MyTorrentsActivityIndicator activityIndicator) {
- UIManager uiManager = plugin_interface.getUIManager();
- TableManager tableManager = uiManager.getTableManager();
- TableColumn activityColumn = tableManager.createColumn(tableID, COLUMN_ID_CHAT_ACTIVITY);
-
- activityColumn.setAlignment(TableColumn.ALIGN_CENTER);
- activityColumn.setPosition(2);
- activityColumn.setRefreshInterval(TableColumn.INTERVAL_GRAPHIC);
- activityColumn.setType(TableColumn.TYPE_GRAPHIC);
-
- activityColumn.addCellRefreshListener(activityIndicator);
-
- tableManager.addColumn(activityColumn);
- }
-*/
+// private void addMyTorrentsColumn() {
+//
+// MyTorrentsActivityIndicator activityIndicator = new MyTorrentsActivityIndicator(this, controller, swtui);
+//
+// addIndicatorToTable(TableManager.TABLE_MYTORRENTS_INCOMPLETE,activityIndicator);
+// addIndicatorToTable(TableManager.TABLE_MYTORRENTS_COMPLETE,activityIndicator);
+// }
+//
+// private void addIndicatorToTable(String tableID,MyTorrentsActivityIndicator activityIndicator) {
+// UIManager uiManager = plugin_interface.getUIManager();
+// TableManager tableManager = uiManager.getTableManager();
+// TableColumn activityColumn = tableManager.createColumn(tableID, COLUMN_ID_CHAT_ACTIVITY);
+//
+// activityColumn.setAlignment(TableColumn.ALIGN_CENTER);
+// activityColumn.setPosition(2);
+// activityColumn.setRefreshInterval(TableColumn.INTERVAL_GRAPHIC);
+// activityColumn.setType(TableColumn.TYPE_GRAPHIC);
+//
+// activityColumn.addCellRefreshListener(activityIndicator);
+//
+// tableManager.addColumn(activityColumn);
+// }
/**
* @return Returns the nick.
@@ -370,9 +369,9 @@ public Download addChannel(String channelName) {
return null;
}
-// public UISWTInstance getSWTUI() {
-// return swtui;
-// }
+ public UISWTInstance getSWTUI() {
+ return swtui;
+ }
public static byte[] bEncode(Map map) {
if (formatters == null) {
View
8 blogracy-vuze/src/main/java/net/blogracy/Blogracy.java
@@ -10,7 +10,6 @@
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
-import net.blogracy.chat.ChatManager;
import net.blogracy.logging.Logger;
import net.blogracy.services.ChatService;
import net.blogracy.services.DownloadService;
@@ -39,7 +38,6 @@
private SeedService seedService;
private DownloadService downloadService;
private ChatService chatService;
- private ChatManager chatManager;
/*
* (non-Javadoc)
@@ -50,7 +48,6 @@
*/
@Override
public void initialize(PluginInterface vuze) throws PluginException {
- // TODO Auto-generated method stub
createQueues(vuze);
}
@@ -66,13 +63,10 @@ void createQueues(final PluginInterface vuze) {
seedService = new SeedService(connection, vuze);
downloadService = new DownloadService(connection, vuze);
-// chatManager = new ChatManager();
-// chatManager.initialize(plugin);
- chatService = new ChatService(connection, /*chatManager,*/ vuze);
+ chatService = new ChatService(connection, vuze);
Logger.info("Blogracy Vuze plugin has started correctly");
} catch (Exception e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
}
View
180 blogracy-web/src/main/java/net/blogracy/controller/ChatController.java
@@ -18,110 +18,80 @@
import org.apache.activemq.ActiveMQConnectionFactory;
public class ChatController {
-
+
private ConnectionFactory connectionFactory;
- private Connection connection;
- private static Session session;
- private static Destination hashQueue;
- private static MessageProducer producer;
-
- private static String localUser, remoteUser;
-
- private static final ChatController THE_INSTANCE = new ChatController();
-
- public static ChatController getSingleton() {
- return THE_INSTANCE;
- }
-
- public ChatController() {
- try {
- connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_BROKER_URL);
- connection = connectionFactory.createConnection();
- connection.start();
- session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- producer = session.createProducer(null);
- producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- hashQueue = session.createQueue("chatService");
- } catch (Exception e) {
- System.out.println("JMS error: creating the text listener");
- }
- }
-
- public static void setLocalUser(String local) {
- if (!local.equals(localUser)){
- localUser = local;
- System.out.println("Creating chat channel for: " + localUser);
- TextMessage msg;
- try {
- msg = session.createTextMessage();
- msg.setText(localUser);
- producer.send(hashQueue, msg);
- } catch (JMSException e) {
- System.out.println("JMS error: sending messages");
- }
- }
- }
-
- public static void createChannel(String channel) {
- System.out.println("Creating chat channel for: " + channel);
- TextMessage msg;
- try {
- msg = session.createTextMessage();
- msg.setText(channel);
- producer.send(hashQueue, msg);
- } catch (JMSException e) {
- System.out.println("JMS error: sending messages");
- }
- }
-
- public static void setRemoteUser(String remote) {
- remoteUser = remote;
- System.out.println("Remote user hash: " + remoteUser);
- }
-
- public static String getRemoteUser() {
- return remoteUser;
- }
-
- public static void chatting(){
- if (!remoteUser.equals(localUser)){
- TextMessage msg;
- try {
- msg = session.createTextMessage();
- msg.setText(remoteUser);
- producer.send(hashQueue, msg);
- System.out.println("Connecting to channel " + remoteUser);
- } catch (JMSException e) {
- System.out.println("JMS error: sending messages");
- }
- }
- }
-
- public static void privateChatting(){
- if (!remoteUser.equals(localUser)){
- TextMessage msg;
- try {
- msg = session.createTextMessage();
- msg.setText(localUser + remoteUser);
- producer.send(hashQueue, msg);
- System.out.println("Creating a private channel");
- } catch (JMSException e) {
- System.out.println("JMS error: sending messages");
- }
- }
- }
-
- public static void privateChatting2(){
- if (!remoteUser.equals(localUser)){
- TextMessage msg;
- try {
- msg = session.createTextMessage();
- msg.setText(remoteUser + localUser);
- producer.send(hashQueue, msg);
- System.out.println("Connecting to a private channel");
- } catch (JMSException e) {
- System.out.println("JMS error: sending messages");
- }
- }
- }
+ private Connection connection;
+ private static Session session;
+ private static Destination topic;
+ private static MessageProducer producer;
+ private String TOPIC_NAME = "CHAT.DEMO";
+
+ private static String localUser, remoteUser;
+
+ private static final ChatController THE_INSTANCE = new ChatController();
+
+ public static ChatController getSingleton() {
+ return THE_INSTANCE;
+ }
+
+ 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");
+ }
+ }
+
+ public static void setLocalUser(String local) {
+ if (! local.equals(localUser)) {
+ localUser = local;
+ createChannel(localUser);
+ }
+ }
+
+ public static void createChannel(String channel) {
+ System.out.println("Creating chat channel: " + channel);
+ TextMessage msg;
+ try {
+ 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 static void setRemoteUser(String remote) {
+ remoteUser = remote;
+ System.out.println("Remote user hash: " + remoteUser);
+ }
+
+ public static String getRemoteUser() {
+ return remoteUser;
+ }
+
+ public static void chatting() {
+ if (! remoteUser.equals(localUser)) {
+ createChannel(remoteUser);
+ }
+ }
+
+ public static void privateChatting() {
+ if (! remoteUser.equals(localUser)) {
+ createChannel(localUser + remoteUser);
+ }
+ }
+
+ public static void privateChatting2() {
+ if (! remoteUser.equals(localUser)) {
+ createChannel(remoteUser + localUser);
+ }
+ }
}

0 comments on commit 9fbed92

Please sign in to comment.