1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Purpose: A class that gets Accession Number, check for uniqueness
|
4
|
* and register it into db
|
5
|
* Copyright: 2000 Regents of the University of California and the
|
6
|
* National Center for Ecological Analysis and Synthesis
|
7
|
* Authors: Jivka Bojilova, Matt Jones
|
8
|
*
|
9
|
* '$Author: leinfelder $'
|
10
|
* '$Date: 2011-11-02 20:40:12 -0700 (Wed, 02 Nov 2011) $'
|
11
|
* '$Revision: 6595 $'
|
12
|
*
|
13
|
* This program is free software; you can redistribute it and/or modify
|
14
|
* it under the terms of the GNU General Public License as published by
|
15
|
* the Free Software Foundation; either version 2 of the License, or
|
16
|
* (at your option) any later version.
|
17
|
*
|
18
|
* This program is distributed in the hope that it will be useful,
|
19
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21
|
* GNU General Public License for more details.
|
22
|
*
|
23
|
* You should have received a copy of the GNU General Public License
|
24
|
* along with this program; if not, write to the Free Software
|
25
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
26
|
*/
|
27
|
package edu.ucsb.nceas.metacat.index;
|
28
|
|
29
|
import java.util.ArrayList;
|
30
|
import java.util.List;
|
31
|
|
32
|
import org.apache.commons.logging.Log;
|
33
|
import org.apache.commons.logging.LogFactory;
|
34
|
import org.apache.solr.client.solrj.SolrServer;
|
35
|
import org.springframework.context.ApplicationContext;
|
36
|
import org.springframework.context.support.FileSystemXmlApplicationContext;
|
37
|
|
38
|
/**
|
39
|
* The start class of the index.
|
40
|
* @author tao
|
41
|
*
|
42
|
*/
|
43
|
public class ApplicationController {
|
44
|
|
45
|
private static String SOLRINDEXES = "solrIndexes";
|
46
|
private static short FIRST = 0;
|
47
|
|
48
|
private List<SolrIndex> solrIndexes = null;
|
49
|
private List<SystemMetadataEventListener> sysmetaListeners = new ArrayList<SystemMetadataEventListener>();
|
50
|
private static ApplicationContext context = null;
|
51
|
private String springConfigFile = "src/main/resources/index-processor-context.xml";
|
52
|
Log log = LogFactory.getLog(ApplicationController.class);
|
53
|
|
54
|
|
55
|
/**
|
56
|
* Constructor
|
57
|
*/
|
58
|
public ApplicationController () throws Exception {
|
59
|
init();
|
60
|
}
|
61
|
|
62
|
/**
|
63
|
* Set the Spring configuration file.
|
64
|
* @param springConfigFile the path of the Spring configuration file
|
65
|
*/
|
66
|
public ApplicationController(String springConfigFile) throws Exception {
|
67
|
this.springConfigFile = springConfigFile;
|
68
|
init();
|
69
|
}
|
70
|
|
71
|
/**
|
72
|
* Initialize the list of the SolrIndex objects from the configuration file.
|
73
|
* Set the SolrServer implementation using the factory.
|
74
|
* Start listening for events on Hazelcast
|
75
|
*/
|
76
|
private void init() throws Exception {
|
77
|
context = getContext();
|
78
|
solrIndexes = (List<SolrIndex>) context.getBean(SOLRINDEXES);
|
79
|
|
80
|
// use factory to create the correct impl
|
81
|
SolrServer solrServer = null;
|
82
|
try {
|
83
|
solrServer = SolrServerFactory.createSolrServer();
|
84
|
} catch (Exception e) {
|
85
|
log.error("Could not create SolrServer form factory", e);
|
86
|
throw e;
|
87
|
}
|
88
|
|
89
|
// start the SystemMetadata listener[s] (only expect there to be one)
|
90
|
for (SolrIndex solrIndex: solrIndexes) {
|
91
|
// set the solr server to use
|
92
|
solrIndex.setSolrServer(solrServer);
|
93
|
|
94
|
// start listening for events
|
95
|
SystemMetadataEventListener smel = new SystemMetadataEventListener();
|
96
|
smel.setSolrIndex(solrIndex);
|
97
|
smel.start();
|
98
|
sysmetaListeners.add(smel);
|
99
|
}
|
100
|
|
101
|
}
|
102
|
|
103
|
/**
|
104
|
* Get the ApplicaionContext of Spring.
|
105
|
*/
|
106
|
private ApplicationContext getContext() {
|
107
|
if (context == null) {
|
108
|
context = new FileSystemXmlApplicationContext(springConfigFile);
|
109
|
}
|
110
|
return context;
|
111
|
}
|
112
|
|
113
|
/**
|
114
|
* Get the path of the Spring configuration file.
|
115
|
* @return the path of the Spring configuration file.
|
116
|
*/
|
117
|
public String getSpringConfigFile() {
|
118
|
return this.springConfigFile;
|
119
|
}
|
120
|
|
121
|
/**
|
122
|
* Get the list of the solr index.
|
123
|
* @return the list of the solr index.
|
124
|
*/
|
125
|
public List<SolrIndex> getSolrIndexes() {
|
126
|
return this.solrIndexes;
|
127
|
}
|
128
|
|
129
|
|
130
|
/**
|
131
|
* Start to generate indexes for those haven't been indexed in another thread.
|
132
|
*/
|
133
|
public void startIndex() {
|
134
|
SolrIndex index = solrIndexes.get(FIRST);
|
135
|
SystemMetadataEventListener listener = sysmetaListeners.get(FIRST);
|
136
|
IndexGenerator generator = new IndexGenerator(index, listener);
|
137
|
Thread indexThread = new Thread(generator);
|
138
|
indexThread.start();
|
139
|
}
|
140
|
}
|