本文整理汇总了Java中org.xmpp.packet.Packet.getClass方法的典型用法代码示例。如果您正苦于以下问题:Java Packet.getClass方法的具体用法?Java Packet.getClass怎么用?Java Packet.getClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xmpp.packet.Packet
的用法示例。
在下文中一共展示了Packet.getClass方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendErrorResponse
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
/**
* Send an error response to the passed incoming request. Throws
* IllegalArgumentException if the original packet is also an error, or is of
* the IQ result type.
*
* According to RFC 3920 (9.3.1), the error packet may contain the original
* packet. However, this implementation does not include it.
*
* @param request packet request, to/from is inverted for response
* @param error packet error describing error condition
*/
void sendErrorResponse(Packet request, PacketError error) {
if (request instanceof IQ) {
IQ.Type type = ((IQ) request).getType();
if (!(type.equals(IQ.Type.get) || type.equals(IQ.Type.set))) {
throw new IllegalArgumentException("May only return an error to IQ get/set, not: " + type);
}
} else if (request instanceof Message) {
Message message = (Message) request;
if (message.getType().equals(Message.Type.error)) {
throw new IllegalArgumentException("Can't return an error to another message error");
}
} else {
throw new IllegalArgumentException("Unexpected Packet subclass, expected Message/IQ: "
+ request.getClass());
}
LOG.fine("Sending error condition in response to " + request.getID() + ": "
+ error.getCondition().name());
// Note that this does not include the original packet; just the ID.
final Packet response = XmppUtil.createResponsePacket(request);
response.setError(error);
transport.sendPacket(response);
}
示例2: interceptPacket
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
@Override
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed)
throws PacketRejectedException {
// Queue intercepted packet only if there are subscribers interested
if (!subscribers.isEmpty()) {
boolean queue = false;
Class packetClass = packet.getClass();
for (Subscription subscription : subscribers.values()) {
if (subscription.isPresenceEnabled() && packetClass == Presence.class) {
queue = true;
}
else if (subscription.isMessageEnabled() && packetClass == Message.class) {
queue = true;
}
else if (subscription.isIQEnabled() && packetClass == IQ.class) {
queue = true;
}
}
if (queue) {
// Queue packet with extra information and let the background thread process it
packetQueue.add(new InterceptedPacket(packet, incoming, processed));
}
}
}
示例3: interceptPacket
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed)
throws PacketRejectedException {
// Queue intercepted packet only if there are subscribers interested
if (!subscribers.isEmpty()) {
boolean queue = false;
Class packetClass = packet.getClass();
for (Subscription subscription : subscribers.values()) {
if (subscription.isPresenceEnabled() && packetClass == Presence.class) {
queue = true;
}
else if (subscription.isMessageEnabled() && packetClass == Message.class) {
queue = true;
}
else if (subscription.isIQEnabled() && packetClass == IQ.class) {
queue = true;
}
}
if (queue) {
// Queue packet with extra information and let the background thread process it
packetQueue.add(new InterceptedPacket(packet, incoming, processed));
}
}
}
示例4: createResponsePacket
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
/**
* Convenience method to create a response {@link Packet} implementation from
* the given source packet. This will return either an {@link IQ} or
* {@link Message} depending on the passed type.
*
* @param request the request message
* @return the new response message
*/
public static Packet createResponsePacket(Packet request) {
if (request instanceof Message) {
return createResponseMessage((Message) request);
} else if (request instanceof IQ) {
return IQ.createResultIQ((IQ) request);
} else {
throw new IllegalArgumentException("Can't respond to unsupported packet type: "
+ request.getClass());
}
}
示例5: 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));
}
}
示例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: InterceptedPacket
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
public InterceptedPacket(Packet packet, boolean incoming, boolean processed) {
packetClass = packet.getClass();
this.element = packet.getElement();
this.incoming = incoming;
this.processed = processed;
creationDate = new Date();
}