1 package org.openslx.imagemaster.thrift.server;
3 import java.security.NoSuchAlgorithmException;
4 import java.util.concurrent.TimeUnit;
6 import javax.net.ssl.SSLContext;
7 import javax.net.ssl.SSLSocketFactory;
9 import org.apache.logging.log4j.LogManager;
10 import org.apache.logging.log4j.Logger;
11 import org.apache.thrift.protocol.TProtocolFactory;
12 import org.apache.thrift.server.THsHaServer;
13 import org.apache.thrift.server.TServer;
14 import org.apache.thrift.server.TThreadPoolServer;
15 import org.apache.thrift.transport.TNonblockingServerSocket;
16 import org.apache.thrift.transport.TNonblockingServerTransport;
17 import org.apache.thrift.transport.TSSLTransportFactory;
18 import org.apache.thrift.transport.TSSLTransportFactory.TSSLTransportParameters;
19 import org.apache.thrift.transport.TServerTransport;
20 import org.apache.thrift.transport.TTransportException;
21 import org.apache.thrift.transport.layered.TFramedTransport;
22 import org.
openslx.bwlp.thrift.iface.MasterServer;
24 import org.
openslx.thrifthelper.TBinaryProtocolSafe;
38 final TProtocolFactory
protFactory =
new TBinaryProtocolSafe.Factory(
true,
true );
46 log.info(
"Starting Binary Thrift" );
48 log.info(
"Stopped Binary Thrift" );
52 public BinaryListener(
int port,
boolean secure )
throws TTransportException, NoSuchAlgorithmException
69 private TServer
initSecure(
int port )
throws NoSuchAlgorithmException, TTransportException
71 SSLContext context = SSLContext.getDefault();
72 SSLSocketFactory sf = context.getSocketFactory();
73 String[] cipherSuites = sf.getSupportedCipherSuites();
75 final TSSLTransportParameters params =
new TSSLTransportParameters(
"TLSv1.2", cipherSuites );
77 TServerTransport serverTransport;
79 serverTransport = TSSLTransportFactory.getServerSocket( port, CLIENT_TIMEOUT_MS, null, params );
80 }
catch ( TTransportException e ) {
81 log.fatal(
"Could not listen on port " + port );
84 TThreadPoolServer.Args args =
new TThreadPoolServer.Args( serverTransport );
85 args.protocolFactory( protFactory );
86 args.processor( processor );
87 args.minWorkerThreads( 4 ).maxWorkerThreads( 256 );
88 args.stopTimeoutVal( 2 ).stopTimeoutUnit( TimeUnit.MINUTES );
89 args.transportFactory(
new TFramedTransport.Factory( MAX_MSG_LEN ) );
90 return new TThreadPoolServer( args );
100 public TServer
initNormal(
int port )
throws TTransportException
102 final TNonblockingServerTransport serverTransport;
104 serverTransport =
new TNonblockingServerSocket( port );
105 }
catch ( TTransportException e ) {
106 log.fatal(
"Could not listen on port " + port );
109 THsHaServer.Args args =
new THsHaServer.Args( serverTransport );
110 args.protocolFactory( protFactory );
111 args.processor( processor );
112 args.minWorkerThreads( 2 ).maxWorkerThreads( 6 );
114 return new THsHaServer( args );
BinaryListener(int port, boolean secure)
TServer initSecure(int port)
Listen with TLS wrapping - has to use the thread pool server, since encrypted servers cannot use nonb...
static final int CLIENT_TIMEOUT_MS
How long a client connection can be idle before we close it to free up resources. ...
static final int MAX_MSG_LEN
final TProtocolFactory protFactory
Class to hold global constants and properties from 'config/global.properties'.
static String getSslKeystoreFile()
TServer initNormal(int port)
Create normal plain server, no encryption.
static String getSslKeystorePassword()
final MasterServer.Processor< MasterServerHandler > processor