Project

General

Profile

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

    
24
import java.util.ArrayList;
25
import java.util.Date;
26
import java.util.List;
27

    
28
import org.dataone.service.types.v1.Event;
29
import org.dataone.service.types.v1.Identifier;
30

    
31
import edu.ucsb.nceas.metacat.common.index.event.IndexEvent;
32
import edu.ucsb.nceas.metacat.index.DistributedMapsFactory;
33

    
34
/**
35
 * @author leinfelder
36
 *
37
 */
38
public class HazelcastIndexEventLog implements IndexEventLog {
39

    
40
	/* (non-Javadoc)
41
	 * @see edu.ucsb.nceas.metacat.index.event.IndexEventLog#write(edu.ucsb.nceas.metacat.index.event.IndexEvent)
42
	 */
43
	@Override
44
	public void write(IndexEvent event) throws IndexEventLogException {
45
		// write to the map
46
		try {
47
			DistributedMapsFactory.getIndexEventMap().put(event.getIdentifier(), event);
48
		} catch (Exception e) {
49
			throw new IndexEventLogException("Could not write to event map", e);
50
		}
51
	}
52

    
53
	/* (non-Javadoc)
54
	 * @see edu.ucsb.nceas.metacat.index.event.IndexEventLog#remove(java.lang.String)
55
	 */
56
	@Override
57
	public void remove(Identifier identifier) throws IndexEventLogException {
58
		// remove from the map
59
		try {
60
			DistributedMapsFactory.getIndexEventMap().remove(identifier);
61
		} catch (Exception e) {
62
			throw new IndexEventLogException("Could not remove from event map", e);
63
		}
64

    
65
	}
66

    
67
	/* (non-Javadoc)
68
	 * @see edu.ucsb.nceas.metacat.index.event.IndexEventLog#getEvents(int, org.dataone.service.types.v1.Identifier, java.util.Date, java.util.Date)
69
	 */
70
	@Override
71
	public List<IndexEvent> getEvents(Event action, Identifier pid, Date start, Date end) throws IndexEventLogException {
72
		try {
73
			// TODO: query the map using the parameters
74
			return new ArrayList<IndexEvent>(DistributedMapsFactory.getIndexEventMap().values());
75
		} catch (Exception e) {
76
			throw new IndexEventLogException("Could not remove from event map", e);
77
		}
78
	}
79

    
80
	/* (non-Javadoc)
81
	 * @see edu.ucsb.nceas.metacat.index.event.IndexEventLog#getLastProcessDate()
82
	 */
83
	@Override
84
	public Date getLastProcessDate() throws IndexEventLogException {
85
		// TODO Auto-generated method stub
86
		return null;
87
	}
88

    
89
	/* (non-Javadoc)
90
	 * @see edu.ucsb.nceas.metacat.index.event.IndexEventLog#setLastProcessDate(java.util.Date)
91
	 */
92
	@Override
93
	public void setLastProcessDate(Date date) throws IndexEventLogException {
94
		// TODO Auto-generated method stub
95

    
96
	}
97

    
98
}
(2-2/5)