本文整理汇总了Java中org.xmpp.packet.Presence.getType方法的典型用法代码示例。如果您正苦于以下问题:Java Presence.getType方法的具体用法?Java Presence.getType怎么用?Java Presence.getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xmpp.packet.Presence
的用法示例。
在下文中一共展示了Presence.getType方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* 处理Presence
*
* @param packet
*/
private void handle(Presence packet) {
try {
Presence.Type type = packet.getType();
// Presence updates (null == 'available')
if (type == null || Presence.Type.unavailable == type) {
presenceUpdateHandler.process(packet);
} else {
log.warn("未知的presence类型");
}
} catch (Exception e) {
log.error("不能路由数据包", e);
Session session = sessionManager.getSession(packet.getFrom());
if (session != null) {
session.close();
}
}
}
示例2: handle
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
private void handle(Presence packet) {
try {
Presence.Type type = packet.getType();
// Presence updates (null == 'available')
if (type == null || Presence.Type.unavailable == type) {
presenceUpdateHandler.process(packet);
} else {
log.warn("Unknown presence type");
}
} catch (Exception e) {
log.error("Could not route packet", e);
Session session = sessionManager.getSession(packet.getFrom());
if (session != null) {
session.close();
}
}
}
示例3: interceptPacket
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) throws PacketRejectedException {
String type = getSubscriptionType();
if (type.equals(DISABLED)) {
return;
}
if ((packet instanceof Presence) && !incoming && !processed) {
Presence presencePacket = (Presence) packet;
Type presenceType = presencePacket.getType();
if (presenceType != null && presenceType.equals(Presence.Type.subscribe)) {
JID toJID = presencePacket.getTo();
JID fromJID = presencePacket.getFrom();
String toNode = toJID.getNode();
if (whiteList.contains(toNode)) {
return;
}
if (type.equals(ACCEPT)) {
acceptSubscription(toJID, fromJID);
}
if (type.equals(REJECT)) {
rejectSubscription(toJID, fromJID);
}
}
}
}
示例4: processPacket
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void processPacket(Packet packet) {
// Check that we are getting an answer to a presence probe
if (packet instanceof Presence) {
Presence presence = (Presence) packet;
if (presence.isAvailable() || presence.getType() == Presence.Type.unavailable ||
presence.getType() == Presence.Type.error) {
// Store answer of presence probes
probedPresence.put(presence.getFrom().toString(), presence);
}
}
}
示例5: process
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
@Override
public void process(Packet packet, String subdomain, String to, String from) throws PacketRejectedException {
Presence myPacket = (Presence) packet;
if (myPacket.getType() != null && myPacket.getType().equals(Presence.Type.unavailable)
&& !myPacket.getElement().getStringValue().equals("Connecting")) {
String username = getUsernameFromJid(to);
Log.debug("Processing packet in NonPersistantRosterProcessor for " + subdomain + "and user " + username + " Packet: "
+ packet.toString());
try {
Roster roster = _rosterManager.getRoster(username);
Collection<RosterItem> items = roster.getRosterItems();
for (RosterItem item : items) {
String itemName = item.getJid().toString();
if (itemName.contains(subdomain)) {
Log.debug("Removing contact " + item.getJid().toString() + " from contact list.");
roster.deleteRosterItem(item.getJid(), false);
}
}
} catch (Exception e) {
Log.debug("Execption occured when cleaning up the Roster.", e);
e.printStackTrace();
}
}
}
示例6: isAvailable
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Return true if the Workgroup is available to take requests.
*
* @return true if the workgroup is available to take requests.
*/
public boolean isAvailable() {
for (RequestQueue requestQueue : getRequestQueues()) {
Presence presence = requestQueue.getDetailedStatusPresence();
if (presence.getType() == null) {
return true;
}
}
return false;
}
示例7: setPresence
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void setPresence(Presence presence) {
try {
doClusterTask(new SetPresenceTask(address, presence));
} catch (IllegalStateException e) {
// Remote node is down
if (presence.getType() == Presence.Type.unavailable) {
// Ignore unavailable presence (since session is already unavailable - at least to us)
return;
}
throw e;
}
}
示例8: process
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* 处理出席数据包
*
* @param packet
*/
public void process(Packet packet) {
ClientSession session = sessionManager.getSession(packet.getFrom());
try {
Presence presence = (Presence) packet;
Presence.Type type = presence.getType();
if (type == null) { // null == available
if (session != null
&& session.getStatus() == Session.STATUS_CLOSED) {
log.warn("Rejected available presence: " + presence + " - "
+ session);
return;
}
if (session != null) {
session.setPresence(presence);
if (!session.isInitialized()) {
// initSession(session);
session.setInitialized(true);
}
List<Notification> list = notificationService
.findNotificationsByUsername(session.getUsername());
if (list != null && list.size() > 0) {
for (Notification notification : list) {
String apiKey = notification.getApiKey();
String title = notification.getTitle();
String message = notification.getMessage();
String uri = notification.getUri();
String imageUrl = notification.getImageUrl();
notificationManager.sendNotifcationToUser(apiKey,
session.getUsername(), title, message, uri,
imageUrl, false);
notificationService
.deleteNotification(notification);
}
}
}
} else if (Presence.Type.unavailable == type) {// 不可用的
if (session != null) {
session.setPresence(presence);
}
} else {
presence = presence.createCopy();
if (session != null) {
presence.setFrom(new JID(null, session.getServerName(),
null, true));
presence.setTo(session.getAddress());
} else {
JID sender = presence.getFrom();
presence.setFrom(presence.getTo());
presence.setTo(sender);
}
presence.setError(PacketError.Condition.bad_request);
PacketDeliverer.deliver(presence);
}
} catch (Exception e) {
log.error("内部服务器错误. Triggered by packet: " + packet, e);
}
}
示例9: process
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void process(Presence packet) {
// Ignore unavailable presences
if (Presence.Type.unavailable == packet.getType()) {
return;
}
// Examine the packet and check if it has caps info,
// if not -- do nothing by returning.
Element capsElement = packet.getChildElement("c", "http://jabber.org/protocol/caps");
if (capsElement == null) {
return;
}
// Examine the packet and check if it's in legacy format (pre version 1.4
// of XEP-0115). If so, do nothing by returning.
// TODO: if this packet is in legacy format, we SHOULD check the 'node',
// 'ver', and 'ext' combinations as specified in the archived version
// 1.3 of the specification, and cache the results. See JM-1447
final String hashAttribute = capsElement.attributeValue("hash");
if (hashAttribute == null || hashAttribute.trim().length() == 0) {
return;
}
// Examine the packet and check if it has and a 'ver' hash
// if not -- do nothing by returning.
final String newVerAttribute = capsElement.attributeValue("ver");
if (newVerAttribute == null || newVerAttribute.trim().length() == 0) {
return;
}
// Check to see if the 'ver' hash is already in our cache.
if (isInCapsCache(newVerAttribute)) {
// The 'ver' hash is in the cache already, so let's update the
// entityCapabilitiesUserMap for the user that sent the caps
// packet.
entityCapabilitiesUserMap.put(packet.getFrom(), newVerAttribute);
}
else {
// The 'ver' hash is not in the cache so send out a disco#info query
// so that we may begin recognizing this 'ver' hash.
IQ iq = new IQ(IQ.Type.get);
iq.setTo(packet.getFrom());
String serverName = XMPPServer.getInstance().getServerInfo().getXMPPDomain();
iq.setFrom(serverName);
iq.setChildElement("query", "http://jabber.org/protocol/disco#info");
String packetId = iq.getID();
final EntityCapabilities caps = new EntityCapabilities();
caps.setHashAttribute(hashAttribute);
caps.setVerAttribute(newVerAttribute);
verAttributes.put(packetId, caps);
final IQRouter iqRouter = XMPPServer.getInstance().getIQRouter();
iqRouter.addIQResultListener(packetId, this);
iqRouter.route(iq);
}
}
示例10: process
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Processes the presence packet.
*
* @param packet the packet
*/
public void process(Packet packet) {
ClientSession session = sessionManager.getSession(packet.getFrom());
try {
Presence presence = (Presence) packet;
Presence.Type type = presence.getType();
if (type == null) { // null == available
if (session != null
&& session.getStatus() == Session.STATUS_CLOSED) {
log.warn("Rejected available presence: " + presence + " - "
+ session);
return;
}
if (session != null) {
session.setPresence(presence);
if (!session.isInitialized()) {
// initSession(session);
session.setInitialized(true);
}
}
} else if (Presence.Type.unavailable == type) {
if (session != null) {
session.setPresence(presence);
}
} else {
presence = presence.createCopy();
if (session != null) {
presence.setFrom(new JID(null, session.getServerName(),
null, true));
presence.setTo(session.getAddress());
} else {
JID sender = presence.getFrom();
presence.setFrom(presence.getTo());
presence.setTo(sender);
}
presence.setError(PacketError.Condition.bad_request);
PacketDeliverer.deliver(presence);
}
} catch (Exception e) {
log.error("Internal server error. Triggered by packet: " + packet,
e);
}
}
示例11: process
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void process(Presence packet) {
// Ignore unavailable presences
if (Presence.Type.unavailable == packet.getType()) {
return;
}
// Examine the packet and check if it has caps info,
// if not -- do nothing by returning.
Element capsElement = packet.getChildElement("c", "http://jabber.org/protocol/caps");
if (capsElement == null) {
return;
}
// Examine the packet and check if it's in legacy format (pre version 1.4
// of XEP-0115). If so, do nothing by returning.
// TODO: if this packet is in legacy format, we SHOULD check the 'node',
// 'ver', and 'ext' combinations as specified in the archived version
// 1.3 of the specification, and cache the results. See JM-1447
final String hashAttribute = capsElement.attributeValue("hash");
if (hashAttribute == null || hashAttribute.trim().length() == 0) {
return;
}
// Examine the packet and check if it has and a 'ver' hash
// if not -- do nothing by returning.
final String newVerAttribute = capsElement.attributeValue("ver");
if (newVerAttribute == null || newVerAttribute.trim().length() == 0) {
return;
}
// Check to see if the 'ver' hash is already in our cache.
if (isInCapsCache(newVerAttribute)) {
// The 'ver' hash is in the cache already, so let's update the
// entityCapabilitiesUserMap for the user that sent the caps
// packet.
entityCapabilitiesUserMap.put(packet.getFrom(), newVerAttribute);
}
else {
// The 'ver' hash is not in the cache so send out a disco#info query
// so that we may begin recognizing this 'ver' hash.
IQ iq = new IQ(IQ.Type.get);
iq.setTo(packet.getFrom());
String serverName = XMPPServer.getInstance().getServerInfo().getXMPPDomain();
iq.setFrom(serverName);
iq.setChildElement("query", "http://jabber.org/protocol/disco#info");
String packetId = iq.getID();
final EntityCapabilities caps = new EntityCapabilities();
caps.setHashAttribute(hashAttribute);
caps.setVerAttribute(newVerAttribute);
verAttributes.put(packetId, caps);
final IQRouter iqRouter = XMPPServer.getInstance().getIQRouter();
iqRouter.addIQResultListener(packetId, this);
iqRouter.route(iq);
}
}
示例12: process
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
private void process(Presence presence, ClientSession session) throws UnauthorizedException, PacketException {
try {
Presence.Type type = presence.getType();
// Available
if (type == null) {
if (session != null && session.getStatus() == Session.STATUS_CLOSED) {
Log.warn("Rejected available presence: " + presence + " - " + session);
return;
}
broadcastUpdate(presence.createCopy());
if (session != null) {
session.setPresence(presence);
if (!session.isInitialized()) {
initSession(session);
session.setInitialized(true);
}
}
// Notify the presence manager that the user is now available. The manager may
// remove the last presence status sent by the user when he went offline.
presenceManager.userAvailable(presence);
}
else if (Presence.Type.unavailable == type) {
broadcastUpdate(presence.createCopy());
broadcastUnavailableForDirectedPresences(presence);
if (session != null) {
session.setPresence(presence);
}
// Notify the presence manager that the user is now unavailable. The manager may
// save the last presence status sent by the user and keep track when the user
// went offline.
presenceManager.userUnavailable(presence);
}
else {
presence = presence.createCopy();
if (session != null) {
presence.setFrom(new JID(null, session.getServerName(), null, true));
presence.setTo(session.getAddress());
}
else {
JID sender = presence.getFrom();
presence.setFrom(presence.getTo());
presence.setTo(sender);
}
presence.setError(PacketError.Condition.bad_request);
deliverer.deliver(presence);
}
}
catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error") + ". Triggered by packet: " + presence, e);
}
}