Project

General

Profile

« Previous | Next » 

Revision 7811

consolidate SystemMetadata map retrieval in preparation for using a different structure for objects to index.

View differences:

metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/ApplicationController.java
26 26
 */
27 27
package edu.ucsb.nceas.metacat.index;
28 28

  
29
import edu.ucsb.nceas.metacat.common.SolrServerFactory;
30
import edu.ucsb.nceas.metacat.common.query.EnabledQueryEngines;
31

  
32 29
import java.io.File;
30
import java.io.FileNotFoundException;
33 31
import java.util.ArrayList;
34 32
import java.util.List;
35 33
import java.util.Timer;
36 34

  
37
import javax.servlet.ServletConfig;
38
import javax.servlet.ServletException;
39

  
40 35
import org.apache.commons.configuration.ConfigurationException;
41 36
import org.apache.commons.logging.Log;
42 37
import org.apache.commons.logging.LogFactory;
......
46 41
import org.springframework.context.ApplicationContext;
47 42
import org.springframework.context.support.FileSystemXmlApplicationContext;
48 43

  
49
import com.hazelcast.client.HazelcastClient;
50 44
import com.ibm.icu.util.Calendar;
51 45

  
46
import edu.ucsb.nceas.metacat.common.SolrServerFactory;
47
import edu.ucsb.nceas.metacat.common.query.EnabledQueryEngines;
48

  
52 49
/**
53 50
 * The start class of the index.
54 51
 * @author tao
......
228 225
    /**
229 226
     * Start the system metadata listener. Prior to call this method, we should call
230 227
     * initialize method first.
228
     * @throws ServiceFailure 
229
     * @throws FileNotFoundException 
231 230
     */
232
    public void startSysmetaListener() {
231
    public void startSysmetaListener() throws FileNotFoundException, ServiceFailure {
233 232
        if(sysmetaListeners != null) {
234 233
            //only expects one listener.
235 234
            for(SystemMetadataEventListener listener : sysmetaListeners) {
metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/SystemMetadataEventListener.java
34 34

  
35 35
import org.apache.commons.logging.Log;
36 36
import org.apache.commons.logging.LogFactory;
37
import org.dataone.configuration.Settings;
37
import org.dataone.service.exceptions.ServiceFailure;
38 38
import org.dataone.service.types.v1.Identifier;
39 39
import org.dataone.service.types.v1.SystemMetadata;
40 40

  
41
import com.hazelcast.client.ClientConfig;
42
import com.hazelcast.client.HazelcastClient;
43
import com.hazelcast.config.Config;
44
import com.hazelcast.config.FileSystemXmlConfig;
45 41
import com.hazelcast.core.EntryEvent;
46 42
import com.hazelcast.core.EntryListener;
47 43
import com.hazelcast.core.IMap;
......
51 47
	private static Log log = LogFactory.getLog(SystemMetadataEventListener.class);
52 48
	
53 49
	private SolrIndex solrIndex = null;
54
	
55
	//private HazelcastClient hzClient;
56

  
57
    private IMap<Identifier, SystemMetadata> systemMetadataMap;
58
    
59
    private IMap<Identifier, String> objectPathMap;
60
    
50
	        
61 51
    /**
62 52
     * Default constructor - caller needs to initialize manually
63 53
     * @see setSolrIndex()
......
72 62
     */
73 63
    public SystemMetadataEventListener(SolrIndex solrIndex) {
74 64
    	this.solrIndex = solrIndex;
75
    	start();
65
    	try {
66
			start();
67
		} catch (Exception e) {
68
			log.error(e.getMessage(), e);
69
		}
76 70
    }
77 71
    
78 72
    /**
......
93 87

  
94 88
	/**
95 89
     * Registers this instance as a system metadata map event listener
90
	 * @throws ServiceFailure 
91
	 * @throws FileNotFoundException 
96 92
     */
97
    public void start() {
93
    public void start() throws FileNotFoundException, ServiceFailure {
98 94
    	
99
        try {
100
            // get shared structures and add listener
101
            this.systemMetadataMap =  DistributedMapsFactory.getSystemMetadataMap();
102
            this.objectPathMap = DistributedMapsFactory.getObjectPathMap();
103

  
104
        } catch (Exception e) {
105
            log.error("Unable to create hazelcast client: ", e);
106
            e.printStackTrace();
107
        }
108
        
109
        this.systemMetadataMap.addEntryListener(this, true);
110
        log.info("System Metadata size: " + this.systemMetadataMap.size());
111
        log.info("Object path size:" + this.objectPathMap.size());
95
        // get shared structures and add listener
96
        IMap<Identifier, String> objectPathMap = DistributedMapsFactory.getObjectPathMap();
97
        IMap<Identifier, SystemMetadata> systemMetadataMap = DistributedMapsFactory.getSystemMetadataMap();
98
		systemMetadataMap.addEntryListener(this, true);
99
        log.info("System Metadata size: " + systemMetadataMap.size());
100
        log.info("Object path size:" + objectPathMap.size());
112 101
    }
113 102

  
114 103
    /**
115 104
     * Removes this instance as a system metadata map event listener
105
     * @throws ServiceFailure 
106
     * @throws FileNotFoundException 
116 107
     */
117
    public void stop() {
108
    public void stop() throws FileNotFoundException, ServiceFailure {
118 109
    	log.info("stopping index entry listener...");
119
        this.systemMetadataMap.removeEntryListener(this);
110
    	DistributedMapsFactory.getSystemMetadataMap().removeEntryListener(this);
120 111
    }
121 112
    
122 113
    /**
123
     * Get the SystemMetadata for the specified id from the distributed Map.
124
     * The null maybe is returned if there is no system metadata found.
125
     * @param id  the specified id.
126
     * @return the SystemMetadata associated with the id.
127
     */
128
    private SystemMetadata getSystemMetadata(String id) {
129
        SystemMetadata metadata = null;
130
        if(systemMetadataMap != null && id != null) {
131
            Identifier identifier = new Identifier();
132
            identifier.setValue(id);
133
            metadata = systemMetadataMap.get(identifier);
134
        }
135
        return metadata;
136
    }
137
    
138
    /**
139 114
     * Get the obsoletes chain of the specified id. The returned list doesn't include
140 115
     * the specified id itself. The newer version has the lower index number in the list.
141 116
     * Empty list will be returned if there is no document to be obsoleted by this id.
142 117
     * @param id
143 118
     * @return
119
     * @throws ServiceFailure
120
     * @throws FileNotFoundException 
144 121
     */
145
    private List<String> getObsoletes(String id) {
122
    private List<String> getObsoletes(String id) throws FileNotFoundException, ServiceFailure {
146 123
        List<String> obsoletes = new ArrayList<String>();
147 124
        while (id != null) {
148
            SystemMetadata metadata = getSystemMetadata(id);
125
            SystemMetadata metadata = DistributedMapsFactory.getSystemMetadata(id);
149 126
            id = null;//set it to be null in order to stop the while loop if the id can't be assinged to a new value in the following code.
150 127
            if(metadata != null) {
151 128
                Identifier identifier = metadata.getObsoletes();
......
196 173
		SystemMetadata systemMetadata = entryEvent.getValue();
197 174
		Identifier obsoletes = systemMetadata.getObsoletes();
198 175
		List<String> obsoletesChain = null;
199
		if(obsoletes != null) {
200
		    obsoletesChain= getObsoletes(pid.getValue());
176
		if (obsoletes != null) {
177
		    try {
178
				obsoletesChain = getObsoletes(pid.getValue());
179
			} catch (Exception e) {
180
	            log.error("Could not look up revision history" + e.getMessage(), e);
181
			}
201 182
		}
202
		String objectPath = objectPathMap.get(pid);
183
		String objectPath = null;
184
		try {
185
			objectPath = DistributedMapsFactory.getObjectPathMap().get(pid);
186
		} catch (Exception e) {
187
			log.error("Could not look up object path" + e.getMessage(), e);
188
		}
203 189
		if(objectPath != null) {
204 190
		    InputStream data = null;
205 191
	        try {

Also available in: Unified diff