1 package org.apache.lucene.index;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 import java.io.IOException;
22 import org.apache.lucene.store.Directory;
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.
30 * <b>NOTE:</b> to avoid processing payloads of certain directories, you can
31 * return <code>null</code> in {@link #getDirProcessor}.
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.
41 * @lucene.experimental
43 public abstract class PayloadProcessorProvider {
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.
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.
54 public static abstract class DirPayloadProcessor {
56 /** Returns a {@link PayloadProcessor} for the given term. */
57 public abstract PayloadProcessor getProcessor(Term term) throws IOException;
62 * Processes the given payload. One should call {@link #payloadLength()} to
63 * get the length of the processed payload.
65 * @lucene.experimental
67 public static abstract class PayloadProcessor {
69 /** Returns the length of the payload that was returned by {@link #processPayload}. */
70 public abstract int payloadLength() throws IOException;
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()}.
78 public abstract byte[] processPayload(byte[] payload, int start, int length) throws IOException;
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.
87 public abstract DirPayloadProcessor getDirProcessor(Directory dir) throws IOException;