Package com.yahoo.documentapi.local
Class LocalDocumentAccess
java.lang.Object
com.yahoo.documentapi.DocumentAccess
com.yahoo.documentapi.local.LocalDocumentAccess
The main class of the local implementation of the document api.
To easily obtain an instance of this, with the documents using the schemas (.sd-files) in a given directoy,
use the
com.yahoo.vespa.application
test module and DocumentAccesses.ofSchemas(schemaDirectory)
- Author:
- bratseth, jonmv
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncreateAsyncSession
(AsyncParameters parameters) Returns a session for asynchronous document access.createSubscription
(SubscriptionParameters parameters) Creates a subscription and returns a session for getting data from it.createSyncSession
(SyncParameters parameters) Returns a session for synchronous document access.Creates a destination session for receiving data from visiting.createVisitorSession
(VisitorParameters parameters) Run a visitor with the given visitor parameters, and get the result back here.openSubscription
(SubscriptionParameters parameters) Returns a session for document subscription.void
Sets aPhaser
for synchronization of otherwise async operations in sessions backed by this.Methods inherited from class com.yahoo.documentapi.DocumentAccess
createForNonContainer, getDocumentTypeManager, shutdown
-
Constructor Details
-
LocalDocumentAccess
-
-
Method Details
-
createSyncSession
Description copied from class:DocumentAccess
Returns a session for synchronous document access. Use this for simple access.- Specified by:
createSyncSession
in classDocumentAccess
- Parameters:
parameters
- the parameters of this sync session- Returns:
- a session to use for synchronous document access
-
createAsyncSession
Description copied from class:DocumentAccess
Returns a session for asynchronous document access. Use this if high operation throughput is required.- Specified by:
createAsyncSession
in classDocumentAccess
- Parameters:
parameters
- the parameters of this async session.- Returns:
- a session to use for asynchronous document access.
-
createVisitorSession
public LocalVisitorSession createVisitorSession(VisitorParameters parameters) throws com.yahoo.document.select.parser.ParseException Description copied from class:DocumentAccess
Run a visitor with the given visitor parameters, and get the result back here.- Specified by:
createVisitorSession
in classDocumentAccess
- 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:
com.yahoo.document.select.parser.ParseException
- if the document selection string could not be parsed
-
createVisitorDestinationSession
public VisitorDestinationSession createVisitorDestinationSession(VisitorDestinationParameters parameters) Description copied from class:DocumentAccess
Creates a destination session for receiving data from visiting. The visitor must be started and progress tracked through a visitor session.- Specified by:
createVisitorDestinationSession
in classDocumentAccess
- Parameters:
parameters
- the parameters of this visitor destination session- Returns:
- a session used to get the actual data returned
-
createSubscription
Description copied from class:DocumentAccess
Creates a subscription and returns a session for getting data from it. Use this to get document operations being done by other parties.- Specified by:
createSubscription
in classDocumentAccess
- Parameters:
parameters
- The parameters of this subscription session- Returns:
- a session to use for document subscription
-
openSubscription
Description copied from class:DocumentAccess
Returns a session for document subscription. Use this to get document operations being done by other parties.- Specified by:
openSubscription
in classDocumentAccess
- Parameters:
parameters
- the parameters of this subscription session- Returns:
- a session to use for document subscription
-
setPhaser
Sets aPhaser
for synchronization of otherwise async operations in sessions backed by this.AsyncSession
andVisitorSession
are by nature async. TheLocalAsyncSession
is, by default, synchronous, i.e., responses are sent by the thread that sends the document operations.LocalVisitorSession
, on the other hand, is asynchronous by default, i.e., all documents are sent by a dedicated sender thread. To enable more advanced testing using theLocalDocumentAccess
, this method lets the user specify aPhaser
used to synchronize the sending of documents from the visitor, and the responses for the document operations — which are then also done by a dedicated thread pool, instead of the caller thread. When this is set, a party is registered with the phaser for the sender thread (visit) or for each document operation (async-session). The thread that sends a document (visit) or response (async-session) then arrives and awaits advance before sending each response, so the user can trigger these documents and responses. After the document or response is delivered, the thread arrives and awaits advance, so the user can wait until the document or response has been delivered. This also ensures memory visibility. The visit sender thread deregisters when the whole visit is done; the async session threads after each operation. Example usage:void testOperations(LocalDocumentAccess access) { List<Response> responses = new ArrayList<>(); Phaser phaser = new Phaser(1); // "1" to register self access.setPhaser(phaser); AsyncSession session = access.createAsyncSession(new AsyncParameters().setReponseHandler(responses::add)); session.put(documentPut); session.get(documentId); // Operations wait for this thread to arrive at "phaser" phaser.arriveAndAwaitAdvance(); // Let operations send their responses // "responses" may or may not hold the responses now phaser.arriveAndAwaitAdvance(); // Wait for operations to complete sending responses, memory visibility, etc. // "responses" now has responses from all previous operations phaser.arriveAndDeregister(); // Deregister so further operations flow freely }
-