When recieving a message I have the following code:
connection.addPacketListener(new PacketListener() {
public void processPacket(Packet packet) {
Message message = (Message) packet;
if (message.getBody() != null) {
String fromName = StringUtils.parseBareAddress(message.getFrom());
if (!mw.nameWindowMap.containsKey(fromName)){
//only get here if this packet is initiaing a conversation.
mw.createChatFrame(fromName); //creates a new Chat class instance
}
}
}
}, new MessageTypeFilter(Message.Type.chat));
Here’s my problem: When a user initiates a conversation with my client, I create the new Chat class instance (which implements the processMessage event listener etc.). Now this processMessage listener get invoked only sometimes… I tihnk I have a race condition so how do I solve this?