001 /* 002 * $RCSfile: CompositeDispatcher.java,v $ 003 * 004 * Created on August 21, 2003, 11:55 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; 025 026 import gov.bnl.star.offline.scheduler.request.Request; 027 import java.util.*; 028 import java.util.Map; 029 import java.util.logging.Level; 030 import org.apache.log4j.Logger; 031 032 /** 033 * @deprecated Replaced by GenericCompositeDispatcher 034 * 035 * @author carcassi 036 * @version $Revision: 1.7 $ $Date: 2006/11/21 00:41:32 $ 037 */ 038 public class CompositeDispatcher implements Dispatcher { 039 static private Logger log = Logger.getLogger(CompositeDispatcher.class.getName()); 040 041 /** Creates a new instance of CompositeDispatcher */ 042 public CompositeDispatcher() { 043 } 044 045 protected Map dispatchers; 046 047 public void setDispatchers(Map dispatchers) { 048 this.dispatchers = dispatchers; 049 } 050 051 public Map getDispatchers() { 052 return dispatchers; 053 } 054 055 public Dispatcher getDispatcher(String name) { 056 return (Dispatcher) dispatchers.get(name); 057 } 058 059 public void dispatch(Request request, List jobs) { 060 log.debug("Selecting the dispatcher for the different jobs"); 061 List[] dispatcherJobs = new ArrayList[dispatchers.size()]; 062 for (int nJob = 0; nJob < jobs.size(); nJob++) { 063 assignJob((Job) jobs.get(nJob), chooser.chooseDispatcher(request, (Job) jobs.get(nJob))); 064 } 065 log.debug("Dispatching to the selected dispatchers"); 066 dispatchJobs(request); 067 } 068 069 private Map dispatcherJobs; 070 071 /** Holds value of property chooser. */ 072 private DispatcherChooser chooser; 073 074 private void assignJob(Job job, String dispatcher) { 075 if (dispatcherJobs == null) dispatcherJobs = new Hashtable(); 076 List jobs = (List) dispatcherJobs.get(dispatcher); 077 if (jobs == null) { 078 jobs = new ArrayList(); 079 dispatcherJobs.put(dispatcher, jobs); 080 } 081 082 jobs.add(job); 083 } 084 085 private void dispatchJobs(Request request) { 086 Set dispatchers = dispatcherJobs.keySet(); 087 Iterator iter = dispatchers.iterator(); 088 while (iter.hasNext()) { 089 String dispatcherName = (String) iter.next(); 090 Dispatcher dispatcher = getDispatcher(dispatcherName); 091 List jobs = (List) dispatcherJobs.get(dispatcherName); 092 System.out.println("Dispatching jobs to " + dispatcherName); 093 dispatcher.dispatch(request, jobs); 094 } 095 dispatcherJobs = null; 096 } 097 098 public void retrieveOutput(Request job, List jobs) { 099 // Not used 100 } 101 102 /** Getter for property chooser. 103 * @return Value of property chooser. 104 * 105 */ 106 public DispatcherChooser getChooser() { 107 return this.chooser; 108 } 109 110 /** Setter for property chooser. 111 * @param chooser New value of property chooser. 112 * 113 */ 114 public void setChooser(DispatcherChooser chooser) { 115 this.chooser = chooser; 116 } 117 118 public void Kill(Request request, List jobs) { 119 // job.getAssociatedDispatcher().Kill(request, jobs); 120 } 121 122 public String Status(Job job, int Processe) { 123 return job.getAssociatedDispatcher().Status(job, Processe); 124 } 125 126 public void stop() { 127 } 128 129 public boolean test(Queue queue) { 130 return true; 131 } 132 133 }