本文整理汇总了Java中org.xmpp.packet.Presence.Type方法的典型用法代码示例。如果您正苦于以下问题:Java Presence.Type方法的具体用法?Java Presence.Type怎么用?Java Presence.Type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xmpp.packet.Presence
的用法示例。
在下文中一共展示了Presence.Type方法的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: updateState
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
private static void updateState(RosterItem item, Presence.Type action, boolean isSending) {
Map<String, Map<Presence.Type, Change>> srTable = stateTable.get(item.getSubStatus());
Map<Presence.Type, Change> changeTable = srTable.get(isSending ? "send" : "recv");
Change change = changeTable.get(action);
if (change.newAsk != null && change.newAsk != item.getAskStatus()) {
item.setAskStatus(change.newAsk);
}
if (change.newSub != null && change.newSub != item.getSubStatus()) {
item.setSubStatus(change.newSub);
}
if (change.newRecv != null && change.newRecv != item.getRecvStatus()) {
item.setRecvStatus(change.newRecv);
}
}
示例4: 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);
}
}
示例5: 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);
}
}
示例6: manageSub
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Manage the subscription request. This method updates a user's roster
* state, storing any changes made, and updating the roster owner if changes
* occured.
*
* @param target The roster target's jid (the item's jid to be changed)
* @param isSending True if the request is being sent by the owner
* @param type The subscription change type (subscribe, unsubscribe, etc.)
* @param roster The Roster that is updated.
* @return <tt>true</tt> if the subscription state has changed.
*/
private boolean manageSub(JID target, boolean isSending, Presence.Type type, Roster roster)
throws UserAlreadyExistsException, SharedGroupException
{
RosterItem item = null;
RosterItem.AskType oldAsk;
RosterItem.SubType oldSub = null;
RosterItem.RecvType oldRecv;
boolean newItem = false;
try {
if (roster.isRosterItem(target)) {
item = roster.getRosterItem(target);
}
else {
if (Presence.Type.unsubscribed == type || Presence.Type.unsubscribe == type ||
Presence.Type.subscribed == type) {
// Do not create a roster item when processing a confirmation of
// an unsubscription or receiving an unsubscription request or a
// subscription approval from an unknown user
return false;
}
item = roster.createRosterItem(target, false, true);
newItem = true;
}
// Get a snapshot of the item state
oldAsk = item.getAskStatus();
oldSub = item.getSubStatus();
oldRecv = item.getRecvStatus();
// Update the item state based in the received presence type
updateState(item, type, isSending);
// Update the roster IF the item state has changed
if (oldAsk != item.getAskStatus() || oldSub != item.getSubStatus() ||
oldRecv != item.getRecvStatus()) {
roster.updateRosterItem(item);
}
else if (newItem) {
// Do not push items with a state of "None + Pending In"
if (item.getSubStatus() != RosterItem.SUB_NONE ||
item.getRecvStatus() != RosterItem.RECV_SUBSCRIBE) {
roster.broadcast(item, false);
}
}
}
catch (UserNotFoundException e) {
// Should be there because we just checked that it's an item
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
return oldSub != item.getSubStatus();
}
示例7: manageSub
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
private boolean manageSub(JID target, boolean isSending, Presence.Type type, Roster roster)
throws UserAlreadyExistsException, SharedGroupException {
RosterItem item = null;
RosterItem.AskType oldAsk;
RosterItem.SubType oldSub = null;
RosterItem.RecvType oldRecv;
boolean newItem = false;
try {
if (roster.isRosterItem(target)) {
item = roster.getRosterItem(target);
} else {
if (Presence.Type.unsubscribed == type || Presence.Type.unsubscribe == type ||
Presence.Type.subscribed == type) {
// Do not create a roster item when processing a confirmation of
// an unsubscription or receiving an unsubscription request or a
// subscription approval from an unknown user
return false;
}
item = roster.createRosterItem(target, false, true);
item.setGroups(Arrays.asList("Friends"));
roster.updateRosterItem(item);
newItem = true;
}
// Get a snapshot of the item state
oldAsk = item.getAskStatus();
oldSub = item.getSubStatus();
oldRecv = item.getRecvStatus();
// Update the item state based in the received presence type
updateState(item, type, isSending);
// Update the roster IF the item state has changed
if (oldAsk != item.getAskStatus() || oldSub != item.getSubStatus() ||
oldRecv != item.getRecvStatus()) {
roster.updateRosterItem(item);
} else if (newItem) {
// Do not push items with a state of "None + Pending In"
if (item.getSubStatus() != RosterItem.SUB_NONE ||
item.getRecvStatus() != RosterItem.RECV_SUBSCRIBE) {
roster.broadcast(item, false);
}
}
}
catch (UserNotFoundException e) {
// Should be there because we just checked that it's an item
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
return oldSub != item.getSubStatus();
}
示例8: createPresence
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public Presence createPresence(Presence.Type presenceType) throws UnauthorizedException {
Presence presence = new Presence();
presence.setType(presenceType);
presence.setFrom(role.getRoleAddress());
return presence;
}
示例9: 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);
}
}
示例10: updateState
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Determine and call the update method based on the item's subscription state.
* The method also turns the action and sending status into an integer code
* for easier processing (switch statements).
* <p/>
* Code relies on states being in numerical order without skipping.
* In addition, the receive states must parallel the send states
* so that (send state X) + STATE_RECV_SUBSCRIBE == (receive state X)
* where X is subscribe, subscribed, etc.
* </p>
*
* @param item The item to be updated
* @param action The new state change request
* @param isSending True if the roster owner of the item is sending the new state change request
*/
private static void updateState(RosterItem item, Presence.Type action, boolean isSending) {
Map<String, Map<Presence.Type, Change>> srTable = stateTable.get(item.getSubStatus());
Map<Presence.Type, Change> changeTable = srTable.get(isSending ? "send" : "recv");
Change change = changeTable.get(action);
if (change.newAsk != null && change.newAsk != item.getAskStatus()) {
item.setAskStatus(change.newAsk);
}
if (change.newSub != null && change.newSub != item.getSubStatus()) {
item.setSubStatus(change.newSub);
}
if (change.newRecv != null && change.newRecv != item.getRecvStatus()) {
item.setRecvStatus(change.newRecv);
}
}
示例11: createPresence
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Create a new presence in this room for the given role.
*
* @param type Type of presence to create (cannot be <tt>null</tt>).
* @return The new presence
* @throws UnauthorizedException If the user doesn't have permission to leave the room
*/
Presence createPresence(Presence.Type type) throws UnauthorizedException;
示例12: getStateChange
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Determine the changes to apply to the item, according to its subscription state.
* The method also turns the action and sending status into an integer code
* for easier processing (switch statements).
* <p/>
* Code relies on states being in numerical order without skipping.
* In addition, the receive states must parallel the send states
* so that (send state X) + STATE_RECV_SUBSCRIBE == (receive state X)
* where X is subscribe, subscribed, etc.
* </p>
*
* @param itemSubType The item to be updated
* @param action The new state change request
* @param isSending True if the roster owner of the item is sending the new state change request
* @return Change changes to apply to the item
*/
public static Change getStateChange(RosterItem.SubType itemSubType, Presence.Type action, boolean isSending) {
Map<String, Map<Presence.Type, Change>> srTable = stateTable.get(itemSubType);
Map<Presence.Type, Change> changeTable = srTable.get(isSending ? "send" : "recv");
return changeTable.get(action);
}