Interface PacketFilter

All Known Implementing Classes:
AndFilter, FromContainsFilter, FromMatchesFilter, IQTypeFilter, MessageTypeFilter, NotFilter, OrFilter, PacketExtensionFilter, PacketIDFilter, PacketTypeFilter, ThreadFilter, ToContainsFilter

public interface PacketFilter

Defines a way to filter packets for particular attributes. Packet filters are used when constructing packet listeners or collectors -- the filter defines what packets match the criteria of the collector or listener for further packet processing.

Several pre-defined filters are defined. These filters can be logically combined for more complex packet filtering by using the AndFilter and OrFilter filters. It's also possible to define your own filters by implementing this interface. The code example below creates a trivial filter for packets with a specific ID.

 // Use an anonymous inner class to define a packet filter that returns
 // all packets that have a packet ID of "RS145".
 PacketFilter myFilter = new PacketFilter() {
     public boolean accept(Packet packet) {
         return "RS145".equals(packet.getPacketID());
 // Create a new packet collector using the filter we created.
 PacketCollector myCollector = packetReader.createPacketCollector(myFilter);

Matt Tucker
See Also:
PacketCollector, PacketListener

Method Summary
 boolean accept(Packet packet)
          Tests whether or not the specified packet should pass the filter.

Method Detail


boolean accept(Packet packet)
Tests whether or not the specified packet should pass the filter.

packet - the packet to test.
true if and only if packet passes the filter.


Copyright © 2003-2007 Jive Software.