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

« back to all changes in this revision

Viewing changes to solr/core/src/java/org/apache/solr/search/SolrCache.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
 
/**
2
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 
 * contributor license agreements.  See the NOTICE file distributed with
4
 
 * this work for additional information regarding copyright ownership.
5
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 
 * (the "License"); you may not use this file except in compliance with
7
 
 * the License.  You may obtain a copy of the License at
8
 
 *
9
 
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 
 *
11
 
 * Unless required by applicable law or agreed to in writing, software
12
 
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 
 * See the License for the specific language governing permissions and
15
 
 * limitations under the License.
16
 
 */
17
 
 
18
 
package org.apache.solr.search;
19
 
 
20
 
import org.apache.solr.core.SolrInfoMBean;
21
 
 
22
 
import java.util.Map;
23
 
import org.slf4j.Logger;
24
 
import org.slf4j.LoggerFactory;
25
 
import java.io.IOException;
26
 
 
27
 
 
28
 
/**
29
 
 * Primary API for dealing with Solr's internal caches.
30
 
 * 
31
 
 * @version $Id: SolrCache.java 890250 2009-12-14 09:42:00Z shalin $
32
 
 */
33
 
public interface SolrCache<K,V> extends SolrInfoMBean {
34
 
  public final static Logger log = LoggerFactory.getLogger(SolrCache.class);
35
 
 
36
 
 
37
 
  /**
38
 
   * The initialization routine.  Instance specific arguments are passed in
39
 
   * the <code>args</code> map.
40
 
   * <p>
41
 
   * The persistence object will exist across different lifetimes of similar caches.
42
 
   * For example, all filter caches will share the same persistence object, sometimes
43
 
   * at the same time (it must be threadsafe).  If null is passed, then the cache
44
 
   * implementation should create and return a new persistence object.  If not null,
45
 
   * the passed in object should be returned again.
46
 
   * <p>
47
 
   * Since it will exist across the lifetime of many caches, care should be taken to
48
 
   * not reference any particular cache instance and prevent it from being
49
 
   * garbage collected (no using inner classes unless they are static).
50
 
   * <p>
51
 
   * The persistence object is designed to be used as a way for statistics
52
 
   * to accumulate across all instances of the same type of cache, however the
53
 
   * object may be of any type desired by the cache implementation.
54
 
   * <p>
55
 
   * The {@link CacheRegenerator} is what the cache uses during auto-warming to
56
 
   * renenerate an item in the new cache from an entry in the old cache.
57
 
   *
58
 
   */
59
 
  public Object init(Map args, Object persistence, CacheRegenerator regenerator);
60
 
  // I don't think we need a factory for faster creation given that these
61
 
  // will be associated with slow-to-create SolrIndexSearchers.
62
 
  // change to NamedList when other plugins do?
63
 
 
64
 
  /**
65
 
   * Name the Cache can be referenced with by SolrRequestHandlers.
66
 
   *
67
 
   * This method must return the identifier that the Cache instance 
68
 
   * expects SolrRequestHandlers to use when requesting access to it 
69
 
   * from the SolrIndexSearcher.  It is <strong>strongly</strong> 
70
 
   * recommended that this method return the value of the "name" 
71
 
   * parameter from the init args.
72
 
   *
73
 
   * :TODO: verify this.
74
 
   */
75
 
  public String name();
76
 
 
77
 
 
78
 
  // Should SolrCache just extend the java.util.Map interface?
79
 
  // Following the conventions of the java.util.Map interface in any case.
80
 
 
81
 
  /** :TODO: copy from Map */
82
 
  public int size();
83
 
 
84
 
  /** :TODO: copy from Map */
85
 
  public V put(K key, V value);
86
 
 
87
 
  /** :TODO: copy from Map */
88
 
  public V get(K key);
89
 
 
90
 
  /** :TODO: copy from Map */
91
 
  public void clear();
92
 
 
93
 
  /** 
94
 
   * Enumeration of possible States for cache instances.
95
 
   * :TODO: only state that seems to ever be set is LIVE ?
96
 
  */
97
 
  public enum State { 
98
 
    /** :TODO */
99
 
    CREATED, 
100
 
    /** :TODO */
101
 
    STATICWARMING, 
102
 
    /** :TODO */
103
 
    AUTOWARMING, 
104
 
    /** :TODO */
105
 
    LIVE 
106
 
  }
107
 
 
108
 
  /**
109
 
   * Set different cache states.
110
 
   * The state a cache is in can have an effect on how statistics are kept.
111
 
   * The cache user (SolrIndexSearcher) will take care of switching
112
 
   * cache states.
113
 
   */
114
 
  public void setState(State state);
115
 
 
116
 
  /**
117
 
   * Returns the last State set on this instance
118
 
   *
119
 
   * @see #setState
120
 
   */
121
 
  public State getState();
122
 
 
123
 
 
124
 
  /**
125
 
   * Warm this cache associated with <code>searcher</code> using the <code>old</code>
126
 
   * cache object.  <code>this</code> and <code>old</code> will have the same concrete type.
127
 
   */
128
 
  void warm(SolrIndexSearcher searcher, SolrCache<K,V> old) throws IOException;
129
 
  // Q: an alternative to passing the searcher here would be to pass it in
130
 
  // init and have the cache implementation save it.
131
 
 
132
 
 
133
 
  /** Frees any non-memory resources */
134
 
  public void close();
135
 
 
136
 
}