|
11 | 11 | @SuppressWarnings("deprecation")
|
12 | 12 | public class SolrIndexer implements Mixin
|
13 | 13 | {
|
14 |
| - private static SolrIndexer fakeInstanceToMakeScriptsWork = new SolrIndexer(); |
| 14 | + private static ThreadLocal<SolrIndexer[]> indexerCache = |
| 15 | + new ThreadLocal<SolrIndexer[]>() |
| 16 | + { |
| 17 | + @Override |
| 18 | + protected SolrIndexer[] initialValue() |
| 19 | + { |
| 20 | + return new SolrIndexer[1]; |
| 21 | + } |
| 22 | + }; |
| 23 | + |
| 24 | + private static SolrIndexer theDefaultBaseIndexer = null; |
| 25 | + private static SolrIndexer theDefaultIndexer = null; |
| 26 | + |
15 | 27 | public static SolrIndexer instance()
|
16 | 28 | {
|
17 |
| - return fakeInstanceToMakeScriptsWork; |
| 29 | + SolrIndexer result = indexerCache.get()[0]; |
| 30 | + if (result == null) |
| 31 | + { |
| 32 | + result = theDefaultIndexer; |
| 33 | + if (result != null) indexerCache.get()[0] = result; |
| 34 | + } |
| 35 | + if (result == null) |
| 36 | + { |
| 37 | + result = theDefaultBaseIndexer; |
| 38 | + } |
| 39 | + return(result); |
18 | 40 | }
|
19 |
| - private SolrIndexer() |
20 |
| - { /* Do-Nothing constructor, for fake Instance To Make Scripts Work */ } |
21 |
| - |
| 41 | + |
| 42 | + public SolrIndexer() |
| 43 | + { |
| 44 | + SolrIndexer[] perThreadCache = indexerCache.get(); |
| 45 | + if (perThreadCache[0] == null) |
| 46 | + { |
| 47 | + perThreadCache[0] = this; |
| 48 | + } |
| 49 | + if (theDefaultBaseIndexer == null) theDefaultBaseIndexer = this; |
| 50 | + } |
| 51 | + |
22 | 52 | public SolrIndexer(final String propertiesMapFile, final String[] propertyDirs)
|
23 |
| - { /* Backwards compatibility constructor, the parameters are all ignored */ } |
| 53 | + { |
| 54 | + SolrIndexer[] perThreadCache = indexerCache.get(); |
| 55 | + perThreadCache[0] = this; |
| 56 | + if (theDefaultIndexer == null) theDefaultIndexer = this; |
| 57 | + } |
24 | 58 |
|
25 | 59 | public void getFieldListCollector(Record record, String tagStr, String mapStr, Collection<String> collector)
|
26 | 60 | {
|
|
0 commit comments