congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
LeafNode
Code IndexAdd Tabnine to your IDE (free)

How to use
LeafNode
in
org.jivesoftware.smackx.pubsub

Best Java code snippets using org.jivesoftware.smackx.pubsub.LeafNode (Showing top 20 results out of 315)

origin: igniterealtime/Smack

/**
 * Try to publish an item and, if the node with the given ID does not exists, auto-create the node.
 * <p>
 * Not every PubSub service supports automatic node creation. You can discover if this service supports it by using
 * {@link #supportsAutomaticNodeCreation()}.
 * </p>
 *
 * @param id The unique id of the node.
 * @param item The item to publish.
 * @param <I> type of the item.
 *
 * @return the LeafNode on which the item was published.
 * @throws NoResponseException
 * @throws XMPPErrorException
 * @throws NotConnectedException
 * @throws InterruptedException
 * @since 4.2.1
 */
public <I extends Item> LeafNode tryToPublishAndPossibleAutoCreate(String id, I item)
        throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
  LeafNode leafNode = new LeafNode(this, id);
  leafNode.publish(item);
  // If LeafNode.publish() did not throw then we have successfully published an item and possible auto-created
  // (XEP-0163 § 3., XEP-0060 § 7.1.4) the node. So we can put the node into the nodeMap.
  nodeMap.put(id, leafNode);
  return leafNode;
}
origin: igniterealtime/Smack

/**
 * Get items persisted on the node, limited to the specified number.
 *
 * @param maxItems Maximum number of items to return
 * @param <T> type of the items.
 *
 * @return List of {@link Item}
 * @throws XMPPErrorException
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException
 * @throws InterruptedException
 */
public <T extends Item> List<T> getItems(int maxItems) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
  PubSub request = createPubsubPacket(Type.get, new GetItemsRequest(getId(), maxItems));
  return getItems(request);
}
origin: igniterealtime/Smack

/**
 * Delete the item with the specified id from the node.
 *
 * @param itemId The id of the item
 * @throws XMPPErrorException
 * @throws NoResponseException
 * @throws NotConnectedException
 * @throws InterruptedException
 */
public void deleteItem(String itemId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
  Collection<String> items = new ArrayList<>(1);
  items.add(itemId);
  deleteItem(items);
}
origin: igniterealtime/Smack

private LeafNode getLeafNodeProsodyWorkaround(final String id) throws NoResponseException, NotConnectedException,
        InterruptedException, NotALeafNodeException, XMPPErrorException {
  LeafNode leafNode = new LeafNode(this, id);
  try {
    // Try to ensure that this is not a collection node by asking for one item form the node.
    leafNode.getItems(1);
  } catch (XMPPErrorException e) {
    Condition condition = e.getStanzaError().getCondition();
    if (condition == Condition.feature_not_implemented) {
      // XEP-0060 § 6.5.9.5: Item retrieval not supported, e.g. because node is a collection node
      throw new PubSubException.NotALeafNodeException(id, pubSubService);
    }
    throw e;
  }
  nodeMap.put(id, leafNode);
  return leafNode;
}
origin: igniterealtime/Smack

/**
 * 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()));
  pubSubManager.getConnection().createStanzaCollectorAndSend(request).nextResultOrThrow();
}
origin: tiandawu/IotXmpp

/**
 * Creates an instant node, if supported.
 * 
 * @return The node that was created
 * @exception XMPPException
 */
public LeafNode createNode()
  throws XMPPException
{
  PubSub reply = (PubSub)sendPubsubPacket(Type.SET, new NodeExtension(PubSubElementType.CREATE));
  NodeExtension elem = (NodeExtension)reply.getExtension("create", PubSubNamespace.BASIC.getXmlns());
  
  LeafNode newNode = new LeafNode(con, elem.getNode());
  newNode.setTo(to);
  nodeMap.put(newNode.getId(), newNode);
  
  return newNode;
}

origin: igniterealtime/Smack

/**
 * 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.
 *
 * @throws NotConnectedException
 * @throws InterruptedException
 * @throws XMPPErrorException
 * @throws NoResponseException
 * @deprecated use {@link #publish()} instead.
 */
@Deprecated
public void send() throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException {
  publish();
}
origin: igniterealtime/Smack

/**
 * Creates a node with specified configuration.
 *
 * Note: This is the only way to create a collection node.
 *
 * @param nodeId 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
 * @throws InterruptedException
 */
public Node createNode(String nodeId, Form config) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
  PubSub request = PubSub.createPubsubPacket(pubSubService, Type.set, new NodeExtension(PubSubElementType.CREATE, nodeId));
  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).toString().equals(NodeType.leaf.toString());
  }
  // Errors will cause exceptions in getReply, so it only returns
  // on success.
  sendPubsubPacket(request);
  Node newNode = isLeafNode ? new LeafNode(this, nodeId) : new CollectionNode(this, nodeId);
  nodeMap.put(newNode.getId(), newNode);
  return newNode;
}
origin: igniterealtime/Smack

List<Item> items = keyNode.getItems(1);
if (items.isEmpty()) {
  LOGGER.log(Level.FINE, "Node " + keyNodeName + " is empty. Publish.");
  keyNode.publish(new PayloadItem<>(pubkeyElement));
} else {
  LOGGER.log(Level.FINE, "Node " + keyNodeName + " already contains key. Skip.");
List<PayloadItem<PublicKeysListElement>> metadataItems = metadataNode.getItems(1);
metadataNode.publish(new PayloadItem<>(builder.build()));
origin: igniterealtime/Smack

/**
 * Get the current items stored in the node.
 *
 * @param <T> type of the items.
 * @return List of {@link Item} in the node
 * @throws XMPPErrorException
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException
 * @throws InterruptedException
 */
public <T extends Item> List<T> getItems() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
  return getItems((List<ExtensionElement>) null, null);
}
origin: igniterealtime/Smack

/**
 * Creates an instant node, if supported.
 *
 * @return The node that was created
 * @throws XMPPErrorException
 * @throws NoResponseException
 * @throws NotConnectedException
 * @throws InterruptedException
 */
public LeafNode createNode() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
  PubSub reply = sendPubsubPacket(Type.set, new NodeExtension(PubSubElementType.CREATE), null);
  NodeExtension elem = reply.getExtension("create", PubSubNamespace.basic.getXmlns());
  LeafNode newNode = new LeafNode(this, elem.getNode());
  nodeMap.put(newNode.getId(), newNode);
  return newNode;
}
origin: igniterealtime/Smack

} finally {
  if (leafNode != null) {
    deleteNode(leafNode.getId());
origin: org.igniterealtime.smack/smackx

/**
 * Publishes an event to the node.  This can be either a simple item
 * with no payload, or one with it.  This is determined by the Node
 * configuration.
 * 
 * If the node has <b>deliver_payload=false</b>, the Item must not
 * have a payload.
 * 
 * If the id is null, an empty item (one without an id) will be sent.
 * Please note that this is not the same as {@link #send()}, which
 * publishes an event with NO item.
 * 
 * This is a synchronous call which will throw an exception 
 * on failure.
 * 
 * For asynchronous calls, use {@link #publish(Item) publish(Item)}.
 * 
 * @param item - The item being sent
 * 
 * @throws XMPPException
 */
public <T extends Item> void send(T item)
  throws XMPPException
{
  Collection<T> items = new ArrayList<T>(1);
  items.add((item == null ? (T)new Item() : item));
  send(items);
}
 
origin: igniterealtime/Smack

    pm.getLeafNode(OmemoConstants.PEP_NODE_BUNDLE_FROM_DEVICE_ID(id)).deleteAllItems();
  } catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException |
      PubSubException.NotALeafNodeException | XMPPException.XMPPErrorException |
  pm.getLeafNode(OmemoConstants.PEP_NODE_DEVICE_LIST).deleteAllItems();
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException |
    PubSubException.NotALeafNodeException | XMPPException.XMPPErrorException |
origin: igniterealtime/Smack

  /**
   * Delete the items with the specified id's from the node.
   *
   * @param itemIds The list of id's of items to delete
   * @throws XMPPErrorException
   * @throws NoResponseException if there was no response from the server.
   * @throws NotConnectedException
   * @throws InterruptedException
   */
  public void deleteItem(Collection<String> itemIds) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    List<Item> items = new ArrayList<>(itemIds.size());

    for (String id : itemIds) {
       items.add(new Item(id));
    }
    PubSub request = createPubsubPacket(Type.set, new ItemsExtension(ItemsExtension.ItemsElementType.retract, getId(), items));
    pubSubManager.getConnection().createStanzaCollectorAndSend(request).nextResultOrThrow();
  }
}
origin: org.igniterealtime.smack/smackx

/**
 * Creates an instant node, if supported.
 * 
 * @return The node that was created
 * @exception XMPPException
 */
public LeafNode createNode()
  throws XMPPException
{
  PubSub reply = (PubSub)sendPubsubPacket(Type.SET, new NodeExtension(PubSubElementType.CREATE));
  NodeExtension elem = (NodeExtension)reply.getExtension("create", PubSubNamespace.BASIC.getXmlns());
  
  LeafNode newNode = new LeafNode(con, elem.getNode());
  newNode.setTo(to);
  nodeMap.put(newNode.getId(), newNode);
  
  return newNode;
}
 
origin: igniterealtime/Smack

/**
 * 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.
 *
 * @param items - The collection of items being sent
 * @param <T> type of the items.
 *
 * @throws NotConnectedException
 * @throws InterruptedException
 * @throws XMPPErrorException
 * @throws NoResponseException
 * @deprecated use {@link #publish(Collection)} instead.
 */
@Deprecated
public <T extends Item> void send(Collection<T> items) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException {
  publish(items);
}
origin: igniterealtime/Smack

node = new LeafNode(this, id);
origin: igniterealtime/Smack

  @SmackIntegrationTest
  public void simplePubSubNodeTest() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    final String nodename = "sinttest-simple-nodename-" + testRunId;
    final String itemId = "sintest-simple-itemid-" + testRunId;
    ConfigureForm defaultConfiguration = pubSubManagerOne.getDefaultConfiguration();
    ConfigureForm config = new ConfigureForm(defaultConfiguration.createAnswerForm());
    // Configure the node as "Notification-Only Node", which in turn means that
    // items do not need payload, to prevent payload-required error responses when
    // publishing the item.
    config.setDeliverPayloads(false);
    config.setPersistentItems(true);
    Node node = pubSubManagerOne.createNode(nodename, config);
    try {
      LeafNode leafNode = (LeafNode) node;
      leafNode.publish(new Item(itemId));
      List<Item> items = leafNode.getItems();
      assertEquals(1, items.size());
      Item item = items.get(0);
      assertEquals(itemId, item.getId());
    }
    finally {
      pubSubManagerOne.deleteNode(nodename);
    }
  }
}
origin: igniterealtime/Smack

private <T extends Item> List<T> getItems(PubSub request) throws NoResponseException,
        XMPPErrorException, NotConnectedException, InterruptedException {
  return getItems(request, null);
}
org.jivesoftware.smackx.pubsubLeafNode

Javadoc

The main class for the majority of pubsub functionality. In general almost all pubsub capabilities are related to the concept of a node. All items are published to a node, and typically subscribed to by other users. These users then retrieve events based on this subscription.

Most used methods

  • <init>
  • publish
    Publishes an event to the node. This is a simple item with no payload. If the id is null, an empty i
  • getItems
    Get the items specified from the node. This would typically be used when the server does not return
  • createPubsubPacket
  • deleteItem
    Delete the items with the specified id's from the node.
  • getId
  • send
    Publishes an event to the node. This can be either a simple item with no payload, or one with it. Th
  • setTo
  • deleteAllItems
    Purges the node of all items.Note: Some implementations may keep the last item sent.
  • addItemEventListener
  • getNodeConfiguration
  • sendConfigurationForm
  • getNodeConfiguration,
  • sendConfigurationForm,
  • subscribe,
  • unsubscribe

Popular in Java

  • Running tasks concurrently on multiple threads
  • runOnUiThread (Activity)
  • setScale (BigDecimal)
  • startActivity (Activity)
  • Point (java.awt)
    A point representing a location in (x,y) coordinate space, specified in integer precision.
  • URL (java.net)
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • ResourceBundle (java.util)
    ResourceBundle is an abstract class which is the superclass of classes which provide Locale-specifi
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • JarFile (java.util.jar)
    JarFile is used to read jar entries and their associated data from jar files.
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now