package org.openslx.imagemaster; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; import org.openslx.imagemaster.Globals.PropInt; import org.openslx.imagemaster.ftp.FtpCredentialsScheduler; import org.openslx.imagemaster.ftp.ImageProcessor; import org.openslx.imagemaster.ftp.MasterFtpServer; import org.openslx.imagemaster.thrift.server.BinaryListener; import org.slf4j.LoggerFactory; public class App { private static Logger log = Logger.getLogger( App.class ); private static List servers = new ArrayList<>(); public static final MasterFtpServer ftpServer = new MasterFtpServer(); static { // TODO: // This is a temporary workaround for this annoying log4j error msg. // It's initializing the logger before anything else is done. LoggerFactory.getLogger("ROOT"); } public static void main( String[] args ) { // Init logging log.info( "Starting Application" ); // Load properties try { Globals.loadProperties(); // don't need to check return, because this should be the first time where props are loaded. if ( !Globals.propertiesValid() ) { log.error( "Config file contains errors." ); System.exit( 1 ); } } catch ( IOException e ) { log.error( "Could not load config file. Quitting." ); System.exit( 1 ); } log.info( "Loaded config file" ); log.info( "Checking !uploading! db entries." ); ImageProcessor.checkUploading(); // Create binary listener Thread t; t = new Thread( new BinaryListener(), "BinaryListener" ); servers.add( t ); t.start(); // Create Ftp Server ftpServer.init( Globals.getPropertyInt( PropInt.FTPPORT ) ); // this init needs to be done, because we have to wait for the config file Thread f; f = new Thread( ftpServer, "FtpServer" ); servers.add( f ); f.start(); // add ftp users from database ftpServer.addDbFtpUsers(); // start FtpCredentialsScheduler FtpCredentialsScheduler.startScheduling(); // testtesteset ftpServer.addUser( "asdfasdfasdf", MasterFtpServer.Mode.DOWNLOADING, "windows7.vmdk" ); // Run more servers // ... // Wait for all servers to die for ( Thread wait : servers ) { boolean success = false; while ( !success ) { try { wait.join(); success = true; } catch ( InterruptedException e ) { // Do nothing... } } } log.info( "All Servers shut down, exiting..." ); } }