本文整理汇总了Java中org.jivesoftware.smack.PacketCollector.nextResultOrThrow方法的典型用法代码示例。如果您正苦于以下问题:Java PacketCollector.nextResultOrThrow方法的具体用法?Java PacketCollector.nextResultOrThrow怎么用?Java PacketCollector.nextResultOrThrow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jivesoftware.smack.PacketCollector
的用法示例。
在下文中一共展示了PacketCollector.nextResultOrThrow方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setStatus
import org.jivesoftware.smack.PacketCollector; //导入方法依赖的package包/类
/**
* Sets the agent's current status with the workgroup. The presence mode affects how offers
* are routed to the agent. The possible presence modes with their meanings are as follows:<ul>
* <p/>
* <li>Presence.Mode.AVAILABLE -- (Default) the agent is available for more chats
* (equivalent to Presence.Mode.CHAT).
* <li>Presence.Mode.DO_NOT_DISTURB -- the agent is busy and should not be disturbed.
* However, special case, or extreme urgency chats may still be offered to the agent.
* <li>Presence.Mode.AWAY -- the agent is not available and should not
* have a chat routed to them (equivalent to Presence.Mode.EXTENDED_AWAY).</ul>
*
* @param presenceMode the presence mode of the agent.
* @param status sets the status message of the presence update.
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws IllegalStateException if the agent is not online with the workgroup.
*/
public void setStatus(Presence.Mode presenceMode, String status) throws NoResponseException, XMPPErrorException, NotConnectedException {
if (!online) {
throw new IllegalStateException("Cannot set status when the agent is not online.");
}
if (presenceMode == null) {
presenceMode = Presence.Mode.available;
}
this.presenceMode = presenceMode;
Presence presence = new Presence(Presence.Type.available);
presence.setMode(presenceMode);
presence.setTo(this.getWorkgroupJID());
if (status != null) {
presence.setStatus(status);
}
presence.addExtension(new MetaData(this.metaData));
PacketCollector collector = this.connection.createPacketCollectorAndSend(new AndFilter(new StanzaTypeFilter(Presence.class),
FromMatchesFilter.create(workgroupJID)), presence);
collector.nextResultOrThrow();
}
示例2: changeNickname
import org.jivesoftware.smack.PacketCollector; //导入方法依赖的package包/类
/**
* Changes the occupant's nickname to a new nickname within the room. Each room occupant
* will receive two presence packets. One of type "unavailable" for the old nickname and one
* indicating availability for the new nickname. The unavailable presence will contain the new
* nickname and an appropriate status code (namely 303) as extended presence information. The
* status code 303 indicates that the occupant is changing his/her nickname.
*
* @param nickname the new nickname within the room.
* @throws XMPPErrorException if the new nickname is already in use by another occupant.
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
*/
public void changeNickname(String nickname) throws NoResponseException, XMPPErrorException, NotConnectedException {
StringUtils.requireNotNullOrEmpty(nickname, "Nickname must not be null or blank.");
// Check that we already have joined the room before attempting to change the
// nickname.
if (!joined) {
throw new IllegalStateException("Must be logged into the room to change nickname.");
}
// We change the nickname by sending a presence packet where the "to"
// field is in the form "[email protected]/nickname"
// We don't have to signal the MUC support again
Presence joinPresence = new Presence(Presence.Type.available);
joinPresence.setTo(room + "/" + nickname);
// Wait for a presence packet back from the server.
StanzaFilter responseFilter =
new AndFilter(
FromMatchesFilter.createFull(room + "/" + nickname),
new StanzaTypeFilter(Presence.class));
PacketCollector response = connection.createPacketCollectorAndSend(responseFilter, joinPresence);
// Wait up to a certain number of seconds for a reply. If there is a negative reply, an
// exception will be thrown
response.nextResultOrThrow();
this.nickname = nickname;
}
示例3: changeSubject
import org.jivesoftware.smack.PacketCollector; //导入方法依赖的package包/类
/**
* Changes the subject within the room. As a default, only users with a role of "moderator"
* are allowed to change the subject in a room. Although some rooms may be configured to
* allow a mere participant or even a visitor to change the subject.
*
* @param subject the new room's subject to set.
* @throws XMPPErrorException if someone without appropriate privileges attempts to change the
* room subject will throw an error with code 403 (i.e. Forbidden)
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
*/
public void changeSubject(final String subject) throws NoResponseException, XMPPErrorException, NotConnectedException {
Message message = createMessage();
message.setSubject(subject);
// Wait for an error or confirmation message back from the server.
StanzaFilter responseFilter = new AndFilter(fromRoomGroupchatFilter, new StanzaFilter() {
@Override
public boolean accept(Stanza packet) {
Message msg = (Message) packet;
return subject.equals(msg.getSubject());
}
});
PacketCollector response = connection.createPacketCollectorAndSend(responseFilter, message);
// Wait up to a certain number of seconds for a reply.
response.nextResultOrThrow();
}
示例4: sendRestDocument
import org.jivesoftware.smack.PacketCollector; //导入方法依赖的package包/类
@Override
public ResourceDocument sendRestDocument(XmppURI uri, ResourceDocument document) throws XMPPException, IOException, SmackException {
AbstractXMPPConnection connection = this.connectionManager.getConnection();
// create an set IQ stanza to uri
RestIQ setIQ = new RestIQ(uri, document);
// send stanza
connection.sendStanza(setIQ);
// wait for response
StanzaFilter filter = new AndFilter(new IQReplyFilter(setIQ, connection));
PacketCollector collector = connection.createPacketCollector(filter);
IQ resultIQ = collector.nextResultOrThrow();
if(resultIQ instanceof RestIQ) {
// create rest doc
return ((RestIQ) resultIQ).getResourceDocument();
} else {
throw new SmackException("Wrong RestIQ has been passed");
}
}
示例5: getXwadlDocument
import org.jivesoftware.smack.PacketCollector; //导入方法依赖的package包/类
@Override
public ResourceTypeDocument getXwadlDocument(XmppURI uri) throws XMPPException, IOException, SmackException {
AbstractXMPPConnection connection = this.connectionManager.getConnection();
// create an get IQ stanza to uri
IQ getIQ = new GetXwadlIQ(uri);
// send stanza
connection.sendStanza(getIQ);
// wait for response
StanzaFilter filter = new AndFilter(new IQReplyFilter(getIQ, connection));
PacketCollector collector = connection.createPacketCollector(filter);
IQ resultIQ = collector.nextResultOrThrow();
if (resultIQ instanceof XwadlIQ) {
// create xwadl
return ((XwadlIQ) resultIQ).getXwadl();
} else {
throw new SmackException("Wrong IQ has been passed");
}
}
示例6: isAvailable
import org.jivesoftware.smack.PacketCollector; //导入方法依赖的package包/类
/**
* Returns true if the workgroup is available for receiving new requests. The workgroup will be
* available only when agents are available for this workgroup.
*
* @return true if the workgroup is available for receiving new requests.
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
*/
public boolean isAvailable() throws NoResponseException, XMPPErrorException, NotConnectedException {
Presence directedPresence = new Presence(Presence.Type.available);
directedPresence.setTo(workgroupJID);
StanzaFilter typeFilter = new StanzaTypeFilter(Presence.class);
StanzaFilter fromFilter = FromMatchesFilter.create(workgroupJID);
PacketCollector collector = connection.createPacketCollectorAndSend(new AndFilter(fromFilter,
typeFilter), directedPresence);
Presence response = (Presence)collector.nextResultOrThrow();
return Presence.Type.available == response.getType();
}
示例7: getMessages
import org.jivesoftware.smack.PacketCollector; //导入方法依赖的package包/类
/**
* Returns a List of Messages with all the offline <tt>Messages</tt> of the user. The returned offline
* messages will not be deleted from the server. Use {@link #deleteMessages(java.util.List)}
* to delete the messages.
*
* @return a List with all the offline <tt>Messages</tt> of the user.
* @throws XMPPErrorException If the user is not allowed to make this request or the server does
* not support offline message retrieval.
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
*/
public List<Message> getMessages() throws NoResponseException, XMPPErrorException, NotConnectedException {
OfflineMessageRequest request = new OfflineMessageRequest();
request.setFetch(true);
PacketCollector resultCollector = connection.createPacketCollectorAndSend(request);
PacketCollector.Configuration messageCollectorConfiguration = PacketCollector.newConfiguration().setStanzaFilter(PACKET_FILTER).setCollectorToReset(resultCollector);
PacketCollector messageCollector = connection.createPacketCollector(messageCollectorConfiguration);
List<Message> messages = null;
try {
resultCollector.nextResultOrThrow();
// Be extra safe, cancel the message collector right here so that it does not collector
// other messages that eventually match (although I've no idea how this could happen in
// case of XEP-13).
messageCollector.cancel();
messages = new ArrayList<>(messageCollector.getCollectedCount());
Message message;
while ((message = messageCollector.pollResult()) != null) {
messages.add(message);
}
}
finally {
// Ensure that the message collector is canceled even if nextResultOrThrow threw. It
// doesn't matter if we cancel the message collector twice
messageCollector.cancel();
}
return messages;
}
示例8: build
import org.jivesoftware.smack.PacketCollector; //导入方法依赖的package包/类
public static XmppRestClient build(XMPPConnection connection,
XmppURI uri) throws XMPPErrorException, XmlException, SmackException {
logger.info("building rest client for uri=" + uri.toString());
// create an get IQ stanza to uri
IQ getIQ = new GetXwadlIQ(uri);
// send stanza
connection.sendStanza(getIQ);
logger.info("the following stanza had been send: " + getIQ.toString());
// wait for response
StanzaFilter filter = new AndFilter(new IQReplyFilter(getIQ,
connection));
PacketCollector collector = connection
.createPacketCollector(filter);
IQ resultIQ = collector.nextResultOrThrow();
ResourceTypeDocument xwadl = null;
if(resultIQ instanceof XwadlIQ) {
// create xwadl
xwadl = ((XwadlIQ) resultIQ).getXwadl();
} else
throw new SmackException("Wrong IQ has been passed");
logger.info("the following stanza had been received: " + xwadl.toString());
// create client
return new XmppRestClient(connection, uri, xwadl);
}
示例9: invoke
import org.jivesoftware.smack.PacketCollector; //导入方法依赖的package包/类
public Representation invoke() throws XMPPErrorException, XmlException, SmackException {
// create an set IQ stanza to uri
RestIQ setIQ = new RestIQ(this.uri, this.getXmlDocument());
// logger.info("invoke: the following stanza will be send: " + this.getXmlDocument().toString());
// send stanza
this.connection.sendStanza(setIQ);
// wait for response
StanzaFilter filter = new AndFilter(new IQReplyFilter(setIQ,
connection));
PacketCollector collector = connection
.createPacketCollector(filter);
IQ resultIQ = collector.nextResultOrThrow();
ResourceDocument doc = null;
if(resultIQ instanceof RestIQ) {
// create rest doc
doc = ((RestIQ) resultIQ).getResourceDocument();
} else
throw new SmackException("Wrong RestIQ has been passed");
// logger.info("the following resource stanza had been received: " + doc.toString());
// create representation
return getPresentation(doc);
}