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.mandel;
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.mandel.*;
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 MandelGrid v" + Version.RELEASE);
046: log.warn("-----------------------------------------------");
047:
048: GridNodeWorkerConfig config = new GridNodeWorkerConfig();
049: GridConfig gc = config.getGridConfig();
050: gc.setServerAddress(MandelConfig.MANDELGRID_SERVER);
051: gc.setServerClientPort(MandelConfig.MANDELGRID_CLIENT_PORT);
052: gc.setServerWorkerPort(MandelConfig.MANDELGRID_WORKER_PORT);
053: gc.setServerAdminPort(MandelConfig.MANDELGRID_ADMIN_PORT);
054: gc
055: .setUseCompression(MandelConfig.MANDELGRID_USE_COMPRESSION);
056: gc.setUseVFS(false);
057:
058: config.autoSessioName();
059:
060: // Parse command line options
061:
062: Options options = new Options();
063: try {
064: CommandLine cmd = MainCmd.parseCommonOptions(options,
065: config, args);
066:
067: if (cmd.getArgs().length > 0)
068: throw new Exception("Unknown command line option");
069: } catch (Exception ex) {
070: log.warn("Error while parsing command line", ex);
071:
072: HelpFormatter formatter = new HelpFormatter();
073: formatter.printHelp("JCGridWorker", options);
074:
075: System.exit(0);
076: }
077:
078: // Start all required Workers
079:
080: GridWorker[] gw = new GridWorker[config.getWorkerCount()];
081: for (int i = 0; i < config.getWorkerCount(); i++) {
082: gw[i] = new GridWorker();
083: gw[i].setNodeConfig((GridNodeGenericConfig) config
084: .clone());
085:
086: ((GridNodeGenericConfig) gw[i].getNodeConfig())
087: .setSessionName(config.getSessionName() + "_"
088: + i);
089: ((GridNodeGenericConfig) gw[i].getNodeConfig())
090: .setWorkingDir(config.getWorkingDir() + "_" + i);
091: gw[i].setWorker(new MandelWorker());
092:
093: gw[i].start();
094: log.warn("Running worker " + i + "...");
095: }
096:
097: // Wait shutdown
098:
099: for (int i = 0; i < config.getWorkerCount(); i++)
100: gw[i].waitShutdown();
101: } catch (Exception ex) {
102: log.warn("Error", ex);
103: System.exit(0);
104: }
105: }
106: }
|