|
From: <de...@us...> - 2003-09-30 14:30:51
|
Update of /cvsroot/babeldoc/babeldoc/modules/scanner/src/com/babeldoc/scanner
In directory sc8-pr-cvs1:/tmp/cvs-serv4443/modules/scanner/src/com/babeldoc/scanner
Modified Files:
Scanner.java
Log Message:
Do not start scanner if no configuration found
Index: Scanner.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/scanner/src/com/babeldoc/scanner/Scanner.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** Scanner.java 17 Sep 2003 21:11:57 -0000 1.29
--- Scanner.java 30 Sep 2003 14:30:47 -0000 1.30
***************
*** 82,86 ****
import com.babeldoc.scanner.rmi.RemoteScannerBridge;
-
/**
* The main scanner entry point and babeldoc command implementer. This class
--- 82,85 ----
***************
*** 91,323 ****
*/
public class Scanner extends BabeldocCommand {
! private static LogService log = LogService.getInstance(Scanner.class.getName());
! private IFeeder feeder;
! private ScannerFactory factory;
! private ScannerWorkerScheduler scheduler;
!
! public static final String SCANNER_FEEDER = "scanner";
! public String scannerConfig;
! /**
! * Constructor with all the command line arguments
! *
! * @param args command line arguments
! */
! public Scanner(String[] args) {
! super("scanner", I18n.get("scanner.Scanner.toolDescription"), args);
! }
! /**
! * Handle the scanner command line
! *
! * @param commandLine
! */
! public void execute(CommandLine commandLine) {
! //super.execute(commandLine);
! // otherwise, continue with normal execution path
! if (commandLine.hasOption('s')) {
! scannerConfig = commandLine.getOptionValue('s');
! }
! try {
! start();
! } catch (ScannerException se) {
! this.stop();
! }
! }
! /**
! * Finish up processing - stop threads, etc
! *
! */
! public void finishUp() {
! this.stop();
! }
! /**
! * Main entry point
! *
! * @param args DOCUMENT ME!
! */
! public static void main(String[] args) {
! new Scanner(args);
! }
! /**
! * Get the list of workers as value objects
! *
! * @param workerName DOCUMENT ME!
! *
! * @return DOCUMENT ME!
! *
! * @throws ScannerException DOCUMENT ME!
! */
! public ScannerWorkerVO listWorker(String workerName)
! throws ScannerException {
! return factory.getWorker(workerName).getValueObject();
! }
! /**
! * List all workers in scanner
! *
! * @return Array of scanner workers
! */
! public ScannerWorkerVO[] listWorkers() {
! 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;
! }
! /**
! *
! */
! public void saveConfiguration() {
! // TODO Auto-generated method stub
! }
! /* (non-Javadoc)
! * @see com.babeldoc.core.BabeldocCommand#setupCommandLine(org.apache.commons.cli.Options)
! */
! public void setupCommandLine(Options options) {
! super.setupCommandLine(options);
! options.addOption(OptionBuilder.isRequired(false).hasArg(true)
! .withDescription(I18n.get(
! "scanner.Scanner.option.scanner")).withLongOpt("scanner").create('s'));
! options.addOption(OptionBuilder.isRequired(false).hasArg(false)
! .withDescription(I18n.get(
! "scanner.Scanner.option.rmi")).withLongOpt("rmi").create('r'));
! options.addOption(OptionBuilder.isRequired(false).hasArg(true)
! .withDescription(I18n.get(
! "scanner.Scanner.option.port")).withLongOpt("port").create('p'));
! }
! /**
! * Start the scanner workers
! *
! * @throws ScannerException
! */
! public void start() throws ScannerException {
! factory = ScannerFactory.getInstance(scannerConfig);
! // log.logInfo("Starting feeder...");
! // feeder = new AsynchronousFeeder(queue);
! try {
! setFeeder(FeederFactory.getInstance().getFeeder(SCANNER_FEEDER));
! } catch (GeneralException e) {
! getLog().logError(e);
! }
! //handleRemoteServer(-1);
! getLog().logInfo("Initializing workers:");
! ScannerWorker[] sw = factory.getWorkers();
! scheduler = new ScannerWorkerScheduler();
! getLog().logInfo("Starting workers...");
! for (int i = 0; i < sw.length; i++) {
! try {
! sw[i].setFeeder(getFeeder());
! scheduler.startWorker(sw[i]);
! } catch (Exception e) {
! getLog().logError("Error starting scanner worker " + sw[i].getName(), e);
! sw[i].stop();
! //stop();
! }
! }
! }
! /**
! * Start worker with the given name
! *
! * @param workerName name of the worker that should be started
! *
! * @throws ScannerException if worker does not exist or some other error
! * occures
! */
! public void startWorker(String workerName) throws ScannerException {
! factory.getWorker(workerName).start();
! }
! /**
! *
! */
! public void stop() {
! // if there is no scheduler, then we haven't started anything that needs to be
! // stopped...
! if (this.scheduler == null) {
! return;
! }
! getLog().logInfo("Shutting down...");
! getLog().logInfo("Stopping workers...");
! this.scheduler.stopAll();
! this.getFeeder().terminate();
! getLog().logInfo("Stopping feeder");
! }
! /**
! * Stop worker with the given name.
! *
! * @param workerName name of worker to be stopped
! *
! * @throws ScannerException if worker with given name does not exist or some
! * other error occures
! */
! public void stopWorker(String workerName) throws ScannerException {
! factory.getWorker(workerName).stop();
! }
! /**
! * Setup the remote server configuration.
! *
! * @param port DOCUMENT ME!
! */
! private void handleRemoteServer(int port) {
! if (System.getSecurityManager() == null) {
! System.setSecurityManager(new RMISecurityManager());
! }
! try {
! RemoteScannerBridge remoteScanner = null;
! if (port > 0) {
! remoteScanner = new RemoteScannerBridge(port);
! } else {
! remoteScanner = new RemoteScannerBridge();
! }
! remoteScanner.setScanner(this);
! if (port > 0) {
! RmiRegistry.rmiPort = port;
! }
! RmiRegistry.rebind(IRemoteScanner.RMI_NAME, remoteScanner);
! } catch (Exception e) {
! LogService.getInstance().logError(I18n.get("scanner.Scanner.error.rmi"), e);
! }
! }
! public static LogService getLog() {
! return log;
! }
! public static void setLog(LogService log) {
! Scanner.log = log;
! }
! public IFeeder getFeeder() {
! return feeder;
! }
! public void setFeeder(IFeeder feeder) {
! this.feeder = feeder;
! }
}
--- 90,343 ----
*/
public class Scanner extends BabeldocCommand {
! private static LogService log =
! LogService.getInstance(Scanner.class.getName());
! private IFeeder feeder;
! private ScannerFactory factory;
! private ScannerWorkerScheduler scheduler;
! public static final String SCANNER_FEEDER = "scanner";
! public String scannerConfig;
! /**
! * Constructor with all the command line arguments
! *
! * @param args command line arguments
! */
! public Scanner(String[] args) {
! super("scanner", I18n.get("scanner.Scanner.toolDescription"), args);
! }
! /**
! * Handle the scanner command line
! *
! * @param commandLine
! */
! public void execute(CommandLine commandLine) {
! //super.execute(commandLine);
! // otherwise, continue with normal execution path
! if (commandLine.hasOption('s')) {
! scannerConfig = commandLine.getOptionValue('s');
! }
! try {
! start();
! } catch (ScannerException se) {
! this.stop();
! }
! }
! /**
! * Finish up processing - stop threads, etc
! *
! */
! public void finishUp() {
! this.stop();
! }
! /**
! * Main entry point
! *
! * @param args DOCUMENT ME!
! */
! public static void main(String[] args) {
! new Scanner(args);
! }
! /**
! * Get the list of workers as value objects
! *
! * @param workerName DOCUMENT ME!
! *
! * @return DOCUMENT ME!
! *
! * @throws ScannerException DOCUMENT ME!
! */
! public ScannerWorkerVO listWorker(String workerName)
! throws ScannerException {
! return factory.getWorker(workerName).getValueObject();
! }
! /**
! * List all workers in scanner
! *
! * @return Array of scanner workers
! */
! public ScannerWorkerVO[] listWorkers() {
! 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;
! }
! /**
! *
! */
! public void saveConfiguration() {
! // TODO Auto-generated method stub
! }
! /* (non-Javadoc)
! * @see com.babeldoc.core.BabeldocCommand#setupCommandLine(org.apache.commons.cli.Options)
! */
! public void setupCommandLine(Options options) {
! super.setupCommandLine(options);
! options.addOption(
! OptionBuilder
! .isRequired(false)
! .hasArg(true)
! .withDescription(I18n.get("scanner.Scanner.option.scanner"))
! .withLongOpt("scanner")
! .create('s'));
! options.addOption(
! OptionBuilder
! .isRequired(false)
! .hasArg(false)
! .withDescription(I18n.get("scanner.Scanner.option.rmi"))
! .withLongOpt("rmi")
! .create('r'));
! options.addOption(
! OptionBuilder
! .isRequired(false)
! .hasArg(true)
! .withDescription(I18n.get("scanner.Scanner.option.port"))
! .withLongOpt("port")
! .create('p'));
! }
! /**
! * Start the scanner workers
! *
! * @throws ScannerException
! */
! public void start() throws ScannerException {
! factory = ScannerFactory.getInstance(scannerConfig);
! // log.logInfo("Starting feeder...");
! // feeder = new AsynchronousFeeder(queue);
! try {
! setFeeder(FeederFactory.getInstance().getFeeder(SCANNER_FEEDER));
! } catch (GeneralException e) {
! getLog().logError(e);
! }
! //handleRemoteServer(-1);
! getLog().logInfo("Initializing workers:");
! ScannerWorker[] sw = factory.getWorkers();
! if (sw.length > 0) {
! scheduler = new ScannerWorkerScheduler();
! getLog().logInfo("Starting workers...");
! for (int i = 0; i < sw.length; i++) {
! try {
! sw[i].setFeeder(getFeeder());
! scheduler.startWorker(sw[i]);
! } catch (Exception e) {
! getLog().logError(
! "Error starting scanner worker " + sw[i].getName(),
! e);
! sw[i].stop();
! //stop();
! }
! }
! } else {
! log.logInfo("No configured workers found!");
! stop();
! }
! }
! /**
! * Start worker with the given name
! *
! * @param workerName name of the worker that should be started
! *
! * @throws ScannerException if worker does not exist or some other error
! * occures
! */
! public void startWorker(String workerName) throws ScannerException {
! factory.getWorker(workerName).start();
! }
! /**
! *
! */
! public void stop() {
! if (this.scheduler != null) {
! getLog().logInfo("Shutting down...");
! getLog().logInfo("Stopping workers...");
! this.scheduler.stopAll();
! }
! if (this.getFeeder()!=null) {
! this.getFeeder().terminate();
! getLog().logInfo("Stopping feeder");
! }
!
! }
! /**
! * Stop worker with the given name.
! *
! * @param workerName name of worker to be stopped
! *
! * @throws ScannerException if worker with given name does not exist or some
! * other error occures
! */
! public void stopWorker(String workerName) throws ScannerException {
! factory.getWorker(workerName).stop();
! }
! /**
! * Setup the remote server configuration.
! *
! * @param port DOCUMENT ME!
! */
! private void handleRemoteServer(int port) {
! if (System.getSecurityManager() == null) {
! System.setSecurityManager(new RMISecurityManager());
! }
! try {
! RemoteScannerBridge remoteScanner = null;
! if (port > 0) {
! remoteScanner = new RemoteScannerBridge(port);
! } else {
! remoteScanner = new RemoteScannerBridge();
! }
! remoteScanner.setScanner(this);
! if (port > 0) {
! RmiRegistry.rmiPort = port;
! }
! RmiRegistry.rebind(IRemoteScanner.RMI_NAME, remoteScanner);
! } catch (Exception e) {
! LogService.getInstance().logError(
! I18n.get("scanner.Scanner.error.rmi"),
! e);
! }
! }
! public static LogService getLog() {
! return log;
! }
! public static void setLog(LogService log) {
! Scanner.log = log;
! }
! public IFeeder getFeeder() {
! return feeder;
! }
! public void setFeeder(IFeeder feeder) {
! this.feeder = feeder;
! }
}
|