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 edu.ucsb.nceas.metacat.common.SolrServerFactory;
|
30
|
import java.util.ArrayList;
|
31
|
import java.util.List;
|
32
|
|
33
|
import org.apache.commons.logging.Log;
|
34
|
import org.apache.commons.logging.LogFactory;
|
35
|
import org.apache.solr.client.solrj.SolrServer;
|
36
|
import org.springframework.context.ApplicationContext;
|
37
|
import org.springframework.context.support.FileSystemXmlApplicationContext;
|
38
|
|
39
|
/**
|
40
|
* The start class of the index.
|
41
|
* @author tao
|
42
|
*
|
43
|
*/
|
44
|
public class ApplicationController {
|
45
|
|
46
|
private static String SOLRINDEXES = "solrIndexes";
|
47
|
private static short FIRST = 0;
|
48
|
|
49
|
private List<SolrIndex> solrIndexes = null;
|
50
|
//private List<SystemMetadataEventListener> sysmetaListeners = new ArrayList<SystemMetadataEventListener>();
|
51
|
private static ApplicationContext context = null;
|
52
|
private String springConfigFile = "src/main/resources/index-processor-context.xml";
|
53
|
Log log = LogFactory.getLog(ApplicationController.class);
|
54
|
|
55
|
|
56
|
/**
|
57
|
* Constructor
|
58
|
*/
|
59
|
public ApplicationController () throws Exception {
|
60
|
init();
|
61
|
}
|
62
|
|
63
|
/**
|
64
|
* Set the Spring configuration file.
|
65
|
* @param springConfigFile the path of the Spring configuration file
|
66
|
*/
|
67
|
public ApplicationController(String springConfigFile) throws Exception {
|
68
|
this.springConfigFile = springConfigFile;
|
69
|
init();
|
70
|
}
|
71
|
|
72
|
/**
|
73
|
* Initialize the list of the SolrIndex objects from the configuration file.
|
74
|
* Set the SolrServer implementation using the factory.
|
75
|
* Start listening for events on Hazelcast
|
76
|
*/
|
77
|
private void init() throws Exception {
|
78
|
context = getContext();
|
79
|
solrIndexes = (List<SolrIndex>) context.getBean(SOLRINDEXES);
|
80
|
|
81
|
// use factory to create the correct impl
|
82
|
SolrServer solrServer = null;
|
83
|
try {
|
84
|
solrServer = SolrServerFactory.createSolrServer();
|
85
|
} catch (Exception e) {
|
86
|
log.error("Could not create SolrServer form factory", e);
|
87
|
throw e;
|
88
|
}
|
89
|
|
90
|
// start the SystemMetadata listener[s] (only expect there to be one)
|
91
|
for (SolrIndex solrIndex: solrIndexes) {
|
92
|
// set the solr server to use
|
93
|
solrIndex.setSolrServer(solrServer);
|
94
|
|
95
|
// start listening for events
|
96
|
SystemMetadataEventListener smel = new SystemMetadataEventListener();
|
97
|
smel.setSolrIndex(solrIndex);
|
98
|
smel.start();
|
99
|
//sysmetaListeners.add(smel);
|
100
|
}
|
101
|
|
102
|
}
|
103
|
|
104
|
/**
|
105
|
* Get the ApplicaionContext of Spring.
|
106
|
*/
|
107
|
private ApplicationContext getContext() {
|
108
|
if (context == null) {
|
109
|
context = new FileSystemXmlApplicationContext(springConfigFile);
|
110
|
}
|
111
|
return context;
|
112
|
}
|
113
|
|
114
|
/**
|
115
|
* Get the path of the Spring configuration file.
|
116
|
* @return the path of the Spring configuration file.
|
117
|
*/
|
118
|
public String getSpringConfigFile() {
|
119
|
return this.springConfigFile;
|
120
|
}
|
121
|
|
122
|
/**
|
123
|
* Get the list of the solr index.
|
124
|
* @return the list of the solr index.
|
125
|
*/
|
126
|
public List<SolrIndex> getSolrIndexes() {
|
127
|
return this.solrIndexes;
|
128
|
}
|
129
|
|
130
|
|
131
|
/**
|
132
|
* Start to generate indexes for those haven't been indexed in another thread.
|
133
|
*/
|
134
|
public void startIndex() {
|
135
|
SolrIndex index = solrIndexes.get(FIRST);
|
136
|
//SystemMetadataEventListener listener = sysmetaListeners.get(FIRST);
|
137
|
IndexGenerator generator = new IndexGenerator(index);
|
138
|
Thread indexThread = new Thread(generator);
|
139
|
indexThread.start();
|
140
|
}
|
141
|
}
|