From: paspes <pa...@us...> - 2007-12-03 17:01:38
|
Update of /cvsroot/babeldoc/babeldoc/modules/scanner/src/com/babeldoc/scanner In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv20577/modules/scanner/src/com/babeldoc/scanner Modified Files: ScannerWorker.java Scanner.java ScannerThread.java Added Files: ScannerController.java Log Message: Activate RMI scanner (babeldoc scanmon) and add Scanner controler Index: Scanner.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/scanner/src/com/babeldoc/scanner/Scanner.java,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** Scanner.java 10 Aug 2004 10:49:06 -0000 1.34 --- Scanner.java 3 Dec 2007 16:37:18 -0000 1.35 *************** *** 95,98 **** --- 95,99 ---- private ScannerFactory factory; private ScannerWorkerScheduler scheduler; + private ScannerController controller; public static final int STATE_STOPPED = 0; *************** *** 102,105 **** --- 103,108 ---- public static final String SCANNER_FEEDER = "scanner"; private String scannerConfig; + private int rmiPort = -1; //Paspes + private boolean backgroud; //Paspes: Babeldoc stops when all scanners finished private int status = STATE_STOPPED; *************** *** 124,128 **** scannerConfig = commandLine.getOptionValue('s'); } ! try { start(); --- 127,154 ---- scannerConfig = commandLine.getOptionValue('s'); } ! ! // Paspes background option ! if (commandLine.hasOption('t')) { ! backgroud = false; ! } ! else{ ! backgroud = true; ! } ! ! //Paspes Read RMI options ! if (commandLine.hasOption('r')) { ! if (commandLine.hasOption('p')){ ! try{ ! rmiPort = new Integer(commandLine.getOptionValue('p')).intValue(); ! }catch (NumberFormatException nfe){ ! getLog().logError("Error scanner port invalid " + commandLine.getOptionValue('p'), ! nfe); ! } ! } ! else{ ! rmiPort = com.babeldoc.core.RmiRegistry.RMI_PORT; ! } ! getLog().logDebug("Load scanner rmi configuration on port "+ rmiPort); ! } try { start(); *************** *** 171,179 **** ScannerWorker[] workers = factory.getWorkers(); ScannerWorkerVO[] result = new ScannerWorkerVO[workers.length]; ! for (int i = 0; i < workers.length; i++) { result[i] = workers[i].getValueObject(); } ! return result; } --- 197,205 ---- ScannerWorker[] workers = factory.getWorkers(); ScannerWorkerVO[] result = new ScannerWorkerVO[workers.length]; ! for (int i = 0; i < workers.length; i++) { result[i] = workers[i].getValueObject(); } ! return result; } *************** *** 212,215 **** --- 238,248 ---- .withLongOpt("port") .create('p')); + options.addOption( + OptionBuilder + .isRequired(false) + .hasArg(false) + .withDescription(I18n.get("scanner.Scanner.option.terminate")) + .withLongOpt("terminate") + .create('t')); } *************** *** 223,231 **** try { setFeeder(FeederFactory.getInstance().getFeeder(SCANNER_FEEDER)); } catch (GeneralException e) { getLog().logError(e); } ! //handleRemoteServer(-1); getLog().logInfo("Initializing workers:"); --- 256,268 ---- try { + //Paspes MiniBug:SCANNER_FEEDER is the ONLY value of tokens feeder/config.properties + //Example SCANNER_FEEDER.type ==>scanner.type setFeeder(FeederFactory.getInstance().getFeeder(SCANNER_FEEDER)); } catch (GeneralException e) { getLog().logError(e); } ! //Paspes activate rmi scannner ! if(rmiPort>0 ) ! handleRemoteServer(rmiPort); getLog().logInfo("Initializing workers:"); *************** *** 246,249 **** --- 283,291 ---- } } + //Paspes: Controller finishes feeder if all scheduler finish + if (!backgroud) { + controller = new ScannerController(feeder,scheduler); + controller.start(); + } } else { log.logInfo("No configured workers found!"); *************** *** 279,282 **** --- 321,328 ---- getLog().logInfo("Stopping feeder"); } + if (controller!=null) {//Paspes + controller.stopThread(); + getLog().logInfo("Stopping controller"); + } status = Scanner.STATE_STOPPED; } *************** *** 303,307 **** System.setSecurityManager(new RMISecurityManager()); } - try { RemoteScannerBridge remoteScanner = null; --- 349,352 ---- *************** *** 318,323 **** RmiRegistry.rmiPort = port; } ! RmiRegistry.rebind(IRemoteScanner.RMI_NAME, remoteScanner); } catch (Exception e) { LogService.getInstance().logError( --- 363,370 ---- RmiRegistry.rmiPort = port; } ! RmiRegistry.rebind(IRemoteScanner.RMI_NAME, remoteScanner); + + getLog().logInfo("Scanner RMI activate on port "+ port); } catch (Exception e) { LogService.getInstance().logError( Index: ScannerWorker.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/scanner/src/com/babeldoc/scanner/ScannerWorker.java,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** ScannerWorker.java 4 Aug 2007 11:37:23 -0000 1.39 --- ScannerWorker.java 3 Dec 2007 16:37:18 -0000 1.40 *************** *** 76,80 **** * implement doScan() method. * ! * @author dejank */ public abstract class ScannerWorker extends Named { --- 76,80 ---- * implement doScan() method. * ! * @author dejank,paspes */ public abstract class ScannerWorker extends Named { *************** *** 127,133 **** protected ScannerWorker(ScannerWorkerInfo info) { this.info = info; - setStatus(ScannerWorkerStatus.STOPPED); setValueObject(new ScannerWorkerVO()); getValueObject().setDateStarted(System.currentTimeMillis()); } --- 127,135 ---- protected ScannerWorker(ScannerWorkerInfo info) { this.info = info; setValueObject(new ScannerWorkerVO()); getValueObject().setDateStarted(System.currentTimeMillis()); + getValueObject().setNumberOfSuccessProcessed(0); + getValueObject().setNumberOfFailedDocuments(0); + setStatus(ScannerWorkerStatus.STOPPED); } *************** *** 301,305 **** --- 303,309 ---- this.setName(configData.getName()); + this.getValueObject().setName(configData.getName()); this.getValueObject().setConfig(configData); + this.getValueObject().setInfo(this.info); this.setStatus(ScannerWorkerStatus.STOPPED); getLog().logInfo( *************** *** 364,368 **** --- 368,374 ---- try { doScan(); + getValueObject().setNumberOfSuccessProcessed(getValueObject().getNumberOfSuccessProcessed()+1); } catch (ScannerException e) { + getValueObject().setNumberOfFailedDocuments(getValueObject().getNumberOfFailedDocuments()+1); //handle exception getLog().logError("Error scanning...", e); *************** *** 499,502 **** --- 505,509 ---- this.setLastStatusChangeTime(System.currentTimeMillis()); this.status = newStatus; + getValueObject().setStatus(newStatus); } --- NEW FILE: ScannerController.java --- /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * Portions of this software are based upon public domain software * originally written at the National Center for Supercomputing Applications, * University of Illinois, Urbana-Champaign. * ==================================================================== * * Babeldoc: The Universal Document Processor * * $Header: /cvsroot/babeldoc/babeldoc/modules/scanner/src/com/babeldoc/scanner/ScannerController.java,v 1.1 2007/12/03 16:37:19 paspes Exp $ * $DateTime$ * $Author: paspes $ * */ /* * Created on 2007.10.25 * * To change this generated comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ package com.babeldoc.scanner; import java.util.Iterator; import com.babeldoc.core.LogService; import com.babeldoc.core.pipeline.feeder.IFeeder; /** * This class controller the execution of ScannerThreads (and scannerWorkers) and Feeder * If detect that all scannnerThreads finished kill the Feeder * * @author paspes */ public class ScannerController extends Thread{ public volatile boolean running = true; private static long SLEEPTIME = 60000; private IFeeder feeder = null; private ScannerWorkerScheduler scheduler = null; /** * Creates a new ScannerController object. * * @param feeder Thread feeder * @param scheduler Scheduler that contains scanner threads */ public ScannerController(IFeeder feeder,ScannerWorkerScheduler scheduler){ this.feeder = feeder; this.scheduler = scheduler; } /** * Activate controller */ public void run() { LogService.getInstance().logInfo("Starting ScannerController"); while (running) { int count = 0; if(LogService.getInstance().isDebugEnabled()) LogService.getInstance().logDebug("ScannerController awaking..."); if(scheduler.getThreads()!=null&&scheduler.getThreads().keySet()!=null) { for (Iterator iterator = scheduler.getThreads().keySet().iterator(); iterator.hasNext();) { ScannerThread thread = (ScannerThread)scheduler.getThreads().get(iterator.next()); if(thread.running) count++; } LogService.getInstance().logDebug("ScannerController have "+ count +" ScannerThreads running"); if(count==0){ LogService.getInstance().logDebug("ScannerController terminate not found ScannerThreads running"); running = false; } } else{ LogService.getInstance().logDebug("ScannerController terminate not found ScannerThreads"); running = false; } try { if(running) sleep(SLEEPTIME); } catch (InterruptedException e) { LogService.getInstance().logInfo("Thread ScannerController interrupted"); } } if (feeder!=null) { feeder.terminate();//shutdownAfterProcessingCurrentlyQueuedTasks( LogService.getInstance().logInfo("Stopping feeder"); } LogService.getInstance().logInfo("Stopping ScannerController"); } /** * stop the controller */ public void stopThread() { running = false; } } Index: ScannerThread.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/scanner/src/com/babeldoc/scanner/ScannerThread.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** ScannerThread.java 24 Jul 2004 00:18:52 -0000 1.18 --- ScannerThread.java 3 Dec 2007 16:37:18 -0000 1.19 *************** *** 114,118 **** } } ! LogService.getInstance().logDebug(this.getName() + "stopping"); } --- 114,118 ---- } } ! running = false; //Paspes LogService.getInstance().logDebug(this.getName() + "stopping"); } *************** *** 130,133 **** --- 130,137 ---- sleepTime = (((currentTime / 60000) + 1) * 60000) - currentTime; + //Paspes: windows system call System.currentTimeMillis() have a resolution error + if(System.getProperty("os.name").toUpperCase().indexOf("WINDOWS")>-1) + sleepTime+= 60; + //System.out.println( "return milliseconds before next minute,current: "+currentTime+" sleep:"+sleepTime ); } else { sleepTime = worker.getInfo().getIntValue(ScannerWorkerInfo.SCANNER_PERIOD); |