root / src / org / gss_project / gss / mbeans / Solr.java @ 1206:292dec4eae08
History | View | Annotate | Download (2.9 kB)
1 |
/*
|
---|---|
2 |
* Copyright 2008, 2009 Electronic Business Systems Ltd.
|
3 |
*
|
4 |
* This file is part of GSS.
|
5 |
*
|
6 |
* GSS is free software: you can redistribute it and/or modify
|
7 |
* it under the terms of the GNU General Public License as published by
|
8 |
* the Free Software Foundation, either version 3 of the License, or
|
9 |
* (at your option) any later version.
|
10 |
*
|
11 |
* GSS is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
18 |
*/
|
19 |
package org.gss_project.gss.mbeans; |
20 |
|
21 |
import static org.gss_project.gss.server.configuration.GSSConfigurationFactory.getConfiguration; |
22 |
import org.gss_project.gss.server.ejb.ExternalAPI; |
23 |
|
24 |
import javax.management.JMRuntimeException; |
25 |
import javax.naming.InitialContext; |
26 |
import javax.naming.NamingException; |
27 |
import javax.rmi.PortableRemoteObject; |
28 |
|
29 |
import org.jboss.system.ServiceMBeanSupport; |
30 |
|
31 |
/**
|
32 |
* @author chstath
|
33 |
*
|
34 |
*/
|
35 |
public class Solr extends ServiceMBeanSupport implements SolrMBean { |
36 |
|
37 |
@Override
|
38 |
public String rebuildIndex() { |
39 |
try {
|
40 |
InitialContext ctx = new InitialContext(); |
41 |
Object ref = ctx.lookup(getConfiguration().getString("externalApiPath")); |
42 |
ExternalAPI service = (ExternalAPI) PortableRemoteObject.narrow(ref, ExternalAPI.class);
|
43 |
return service.rebuildSolrIndex();
|
44 |
} catch (ClassCastException e) { |
45 |
throw new JMRuntimeException(e.getMessage()); |
46 |
} catch (NamingException e) { |
47 |
throw new JMRuntimeException(e.getMessage()); |
48 |
} |
49 |
} |
50 |
|
51 |
@Override
|
52 |
public String refreshIndex() { |
53 |
try {
|
54 |
InitialContext ctx = new InitialContext(); |
55 |
Object ref = ctx.lookup(getConfiguration().getString("externalApiPath")); |
56 |
ExternalAPI service = (ExternalAPI) PortableRemoteObject.narrow(ref, ExternalAPI.class);
|
57 |
return service.refreshSolrIndex();
|
58 |
} catch (ClassCastException e) { |
59 |
throw new JMRuntimeException(e.getMessage()); |
60 |
} catch (NamingException e) { |
61 |
throw new JMRuntimeException(e.getMessage()); |
62 |
} |
63 |
} |
64 |
|
65 |
public String indexFile(Long id) { |
66 |
try {
|
67 |
InitialContext ctx = new InitialContext(); |
68 |
Object ref = ctx.lookup(getConfiguration().getString("externalApiPath")); |
69 |
ExternalAPI service = (ExternalAPI) PortableRemoteObject.narrow(ref, ExternalAPI.class);
|
70 |
try {
|
71 |
service.postFileToSolr(id); |
72 |
} |
73 |
catch (Exception e) { |
74 |
return "Indexing of file " + id + " failed"; |
75 |
} |
76 |
return "File " + id + " added to the index"; |
77 |
} catch (ClassCastException e) { |
78 |
throw new JMRuntimeException(e.getMessage()); |
79 |
} catch (NamingException e) { |
80 |
throw new JMRuntimeException(e.getMessage()); |
81 |
} |
82 |
} |
83 |
} |