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


Java Presence类代码示例

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


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

示例1: route

import org.xmpp.packet.Presence; //导入依赖的package包/类
/**
 * 路由这个Presence包
 * 
 * @param packet
 */
public void route(Presence packet) {
	if (packet == null) {
		throw new NullPointerException();
	}
	ClientSession session = sessionManager.getSession(packet.getFrom());

	if (session == null || session.getStatus() != Session.STATUS_CONNECTED) {
		handle(packet);
	} else {
		packet.setTo(session.getAddress());
		packet.setFrom((JID) null);
		packet.setError(PacketError.Condition.not_authorized);
		session.process(packet);
	}
}
 
开发者ID:lijian17,项目名称:androidpn-server,代码行数:21,代码来源:PresenceRouter.java

示例2: 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();
		}
	}
}
 
开发者ID:lijian17,项目名称:androidpn-server,代码行数:24,代码来源:PresenceRouter.java

示例3: sendInfo

import org.xmpp.packet.Presence; //导入依赖的package包/类
@Override
public void sendInfo(HttpServletRequest request,
        HttpServletResponse response, Presence presence) throws IOException {
    if (presence == null) {
        writeImageContent(request, response, "offline", servlet.offline);
    }
    else if (presence.getShow() == null) {
        writeImageContent(request, response, "available", servlet.available);
    }
    else if (presence.getShow().equals(org.xmpp.packet.Presence.Show.away)) {
        writeImageContent(request, response, "away", servlet.away);
    }
    else if (presence.getShow().equals(org.xmpp.packet.Presence.Show.chat)) {
        writeImageContent(request, response, "chat", servlet.chat);
    }
    else if (presence.getShow().equals(org.xmpp.packet.Presence.Show.dnd)) {
        writeImageContent(request, response, "dnd", servlet.dnd);
    }
    else if (presence.getShow().equals(org.xmpp.packet.Presence.Show.xa)) {
        writeImageContent(request, response, "xa", servlet.xa);
    }
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:23,代码来源:ImagePresenceProvider.java

示例4: initializePlugin

import org.xmpp.packet.Presence; //导入依赖的package包/类
public void initializePlugin(PluginManager manager, File pluginDirectory) {
    pluginManager = manager;
    XMPPServer server = XMPPServer.getInstance();
    userManager = server.getUserManager();
    presenceManager = server.getPresenceManager();
    hostname = server.getServerInfo().getXMPPDomain();
    probedPresence = new ConcurrentHashMap<String, Presence>();
    componentJID = new JID(subdomain + "." + hostname);
    // Register new component
    componentManager = ComponentManagerFactory.getComponentManager();
    try {
        componentManager.addComponent(subdomain, this);
    }
    catch (Exception e) {
        Log.error(e.getMessage(), e);
    }
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:18,代码来源:PresencePlugin.java

示例5: process

import org.xmpp.packet.Presence; //导入依赖的package包/类
/**
 * Handle presence updates that affect roster subscriptions.
 *
 * @param presence The presence presence to handle
 * @throws PacketException if the packet is null or the packet could not be routed.
 */
public void process(Presence presence) throws PacketException {
    try {
        process((Packet)presence);
    }
    catch (UnauthorizedException e) {
        try {
            LocalSession session = (LocalSession) sessionManager.getSession(presence.getFrom());
            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.not_authorized);
            deliverer.deliver(presence);
        }
        catch (Exception err) {
            Log.error(LocaleUtils.getLocalizedString("admin.error"), err);
        }
    }
}
 
开发者ID:coodeer,项目名称:g3server,代码行数:32,代码来源:PresenceUpdateHandler.java

示例6: setVerboseStatus

import org.xmpp.packet.Presence; //导入依赖的package包/类
/**
 * Sets the current verbose status.
 *
 * @param newstatus New verbose status.
 */
public void setVerboseStatus(String newstatus) {
    if (newstatus == null) {
        newstatus = "";
    }
    if (!verboseStatus.equals(newstatus)) {
        Presence p = new Presence();
        p.setTo(getManager().getSession().getJID());
        p.setFrom(jid);
        getManager().getSession().getTransport().setUpPresencePacket(p, presence);
        if (!newstatus.equals("")) {
            p.setStatus(newstatus);
        }
        if (avatarSet && avatar != null) {
            Element vcard = p.addChildElement("x", NameSpace.VCARD_TEMP_X_UPDATE);
            vcard.addElement("photo").addCDATA(avatar.getXmppHash());
            vcard.addElement("hash").addCDATA(avatar.getXmppHash());
        }
        getManager().sendPacket(p);
    }
    verboseStatus = newstatus;
    lastActivityTimestamp = new Date().getTime();
    lastActivityEvent = verboseStatus;
}
 
开发者ID:coodeer,项目名称:g3server,代码行数:29,代码来源:TransportBuddy.java

示例7: addParticipant

import org.xmpp.packet.Presence; //导入依赖的package包/类
@Override
public Presence addParticipant(JID jid, String reason, MUCRole senderRole)
        throws NotAllowedException, ForbiddenException {
    if (MUCRole.Role.moderator != senderRole.getRole()) {
        throw new ForbiddenException();
    }
    // Update the presence with the new role and inform all occupants
    Presence updatedPresence = changeOccupantRole(jid, MUCRole.Role.participant);
    if (updatedPresence != null) {
        Element frag = updatedPresence.getChildElement(
                "x", "http://jabber.org/protocol/muc#user");
        // Add the reason why the user was granted voice
        if (reason != null && reason.trim().length() > 0) {
            frag.element("item").addElement("reason").setText(reason);
        }
    }
    return updatedPresence;
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:19,代码来源:LocalMUCRoom.java

示例8: setMembersOnly

import org.xmpp.packet.Presence; //导入依赖的package包/类
public List<Presence> setMembersOnly(boolean membersOnly) {
    List<Presence> presences = new ArrayList<Presence>();
    if (membersOnly && !this.membersOnly) {
        // If the room was not members-only and now it is, kick occupants that aren't member
        // of the room
        for (MUCRole occupant : occupantsByFullJID.values()) {
            if (occupant.getAffiliation().compareTo(MUCRole.Affiliation.member) > 0) {
                try {
                    presences.add(kickOccupant(occupant.getRoleAddress(), null,
                            LocaleUtils.getLocalizedString("muc.roomIsNowMembersOnly")));
                }
                catch (NotAllowedException e) {
                    Log.error(e.getMessage(), e);
                }
            }
        }
    }
    this.membersOnly = membersOnly;
    return presences;
}
 
开发者ID:idwanglu2010,项目名称:openfire,代码行数:21,代码来源:LocalMUCRoom.java

示例9: sendInfo

import org.xmpp.packet.Presence; //导入依赖的package包/类
@Override
public void sendInfo(HttpServletRequest request,
           HttpServletResponse response, Presence presence) throws IOException {
       if (presence == null) {
           writeImageContent(request, response, "offline", servlet.offline);
       }
       else if (presence.getShow() == null) {
           writeImageContent(request, response, "available", servlet.available);
       }
       else if (presence.getShow().equals(org.xmpp.packet.Presence.Show.away)) {
           writeImageContent(request, response, "away", servlet.away);
       }
       else if (presence.getShow().equals(org.xmpp.packet.Presence.Show.chat)) {
           writeImageContent(request, response, "chat", servlet.chat);
       }
       else if (presence.getShow().equals(org.xmpp.packet.Presence.Show.dnd)) {
           writeImageContent(request, response, "dnd", servlet.dnd);
       }
       else if (presence.getShow().equals(org.xmpp.packet.Presence.Show.xa)) {
           writeImageContent(request, response, "xa", servlet.xa);
       }
   }
 
开发者ID:coodeer,项目名称:g3server,代码行数:23,代码来源:ImagePresenceProvider.java

示例10: notifyConnectionError

import org.xmpp.packet.Presence; //导入依赖的package包/类
/**
 * Sends out a notification that there was an error with the connection and
 * closes the connection. Also prints the stack trace of the given exception
 * 
 * @param e
 *            the exception that causes the connection close event.
 */
synchronized void notifyConnectionError(Exception e) {
    // Listeners were already notified of the exception, return right here.
    if ((packetReader == null || packetReader.done)
            && (packetWriter == null || packetWriter.done))
        return;

    if (packetReader != null)
        packetReader.done = true;
    if (packetWriter != null)
        packetWriter.done = true;
    // Closes the connection temporary. A reconnection is possible
    shutdown(new Presence(Presence.Type.unavailable));
    // Notify connection listeners of the error.
    for (ConnectionListener listener : getConnectionListeners()) {
        try {
            listener.connectionClosedOnError(e);
        } catch (Exception e2) {
            // Catch and print any exception so we can recover
            // from a faulty listener
            e2.printStackTrace();
        }
    }
}
 
开发者ID:abmargb,项目名称:jamppa,代码行数:31,代码来源:XMPPConnection.java

示例11: onConnectionClose

import org.xmpp.packet.Presence; //导入依赖的package包/类
public void onConnectionClose(Object handback) {
    try {
        ClientSession session = (ClientSession) handback;
        try {
            if ((session.getPresence().isAvailable() || !session
                    .wasAvailable())) {
                // Send an unavailable presence to the user's subscribers
                Presence presence = new Presence();
                presence.setType(Presence.Type.unavailable);
                presence.setFrom(session.getAddress());
                // router.route(presence);
            }
        } finally {
            removeSession(session);
        }
    } catch (Exception e) {
        // Can't do anything about this problem...
        log.error("Could not close socket", e);
    }
}
 
开发者ID:elphinkuo,项目名称:Androidpn,代码行数:21,代码来源:SessionManager.java

示例12: presenceSubscriptionRequired

import org.xmpp.packet.Presence; //导入依赖的package包/类
/**
 * Requests the pubsub service to unsubscribe from the presence of the user. If the service
 * was not subscribed to the user's presence or any node still requires to be subscribed to
 * the user presence then do nothing.
 *
 * @param service the PubSub service this action is to be performed for.
 * @param node the node that originated the unsubscription request.
 * @param user the JID of the affiliate to unsubscribe from his presence.
 */
public static void presenceSubscriptionRequired(PubSubService service, Node node, JID user) {
    Map<String, String> fullPresences = service.getBarePresences().get(user.toString());
    if (fullPresences == null || fullPresences.isEmpty()) {
        Presence subscription = new Presence(Presence.Type.subscribe);
        subscription.setTo(user);
        subscription.setFrom(service.getAddress());
        service.send(subscription);
        // Sending subscription requests based on received presences may generate
        // that a sunscription request is sent to an offline user (since offline
        // presences are not stored in the service's "barePresences"). However, this
        // not optimal algorithm shouldn't bother the user since the user's server
        // should reply when already subscribed to the user's presence instead of
        // asking the user to accept the subscription request.
    }
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:25,代码来源:PubSubEngine.java

示例13: process

import org.xmpp.packet.Presence; //导入依赖的package包/类
public void process(Packet packet) {
    InterceptorManager interceptorManager = WorkgroupInterceptorManager.getInstance();
    try {
        interceptorManager.invokeInterceptors(getJID().toBareJID(), packet, true, false);

        String mucDomain = WorkgroupManager.getInstance().getMUCServiceName();
        if (mucDomain.equals(packet.getFrom().getDomain())) {
            roomActivity(packet);
        }
        else if (packet instanceof Message) {
            process((Message)packet);
        }
        else if (packet instanceof Presence) {
            process((Presence)packet);
        }
        else if (packet instanceof IQ) {
            process((IQ)packet);
        }
        interceptorManager.invokeInterceptors(getJID().toBareJID(), packet, true, true);
    }
    catch (PacketRejectedException e) {
        rejectPacket(packet, e);
    }
}
 
开发者ID:coodeer,项目名称:g3server,代码行数:25,代码来源:Workgroup.java

示例14: broadcastPresenceToOtherResources

import org.xmpp.packet.Presence; //导入依赖的package包/类
/**
 * Broadcasts presence updates from the originating user's resource to any of the user's
 * existing available resources (if any).
 *
 * @param originatingResource the full JID of the session that sent the presence update.
 * @param presence the presence.
 */
public void broadcastPresenceToOtherResources(JID originatingResource, Presence presence) {
    // RFC 6121 4.4.2 says we always send to the originating resource.
    // Also RFC 6121 4.2.2 for updates.
    presence.setTo(originatingResource);
    routingTable.routePacket(originatingResource, presence, false);
    if (!SessionManager.isOtherResourcePresenceEnabled()) {
        return;
    }
    // Get list of sessions of the same user
    JID searchJID = new JID(originatingResource.getNode(), originatingResource.getDomain(), null);
    List<JID> addresses = routingTable.getRoutes(searchJID, null);
    for (JID address : addresses) {
        if (!originatingResource.equals(address)) {
            // Send the presence of the session whose presence has changed to
            // this user's other session(s)
            presence.setTo(address);
            routingTable.routePacket(address, presence, false);
        }
    }
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:28,代码来源:SessionManager.java

示例15: workgroupDestroyed

import org.xmpp.packet.Presence; //导入依赖的package包/类
/**
 * The workgroup is being destroyed so remove all the accepted presence subscriptions.
 */
void workgroupDestroyed() {
    TaskEngine.getInstance().submit(new Runnable() {
        public void run() {
            try {
                for (String bareJID : presenceSubscribers) {
                    // Cancel the previously granted subscription request
                    Presence reply = new Presence();
                    reply.setTo(bareJID);
                    reply.setFrom(workgroup.getJID());
                    reply.setType(Presence.Type.unsubscribed);
                    workgroup.send(reply);
                }
                // Delete the subscribers from the database
                deleteRosterItems();
            }
            catch (Exception e) {
                Log.error(
                        "Error broadcasting available presence", e);
            }
        }
    });
}
 
开发者ID:idwanglu2010,项目名称:openfire,代码行数:26,代码来源:WorkgroupPresence.java


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