powered by Jive Software

How can i use PacketCollector for get all messages?

I write this pice of code for example:

PacketCollector collector = connection.createPacketCollector(new PacketTypeFilter(Message.class));

Message message = (Message) collector.nextResult();

String from = message.getFrom();

String body = message.getBody();

System.out.println("\n" + from + ": " + body);

But when i try, it return only one message from queue. How to process collector.nextResult() to get all messages?

Best regards

You should setup a while loop to help you retrieve all packets.

Thank you AWenckus!

But can you else show me several cople example how to do it ?

Best regards!

PacketCollector collector = connection.createPacketCollector(new PacketTypeFilter(Message.class));

message = (Message) collector.nextResult();

while (message.getBody() != null) {

String from = message.getFrom();

String body = message.getBody();

System.out.println("\n" + from + ": " + body);

message = (Message) collector.nextResult();

}

It’'s pice of code work, but block to wait next messages. How to break while statment to do next pice of code ?