001: /*
002: Copyright (C) 2004 David Bucciarelli (davibu@interfree.it)
003:
004: This program is free software; you can redistribute it and/or
005: modify it under the terms of the GNU General Public License
006: as published by the Free Software Foundation; either version 2
007: of the License, or (at your option) any later version.
008:
009: This program is distributed in the hope that it will be useful,
010: but WITHOUT ANY WARRANTY; without even the implied warranty of
011: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: GNU General Public License for more details.
013:
014: You should have received a copy of the GNU General Public License
015: along with this program; if not, write to the Free Software
016: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: */
018:
019: package org.homedns.dade.jcgrid.cmd.povray;
020:
021: import org.apache.log4j.*;
022: import org.apache.commons.cli.*;
023:
024: import org.homedns.dade.jcgrid.*;
025: import org.homedns.dade.jcgrid.cmd.*;
026: import org.homedns.dade.jcgrid.worker.*;
027: import org.homedns.dade.jcgrid.worker.impl.povray.*;
028:
029: public class JCGridWorker {
030: private final static String className = JCGridWorker.class
031: .getName();
032: private static Logger log = Logger.getLogger(className);
033: private static Logger logDetail = Logger.getLogger("DETAIL."
034: + className);
035:
036: public static void main(String[] args) {
037: try {
038: // Setup log4j
039:
040: MainCmd.setUpLog4J("worker", true);
041:
042: // Setup GridServer
043:
044: log.warn("-----------------------------------------------");
045: log.warn("-- JCGridWorker POVRay v" + Version.RELEASE);
046: log.warn("-----------------------------------------------");
047:
048: GridNodeWorkerConfig config = new GridNodeWorkerConfig();
049:
050: // Try to guess if we are running under Windows
051:
052: String osName = System.getProperty("os.name");
053: log.warn("OS Name: " + osName);
054:
055: boolean usePVEngineEXE;
056: if (osName.matches("Windows.*"))
057: usePVEngineEXE = true;
058: else
059: usePVEngineEXE = false;
060:
061: // Parse command line options
062:
063: Options options = new Options();
064: options.addOption("v", false,
065: "Execute pvengine.exe instead of povray command");
066: try {
067: CommandLine cmd = MainCmd.parseCommonOptions(options,
068: config, args);
069:
070: // POVRay options
071:
072: if (cmd.hasOption("v"))
073: usePVEngineEXE = true;
074:
075: if (cmd.getArgs().length > 0)
076: throw new Exception("Unknown command line option");
077: } catch (Exception ex) {
078: log.warn("Error while parsing command line", ex);
079:
080: HelpFormatter formatter = new HelpFormatter();
081: formatter.printHelp("JCGridWorker", options);
082:
083: System.exit(0);
084: }
085:
086: // Start all required Workers
087:
088: GridWorker[] gw = new GridWorker[config.getWorkerCount()];
089: for (int i = 0; i < config.getWorkerCount(); i++) {
090: gw[i] = new GridWorker();
091: gw[i].setNodeConfig((GridNodeGenericConfig) config
092: .clone());
093:
094: ((GridNodeGenericConfig) gw[i].getNodeConfig())
095: .setSessionName(config.getSessionName() + "_"
096: + i);
097: ((GridNodeGenericConfig) gw[i].getNodeConfig())
098: .setWorkingDir(config.getWorkingDir() + "_" + i);
099: gw[i].setWorker(new POVWorker(usePVEngineEXE));
100:
101: gw[i].start();
102: log.warn("Running worker " + i + "...");
103: }
104:
105: // Wait shutdown
106:
107: for (int i = 0; i < config.getWorkerCount(); i++)
108: gw[i].waitShutdown();
109: } catch (Exception ex) {
110: log.warn("Error", ex);
111: System.exit(0);
112: }
113: }
114: }
|