blob: 6c834b085dd86390b202238dad562772ed88299e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
package org.openslx.imagemaster;
import java.net.InetAddress;
import java.net.SocketException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import org.apache.thrift.transport.TTransportException;
import org.openslx.imagemaster.localrpc.NetworkHandler;
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 ) throws TTransportException, NoSuchAlgorithmException, SocketException
{
// Init logging
log.info( "Starting Application" );
// Create binary listener
Thread t;
t = new Thread( new BinaryListener( 9090, false ), "Thrift PLAIN" );
servers.add( t );
t.start();
// Create UDP RPC local interface
t = new Thread( new NetworkHandler( 1333, InetAddress.getLoopbackAddress() ) );
servers.add( t );
t.start();
// Create SSL binary listener
try {
t = new Thread( new BinaryListener( 9091, true ), "Thrift TLS" );
servers.add( t );
t.start();
} catch ( Exception e ) {
log.warn( "No TLS available:", e );
}
// 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 ) {
if ( wait.isInterrupted() || !wait.isAlive() )
break;
}
}
}
log.info( "All Servers shut down, exiting..." );
}
}
|