@ CommandArgument public void start ( @ OptionArgument ( "ncpus" ) int numberOfCpus , @ OptionArgument ( "host" ) final String host , @ OptionArgument ( "username" ) final String username , @ OptionArgument ( "password" ) final String password , @ OptionArgument ( value = "nodb" , shortKey = ' ' ) final boolean internal , @ OptionArgument ( "courtesy" ) final String courtesyCommand , @ OptionArgument ( value = "courtesyWorkingDirectory" , shortKey = ' ' ) File courtesyWorkingDirectory , @ OptionArgument ( value = "courtesyPollingInterval" , shortKey = ' ' ) long courtesyPollingInterval ) { int availableCpus = Runtime . getRuntime ( ) . availableProcessors ( ) ; if ( numberOfCpus <= 0 || numberOfCpus > availableCpus ) { numberOfCpus = availableCpus ; } System . out . println ( "Starting worker with " + Integer . toString ( numberOfCpus ) + " cpus" ) ; if ( worker != null ) { logger . info ( "Shutting down worker" ) ; worker . shutdown ( ) ; try { workerThread . join ( ) ; } catch ( InterruptedException e ) { } } logger . info ( "Starting worker" ) ; JobServiceFactory serviceFactory = new JobServiceFactory ( ) { public JobService connect ( ) { return waitForService ( host . equals ( "" ) ? "localhost" : host , username . equals ( "" ) ? "guest" : username , password , RECONNECT_INTERVAL ) ; } } ; CourtesyMonitor courtesyMonitor ; if ( ! courtesyCommand . equals ( "" ) ) { logger . info ( "Initializing courtesy monitor" ) ; if ( courtesyPollingInterval == 0 ) { courtesyPollingInterval = DEFAULT_COURTESY_POLLING_INTERVAL ; } ExecCourtesyMonitor exec = new ExecCourtesyMonitor ( courtesyCommand , courtesyWorkingDirectory ) ; exec . startPolling ( courtesyPollingInterval , TimeUnit . SECONDS ) ; courtesyMonitor = exec ; } else { courtesyMonitor = new UnconditionalCourtesyMonitor ( ) ; } ThreadFactory threadFactory = new BackgroundThreadFactory ( ) ; ProgressStateFactory monitorFactory = new ProgressStateFactory ( ) ; worker = new ThreadServiceWorker ( serviceFactory , threadFactory , monitorFactory , courtesyMonitor ) ; worker . setMaxWorkers ( numberOfCpus ) ; taskProgressStates = monitorFactory . getProgressStates ( ) ; if ( ! internal ) { logger . info ( "Preparing data source" ) ; EmbeddedDataSource ds = null ; try { Class . forName ( "org.apache.derby.jdbc.EmbeddedDriver" ) ; ds = new EmbeddedDataSource ( ) ; ds . setConnectionAttributes ( "create=true" ) ; ds . setDatabaseName ( "classes" ) ; worker . setDataSource ( ds ) ; } catch ( ClassNotFoundException e ) { logger . error ( "Could not locate database driver." , e ) ; } catch ( SQLException e ) { logger . error ( "Error occurred while initializing data source." , e ) ; } } workerThread = new Thread ( worker ) ; workerThread . start ( ) ; }
Starts the worker process .