summaryrefslogblamecommitdiffstats
path: root/src/main/java/org/openslx/imagemaster/App.java
blob: 5a325ba7b54ce8dfbfe4239ee5b9859edfe5e21e (plain) (tree)
1
2
3
4
5
6
7
8
9




                                
                               
                                                             
                                                            
                               
 


                                               



                                                                  

                                                                
 
                

                                                                                    
                                                  
         
 

                                                
                               
                                                   
 
                                                                              
                               
 

                                         

                                                                         
                          
 
                                                   
                                               
 


                                              
                                               
                                                
                                            


                                                       
                                                                    



                                                        

                                                                

         
package org.openslx.imagemaster;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.openslx.imagemaster.serverconnection.CrcScheduler;
import org.openslx.imagemaster.thrift.server.BinaryListener;
import org.slf4j.LoggerFactory;

/**
 * The main class that starts all the services.
 */
public class App
{

	private static Logger log = Logger.getLogger( App.class );

	private static List<Thread> servers = new ArrayList<>();

	static {
		// 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" );

		// Init the properties and load uploading images from database
		Globals.init();

		// Create binary listener
		Thread t;
		t = new Thread( new BinaryListener(), "BinaryListener" );
		servers.add( t );
		t.start();

		// start the crc checking scheduler
		CrcScheduler.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..." );
	}
}