001 /* 002 * $RCSfile: StopWhenSatisfiedStrategy.java,v $ 003 * 004 * Created on March 13, 10:20 AM 005 * 006 * This file is part of the STAR Scheduler. 007 * Copyright (c) 2002-2006 STAR Collaboration - Brookhaven National Laboratory 008 * 009 * STAR Scheduler is free software; you can redistribute it and/or modify 010 * it under the terms of the GNU General Public License as published by 011 * the Free Software Foundation; either version 2 of the License, or 012 * (at your option) any later version. 013 * 014 * STAR Scheduler is distributed in the hope that it will be useful, 015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 017 * GNU General Public License for more details. 018 * 019 * You should have received a copy of the GNU General Public License 020 * along with STAR Scheduler; if not, write to the Free Software 021 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 022 */ 023 024 package gov.bnl.star.offline.scheduler.catalog; 025 026 import gov.bnl.star.offline.scheduler.CatalogQuery; 027 028 import java.util.Iterator; 029 030 /**@deprecated please see gov.bnl.star.offline.scheduler.dataset.* for replacements. 031 * @author Gabriele Carcassi & Pavel Jakl 032 * @version $Revision: 1.7 $ $Date: 2006/11/21 00:41:31 $ 033 */ 034 public class StopWhenSatisfiedStrategy implements QueryStrategy { 035 036 public QueryResult resolveQuery(FileCatalog catalog, CatalogQuery query) { 037 double prefetch = 1.01; 038 if (query.isSingleCopy()) prefetch = 2.5; 039 QueryResult result = new QueryResult(); 040 Iterator iter = catalog.executeQuery(query.getQuery(), (int) (query.getNFiles().intValue() * prefetch)); 041 while (iter.hasNext() && !satisfied(result, query)) { 042 PhysicalFile file = (PhysicalFile) iter.next(); 043 result.add(file.getLogicalID(), file); 044 } 045 return result; 046 } 047 048 private boolean satisfied(QueryResult list, CatalogQuery query) { 049 int nFiles = query.getNFiles().intValue(); 050 if (query.isSingleCopy()) { 051 if (nFiles <= list.getLogicalCount()) return true; 052 } else { 053 if (nFiles <= list.getPhysicalCount()) return true; 054 } 055 return false; 056 } 057 }