Class DocumentAccess

java.lang.Object
com.yahoo.documentapi.DocumentAccess
Direct Known Subclasses:
LocalDocumentAccess, MessageBusDocumentAccess

public abstract class DocumentAccess extends Object

This is the starting point of the document api. This api provides access to documents in a document repository. The document api contains four separate access types:

  • Synchronous random access - provided by SyncSession, allows simple access where throughput is not a concern.
  • Asynchronous random access - provided by AsyncSession, allows document repository writes and random access with high throughput.
  • Visiting - provided by VisitorSession, allows a set of documents to be accessed in an order decided by the document repository. This allows much higher read throughput than random access.
  • Subscription - provided by SubscriptionSession, allows changes to a defined set of documents in the repository to be visited.

This class is the factory for creating the four session types mentioned above.

There may be multiple implementations of the document api classes. If default configuration is sufficient, simply inject a DocumentAccess to obtain a running document access. If you instead create a concrete implementation, note that there are running threads within an access object, so you must shut it down when done.

An implementation of the Document Api may support just a subset of the access types defined in this interface. For example, some document repositories, like indexes, are write only. Others may support random access, but not visiting and subscription. Any method which is not supported by the underlying implementation will throw UnsupportedOperationException.

Access to this class is thread-safe.

Author:
bratseth, Einar Rosenvinge, Simon Thoresen Hult
  • Constructor Details

    • DocumentAccess

      protected DocumentAccess(DocumentAccessParams params)
      Constructs a new document access object.
      Parameters:
      params - the parameters to use for setup
  • Method Details

    • createForNonContainer

      public static DocumentAccess createForNonContainer()
      This is a convenience method to return a document access object when running outside of a Vespa application container, with all default parameter values. The client that calls this method is also responsible for shutting the object down when done. If an error occurred while attempting to create such an object, this method will throw an exception. This document access requires new config subscriptions to be set up, which should be avoided in application containers, but is suitable for, e.g., CLIs.
      Returns:
      a running document access object with all default configuration
    • createSyncSession

      public abstract SyncSession createSyncSession(SyncParameters parameters)
      Returns a session for synchronous document access. Use this for simple access.
      Parameters:
      parameters - the parameters of this sync session
      Returns:
      a session to use for synchronous document access
      Throws:
      UnsupportedOperationException - if this access implementation does not support synchronous access
      RuntimeException - if an error prevented the session from being created.
    • createAsyncSession

      public abstract AsyncSession createAsyncSession(AsyncParameters parameters)
      Returns a session for asynchronous document access. Use this if high operation throughput is required.
      Parameters:
      parameters - the parameters of this async session.
      Returns:
      a session to use for asynchronous document access.
      Throws:
      UnsupportedOperationException - if this access implementation does not support asynchronous access.
      RuntimeException - if an error prevented the session from being created
    • createVisitorSession

      public abstract VisitorSession createVisitorSession(VisitorParameters parameters) throws com.yahoo.document.select.parser.ParseException
      Run a visitor with the given visitor parameters, and get the result back here.
      Parameters:
      parameters - The parameters of this visitor session.
      Returns:
      a session used to track progress of the visitor and get the actual data returned.
      Throws:
      UnsupportedOperationException - if this access implementation does not support visiting
      RuntimeException - if an error prevented the session from being created
      com.yahoo.document.select.parser.ParseException - if the document selection string could not be parsed
    • createVisitorDestinationSession

      public abstract VisitorDestinationSession createVisitorDestinationSession(VisitorDestinationParameters parameters)
      Creates a destination session for receiving data from visiting. The visitor must be started and progress tracked through a visitor session.
      Parameters:
      parameters - the parameters of this visitor destination session
      Returns:
      a session used to get the actual data returned
      Throws:
      UnsupportedOperationException - if this access implementation does not support visiting.
    • createSubscription

      public abstract SubscriptionSession createSubscription(SubscriptionParameters parameters)
      Creates a subscription and returns a session for getting data from it. Use this to get document operations being done by other parties.
      Parameters:
      parameters - The parameters of this subscription session
      Returns:
      a session to use for document subscription
      Throws:
      UnsupportedOperationException - if this access implementation does not support subscription
      RuntimeException - if an error prevented the session from being created
    • openSubscription

      public abstract SubscriptionSession openSubscription(SubscriptionParameters parameters)
      Returns a session for document subscription. Use this to get document operations being done by other parties.
      Parameters:
      parameters - the parameters of this subscription session
      Returns:
      a session to use for document subscription
      Throws:
      UnsupportedOperationException - if this access implementation does not support subscription
      RuntimeException - if an error prevented the session from being created
    • shutdown

      public void shutdown()
      Shuts down the underlying sessions used by this DocumentAccess; subsequent use of this DocumentAccess will throw unspecified exceptions, depending on implementation. Classes overriding this must call super.shutdown().
    • getDocumentTypeManager

      public com.yahoo.document.DocumentTypeManager getDocumentTypeManager()
      Returns the DocumentTypeManager used by this DocumentAccess.