开发者

Smack ChatManager not behaving properly

I've searched around quite a bit to try and find some additional information on Smack and their ChatManager, but there isn't much, so it's time to come to SOF.

I'm doing something very basic at a certain point in my cod开发者_运维技巧e:

 chatmanager = con.getChatManager();
 chatmanager.createChat(name, message.getThread(),
 new MessageListener() {
  public void processMessage(Chat chat, Message message) {
  }
 });
 System.out.println("Chat created");
 Chat chat = chatmanager.getThreadChat(message.getThread());
 if (chat == null)
   System.out.print("Newly created chat is null");
 else
   System.out.println("Newly created chat is saved in manager");

I'm trying to verify that the chat I just created, is actually in the chatManager

In my program I have only 1 instance of chatManager ever created, but multiple times I do this:

 chatmanager = con.getChatManager();

I have a feeling that each time I do that, the chatManager is being re-initialized. Am I completely mistaken?

Anyway, the problem is that I don't get any output. Neither, "chat is null" or "chat is saved". Leads me to believe that the chatManager is causing problems.

Can anyone help?


The chatManager should always be linked directly to the connection. Here is the original source for the connection class:

http://fisheye.igniterealtime.org/browse/smack/trunk/source/org/jivesoftware/smack/Connection.java?r=11613

You can see it stores the reference to the chat manager:

public synchronized ChatManager getChatManager() {
    if (this.chatManager == null) {
        this.chatManager = new ChatManager(this);
    }
    return this.chatManager;
}

Are you seeing "chat created" in the log? I am not familiar with google's impl of ChatManager or Smack for that matter but ChatManager stores a simple map of thread id to chat object


Are you sure the problem is whithin the chatmanager? Ensure the connection is connected, before trying to create one chat.

To do that, you can for example retrieve the contact list:

        try {
        connection.connect();
        connection.login(user, password);
        System.out.println("Secured:" + connection.isSecureConnection());
        for (RosterGroup group : connection.getRoster().getGroups()) {
            System.out.println(group.getName());
            for (RosterEntry entry : group.getEntries()) {
                System.out.println("\t" + entry.getName() + "\t" + entry.getUser());
            }
        }
    } catch (XMPPException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜