當前位置: 首頁>>代碼示例>>Java>>正文


Java Presence.getError方法代碼示例

本文整理匯總了Java中org.jivesoftware.smack.packet.Presence.getError方法的典型用法代碼示例。如果您正苦於以下問題:Java Presence.getError方法的具體用法?Java Presence.getError怎麽用?Java Presence.getError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jivesoftware.smack.packet.Presence的用法示例。


在下文中一共展示了Presence.getError方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getInitialOnlineUsers

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
 * Get online users from roster and store in onlineUsers
 */
private void getInitialOnlineUsers() {
	Roster roster = Roster.getInstanceFor(connection);
	Collection<RosterEntry> entries = roster.getEntries();
	if (entries != null && !entries.isEmpty()) {
		for (RosterEntry entry : entries) {
			String jid = entry.getUser();
			Presence presence = roster.getPresence(jid);
			if (presence != null) {
				XMPPError xmppError = presence.getError();
				if (xmppError != null) {
					logger.error(xmppError.getDescriptiveText());
				} else {
					try {
						if (presence.getType() == Type.available) {
							onlineUsers.add(jid.substring(0, jid.indexOf('@')));
						} else if (presence.getType() == Type.unavailable) {
							onlineUsers.remove(jid.substring(0, jid.indexOf('@')));
						}
					} catch (Exception e) {
						logger.error(e.getMessage(), e);
					}
				}
			}
		}
	}
	logger.debug("Online users: {}", onlineUsers.toString());
}
 
開發者ID:Pardus-LiderAhenk,項目名稱:lider,代碼行數:31,代碼來源:OnlineRosterListener.java

示例2: isAgentOnline

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
 * Checks the availability of the specified agent.
 *
 * @param agentJID the jid of the agent to check.
 * @return true if the agent is available to accept a request.
 */
public static boolean isAgentOnline(String agentJID) {
    ChatManager chatManager = ChatManager.getInstance();
    XMPPConnection globalConnection = chatManager.getGlobalConnection();

    Presence directedPresence = new Presence(Presence.Type.available);
    directedPresence.setProperty("anonymous", true);
    directedPresence.setTo(agentJID);
    PacketFilter typeFilter = new PacketTypeFilter(Presence.class);
    PacketFilter fromFilter = new FromContainsFilter(agentJID);
    PacketCollector collector = globalConnection.createPacketCollector(new AndFilter(fromFilter,
            typeFilter));

    globalConnection.sendPacket(directedPresence);

    Presence response = (Presence)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        return false;
    }
    if (response.getError() != null) {
        return false;
    }
    return Presence.Type.available == response.getType();
}
 
開發者ID:igniterealtime,項目名稱:Fastpath-webchat,代碼行數:33,代碼來源:WorkgroupStatus.java

示例3: create

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
 * Creates the room according to some default configuration, assign the requesting user
 * as the room owner, and add the owner to the room but not allow anyone else to enter
 * the room (effectively "locking" the room). The requesting user will join the room
 * under the specified nickname as soon as the room has been created.<p>
 *
 * To create an "Instant Room", that means a room with some default configuration that is
 * available for immediate access, the room's owner should send an empty form after creating
 * the room. {@link #sendConfigurationForm(Form)}<p>
 *
 * To create a "Reserved Room", that means a room manually configured by the room creator
 * before anyone is allowed to enter, the room's owner should complete and send a form after
 * creating the room. Once the completed configutation form is sent to the server, the server
 * will unlock the room. {@link #sendConfigurationForm(Form)}
 *
 * @param nickname the nickname to use.
 * @throws XMPPException if the room couldn't be created for some reason
 *          (e.g. room already exists; user already joined to an existant room or
 *          405 error if the user is not allowed to create the room)
 */
public synchronized void create(String nickname) throws XMPPException {
    if (nickname == null || nickname.equals("")) {
        throw new IllegalArgumentException("Nickname must not be null or blank.");
    }
    // If we've already joined the room, leave it before joining under a new
    // nickname.
    if (joined) {
        throw new IllegalStateException("Creation failed - User already joined the room.");
    }
    // We create a room by sending a presence packet to [email protected]/nick
    // and signal support for MUC. The owner will be automatically logged into the room.
    Presence joinPresence = new Presence(Presence.Type.available);
    joinPresence.setTo(room + "/" + nickname);
    // Indicate the the client supports MUC
    joinPresence.addExtension(new MUCInitialPresence());
    // Invoke presence interceptors so that extra information can be dynamically added
    for (PacketInterceptor packetInterceptor : presenceInterceptors) {
        packetInterceptor.interceptPacket(joinPresence);
    }

    // Wait for a presence packet back from the server.
    PacketFilter responseFilter =
        new AndFilter(
            new FromMatchesFilter(room + "/" + nickname),
            new PacketTypeFilter(Presence.class));
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send create & join packet.
    connection.sendPacket(joinPresence);
    // Wait up to a certain number of seconds for a reply.
    Presence presence =
        (Presence) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (presence == null) {
        throw new XMPPException("No response from server.");
    }
    else if (presence.getError() != null) {
        throw new XMPPException(presence.getError());
    }
    // Whether the room existed before or was created, the user has joined the room
    this.nickname = nickname;
    joined = true;
    userHasJoined();

    // Look for confirmation of room creation from the server
    MUCUser mucUser = getMUCUserExtension(presence);
    if (mucUser != null && mucUser.getStatus() != null) {
        if ("201".equals(mucUser.getStatus().getCode())) {
            // Room was created and the user has joined the room
            return;
        }
    }
    // We need to leave the room since it seems that the room already existed
    leave();
    throw new XMPPException("Creation failed - Missing acknowledge of room creation.");
}
 
開發者ID:ice-coffee,項目名稱:EIM,代碼行數:78,代碼來源:MultiUserChat.java

示例4: changeNickname

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
 * Changes the occupant's nickname to a new nickname within the room. Each room occupant
 * will receive two presence packets. One of type "unavailable" for the old nickname and one
 * indicating availability for the new nickname. The unavailable presence will contain the new
 * nickname and an appropriate status code (namely 303) as extended presence information. The
 * status code 303 indicates that the occupant is changing his/her nickname.
 *
 * @param nickname the new nickname within the room.
 * @throws XMPPException if the new nickname is already in use by another occupant.
 */
public void changeNickname(String nickname) throws XMPPException {
    if (nickname == null || nickname.equals("")) {
        throw new IllegalArgumentException("Nickname must not be null or blank.");
    }
    // Check that we already have joined the room before attempting to change the
    // nickname.
    if (!joined) {
        throw new IllegalStateException("Must be logged into the room to change nickname.");
    }
    // We change the nickname by sending a presence packet where the "to"
    // field is in the form "[email protected]/nickname"
    // We don't have to signal the MUC support again
    Presence joinPresence = new Presence(Presence.Type.available);
    joinPresence.setTo(room + "/" + nickname);
    // Invoke presence interceptors so that extra information can be dynamically added
    for (PacketInterceptor packetInterceptor : presenceInterceptors) {
        packetInterceptor.interceptPacket(joinPresence);
    }

    // Wait for a presence packet back from the server.
    PacketFilter responseFilter =
        new AndFilter(
            new FromMatchesFilter(room + "/" + nickname),
            new PacketTypeFilter(Presence.class));
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send join packet.
    connection.sendPacket(joinPresence);
    // Wait up to a certain number of seconds for a reply.
    Presence presence =
        (Presence) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();

    if (presence == null) {
        throw new XMPPException("No response from server.");
    }
    else if (presence.getError() != null) {
        throw new XMPPException(presence.getError());
    }
    this.nickname = nickname;
}
 
開發者ID:ice-coffee,項目名稱:EIM,代碼行數:52,代碼來源:MultiUserChat.java

示例5: changeNickname

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
 * Changes the occupant's nickname to a new nickname within the room. Each
 * room occupant will receive two presence packets. One of type
 * "unavailable" for the old nickname and one indicating availability for
 * the new nickname. The unavailable presence will contain the new nickname
 * and an appropriate status code (namely 303) as extended presence
 * information. The status code 303 indicates that the occupant is changing
 * his/her nickname.
 * 
 * @param nickname
 *            the new nickname within the room.
 * @throws XMPPException
 *             if the new nickname is already in use by another occupant.
 */
public void changeNickname(String nickname) throws XMPPException {
	if (nickname == null || nickname.equals("")) {
		throw new IllegalArgumentException(
				"Nickname must not be null or blank.");
	}
	// Check that we already have joined the room before attempting to
	// change the
	// nickname.
	if (!joined) {
		throw new IllegalStateException(
				"Must be logged into the room to change nickname.");
	}
	// We change the nickname by sending a presence packet where the "to"
	// field is in the form "[email protected]/nickname"
	// We don't have to signal the MUC support again
	Presence joinPresence = new Presence(Presence.Type.available);
	joinPresence.setTo(room + "/" + nickname);
	// Invoke presence interceptors so that extra information can be
	// dynamically added
	for (PacketInterceptor packetInterceptor : presenceInterceptors) {
		packetInterceptor.interceptPacket(joinPresence);
	}

	// Wait for a presence packet back from the server.
	PacketFilter responseFilter = new AndFilter(new FromMatchesFilter(room
			+ "/" + nickname), new PacketTypeFilter(Presence.class));
	PacketCollector response = connection
			.createPacketCollector(responseFilter);
	// Send join packet.
	connection.sendPacket(joinPresence);
	// Wait up to a certain number of seconds for a reply.
	Presence presence = (Presence) response.nextResult(SmackConfiguration
			.getPacketReplyTimeout());
	// Stop queuing results
	response.cancel();

	if (presence == null) {
		throw new XMPPException("No response from server.");
	} else if (presence.getError() != null) {
		throw new XMPPException(presence.getError());
	}
	this.nickname = nickname;
}
 
開發者ID:ikantech,項目名稱:xmppsupport_v2,代碼行數:58,代碼來源:MultiUserChat.java


注:本文中的org.jivesoftware.smack.packet.Presence.getError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。