powered by Jive Software

Chatmanager doesn''t fire event on incoming messages, Packetlistener does


I’‘m rewriting an old program using Smack 3.0. I’‘m trying to use the ChatManager to handle one on one messaging but for some reason the Chatmanager doesn’'t fire an event when a message is recieved for that chat.

I’'ve registered a PacketListener to see if that works and in fact it does. I was under the believe that the Chatmanager created the same PacketListener internally and just reroute the message to my other listener.

Below is the code snippet and the debug output from the wonderfull debug tool

package org.tilleuil.Jtalk.model;

import java.util.ArrayList;

import java.util.Collection;

import java.util.List;

import org.apache.log4j.Logger;

import org.jivesoftware.smack.Chat;

import org.jivesoftware.smack.ChatManagerListener;

import org.jivesoftware.smack.MessageListener;

import org.jivesoftware.smack.PacketListener;

import org.jivesoftware.smack.XMPPException;

import org.jivesoftware.smack.filter.AndFilter;

import org.jivesoftware.smack.filter.FromContainsFilter;

import org.jivesoftware.smack.filter.PacketFilter;

import org.jivesoftware.smack.filter.PacketTypeFilter;

import org.jivesoftware.smack.packet.Message;

import org.jivesoftware.smack.packet.Packet;

public class Conversation implements MessageListener, PacketListener {

private static final Logger logger = Logger.getLogger(Conversation.class);

private static final int MAX_BUFFER_SIZE = 100;

private PacketFilter filter = null;

private Chat chat = null;

private Buddy participant = null;

private List();

this.chat = Connection.getInstance().getConnection().getChatManager()

.createChat(this.participant.getEntry().getUser(), this);

this.filter = new AndFilter(new PacketTypeFilter(Message.class),

new FromContainsFilter(this.participant.getEntry().getUser()));



logger.debug("created a chat instance " + chat.getParticipant());



  • Method to send a message to the participant of this converstation, this

  • will create a standard message object containing a to and

  • the body

  • @param message

  • the body of the message

  • @throws XMPPException


public void sendMessage(String message) throws XMPPException {

logger.debug("sending following message : " + message);




  • Send the message to the participant of this conversation. This method is

  • provided to provide more flexibilty in the message sending.

  • @param msg

  • The message that should be send to the participant

  • @throws XMPPException


public void sendMessage(Message msg) throws XMPPException {




  • Method to add a message to the buffer. If MAX_BUFFER_SIZE is reached the

  • first element in the buffer will be removed. FILO style

  • @return void

  • @param msg

  • The message to add


private void addMessageToBuffer(MessageBufferEntry msg) {

if (this.buffer.size() <= MAX_BUFFER_SIZE) {






  • Returns a List of MessageBufferEntry wich is the current

  • buffer for messages.

  • @return Buffer

  • @param void


public List getBuffer() {

return buffer;



  • Returns the latest message

  • @return MessageBufferEntry The latest message in the buffer


public MessageBufferEntry getLatestMessage() {

if (this.buffer != null && this.buffer.size() > 0) {

return buffer.get(buffer.size());


return null;



  • @return Buddy The participant in this chat


public Buddy getParticipant() {

return participant;


public void processPacket(Packet packet) {

logger.debug(“Recieved packet with PacketListener”);

if (packet instanceof Message) {

Message msg = (Message) packet;

logger.debug("Message recieved for conversation with "

  • this.participant.getEntry().getUser());

logger.debug("Message body : " + msg.getBody());



public void processMessage(org.jivesoftware.smack.Chat chat, Message message) {

logger.debug(“Recieved Message with MessageListener”);

MessageBufferEntry msg = new MessageBufferEntry(message);

logger.debug("new message recieved from "

  • this.participant.getEntry().getUser());

logger.debug("Body : " + msg.toString());


// TODO notify someone that there is a new message for this

// converstation



  • This method unregisters all listeners for this converstation. Note that

  • this method should always be called when you end a chat Otherwise the

  • listeners will keep grabbing packages forever !!!


public void unregisterAll() {

Collection node to link the message to the chat instance, but gtalk isn’'t sending it back.