Project

General

Profile

« Previous | Next » 

Revision 7842

only use MapStore/MapLoader for saving/loading IndexEvent objects. No need to use a listener since there is only the single node -- all entries are persisted to DB using the hazelcast.xml config we have for the map. https://projects.ecoinformatics.org/ecoinfo/issues/5944

View differences:

src/edu/ucsb/nceas/metacat/index/IndexEventEntryListener.java
1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: Implements a service for managing a Hazelcast cluster member
4
 *  Copyright: 2013 Regents of the University of California and the
5
 *             National Center for Ecological Analysis and Synthesis
6
 *    Authors: Leinfelder
7
 * 
8
 *   '$Author$'
9
 *     '$Date$'
10
 * '$Revision$'
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
 */
26
package edu.ucsb.nceas.metacat.index;
27

  
28
import java.sql.SQLException;
29
import java.util.Collection;
30
import java.util.Map;
31
import java.util.Set;
32
import java.util.TreeMap;
33

  
34
import org.apache.log4j.Logger;
35
import org.dataone.service.types.v1.Identifier;
36

  
37
import com.hazelcast.core.EntryEvent;
38
import com.hazelcast.core.EntryListener;
39
import com.hazelcast.core.MapLoader;
40
import com.hazelcast.core.MapStore;
41

  
42
import edu.ucsb.nceas.metacat.common.index.event.IndexEvent;
43

  
44
public class IndexEventEntryListener implements MapStore<Identifier, IndexEvent>, MapLoader<Identifier, IndexEvent>, EntryListener<Identifier, IndexEvent> {
45

  
46
	private Logger logMetacat = Logger.getLogger(IndexEventEntryListener.class);
47

  
48
	/**
49
	 * The map store/loader methods
50
	 */
51
	
52
	@Override
53
	public IndexEvent load(Identifier identifier) {
54
		try {
55
			return IndexEventDAO.getInstance().get(identifier);
56
		} catch (SQLException e) {
57
			logMetacat.error(e.getMessage(), e);
58
		}
59
		return null;
60
	}
61

  
62
	@Override
63
	public Map<Identifier, IndexEvent> loadAll(Collection<Identifier> identifiers) {
64
		Map<Identifier, IndexEvent> eventMap = new TreeMap<Identifier, IndexEvent>();
65
		for (Identifier identifier: identifiers) {
66
			IndexEvent event = null;
67
			try {
68
				event = IndexEventDAO.getInstance().get(identifier);
69
				eventMap.put(identifier, event);
70
			} catch (SQLException e) {
71
				logMetacat.error(e.getMessage(), e);
72
			}
73
		}
74
		return eventMap;
75
	}
76

  
77
	@Override
78
	public Set<Identifier> loadAllKeys() {
79
		try {
80
			return IndexEventDAO.getInstance().getAllIdentifiers();
81
		} catch (SQLException e) {
82
			logMetacat.error(e.getMessage(), e);
83
		}
84
		return null;
85
	}
86

  
87
	@Override
88
	public void delete(Identifier identifier) {
89
		try {
90
			IndexEventDAO.getInstance().remove(identifier);
91
		} catch (SQLException e) {
92
			logMetacat.error(e.getMessage(), e);
93
		}		
94
	}
95

  
96
	@Override
97
	public void deleteAll(Collection<Identifier> identifiers) {
98
		for (Identifier identifier: identifiers) {
99
			try {
100
				IndexEventDAO.getInstance().remove(identifier);
101
			} catch (SQLException e) {
102
				logMetacat.error(e.getMessage(), e);
103
			}
104
		}
105
	}
106

  
107
	@Override
108
	public void store(Identifier identifier, IndexEvent event) {
109
		try {
110
			IndexEventDAO.getInstance().add(event);
111
		} catch (SQLException e) {
112
			logMetacat.error(e.getMessage(), e);
113
		}		
114
	}
115

  
116
	@Override
117
	public void storeAll(Map<Identifier, IndexEvent> indexEventMap) {
118
		for (IndexEvent event: indexEventMap.values()) {
119
			try {
120
				IndexEventDAO.getInstance().add(event);
121
			} catch (SQLException e) {
122
				logMetacat.error(e.getMessage(), e);
123
			}
124
		}
125
	}
126
	
127
	/**
128
	 * The EntryListener methods below
129
	 */
130

  
131
	@Override
132
	public void entryAdded(EntryEvent<Identifier, IndexEvent> event) {
133
		try {
134
			IndexEventDAO.getInstance().add(event.getValue());
135
		} catch (SQLException e) {
136
			logMetacat.error(e.getMessage(), e);
137
		}		
138
	}
139

  
140
	@Override
141
	public void entryEvicted(EntryEvent<Identifier, IndexEvent> arg0) {
142
		// do nothing
143
		
144
	}
145

  
146
	@Override
147
	public void entryRemoved(EntryEvent<Identifier, IndexEvent> event) {
148
		try {
149
			IndexEventDAO.getInstance().remove(event.getKey());
150
		} catch (SQLException e) {
151
			logMetacat.error(e.getMessage(), e);
152
		}		
153
	}
154

  
155
	@Override
156
	public void entryUpdated(EntryEvent<Identifier, IndexEvent> event) {
157
		try {
158
			IndexEventDAO.getInstance().add(event.getValue());
159
		} catch (SQLException e) {
160
			logMetacat.error(e.getMessage(), e);
161
		}		
162
	}
163

  
164
}
165 0

  
lib/hazelcast.xml
89 89
    <eviction-percentage>25</eviction-percentage>
90 90
    <merge-policy>hz.ADD_NEW_ENTRY</merge-policy>
91 91
    <map-store enabled="true">
92
      <class-name>edu.ucsb.nceas.metacat.index.IndexEventEntryListener</class-name>
92
      <class-name>edu.ucsb.nceas.metacat.index.IndexEventMapStore</class-name>
93 93
      <write-delay-seconds>0</write-delay-seconds>
94 94
    </map-store>
95 95
  </map>
src/edu/ucsb/nceas/metacat/dataone/hazelcast/HazelcastService.java
63 63
import edu.ucsb.nceas.metacat.IdentifierManager;
64 64
import edu.ucsb.nceas.metacat.McdbDocNotFoundException;
65 65
import edu.ucsb.nceas.metacat.common.index.event.IndexEvent;
66
import edu.ucsb.nceas.metacat.index.IndexEventEntryListener;
67 66
import edu.ucsb.nceas.metacat.properties.PropertyService;
68 67
import edu.ucsb.nceas.metacat.shared.BaseService;
69 68
import edu.ucsb.nceas.metacat.shared.ServiceException;
src/edu/ucsb/nceas/metacat/index/IndexEventMapStore.java
1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: Implements a service for managing a Hazelcast cluster member
4
 *  Copyright: 2013 Regents of the University of California and the
5
 *             National Center for Ecological Analysis and Synthesis
6
 *    Authors: Leinfelder
7
 * 
8
 *   '$Author$'
9
 *     '$Date$'
10
 * '$Revision$'
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
 */
26
package edu.ucsb.nceas.metacat.index;
27

  
28
import java.sql.SQLException;
29
import java.util.Collection;
30
import java.util.Map;
31
import java.util.Set;
32
import java.util.TreeMap;
33

  
34
import org.apache.log4j.Logger;
35
import org.dataone.service.types.v1.Identifier;
36

  
37
import com.hazelcast.core.MapLoader;
38
import com.hazelcast.core.MapStore;
39

  
40
import edu.ucsb.nceas.metacat.common.index.event.IndexEvent;
41

  
42
public class IndexEventMapStore implements MapStore<Identifier, IndexEvent>, MapLoader<Identifier, IndexEvent> {
43

  
44
	private Logger logMetacat = Logger.getLogger(IndexEventMapStore.class);
45

  
46
	/**
47
	 * The map store/loader methods
48
	 */
49
	
50
	@Override
51
	public IndexEvent load(Identifier identifier) {
52
		try {
53
			return IndexEventDAO.getInstance().get(identifier);
54
		} catch (SQLException e) {
55
			logMetacat.error(e.getMessage(), e);
56
		}
57
		return null;
58
	}
59

  
60
	@Override
61
	public Map<Identifier, IndexEvent> loadAll(Collection<Identifier> identifiers) {
62
		Map<Identifier, IndexEvent> eventMap = new TreeMap<Identifier, IndexEvent>();
63
		for (Identifier identifier: identifiers) {
64
			IndexEvent event = null;
65
			try {
66
				event = IndexEventDAO.getInstance().get(identifier);
67
				eventMap.put(identifier, event);
68
			} catch (SQLException e) {
69
				logMetacat.error(e.getMessage(), e);
70
			}
71
		}
72
		return eventMap;
73
	}
74

  
75
	@Override
76
	public Set<Identifier> loadAllKeys() {
77
		try {
78
			return IndexEventDAO.getInstance().getAllIdentifiers();
79
		} catch (SQLException e) {
80
			logMetacat.error(e.getMessage(), e);
81
		}
82
		return null;
83
	}
84

  
85
	@Override
86
	public void delete(Identifier identifier) {
87
		try {
88
			IndexEventDAO.getInstance().remove(identifier);
89
		} catch (SQLException e) {
90
			logMetacat.error(e.getMessage(), e);
91
		}		
92
	}
93

  
94
	@Override
95
	public void deleteAll(Collection<Identifier> identifiers) {
96
		for (Identifier identifier: identifiers) {
97
			try {
98
				IndexEventDAO.getInstance().remove(identifier);
99
			} catch (SQLException e) {
100
				logMetacat.error(e.getMessage(), e);
101
			}
102
		}
103
	}
104

  
105
	@Override
106
	public void store(Identifier identifier, IndexEvent event) {
107
		try {
108
			IndexEventDAO.getInstance().add(event);
109
		} catch (SQLException e) {
110
			logMetacat.error(e.getMessage(), e);
111
		}		
112
	}
113

  
114
	@Override
115
	public void storeAll(Map<Identifier, IndexEvent> indexEventMap) {
116
		for (IndexEvent event: indexEventMap.values()) {
117
			try {
118
				IndexEventDAO.getInstance().add(event);
119
			} catch (SQLException e) {
120
				logMetacat.error(e.getMessage(), e);
121
			}
122
		}
123
	}
124
	
125
}
0 126

  

Also available in: Unified diff