001 /* 002 * AllCopiesSelector.java 003 * 004 * Created on March 13, 2003, 11:01 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 package gov.bnl.star.offline.scheduler.policy.copyselector; 024 025 import gov.bnl.star.offline.scheduler.CatalogQuery; 026 import gov.bnl.star.offline.scheduler.catalog.PhysicalFile; 027 import gov.bnl.star.offline.scheduler.catalog.QueryResult; 028 import gov.bnl.star.offline.scheduler.policy.FileAssignment; 029 030 import java.util.Iterator; 031 import java.util.List; 032 import java.util.Set; 033 034 035 /** 036 * Select all the copies returned by the query. All the physical files present 037 * in the query result are added to the assignment. This is used when 038 * singleCopy="false" is set in the description. 039 * 040 * @author Gabriele Carcassi & Pavel Jakl 041 */ 042 public class AllCopiesSelector implements CopySelector { 043 044 private boolean HPSSAllowed = false; 045 046 public AllCopiesSelector(boolean HPSS) { 047 this.HPSSAllowed = HPSS; 048 } 049 050 public int selectCopy(QueryResult list, CatalogQuery query, 051 FileAssignment assignment) { 052 int currentFile = 0; 053 054 Set logicalIDs = list.getLogicalNames(); 055 Iterator iter = logicalIDs.iterator(); 056 057 // put this before iterations to improve performance 058 if (HPSSAllowed) { 059 while (iter.hasNext()) { 060 List physicalFiles = list.getCopies(iter.next()); 061 062 // All copies: put all them in list 063 Iterator iterPhys = physicalFiles.iterator(); 064 065 while (iterPhys.hasNext()) { 066 PhysicalFile phfile = (PhysicalFile) iterPhys.next(); 067 assignment.add(phfile); 068 currentFile++; 069 } 070 071 } 072 } else { 073 while (iter.hasNext()) { 074 List physicalFiles = list.getCopies(iter.next()); 075 076 // All copies: put them all except off HPSS files 077 Iterator iterPhys = physicalFiles.iterator(); 078 079 while (iterPhys.hasNext()) { 080 PhysicalFile phfile = (PhysicalFile) iterPhys.next(); 081 if (!"HPSS".equals(phfile.getStorage())) { 082 assignment.add(phfile); 083 currentFile++; 084 } 085 } 086 } 087 } 088 return currentFile; 089 } 090 }