001    /*
002     * CopySelectorFactory.java
003     *
004     * Created on March 13, 2003, 11:03 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.policy.PassivePolicy;
027    import gov.bnl.star.offline.scheduler.request.Request;
028    
029    
030    /**
031     * Selects which Copyselector should be used for the given query. The factory
032     * allows different CopySelectors to be built, and used in different circumstances.
033     * It makes the code more manageble and mantainable.
034     *
035     * @author Gabriele Carcassi & Pavel Jakl
036     */
037    public class CopySelectorFactory {
038    
039        /** Returns the Copy selector to be used on a given query of a given request.
040         * Parameters of the query and the request are used to determine which
041         * CopySelector to use. For example, if singleCopy="false" in the query,
042         * then AllCopiesSelector will be used; if minFilesPerProcess is specified,
043         * than MinMaxSingleCopySelector is used.
044         * @param query the query on which result the selection should be made
045         * @param request the request that contained the query
046         * @return the CopySelector to use
047         */
048        public static CopySelector createCopySelector(CatalogQuery query,
049            Request request) {
050    
051            // set HPSS files default false
052            boolean HPSSAllowed = false;
053             if ("xrootd".equals(request.getFileListType())) {
054                 HPSSAllowed=true;
055             }
056    
057            if (query.isSingleCopy()) {
058                if (request.getResource("FilesPerProcess").getMin() != -1) {
059                    if (HPSSAllowed) {
060                        return new XrootdMinMaxSingleCopySelector();
061                    }else if ("rootd".equals(request.getFileListType())){
062                        return new RootdMinMaxSingleCopySelector();
063                    }
064                    return new MinMaxSingleCopySelector();
065                }
066                return new SingleCopySelector(HPSSAllowed);
067            } else {
068                return new AllCopiesSelector(HPSSAllowed);
069            }
070        }
071    }