Project

General

Profile

« Previous | Next » 

Revision 7432

clean up index queue code before tackling index/delete race condition. http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5750

View differences:

src/edu/ucsb/nceas/metacat/IndexingQueue.java
36 36
import edu.ucsb.nceas.metacat.database.DBConnection;
37 37
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
38 38
import edu.ucsb.nceas.metacat.properties.PropertyService;
39
import edu.ucsb.nceas.metacat.util.MetacatUtil;
40 39
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
41 40

  
42 41
import org.apache.log4j.Logger;
43 42

  
44 43
public class IndexingQueue {
45 44

  
46
	private Logger logMetacat = Logger.getLogger(IndexingQueue.class);
45
	private static Logger logMetacat = Logger.getLogger(IndexingQueue.class);
47 46
	//	 Map used to keep tracks of docids to be indexed
48
	private HashMap indexingMap = new HashMap();     
49
	private Vector currentThreads = new Vector();
50
	public Vector currentDocidsBeingIndexed = new Vector();
47
	private HashMap<String, IndexingQueueObject> indexingMap = new HashMap<String, IndexingQueueObject>();     
48
	private Vector<IndexingTask> currentThreads = new Vector<IndexingTask>();
49
	public Vector<String> currentDocidsBeingIndexed = new Vector<String>();
51 50
	private boolean metacatRunning = true;
52 51
	
53 52
	private static IndexingQueue instance = null;
......
59 58
			numIndexingThreads = 
60 59
				Integer.parseInt(PropertyService.getProperty("database.numberOfIndexingThreads"));
61 60
		} catch (PropertyNotFoundException pnfe) {
62
			System.err.println("Could not get property in static block: " 
61
			logMetacat.error("Could not get property in static block: " 
63 62
					+ pnfe.getMessage());
64 63
		}
65 64
		NUMBEROFINDEXINGTHREADS = numIndexingThreads;
66 65
	}
67 66

  
68
	
69
	private int sleepTime = 2000; 
70

  
71 67
    private IndexingQueue() {
72 68
	    for (int i = 0; i < NUMBEROFINDEXINGTHREADS; i++) {
73
	      Thread thread = new IndexingTask();
74
	      thread.start();
75
	      currentThreads.add(thread);
69
	    	IndexingTask thread = new IndexingTask();
70
	    	thread.start();
71
	    	currentThreads.add(thread);
76 72
	    }
77 73
    }
78 74
	
......
93 89
	    		indexingMap.put(queueObject.getDocid(), queueObject);
94 90
	    		indexingMap.notify();
95 91
	    	} else {
96
	    		IndexingQueueObject oldQueueObject = 
97
	    			(IndexingQueueObject) indexingMap.get(queueObject.getDocid());
92
	    		IndexingQueueObject oldQueueObject = indexingMap.get(queueObject.getDocid());
98 93
	    		if(oldQueueObject.compareTo(queueObject) < 0){
99 94
	    	  		indexingMap.put(queueObject.getDocid(), queueObject);
100 95
		    		indexingMap.notify();  			
......
112 107
		
113 108
		if(!metacatRunning){
114 109
			for(int count=0; count<currentThreads.size(); count++){
115
				((IndexingTask)currentThreads.get(count)).metacatRunning = false;
116
				((Thread)currentThreads.get(count)).interrupt();
110
				currentThreads.get(count).metacatRunning = false;
111
				currentThreads.get(count).interrupt();
117 112
			}
118 113
		}
119 114
	}
......
130 125
          }
131 126
          
132 127
          if(metacatRunning){
133
        	  String docid = (String) indexingMap.keySet().iterator().next();
134
        	  returnVal = (IndexingQueueObject)indexingMap.get(docid);
128
        	  String docid = indexingMap.keySet().iterator().next();
129
        	  returnVal = indexingMap.get(docid);
135 130
        	  indexingMap.remove(docid);
136 131
          }
137 132
        }

Also available in: Unified diff