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.io.FileInputStream;
|
30
|
import java.io.InputStream;
|
31
|
|
32
|
import org.apache.commons.logging.Log;
|
33
|
import org.apache.commons.logging.LogFactory;
|
34
|
import org.dataone.configuration.Settings;
|
35
|
import org.dataone.service.types.v1.Identifier;
|
36
|
import org.dataone.service.types.v1.SystemMetadata;
|
37
|
|
38
|
import com.hazelcast.client.ClientConfig;
|
39
|
import com.hazelcast.client.HazelcastClient;
|
40
|
import com.hazelcast.core.EntryEvent;
|
41
|
import com.hazelcast.core.EntryListener;
|
42
|
import com.hazelcast.core.IMap;
|
43
|
|
44
|
public class SystemMetadataEventListener implements EntryListener<Identifier, SystemMetadata> {
|
45
|
|
46
|
private static Log log = LogFactory.getLog(SystemMetadataEventListener.class);
|
47
|
|
48
|
private SolrIndex solrIndex = null;
|
49
|
|
50
|
private HazelcastClient hzClient;
|
51
|
|
52
|
private IMap<Identifier, SystemMetadata> systemMetadataMap;
|
53
|
|
54
|
private IMap<Identifier, String> objectPathMap;
|
55
|
|
56
|
/**
|
57
|
* Register this instance as a system metadata map event listener.
|
58
|
*/
|
59
|
public void start() {
|
60
|
|
61
|
// get config values
|
62
|
String hzSystemMetadata = Settings.getConfiguration().getString(
|
63
|
"dataone.hazelcast.systemMetadata");
|
64
|
String hzObjectPath = Settings.getConfiguration().getString(
|
65
|
"dataone.hazelcast.objectPath");
|
66
|
String hzGroupName = Settings.getConfiguration().getString(
|
67
|
"dataone.hazelcast.groupName");
|
68
|
String hzGroupPassword = Settings.getConfiguration().getString(
|
69
|
"dataone.hazelcast.groupPassword");
|
70
|
String hzAddress = Settings.getConfiguration().getString(
|
71
|
"dataone.hazelcast.address");
|
72
|
|
73
|
log.info("starting index entry listener...");
|
74
|
log.info("System Metadata value: " + hzSystemMetadata);
|
75
|
log.info("Object path value: " + hzObjectPath);
|
76
|
log.info("Group Name: " + hzGroupName);
|
77
|
log.info("Group Password: " + "*****"); // don't show value
|
78
|
log.info("HZ Address: " + hzAddress);
|
79
|
|
80
|
// connect to the HZ cluster
|
81
|
ClientConfig cc = new ClientConfig();
|
82
|
cc.getGroupConfig().setName(hzGroupName);
|
83
|
cc.getGroupConfig().setPassword(hzGroupPassword);
|
84
|
cc.addAddress(hzAddress );
|
85
|
try {
|
86
|
this.hzClient = HazelcastClient.newHazelcastClient(cc);
|
87
|
} catch (Exception e) {
|
88
|
log.error("Unable to create hazelcast client: ", e);
|
89
|
e.printStackTrace();
|
90
|
}
|
91
|
|
92
|
// get shared structures and add listener
|
93
|
this.systemMetadataMap = this.hzClient.getMap(hzSystemMetadata);
|
94
|
this.objectPathMap = this.hzClient.getMap(hzObjectPath);
|
95
|
this.systemMetadataMap.addEntryListener(this, true);
|
96
|
|
97
|
log.info("System Metadata size: " + this.systemMetadataMap.size());
|
98
|
log.info("Object path size:" + this.objectPathMap.size());
|
99
|
}
|
100
|
|
101
|
/**
|
102
|
* Removes this instance as a system metadata map event listener.
|
103
|
*/
|
104
|
public void stop() {
|
105
|
log.info("stopping index entry listener...");
|
106
|
this.systemMetadataMap.removeEntryListener(this);
|
107
|
}
|
108
|
|
109
|
public void entryAdded(EntryEvent<Identifier, SystemMetadata> entryEvent) {
|
110
|
// add to the index
|
111
|
Identifier pid = entryEvent.getKey();
|
112
|
SystemMetadata systemMetadata = entryEvent.getValue();
|
113
|
|
114
|
String objectPath = objectPathMap.get(pid);
|
115
|
InputStream data = null;
|
116
|
try {
|
117
|
data = new FileInputStream(objectPath);
|
118
|
// TODO: pass the SM object
|
119
|
solrIndex.insert(pid.getValue(), null, data);
|
120
|
} catch (Exception e) {
|
121
|
log.error(e.getMessage(), e);
|
122
|
}
|
123
|
|
124
|
}
|
125
|
|
126
|
public void entryEvicted(EntryEvent<Identifier, SystemMetadata> entryEvent) {
|
127
|
// TODO Auto-generated method stub
|
128
|
|
129
|
}
|
130
|
|
131
|
public void entryRemoved(EntryEvent<Identifier, SystemMetadata> entryEvent) {
|
132
|
// TODO Auto-generated method stub
|
133
|
|
134
|
}
|
135
|
|
136
|
public void entryUpdated(EntryEvent<Identifier, SystemMetadata> entryEvent) {
|
137
|
// TODO Auto-generated method stub
|
138
|
|
139
|
}
|
140
|
|
141
|
}
|