View Javadoc

1   package com.atlassian.bonnie.index;
2   
3   import java.util.Collection;
4   
5   /**
6    * <p>Queue of objects that need to be indexed. Partitions the total collection of objects to be
7    * indexed into sub-collections that individual threads can grab and process.</p>
8    * <p>An ObjectQueue MUST be read-only and MUST NOT be externally modified once it has been created.</p>
9    * <p>There is no need for implementations to be thread-safe. Synchronization will be handled by clients.</p>
10   */
11  public interface ObjectQueue
12  {
13      /**
14       * Pops a block of objects to index. Returns a collection of objects instead of
15       * a single object to minimize lock contention.
16       *
17       * @return objects to index
18       */
19      Collection pop();
20  
21      /**
22       * Are there more objects in the queue?
23       *
24       * @return
25       */
26      boolean hasMore();
27  
28      /**
29       * Size of queue. For Iterator-backed implementations, the size is not known.
30       * Clients should only use this method to obtain an approximation of the actual
31       * number of objects to index.
32       *
33       * @return
34       */
35      int size();
36  
37      /**
38       * Get this queue's processor. Implementations must either return a thread-safe processor
39       * or a thread-local instance of the processor.
40       *
41       * @return
42       */
43      Processor getProcessor();
44  
45      /**
46       * <p>Creates {@link Document}s from objects via
47       * {@link ObjectToDocumentConverter}, then passes the created Document to a {@link Callback}.</p>
48       * <p>The premise of this class is that the creation of Documents (NOT their addition to the index) is the bottleneck
49       * in an indexing process, and performance gains will be achieved by running this operation in a concurrent fashion.
50       * </p>
51       */
52      interface Processor
53      {
54          void indexCollection(Collection collection, BatchOpIndexer.DocumentWritingScheme documentWritingScheme);
55      }
56  }