Received treatment Stanzas

Received treatment Stanzas

Back

Smack use two structures provides a flexible framework to handle incoming sections:

  • org.jivesoftware.smack.StanzaCollector - allows you to synchronize wait for a new class section.
  • org.jivesoftware.smack.StanzaListener - for asynchronous notification interface you pass Festival. Festival event listener for event programming style, and a collection section has a section of the result queue, you can be polled and stop operations. Therefore, when you want to take certain actions in the section just entering section listener is useful when you want to wait for a particular segment of the Section collector useful. You can use XMPPConnectionexamples to create Stanza collectors and listeners .

The org.jivesoftware.smack.filter.StanzaFilterinterface determines which specific section will be passed to a StanzaCollectoror StanzaListener. You can org.jivesoftware.smack.filterpack find many predefined filters .

The following code fragment demonstrates how to register a collector section and Section listener:

// Create a stanza filter to listen for new messages from a particular
// user. We use an AndFilter to combine two other filters._
StanzaFilter filter = new AndFilter(StanzaTypeFilter.Message, FromMatchesFilter.create("[email protected]"));
// Assume we've created an XMPPConnection named "connection".

// First, register a stanza collector using the filter we created.
StanzaCollector myCollector = connection.createStanzaCollector(filter);
// Normally, you'd do something with the collector, like wait for new packets.

// Next, create a stanza listener. We use an anonymous inner class for brevity.
StanzaListener myListener = new StanzaListener() {
		**public** **void** processStanza(Stanza stanza) {
			// Do something with the incoming stanza here._
		}
	};
// Register the listener._
connection.addAsyncStanzaListener(myListener, filter);
// or for a synchronous stanza listener use
connection.addSyncStanzaListener(myListener, filter);

Stanza standard filter

Smack section contains a rich set of filters, or you can encode to StanzaFilterinterface to create your own filters . The default set of filters comprising:

  • StanzaTypeFilter - sections for the particular class type of filter.
  • StanzaIdFilter - having a specific packet ID filter section.
  • ThreadFilter - the filter section having a specific message thread ID.
  • ToMatchesFilter - sent to the filter sections to a specific address.
  • FromMatchesFilter - the filter section transmitted from a particular address.
  • StanzaExtensionFilter - has a specific section of the extension of the section of the filter.
  • AndFilter - implement a logical AND operation by the two filters.
  • OrFilter - implementing logical OR operation by the two filters.
  • NotFilter - implementing logical NOT operation on the filter.

Guess you like

Origin www.cnblogs.com/endv/p/11420126.html