本文整理汇总了Java中org.xmpp.packet.Packet.getID方法的典型用法代码示例。如果您正苦于以下问题:Java Packet.getID方法的具体用法?Java Packet.getID怎么用?Java Packet.getID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xmpp.packet.Packet
的用法示例。
在下文中一共展示了Packet.getID方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
/**
* Here we process the response of the remote command sent to Spectrum. We have to identify what kind of response it
* is, as no tag for the command being responded is being sent. Currently these commands are used in Gojara
* TransportSessionManager: online_users ( Chatmsg of online users for specific transport), usernames seperated by
* newlines
*/
@Override
public void process(Packet packet, String subdomain, String to, String from) throws PacketRejectedException {
Message message = (Message) packet;
// handle different commands
Log.debug("Intercepted spectrum message: " + message.toString());
String command = packet.getID();
if (command.equals("online_users")) {
handleOnlineUsers(message, subdomain);
} else if (command.equals("unregister")) {
handleUnregister(message, subdomain);
} else if (command.equals("config_check")) {
handleConfigCheck(subdomain);
} else if (command.equals("uptime")) {
handleStatistic(message, subdomain, "uptime");
} else if (command.equals("messages_from_xmpp")) {
handleStatistic(message, subdomain, "messages_from_xmpp");
} else if (command.equals("messages_to_xmpp")) {
handleStatistic(message, subdomain, "messages_to_xmpp");
} else if (command.equals("used_memory")) {
handleStatistic(message, subdomain, "used_memory");
} else if (command.equals("average_memory_per_user")) {
handleStatistic(message, subdomain, "average_memory_per_user");
}
}
示例2: getReply
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
static public Packet getReply(Connection connection, Packet packet,
long timeout) throws XMPPException {
PacketFilter responseFilter = new PacketIDFilter(packet.getID());
PacketCollector response = connection
.createPacketCollector(responseFilter);
connection.sendPacket(packet);
// Wait up to a certain number of seconds for a reply.
Packet result = response.nextResult(timeout);
// Stop queuing results
response.cancel();
if (result == null) {
throw new XMPPException(SmackError.NO_RESPONSE_FROM_SERVER);
} else if (result.getError() != null) {
throw new XMPPException(result.getError());
}
return result;
}
示例3: process
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
/**
* Here we process the response of the remote command sent to Spectrum. We have to identify what kind of response it
* is, as no tag for the command being responded is being sent. Currently these commands are used in Gojara
* TransportSessionManager: online_users ( Chatmsg of online users for specific transport), usernames seperated by
* newlines
*/
@Override
public void process(Packet packet, String subdomain, String to, String from) throws PacketRejectedException {
Message message = (Message) packet;
// handle different commands
Log.debug("Intercepted spectrum message: " + message.toString());
String command = packet.getID();
if (command.equals("online_users")) {
handleOnlineUsers(message, subdomain);
} else if (command.equals("unregister")) {
handleUnregister(message, subdomain);
} else if (command.equals("config_check")) {
handleConfigCheck(subdomain);
} else if (command.equals("uptime")) {
handleStatistic(message, subdomain, "uptime");
} else if (command.equals("messages_from_xmpp")) {
handleStatistic(message, subdomain, "messages_from_xmpp");
} else if (command.equals("messages_to_xmpp")) {
handleStatistic(message, subdomain, "messages_to_xmpp");
} else if (command.equals("used_memory")) {
handleStatistic(message, subdomain, "used_memory");
} else if (command.equals("average_memory_per_user")) {
handleStatistic(message, subdomain, "average_memory_per_user");
}
}
示例4: send
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
/**
* Sends the given XMPP packet over the backing transport. This accepts a
* callback which is guaranteed to be invoked at a later point, either through
* a normal response, error response, or timeout.
*
* @param packet packet to be sent
* @param callback callback to be invoked on response or timeout
* @param timeout timeout, in seconds, for this callback
*/
public void send(Packet packet, final PacketCallback callback, int timeout) {
final String key = packet.getID() + "#" + packet.getTo() + "#" + packet.getFrom();
final OutgoingCall call = new OutgoingCall(packet.getClass(), callback);
if (callbacks.putIfAbsent(key, call) == null) {
// Timeout runnable to be invoked on packet expiry.
Runnable timeoutTask = new Runnable() {
@Override
public void run() {
if (callbacks.remove(key, call)) {
callback.error(
FederationErrors.newFederationError(FederationError.Code.REMOTE_SERVER_TIMEOUT));
} else {
// Likely race condition where success has actually occurred. Ignore.
}
}
};
call.start(timeoutExecutor.schedule(timeoutTask, timeout, TimeUnit.SECONDS));
transport.sendPacket(packet);
} else {
String msg = "Could not send packet, ID already in-flight: " + key;
LOG.warning(msg);
// Invoke the callback with an internal error.
callback.error(
FederationErrors.newFederationError(FederationError.Code.UNDEFINED_CONDITION, msg));
}
}
示例5: causeImmediateTimeout
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
/**
* Cause an immediate timeout for the given packet, which is presumed to have
* already been sent via {@link #send}.
*/
@VisibleForTesting
void causeImmediateTimeout(Packet packet) {
String key = packet.getID() + "#" + packet.getTo() + "#" + packet.getFrom();
OutgoingCall call = callbacks.remove(key);
if (call != null) {
call.callback.error(FederationErrors.newFederationError(
FederationError.Code.REMOTE_SERVER_TIMEOUT, "Forced immediate timeout"));
}
}
示例6: response
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
/**
* Invoke the callback for a packet already identified as a response. This may
* either invoke the error or normal callback as necessary.
*/
private void response(Packet packet) {
String key = packet.getID() + "#" + packet.getFrom() + "#" + packet.getTo();
OutgoingCall call = callbacks.remove(key);
if (call == null) {
LOG.warning("Received response packet without paired request: " + packet.getID());
} else {
// Cancel the outstanding timeout.
call.timeout.cancel(false);
// Look for error condition and invoke the relevant callback.
Element element = packet.getElement().element("error");
if (element != null) {
LOG.fine("Invoking error callback for: " + packet.getID());
call.callback.error(toFederationError(new PacketError(element)));
} else {
if (call.responseType.equals(packet.getClass())) {
LOG.fine("Invoking normal callback for: " + packet.getID());
call.callback.run(packet);
} else {
String msg =
"Received mismatched response packet type: expected " + call.responseType
+ ", given " + packet.getClass();
LOG.warning(msg);
call.callback.error(FederationErrors.newFederationError(
FederationError.Code.UNDEFINED_CONDITION, msg));
}
}
// Clear call's reference to callback, otherwise callback only
// becomes eligible for GC once the timeout expires, because
// timeoutExecutor holds on to the call object till then, even
// though we cancelled the timeout.
call.callback = null;
}
}
示例7: processIncoming
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
@Override
public void processIncoming(Packet packet) {
if (packet instanceof Message) {
Message message = (Message) packet;
JID fromJID = packet.getFrom();
JID toJID = packet.getTo();
packet.setTo(fromJID);
Element mmx = message.getChildElement(Constants.MMX, Constants.MMX_NS_MSG_PAYLOAD);
Element meta = mmx.element(Constants.MMX_META);
if (meta == null) {
LOGGER.info("No meta in the message with id:{}", message.getID());
return;
}
//Simulate SDK ack
String originalMessageId = packet.getID();
String from = fromJID.toString();
String to = toJID.toString();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Attempting to deliver ack");
}
IQ ackIQ = BotRegistrationImpl.buildAckIQ(from, to, originalMessageId);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Ack IQ:{}", ackIQ.toXML());
}
connection.sendPacket(ackIQ);
String metaJSON = meta.getText();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Meta JSON:{}", metaJSON);
}
RPSLSGameInfo gameInfo = GsonData.getGson().fromJson(metaJSON, RPSLSGameInfo.class);
if (gameInfo.getType() == RPSLSMessageType.INVITATION) {
//process an invitation
//step 1. Send an acceptance
//step 2. Send a choice after 2 seconds.
processRPSLSInvitationMessage(fromJID, toJID, gameInfo);
} else {
//ignore the other types
LOGGER.info("Ignoring a message with type:{} message:{}", gameInfo.getType(), message);
}
}
}