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.MasterFtpServer; import org.openslx.imagemaster.thrift.server.BinaryListener; public class App { private static Logger log = Logger.getLogger( App.class ); private static List servers = new ArrayList<>(); public static final MasterFtpServer ftpServer = new MasterFtpServer(); 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" ); // 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 ) ); Thread f; f = new Thread( ftpServer, "FtpServer" ); servers.add( f ); f.start(); // start FtpCredentialsScheduler FtpCredentialsScheduler.startScheduling(); // 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..." ); } }