Project

General

Profile

« Previous | Next » 

Revision 2901

Added by sgarg over 18 years ago

Added a flag for indexing threads so that they exit once Metacat has unloaded.

View differences:

src/edu/ucsb/nceas/metacat/IndexingQueue.java
43 43
	private HashMap indexingMap = new HashMap();     
44 44
	private Vector currentThreads = new Vector();
45 45
	public Vector currentDocidsBeingIndexed = new Vector();
46
	private boolean metacatRunning = true;
46 47
	
47 48
	private static IndexingQueue instance = null;
48 49

  
......
84 85
	    }
85 86
	  }
86 87
    
88
	public boolean getMetacatRunning(){
89
		return this.metacatRunning;
90
	}
87 91
	
92
	public void setMetacatRunning(boolean metacatRunning){
93
		this.metacatRunning = metacatRunning;
94
		
95
		if(metacatRunning == false){
96
			indexingMap.notifyAll();
97
		}
98
	}
99
	
88 100
    protected IndexingQueueObject getNext() {
89 101
    	IndexingQueueObject returnVal = null;
90 102
        synchronized (indexingMap) {
91
          while (indexingMap.isEmpty()) {
103
          while (indexingMap.isEmpty() && metacatRunning) {
92 104
            try {
93 105
            	indexingMap.wait();
94 106
            } catch (InterruptedException ex) {
95 107
              System.err.println("Interrupted");
96 108
            }
97 109
          }
98
          String docid = (String) indexingMap.keySet().iterator().next();
99
          returnVal = (IndexingQueueObject)indexingMap.get(docid);
100
          indexingMap.remove(docid);
110
          
111
          if(metacatRunning){
112
        	  String docid = (String) indexingMap.keySet().iterator().next();
113
        	  returnVal = (IndexingQueueObject)indexingMap.get(docid);
114
        	  indexingMap.remove(docid);
115
          }
101 116
        }
102 117
        return returnVal;
103 118
      }
......
110 125
      	parseInt(MetaCatUtil.getOption("maximumIndexDelay"));;
111 126

  
112 127
	  public void run() {
113
	    while (true) {
128
	    while (IndexingQueue.getInstance().getMetacatRunning()) {
114 129
	      // blocks until job
115 130
	      IndexingQueueObject returnVal = 
116 131
	    	  IndexingQueue.getInstance().getNext();
117 132

  
118
    	  if(!IndexingQueue.getInstance().
133
	      if(returnVal != null){
134
	    	  if(!IndexingQueue.getInstance().
119 135
	    			currentDocidsBeingIndexed.contains(returnVal.getDocid())){
120 136
    		  try {
121 137
    			  IndexingQueue.getInstance().
......
132 148
	                  throw(new Exception("Couldn't find the docid:" + docid 
133 149
	                			+ " in xml_documents table"));
134 150
    			  }
135
    		  } catch (Exception e) {
151
    		  	} catch (Exception e) {
136 152
    			  logMetacat.warn("Exception: " + e);
137 153
    			  e.printStackTrace();
138 154
	        
......
146 162
	        			+ "more than 25 times. Not adding the docid to"
147 163
	        			+ " the queue again.");
148 164
    			  }
149
    		  } finally {
150
    			  IndexingQueue.getInstance().currentDocidsBeingIndexed
151
	    	  			.remove(returnVal.getDocid());	    	  
152
    		  }
153
    	  } else {
154
				returnVal.setCount(returnVal.getCount()+1);
155
				IndexingQueue.getInstance().add(returnVal);    		  
156
    	  }
165
    		  	} finally {
166
    			  	IndexingQueue.getInstance().currentDocidsBeingIndexed
167
    			  		.remove(returnVal.getDocid());	    	  
168
    		  	}
169
	    	  } else {
170
	    		  returnVal.setCount(returnVal.getCount()+1);
171
	    		  IndexingQueue.getInstance().add(returnVal);    		  
172
	    	  }
173
	      }
157 174
	    }
158 175
	  }
159 176
	  
src/edu/ucsb/nceas/metacat/MetaCatServlet.java
223 223
        // Close all db connection
224 224
        System.out.println("Destroying MetacatServlet");
225 225
        timer.cancel();
226
        IndexingQueue.getInstance().setMetacatRunning(false);
226 227
        DBConnectionPool.release();
227 228
    }
228 229

  

Also available in: Unified diff