Skip to content

Commit f7371aa

Browse files
committed
Handle tricky situation where a script accesses a member defined in a legacy custom class derived from SolrIndexer.
1 parent ff5aa8c commit f7371aa

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

src/org/solrmarc/index/SolrIndexer.java

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,50 @@
1111
@SuppressWarnings("deprecation")
1212
public class SolrIndexer implements Mixin
1313
{
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+
1527
public static SolrIndexer instance()
1628
{
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);
1840
}
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+
2252
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+
}
2458

2559
public void getFieldListCollector(Record record, String tagStr, String mapStr, Collection<String> collector)
2660
{

0 commit comments

Comments
 (0)