bwLehrpool Masterserver
Manages authentication and sharing of virtual machines between participating institutions
App.java
Go to the documentation of this file.
1 package org.openslx.imagemaster;
2 
3 import java.net.InetAddress;
4 import java.net.SocketException;
5 import java.security.NoSuchAlgorithmException;
6 import java.util.ArrayList;
7 import java.util.List;
8 
9 import org.apache.logging.log4j.LogManager;
10 import org.apache.logging.log4j.Logger;
11 import org.apache.logging.log4j.core.config.Configurator;
12 import org.apache.logging.log4j.core.config.DefaultConfiguration;
13 import org.apache.thrift.transport.TTransportException;
17 import org.openslx.sat.thrift.version.Version;
18 import org.openslx.util.AppUtil;
19 
23 public class App
24 {
25 
26  private static Logger log = LogManager.getLogger( App.class );
27 
28  private static final String NAME = "Master-Server";
29 
30  private static List<Thread> servers = new ArrayList<>();
31 
32  public static void main( String[] args ) throws TTransportException, NoSuchAlgorithmException, SocketException
33  {
34  // setup basic logging appender to log output on console if no external appender (log4j.properties) is configured
35  if ( org.apache.logging.log4j.core.Logger.class.cast( LogManager.getRootLogger() ).getAppenders().isEmpty() ) {
36  Configurator.initialize( new DefaultConfiguration() );
37  }
38 
39  AppUtil.logHeader( log, App.NAME, App.class.getPackage().getImplementationVersion() );
40  AppUtil.logProperty( log, "rpc.version", Long.toString( Version.VERSION ) );
41 
42  // Create binary listener
43  Thread t;
44  if ( Globals.getThriftPortPlain() != 0 ) {
45  t = new Thread( new BinaryListener( Globals.getThriftPortPlain(), false ), "Thrift PLAIN" );
46  servers.add( t );
47  t.start();
48  }
49 
50  // Create UDP RPC local interface
51  t = new Thread( new NetworkHandler( 1333, InetAddress.getLoopbackAddress() ) );
52  servers.add( t );
53  t.start();
54 
55  if ( Globals.getThriftPortSsl() != 0 ) {
56  // Create SSL binary listener
57  try {
58  t = new Thread( new BinaryListener( Globals.getThriftPortSsl(), true ), "Thrift TLS" );
59  servers.add( t );
60  t.start();
61  } catch ( Exception e ) {
62  log.warn( "No TLS available", e );
63  }
64  }
65 
66  // Spawn HTTP thrift listener - always do this on localhost, expected to be proxied with SSL
67  try {
68  t = new Thread( new HttpListener( "127.0.0.1", 8090 ), "JSON-HTTP" );
69  servers.add( t );
70  t.start();
71  } catch ( Exception e ) {
72  log.warn( "No JSON-HTTP available", e );
73  }
74 
75  // Run more servers
76  // ...
77  // Wait for all servers to die
78  for ( Thread wait : servers ) {
79  boolean success = false;
80  while ( !success ) {
81  try {
82  wait.join();
83  success = true;
84  } catch ( InterruptedException e ) {
85  if ( wait.isInterrupted() || !wait.isAlive() )
86  break;
87  }
88  }
89  }
90 
91  log.info( "All Servers shut down, exiting..." );
92  }
93 }
The main class that starts all the services.
Definition: App.java:23
static List< Thread > servers
Definition: App.java:30
static final String NAME
Definition: App.java:28
static Logger log
Definition: App.java:26
Class to hold global constants and properties from 'config/global.properties'.
Definition: Globals.java:16
static void main(String[] args)
Definition: App.java:32
The network listener that will receive incoming UDP packets, try to process them, and then send a rep...