当前位置: 首页>>代码示例>>Java>>正文


Java Presence.toXML方法代码示例

本文整理汇总了Java中org.xmpp.packet.Presence.toXML方法的典型用法代码示例。如果您正苦于以下问题:Java Presence.toXML方法的具体用法?Java Presence.toXML怎么用?Java Presence.toXML使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.xmpp.packet.Presence的用法示例。


在下文中一共展示了Presence.toXML方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: userUnavailable

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void userUnavailable(Presence presence) {
    // Only save the last presence status and keep track of the time when the user went
    // offline if this is an unavailable presence sent to THE SERVER and the presence belongs
    // to a local user.
    if (presence.getTo() == null && server.isLocal(presence.getFrom())) {
        String username = presence.getFrom().getNode();
        if (username == null || !userManager.isRegisteredUser(username)) {
            // Ignore anonymous users
            return;
        }

        // If the user has any remaining sessions, don't record the offline info.
        if (sessionManager.getActiveSessionCount(username) > 0) {
            return;
        }

        String offlinePresence = null;
        // Save the last unavailable presence of this user if the presence contains any
        // child element such as <status>.
        if (!presence.getElement().elements().isEmpty()) {
            offlinePresence = presence.toXML();
        }
        // Keep track of the time when the user went offline
        java.util.Date offlinePresenceDate = new java.util.Date();

        boolean addedToCache;
        if (offlinePresence == null) {
            addedToCache = !NULL_STRING.equals(offlinePresenceCache.put(username, NULL_STRING));
        }
        else {
            addedToCache = !offlinePresence.equals(offlinePresenceCache.put(username, offlinePresence));
        }
        if (!addedToCache) {
            return;
        }
        lastActivityCache.put(username, offlinePresenceDate.getTime());

        writeToDatabase(username, offlinePresence, offlinePresenceDate);
    }
}
 
开发者ID:idwanglu2010,项目名称:openfire,代码行数:41,代码来源:PresenceManagerImpl.java

示例2: userUnavailable

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
@Override
public void userUnavailable(Presence presence) {
    // Only save the last presence status and keep track of the time when the user went
    // offline if this is an unavailable presence sent to THE SERVER and the presence belongs
    // to a local user.
    if (presence.getTo() == null && server.isLocal(presence.getFrom())) {
        String username = presence.getFrom().getNode();
        if (username == null || !userManager.isRegisteredUser(username)) {
            // Ignore anonymous users
            return;
        }

        // If the user has any remaining sessions, don't record the offline info.
        if (sessionManager.getActiveSessionCount(username) > 0) {
            return;
        }

        String offlinePresence = null;
        // Save the last unavailable presence of this user if the presence contains any
        // child element such as <status>.
        if (!presence.getElement().elements().isEmpty()) {
            offlinePresence = presence.toXML();
        }
        // Keep track of the time when the user went offline
        java.util.Date offlinePresenceDate = new java.util.Date();

        boolean addedToCache;
        if (offlinePresence == null) {
            addedToCache = !NULL_STRING.equals(offlinePresenceCache.put(username, NULL_STRING));
        }
        else {
            addedToCache = !offlinePresence.equals(offlinePresenceCache.put(username, offlinePresence));
        }
        if (!addedToCache) {
            return;
        }
        lastActivityCache.put(username, offlinePresenceDate.getTime());

        writeToDatabase(username, offlinePresence, offlinePresenceDate);
    }
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:42,代码来源:PresenceManagerImpl.java

示例3: userUnavailable

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void userUnavailable(Presence presence) {
    // Only save the last presence status and keep track of the time when the user went
    // offline if this is an unavailable presence sent to THE SERVER and the presence belongs
    // to a local user.
    if (presence.getTo() == null && server.isLocal(presence.getFrom())) {
        String username = presence.getFrom().getNode();
        if (username == null || !userManager.isRegisteredUser(username)) {
            // Ignore anonymous users
            return;
        }

        // If the user has any remaining sessions, don't record the offline info.
        if (sessionManager.getActiveSessionCount(username) > 0) {
            return;
        }

        String offlinePresence = null;
        // Save the last unavailable presence of this user if the presence contains any
        // child element such as <status>.
        if (!presence.getElement().elements().isEmpty()) {
            offlinePresence = presence.toXML();
        }
        // Keep track of the time when the user went offline
        java.util.Date offlinePresenceDate = new java.util.Date();

        boolean addedToCache;
        if (offlinePresence == null) {
            addedToCache = !NULL_STRING.equals(offlinePresenceCache.put(username, NULL_STRING));
        }
        else {
            addedToCache = !offlinePresence.equals(offlinePresenceCache.put(username, offlinePresence));
        }
        if (!addedToCache) {
            return;
        }
        lastActivityCache.put(username, offlinePresenceDate.getTime());

        // Insert data into the database.
        Connection con = null;
        PreparedStatement pstmt = null;
        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(INSERT_OFFLINE_PRESENCE);
            pstmt.setString(1, username);
            if (offlinePresence != null) {
                DbConnectionManager.setLargeTextField(pstmt, 2, offlinePresence);
            }
            else {
                pstmt.setNull(2, Types.VARCHAR);
            }
            pstmt.setString(3, StringUtils.dateToMillis(offlinePresenceDate));
            pstmt.execute();
        }
        catch (SQLException sqle) {
            Log.error("Error storing offline presence of user: " + username, sqle);
        }
        finally {
            DbConnectionManager.closeConnection(pstmt, con);
        }
    }
}
 
开发者ID:coodeer,项目名称:g3server,代码行数:62,代码来源:PresenceManagerImpl.java


注:本文中的org.xmpp.packet.Presence.toXML方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。