Search in sources :

Example 6 with PubSub

use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.

the class LeafNode method getItems.

/**
     * 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 XMPPErrorException 
     * @throws NoResponseException if there was no response from the server.
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public <T extends Item> List<T> getItems(Collection<String> ids) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    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));
    return getItems(request);
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) ArrayList(java.util.ArrayList)

Example 7 with PubSub

use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.

the class LeafNode method send.

/**
     * Publishes multiple events to the node.  Same rules apply as in {@link #send(Item)}.
     * 
     * In addition, if {@link ConfigureForm#isPersistItems()}=false, only the last item in the input
     * list will get stored on the node, assuming it stores the last sent item.
     *  
     * This is a synchronous call which will throw an exception 
     * on failure.
     * 
     * For asynchronous calls, use {@link #publish(Collection) publish(Collection))}.
     * 
     * @param items - The collection of {@link Item} objects being sent
     * @throws XMPPErrorException 
     * @throws NoResponseException 
     * @throws NotConnectedException 
     * @throws InterruptedException 
     * 
     */
public <T extends Item> void send(Collection<T> items) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    PubSub packet = createPubsubPacket(Type.set, new PublishItem<T>(getId(), items));
    pubSubManager.getConnection().createStanzaCollectorAndSend(packet).nextResultOrThrow();
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub)

Example 8 with PubSub

use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.

the class LeafNode method deleteAllItems.

/**
     * Purges the node of all items.
     *   
     * <p>Note: Some implementations may keep the last item
     * sent.
     * @throws XMPPErrorException 
     * @throws NoResponseException if there was no response from the server.
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public void deleteAllItems() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    PubSub request = createPubsubPacket(Type.set, new NodeExtension(PubSubElementType.PURGE_OWNER, getId()), PubSubElementType.PURGE_OWNER.getNamespace());
    pubSubManager.getConnection().createStanzaCollectorAndSend(request).nextResultOrThrow();
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub)

Example 9 with PubSub

use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.

the class LeafNode method publish.

/**
     * Publishes an event to the node.  This is an empty event
     * with no item.
     * 
     * This is only acceptable for nodes with {@link ConfigureForm#isPersistItems()}=false
     * and {@link ConfigureForm#isDeliverPayloads()}=false.
     * 
     * This is an asynchronous call which returns as soon as the 
     * stanza(/packet) has been sent.
     * 
     * For synchronous calls use {@link #send() send()}.
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public void publish() throws NotConnectedException, InterruptedException {
    PubSub packet = createPubsubPacket(Type.set, new NodeExtension(PubSubElementType.PUBLISH, getId()));
    pubSubManager.getConnection().sendStanza(packet);
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub)

Example 10 with PubSub

use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.

the class LeafNode method publish.

/**
     * Publishes multiple events to the node.  Same rules apply as in {@link #publish(Item)}.
     * 
     * In addition, if {@link ConfigureForm#isPersistItems()}=false, only the last item in the input
     * list will get stored on the node, assuming it stores the last sent item.
     * 
     * This is an asynchronous call which returns as soon as the 
     * stanza(/packet) has been sent.
     * 
     * For synchronous calls use {@link #send(Collection) send(Collection))}.
     * 
     * @param items - The collection of items being sent
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public <T extends Item> void publish(Collection<T> items) throws NotConnectedException, InterruptedException {
    PubSub packet = createPubsubPacket(Type.set, new PublishItem<T>(getId(), items));
    pubSubManager.getConnection().sendStanza(packet);
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub)

Aggregations

PubSub (org.jivesoftware.smackx.pubsub.packet.PubSub)25 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 ThreadedDummyConnection (org.jivesoftware.smack.ThreadedDummyConnection)2 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)2 HashMap (java.util.HashMap)1 List (java.util.List)1 RuntimeExchangeException (org.apache.camel.RuntimeExchangeException)1 XMPPException (org.jivesoftware.smack.XMPPException)1 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)1 DefaultPacketExtension (org.jivesoftware.smack.packet.DefaultPacketExtension)1 Message (org.jivesoftware.smack.packet.Message)1 PacketExtension (org.jivesoftware.smack.packet.PacketExtension)1 Stanza (org.jivesoftware.smack.packet.Stanza)1 XMPPError (org.jivesoftware.smack.packet.XMPPError)1 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)1 Identity (org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity)1 JivePropertiesExtension (org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)1 Subscription (org.jivesoftware.smackx.pubsub.Subscription)1 SubscriptionsExtension (org.jivesoftware.smackx.pubsub.SubscriptionsExtension)1