/** * '$RCSfile$' * Purpose: A Class that tracks sessions for MetaCatServlet users. * Copyright: 2000 Regents of the University of California and the * National Center for Ecological Analysis and Synthesis * Authors: Matt Jones * * '$Author$' * '$Date$' * '$Revision$' * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package edu.ucsb.nceas.metacat; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Vector; import java.util.HashMap; import java.lang.Comparable; import edu.ucsb.nceas.metacat.common.query.EnabledQueryEngines; import edu.ucsb.nceas.metacat.database.DBConnection; import edu.ucsb.nceas.metacat.database.DBConnectionPool; import edu.ucsb.nceas.metacat.properties.PropertyService; import edu.ucsb.nceas.utilities.PropertyNotFoundException; import org.apache.log4j.Logger; public class IndexingQueue { private static Logger logMetacat = Logger.getLogger(IndexingQueue.class); // Map used to keep tracks of docids to be indexed private HashMap indexingMap = new HashMap(); private Vector currentThreads = new Vector(); public Vector currentDocidsBeingIndexed = new Vector(); private boolean metacatRunning = true; private static IndexingQueue instance = null; final static int NUMBEROFINDEXINGTHREADS; static { int numIndexingThreads = 0; try { numIndexingThreads = Integer.parseInt(PropertyService.getProperty("database.numberOfIndexingThreads")); } catch (PropertyNotFoundException pnfe) { logMetacat.error("Could not get property in static block: " + pnfe.getMessage()); } NUMBEROFINDEXINGTHREADS = numIndexingThreads; } private IndexingQueue() { if(!EnabledQueryEngines.getInstance().isEnabled(EnabledQueryEngines.PATHQUERYENGINE)) { return; } for (int i = 0; i < NUMBEROFINDEXINGTHREADS; i++) { IndexingTask thread = new IndexingTask(); thread.start(); currentThreads.add(thread); } } public static synchronized IndexingQueue getInstance(){ if (instance == null) { instance = new IndexingQueue(); } return instance; }//getInstance public void add(String docid, String rev) { if(!EnabledQueryEngines.getInstance().isEnabled(EnabledQueryEngines.PATHQUERYENGINE)) { return; } add(new IndexingQueueObject(docid, rev, 0)); } protected void add(IndexingQueueObject queueObject) { synchronized (indexingMap) { if(!indexingMap.containsKey(queueObject.getDocid())){ indexingMap.put(queueObject.getDocid(), queueObject); indexingMap.notify(); } else { IndexingQueueObject oldQueueObject = indexingMap.get(queueObject.getDocid()); if(oldQueueObject.compareTo(queueObject) < 0){ indexingMap.put(queueObject.getDocid(), queueObject); indexingMap.notify(); } } } } public boolean getMetacatRunning(){ return this.metacatRunning; } public void setMetacatRunning(boolean metacatRunning){ if(!EnabledQueryEngines.getInstance().isEnabled(EnabledQueryEngines.PATHQUERYENGINE)) { return; } this.metacatRunning = metacatRunning; if(!metacatRunning){ for(int count=0; count oRevision) { return 1; } else { return -1; } } else { throw new java.lang.ClassCastException(); } } }