pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / src / java / org / apache / lucene / index / PayloadProcessorProvider.java
1 package org.apache.lucene.index;
2
3 /**
4  * Licensed to the Apache Software Foundation (ASF) under one or more
5  * contributor license agreements.  See the NOTICE file distributed with
6  * this work for additional information regarding copyright ownership.
7  * The ASF licenses this file to You under the Apache License, Version 2.0
8  * (the "License"); you may not use this file except in compliance with
9  * the License.  You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 import java.io.IOException;
21
22 import org.apache.lucene.store.Directory;
23
24 /**
25  * Provides a {@link DirPayloadProcessor} to be used for a {@link Directory}.
26  * This allows using different {@link DirPayloadProcessor}s for different
27  * directories, for e.g. to perform different processing of payloads of
28  * different directories.
29  * <p>
30  * <b>NOTE:</b> to avoid processing payloads of certain directories, you can
31  * return <code>null</code> in {@link #getDirProcessor}.
32  * <p>
33  * <b>NOTE:</b> it is possible that the same {@link DirPayloadProcessor} will be
34  * requested for the same {@link Directory} concurrently. Therefore, to avoid
35  * concurrency issues you should return different instances for different
36  * threads. Usually, if your {@link DirPayloadProcessor} does not maintain state
37  * this is not a problem. The merge code ensures that the
38  * {@link DirPayloadProcessor} instance you return will be accessed by one
39  * thread to obtain the {@link PayloadProcessor}s for different terms.
40  * 
41  * @lucene.experimental
42  */
43 public abstract class PayloadProcessorProvider {
44
45   /**
46    * Returns a {@link PayloadProcessor} for a given {@link Term} which allows
47    * processing the payloads of different terms differently. If you intent to
48    * process all your payloads the same way, then you can ignore the given term.
49    * <p>
50    * <b>NOTE:</b> if you protect your {@link DirPayloadProcessor} from
51    * concurrency issues, then you shouldn't worry about any such issues when
52    * {@link PayloadProcessor}s are requested for different terms.
53    */
54   public static abstract class DirPayloadProcessor {
55
56     /** Returns a {@link PayloadProcessor} for the given term. */
57     public abstract PayloadProcessor getProcessor(Term term) throws IOException;
58     
59   }
60
61   /**
62    * Processes the given payload. One should call {@link #payloadLength()} to
63    * get the length of the processed payload.
64    * 
65    * @lucene.experimental
66    */
67   public static abstract class PayloadProcessor {
68
69     /** Returns the length of the payload that was returned by {@link #processPayload}. */
70     public abstract int payloadLength() throws IOException;
71
72     /**
73      * Process the incoming payload and returns the resulting byte[]. Note that
74      * a new array might be allocated if the given array is not big enough. The
75      * length of the new payload data can be obtained via
76      * {@link #payloadLength()}.
77      */
78     public abstract byte[] processPayload(byte[] payload, int start, int length) throws IOException;
79
80   }
81
82   /**
83    * Returns a {@link DirPayloadProcessor} for the given {@link Directory},
84    * through which {@link PayloadProcessor}s can be obtained for each
85    * {@link Term}, or <code>null</code> if none should be used.
86    */
87   public abstract DirPayloadProcessor getDirProcessor(Directory dir) throws IOException;
88
89 }