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


Java Type类代码示例

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


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

示例1: sendStanza

import org.jivesoftware.smack.packet.IQ.Type; //导入依赖的package包/类
@Override
public void sendStanza(Stanza packet) throws NotConnectedException {
    super.sendStanza(packet);

    if (packet instanceof IQ && !timeout) {
        timeout = false;
        // Set reply packet to match one being sent. We haven't started the
        // other thread yet so this is still safe.
        IQ replyPacket = replyQ.peek();

        // If no reply has been set via addIQReply, then we create a simple reply
        if (replyPacket == null) {
            replyPacket = IQ.createResultIQ((IQ) packet);
            replyQ.add(replyPacket);
        }
        replyPacket.setStanzaId(packet.getStanzaId());
        replyPacket.setFrom(packet.getTo());
        replyPacket.setTo(packet.getFrom());
        replyPacket.setType(Type.result);

        new ProcessQueue(replyQ).start();
    }
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:24,代码来源:ThreadedDummyConnection.java

示例2: removeEntry

import org.jivesoftware.smack.packet.IQ.Type; //导入依赖的package包/类
/**
 * Removes a roster entry from the roster. The roster entry will also be removed from the
 * unfiled entries or from any roster group where it could belong and will no longer be part
 * of the roster. Note that this is a synchronous call -- Smack must wait for the server
 * to send an updated subscription status.
 *
 * @param entry a roster entry.
 * @throws XMPPErrorException if an XMPP error occurs.
 * @throws NotLoggedInException if not logged in.
 * @throws NoResponseException SmackException if there was no response from the server.
 * @throws NotConnectedException 
 * @throws IllegalStateException if connection is not logged in or logged in anonymously
 */
public void removeEntry(RosterEntry entry) throws NotLoggedInException, NoResponseException, XMPPErrorException, NotConnectedException {
    final XMPPConnection connection = connection();
    if (!connection.isAuthenticated()) {
        throw new NotLoggedInException();
    }
    if (connection.isAnonymous()) {
        throw new IllegalStateException("Anonymous users can't have a roster.");
    }

    // Only remove the entry if it's in the entry list.
    // The actual removal logic takes place in RosterPacketListenerprocess>>Packet(Packet)
    if (!entries.containsKey(entry.getUser())) {
        return;
    }
    RosterPacket packet = new RosterPacket();
    packet.setType(IQ.Type.set);
    RosterPacket.Item item = RosterEntry.toRosterItem(entry);
    // Set the item type as REMOVE so that the server will delete the entry
    item.setItemType(RosterPacket.ItemType.remove);
    packet.addRosterItem(item);
    connection.createPacketCollectorAndSend(packet).nextResultOrThrow();
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:36,代码来源:Roster.java

示例3: getAllPresences

import org.jivesoftware.smack.packet.IQ.Type; //导入依赖的package包/类
/**
 * Returns a List of Presence objects for all of a user's current presences if no presence information is available,
 * such as when you are not subscribed to the user's presence updates.
 *
 * @param bareJid an XMPP ID, e.g. [email protected]
 * @return a List of Presence objects for all the user's current presences, or an unavailable presence if no
 *         presence information is available.
 */
public List<Presence> getAllPresences(String bareJid) {
    Map<String, Presence> userPresences = presenceMap.get(getMapKey(bareJid));
    List<Presence> res;
    if (userPresences == null) {
        // Create an unavailable presence if none was found
        Presence unavailable = new Presence(Presence.Type.unavailable);
        unavailable.setFrom(bareJid);
        res = new ArrayList<>(Arrays.asList(unavailable));
    } else {
        res = new ArrayList<>(userPresences.values().size());
        for (Presence presence : userPresences.values()) {
            res.add(presence.clone());
        }
    }
    return res;
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:25,代码来源:Roster.java

示例4: testIgnoreInvalidFrom

import org.jivesoftware.smack.packet.IQ.Type; //导入依赖的package包/类
/**
 * Tests that roster pushes with invalid from are ignored.
 *
 * @see <a href="http://xmpp.org/rfcs/rfc6121.html#roster-syntax-actions-push">RFC 6121, Section 2.1.6</a>
 */
@Test
public void testIgnoreInvalidFrom() {
    RosterPacket packet = new RosterPacket();
    packet.setType(Type.set);
    packet.setTo(connection.getUser());
    packet.setFrom("[email protected]");
    packet.addRosterItem(new Item("[email protected]", "Cool products!"));

    final String requestId = packet.getStanzaId();
    // Simulate receiving the roster push
    connection.processPacket(packet);

    // Smack should reply with an error IQ
    ErrorIQ errorIQ = (ErrorIQ) connection.getSentPacket();
    assertEquals(requestId, errorIQ.getStanzaId());
    assertEquals(Condition.service_unavailable, errorIQ.getError().getCondition());

    assertNull("Contact was added to roster", Roster.getInstanceFor(connection).getEntry("[email protected]"));
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:25,代码来源:RosterTest.java

示例5: removeAllRosterEntries

import org.jivesoftware.smack.packet.IQ.Type; //导入依赖的package包/类
/**
 * Remove all roster entries by iterating trough {@link Roster#getEntries()}
 * and simulating receiving roster pushes from the server.
 * 
 * @param connection the dummy connection of which the provided roster belongs to.
 * @param roster the roster (or buddy list) which should be initialized.
 */
public static void removeAllRosterEntries(DummyConnection connection, Roster roster)
        throws InterruptedException, XMPPException {
    for(RosterEntry entry : roster.getEntries()) {
        // prepare the roster push packet
        final RosterPacket rosterPush= new RosterPacket();
        rosterPush.setType(Type.set);
        rosterPush.setTo(connection.getUser());

        // prepare the buddy's item entry which should be removed
        final RosterPacket.Item item = new RosterPacket.Item(entry.getUser(), entry.getName());
        item.setItemType(ItemType.remove);
        rosterPush.addRosterItem(item);

        // simulate receiving the roster push
        connection.processPacket(rosterPush);
    }
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:25,代码来源:RosterTest.java

示例6: createNode

import org.jivesoftware.smack.packet.IQ.Type; //导入依赖的package包/类
/**
 * Creates a node with specified configuration.
 * 
 * Note: This is the only way to create a collection node.
 * 
 * @param name The name of the node, which must be unique within the 
 * pubsub service
 * @param config The configuration for the node
 * @return The node that was created
 * @throws XMPPErrorException 
 * @throws NoResponseException 
 * @throws NotConnectedException 
 */
public Node createNode(String name, Form config) throws NoResponseException, XMPPErrorException, NotConnectedException
{
	PubSub request = PubSub.createPubsubPacket(to, Type.set, new NodeExtension(PubSubElementType.CREATE, name), null);
	boolean isLeafNode = true;
	
	if (config != null)
	{
		request.addExtension(new FormNode(FormNodeType.CONFIGURE, config));
		FormField nodeTypeField = config.getField(ConfigureNodeFields.node_type.getFieldName());
		
		if (nodeTypeField != null)
			isLeafNode = nodeTypeField.getValues().get(0).equals(NodeType.leaf.toString());
	}

	// Errors will cause exceptions in getReply, so it only returns
	// on success.
	sendPubsubPacket(con, request);
	Node newNode = isLeafNode ? new LeafNode(con, name) : new CollectionNode(con, name);
	newNode.setTo(to);
	nodeMap.put(newNode.getId(), newNode);
	
	return newNode;
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:37,代码来源:PubSubManager.java

示例7: getSubscriptions

import org.jivesoftware.smack.packet.IQ.Type; //导入依赖的package包/类
private List<Subscription> getSubscriptions(List<ExtensionElement> additionalExtensions,
                Collection<ExtensionElement> returnedExtensions, PubSubNamespace pubSubNamespace)
                throws NoResponseException, XMPPErrorException, NotConnectedException {
    PubSub pubSub = createPubsubPacket(Type.get, new NodeExtension(PubSubElementType.SUBSCRIPTIONS, getId()), pubSubNamespace);
    if (additionalExtensions != null) {
        for (ExtensionElement pe : additionalExtensions) {
            pubSub.addExtension(pe);
        }
    }
    PubSub reply = sendPubsubPacket(pubSub);
    if (returnedExtensions != null) {
        returnedExtensions.addAll(reply.getExtensions());
    }
    SubscriptionsExtension subElem = (SubscriptionsExtension) reply.getExtension(PubSubElementType.SUBSCRIPTIONS);
    return subElem.getSubscriptions();
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:17,代码来源:Node.java

示例8: getAffiliations

import org.jivesoftware.smack.packet.IQ.Type; //导入依赖的package包/类
/**
 * Get the affiliations of this node.
 * <p>
 * {@code additionalExtensions} can be used e.g. to add a "Result Set Management" extension.
 * {@code returnedExtensions} will be filled with the stanza(/packet) extensions found in the answer.
 * </p>
 *
 * @param additionalExtensions additional {@code PacketExtensions} add to the request
 * @param returnedExtensions a collection that will be filled with the returned packet
 *        extensions
 * @return List of {@link Affiliation}
 * @throws NoResponseException
 * @throws XMPPErrorException
 * @throws NotConnectedException
 */
public List<Affiliation> getAffiliations(List<ExtensionElement> additionalExtensions, Collection<ExtensionElement> returnedExtensions)
                throws NoResponseException, XMPPErrorException, NotConnectedException {
    PubSub pubSub = createPubsubPacket(Type.get, new NodeExtension(PubSubElementType.AFFILIATIONS, getId()));
    if (additionalExtensions != null) {
        for (ExtensionElement pe : additionalExtensions) {
            pubSub.addExtension(pe);
        }
    }
    PubSub reply = sendPubsubPacket(pubSub);
    if (returnedExtensions != null) {
        returnedExtensions.addAll(reply.getExtensions());
    }
    AffiliationsExtension affilElem = (AffiliationsExtension) reply.getExtension(PubSubElementType.AFFILIATIONS);
    return affilElem.getAffiliations();
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:31,代码来源:Node.java

示例9: EntityTimeManager

import org.jivesoftware.smack.packet.IQ.Type; //导入依赖的package包/类
private EntityTimeManager(XMPPConnection connection) {
    super(connection);
    if (autoEnable)
        enable();

    connection.registerIQRequestHandler(new AbstractIqRequestHandler(Time.ELEMENT, Time.NAMESPACE, Type.get,
                    Mode.async) {
        @Override
        public IQ handleIQRequest(IQ iqRequest) {
            if (enabled) {
                return Time.createResponse(iqRequest);
            }
            else {
                return IQ.createErrorResponse(iqRequest, new XMPPError(Condition.not_acceptable));
            }
        }
    });
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:19,代码来源:EntityTimeManager.java

示例10: createNode

import org.jivesoftware.smack.packet.IQ.Type; //导入依赖的package包/类
/**
 * Creates a node with specified configuration.
 * 
 * Note: This is the only way to create a collection node.
 * 
 * @param name The name of the node, which must be unique within the 
 * pubsub service
 * @param config The configuration for the node
 * @return The node that was created
 * @exception XMPPException
 */
public Node createNode(String name, Form config)
	throws XMPPException
{
	PubSub request = createPubsubPacket(to, Type.SET, new NodeExtension(PubSubElementType.CREATE, name));
	boolean isLeafNode = true;
	
	if (config != null)
	{
		request.addExtension(new FormNode(FormNodeType.CONFIGURE, config));
		FormField nodeTypeField = config.getField(ConfigureNodeFields.node_type.getFieldName());
		
		if (nodeTypeField != null)
			isLeafNode = nodeTypeField.getValues().next().equals(NodeType.leaf.toString());
	}

	// Errors will cause exceptions in getReply, so it only returns
	// on success.
	sendPubsubPacket(con, to, Type.SET, request);
	Node newNode = isLeafNode ? new LeafNode(con, name) : new CollectionNode(con, name);
	newNode.setTo(to);
	nodeMap.put(newNode.getId(), newNode);
	
	return newNode;
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:36,代码来源:PubSubManager.java

示例11: getItems

import org.jivesoftware.smack.packet.IQ.Type; //导入依赖的package包/类
/**
 * Get the items specified from the node.  This would typically be
 * used when the server does not return the payload due to size 
 * constraints.  The user would be required to retrieve the payload 
 * after the items have been retrieved via {@link #getItems()} or an
 * event, that did not include the payload.
 * 
 * @param ids Item ids of the items to retrieve
 * 
 * @return The list of {@link Item} with payload
 * 
 * @throws XMPPException
 */
public <T extends Item> List<T> getItems(Collection<String> ids)
	throws XMPPException
{
	List<Item> itemList = new ArrayList<Item>(ids.size());
	
	for (String id : ids)
	{
		itemList.add(new Item(id));
	}
	PubSub request = createPubsubPacket(Type.GET, new ItemsExtension(ItemsExtension.ItemsElementType.items, getId(), itemList));
	
	PubSub result = (PubSub)SyncPacketSend.getReply(con, request);
	ItemsExtension itemsElem = (ItemsExtension)result.getExtension(PubSubElementType.ITEMS);
	return (List<T>)itemsElem.getItems();
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:29,代码来源:LeafNode.java

示例12: sendReadedInfo

import org.jivesoftware.smack.packet.IQ.Type; //导入依赖的package包/类
public static void sendReadedInfo(String packetId, String to) {
	IQ result = new IQ() {
		@Override
		public String getChildElementXML() {
			return null;
		}
	};
	result.setType(Type.RESULT);
	result.setPacketID(packetId);
	result.setTo(to);
	try {
		Constants.xmppManager.getConnection().sendPacket(result);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:bestarandyan,项目名称:ShoppingMall,代码行数:17,代码来源:Notifier.java

示例13: setStatusFromConfig

import org.jivesoftware.smack.packet.IQ.Type; //导入依赖的package包/类
@Override
public void setStatusFromConfig() {// 设置自己的当前状态,供外部服务调用
	boolean messageCarbons = PreferenceUtils.getPrefBoolean(mService,
			PreferenceConstants.MESSAGE_CARBONS, true);
	String statusMode = PreferenceUtils.getPrefString(mService,
			PreferenceConstants.STATUS_MODE, PreferenceConstants.AVAILABLE);
	String statusMessage = PreferenceUtils.getPrefString(mService,
			PreferenceConstants.STATUS_MESSAGE,
			mService.getString(R.string.status_online));
	int priority = PreferenceUtils.getPrefInt(mService,
			PreferenceConstants.PRIORITY, 0);
	if (messageCarbons)
		CarbonManager.getInstanceFor(mXMPPConnection).sendCarbonsEnabled(
				true);

	Presence presence = new Presence(Presence.Type.available);
	Mode mode = Mode.valueOf(statusMode);
	presence.setMode(mode);
	presence.setStatus(statusMessage);
	presence.setPriority(priority);
	mXMPPConnection.sendPacket(presence);
}
 
开发者ID:victoryckl,项目名称:XmppTest,代码行数:23,代码来源:SmackImpl.java

示例14: sendMessage

import org.jivesoftware.smack.packet.IQ.Type; //导入依赖的package包/类
@Override
public void sendMessage(String toJID, String message) {// 发送消息
	// TODO Auto-generated method stub
	final Message newMessage = new Message(toJID, Message.Type.chat);
	newMessage.setBody(message);
	newMessage.addExtension(new DeliveryReceiptRequest());
	if (isAuthenticated()) {
		addChatMessageToDB(ChatConstants.OUTGOING, toJID, message,
				ChatConstants.DS_SENT_OR_READ, System.currentTimeMillis(),
				newMessage.getPacketID());
		mXMPPConnection.sendPacket(newMessage);
	} else {
		// send offline -> store to DB
		addChatMessageToDB(ChatConstants.OUTGOING, toJID, message,
				ChatConstants.DS_NEW, System.currentTimeMillis(),
				newMessage.getPacketID());
	}
}
 
开发者ID:victoryckl,项目名称:XmppTest,代码行数:19,代码来源:SmackImpl.java

示例15: sendServerPing

import org.jivesoftware.smack.packet.IQ.Type; //导入依赖的package包/类
@Override
public void sendServerPing() {
	if (mPingID != null) {// 此时说明上一次ping服务器还未回应,直接返回,直到连接超时
		L.d("Ping: requested, but still waiting for " + mPingID);
		return; // a ping is still on its way
	}
	Ping ping = new Ping();
	ping.setType(Type.GET);
	ping.setTo(PreferenceUtils.getPrefString(mService,
			PreferenceConstants.Server, PreferenceConstants.GMAIL_SERVER));
	mPingID = ping.getPacketID();// 此id其实是随机生成,但是唯一的
	mPingTimestamp = System.currentTimeMillis();
	L.d("Ping: sending ping " + mPingID);
	mXMPPConnection.sendPacket(ping);// 发送ping消息

	// register ping timeout handler: PACKET_TIMEOUT(30s) + 3s
	((AlarmManager) mService.getSystemService(Context.ALARM_SERVICE)).set(
			AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
					+ PACKET_TIMEOUT + 3000, mPongTimeoutAlarmPendIntent);// 此时需要启动超时判断的闹钟了,时间间隔为30+3秒
}
 
开发者ID:victoryckl,项目名称:XmppTest,代码行数:21,代码来源:SmackImpl.java


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