Interface FeedClient

  • All Superinterfaces:
    java.lang.AutoCloseable

    public interface FeedClient
    extends java.lang.AutoCloseable
    API for feeding document operations (add, removes or updates) to one or many Vespa clusters. Use the factory to configure and set up an instance of this API. The feedclient does automatic error recovery and reconnects to hosts when connections die. A FeedClientFactory is provided to instantiate Sessions.
    Author:
    dybis
    See Also:
    FeedClientFactory, to remove invalid characters from string fields before feeding
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static interface  FeedClient.ResultCallback
      This callback is executed when new results are arriving or an error occur.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      void close()
      Waits for all results to arrive and closes the FeedClient.
      static void feedJson​(java.io.InputStream inputStream, FeedClient feedClient, java.util.concurrent.atomic.AtomicInteger numSent)
      Utility function that takes an array of JSON documents and calls the FeedClient for each element.
      static void feedXml​(java.io.InputStream inputStream, FeedClient feedClient, java.util.concurrent.atomic.AtomicInteger numSent)
      Utility function that takes an array of XML documents and calls the FeedClient for each element.
      java.lang.String getStatsAsJson()
      Returns stats about the cluster.
      default void stream​(java.lang.String documentId, java.lang.CharSequence documentData)
      Streams a document to cluster(s).
      default void stream​(java.lang.String documentId, java.lang.CharSequence documentData, java.lang.Object context)
      Streams a document to cluster(s).
      void stream​(java.lang.String documentId, java.lang.String operationId, java.lang.CharSequence documentData, java.lang.Object context)
      Streams a document to cluster(s).
    • Method Detail

      • stream

        default void stream​(java.lang.String documentId,
                            java.lang.CharSequence documentData)
        Streams a document to cluster(s). If the pipeline and buffers are full, this call will be blocking. Documents might time out before they are sent. Failed documents are not retried. Don't call stream() after close is called.
        Parameters:
        documentId - the document id of the document.
        documentData - the document data as JSON or XML (as specified when using the factory to create the API)
      • stream

        default void stream​(java.lang.String documentId,
                            java.lang.CharSequence documentData,
                            java.lang.Object context)
        Streams a document to cluster(s). If the pipeline and buffers are full, this call will be blocking. Documents might time out before they are sent. Failed documents are not retried. Don't call stream() after close is called.
        Parameters:
        documentId - the document id of the document.
        documentData - the document data as JSON or XML (as specified when using the factory to create the API)
        context - a context object which will be accessible in the result of the callback, or null if none
      • stream

        void stream​(java.lang.String documentId,
                    java.lang.String operationId,
                    java.lang.CharSequence documentData,
                    java.lang.Object context)
        Streams a document to cluster(s). If the pipeline and buffers are full, this call will be blocking. Documents might time out before they are sent. Failed documents are not retried. Don't call stream() after close is called.
        Parameters:
        documentId - the document id of the document.
        operationId - the id to use for this operation, or null to let the client decide an operation id. This id must be unique for every operation. Passing the operation id allows clients to prepare to receive a response for it before issuing the operation to the client.
        documentData - the document data as JSON or XML (as specified when using the factory to create the API)
        context - a context object which will be accessible in the result of the callback, or null if none
      • close

        void close()
        Waits for all results to arrive and closes the FeedClient. Don't call any other method after calling close(). Does not throw any exceptions.
        Specified by:
        close in interface java.lang.AutoCloseable
      • getStatsAsJson

        java.lang.String getStatsAsJson()
        Returns stats about the cluster.
        Returns:
        JSON string with information about cluster.
      • feedJson

        static void feedJson​(java.io.InputStream inputStream,
                             FeedClient feedClient,
                             java.util.concurrent.atomic.AtomicInteger numSent)
        Utility function that takes an array of JSON documents and calls the FeedClient for each element.
        Parameters:
        inputStream - the stream to feed. This can be a very large stream. The outer element must be an array of document operations.
        feedClient - the feed client that will receive the document operations
        numSent - increased per document sent to API (but not waiting for results)
      • feedXml

        static void feedXml​(java.io.InputStream inputStream,
                            FeedClient feedClient,
                            java.util.concurrent.atomic.AtomicInteger numSent)
        Utility function that takes an array of XML documents and calls the FeedClient for each element. The XML document has to be formatted with line space on each line (like "regular" XML, but stricter than the specifications of XML).
        Parameters:
        inputStream - the stream to feed. This can be a very large stream. Operations must be enclosed in a top-level <vespafeed> tag
        feedClient - the feed client that will receive the document operations
        numSent - increased per document sent to API (but not waiting for results)