~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to solr/core/src/java/org/apache/solr/core/MMapDirectoryFactory.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.apache.solr.core;
2
 
/**
3
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
4
 
 * contributor license agreements.  See the NOTICE file distributed with
5
 
 * this work for additional information regarding copyright ownership.
6
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
7
 
 * (the "License"); you may not use this file except in compliance with
8
 
 * the License.  You may obtain a copy of the License at
9
 
 *
10
 
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 
 *
12
 
 * Unless required by applicable law or agreed to in writing, software
13
 
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 
 * See the License for the specific language governing permissions and
16
 
 * limitations under the License.
17
 
 */
18
 
 
19
 
 
20
 
import org.apache.lucene.store.Directory;
21
 
import org.apache.lucene.store.MMapDirectory;
22
 
import org.apache.solr.common.params.SolrParams;
23
 
import org.apache.solr.common.util.NamedList;
24
 
import org.slf4j.Logger;
25
 
import org.slf4j.LoggerFactory;
26
 
 
27
 
import java.io.File;
28
 
import java.io.IOException;
29
 
 
30
 
 
31
 
/**
32
 
 *  Directly provide MMapDirectory instead of relying on {@link org.apache.lucene.store.FSDirectory#open}
33
 
 *
34
 
 * Can set the following parameters:
35
 
 * <ul>
36
 
 *  <li>unmap -- See {@link org.apache.lucene.store.MMapDirectory#setUseUnmap(boolean)}</li>
37
 
 *  <li>maxChunkSize -- The Max chunk size.  See {@link org.apache.lucene.store.MMapDirectory#setMaxChunkSize(int)}</li>
38
 
 * </ul>
39
 
 *
40
 
 **/
41
 
public class MMapDirectoryFactory extends DirectoryFactory {
42
 
  private transient static Logger log = LoggerFactory.getLogger(MMapDirectoryFactory.class);
43
 
  boolean unmapHack;
44
 
  private int maxChunk;
45
 
 
46
 
  @Override
47
 
  public Directory open(String path) throws IOException {
48
 
    MMapDirectory mapDirectory = new MMapDirectory(new File(path));
49
 
    try {
50
 
      mapDirectory.setUseUnmap(unmapHack);
51
 
    } catch (Exception e) {
52
 
      log.warn("Unmap not supported on this JVM, continuing on without setting unmap", e);
53
 
    }
54
 
    mapDirectory.setMaxChunkSize(maxChunk);
55
 
    return mapDirectory;
56
 
  }
57
 
 
58
 
  @Override
59
 
  public void init(NamedList args) {
60
 
    SolrParams params = SolrParams.toSolrParams( args );
61
 
    maxChunk = params.getInt("maxChunkSize", MMapDirectory.DEFAULT_MAX_BUFF);
62
 
    if (maxChunk <= 0){
63
 
      throw new IllegalArgumentException("maxChunk must be greater than 0");
64
 
    }
65
 
    unmapHack = params.getBool("unmap", true);
66
 
  }
67
 
}