use of org.apache.thrift.transport.TServerSocket in project airavata by apache.
the class ProfileServiceServer method start.
public void start() throws Exception {
try {
setStatus(ServerStatus.STARTING);
final int serverPort = Integer.parseInt(ServerSettings.getProfileServiceServerPort());
final String serverHost = ServerSettings.getProfileServiceServerHost();
// create multiple processors for each profile-service
UserProfileService.Processor userProfileProcessor = new UserProfileService.Processor(new UserProfileServiceHandler());
TenantProfileService.Processor teneantProfileProcessor = new TenantProfileService.Processor(new TenantProfileServiceHandler());
IamAdminServices.Processor iamAdminServicesProcessor = new IamAdminServices.Processor(new IamAdminServicesHandler());
// create a multiplexed processor
TMultiplexedProcessor profileServiceProcessor = new TMultiplexedProcessor();
profileServiceProcessor.registerProcessor(profile_user_cpiConstants.USER_PROFILE_CPI_NAME, userProfileProcessor);
profileServiceProcessor.registerProcessor(profile_tenant_cpiConstants.TENANT_PROFILE_CPI_NAME, teneantProfileProcessor);
profileServiceProcessor.registerProcessor(iam_admin_services_cpiConstants.IAM_ADMIN_SERVICES_CPI_NAME, iamAdminServicesProcessor);
TServerTransport serverTransport;
if (serverHost == null) {
serverTransport = new TServerSocket(serverPort);
} else {
InetSocketAddress inetSocketAddress = new InetSocketAddress(serverHost, serverPort);
serverTransport = new TServerSocket(inetSocketAddress);
}
TThreadPoolServer.Args options = new TThreadPoolServer.Args(serverTransport);
options.minWorkerThreads = 30;
server = new TThreadPoolServer(options.processor(profileServiceProcessor));
new Thread() {
public void run() {
server.serve();
setStatus(ServerStatus.STOPPED);
logger.info("Profile Service Server Stopped.");
}
}.start();
new Thread() {
public void run() {
while (!server.isServing()) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
break;
}
}
if (server.isServing()) {
setStatus(ServerStatus.STARTED);
logger.info("Starting Profile Service Server on Port " + serverPort);
logger.info("Listening to Profile Service Server clients ....");
}
}
}.start();
} catch (TTransportException e) {
setStatus(ServerStatus.FAILED);
throw new Exception("Error while starting the Profile Service Server", e);
}
}
use of org.apache.thrift.transport.TServerSocket in project airavata by apache.
the class OrchestratorServer method StartOrchestratorServer.
public void StartOrchestratorServer(OrchestratorService.Processor<OrchestratorServerHandler> orchestratorServerHandlerProcessor) throws Exception {
final int serverPort = Integer.parseInt(ServerSettings.getSetting(Constants.ORCHESTRATOT_SERVER_PORT, "8940"));
try {
final String serverHost = ServerSettings.getSetting(Constants.ORCHESTRATOT_SERVER_HOST, null);
TServerTransport serverTransport;
if (serverHost == null) {
serverTransport = new TServerSocket(serverPort);
} else {
InetSocketAddress inetSocketAddress = new InetSocketAddress(serverHost, serverPort);
serverTransport = new TServerSocket(inetSocketAddress);
}
// server = new TSimpleServer(
// new TServer.Args(serverTransport).processor(orchestratorServerHandlerProcessor));
TThreadPoolServer.Args options = new TThreadPoolServer.Args(serverTransport);
options.minWorkerThreads = Integer.parseInt(ServerSettings.getSetting(Constants.ORCHESTRATOT_SERVER_MIN_THREADS, "30"));
server = new TThreadPoolServer(options.processor(orchestratorServerHandlerProcessor));
new Thread() {
public void run() {
server.serve();
setStatus(ServerStatus.STARTING);
logger.info("Starting Orchestrator Server ... ");
}
}.start();
new Thread() {
public void run() {
while (!server.isServing()) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
break;
}
}
if (server.isServing()) {
setStatus(ServerStatus.STARTED);
logger.info("Started Orchestrator Server on Port " + serverPort + " ...");
}
}
}.start();
} catch (TTransportException e) {
logger.error(e.getMessage());
setStatus(ServerStatus.FAILED);
logger.error("Failed to start Orchestrator server on port " + serverPort + " ...");
}
}
use of org.apache.thrift.transport.TServerSocket in project mlib by myshzzx.
the class ThriftServerFactory method build.
/**
* @return build but not start server.
* @throws Exception
*/
@SuppressWarnings("ConstantConditions")
public TServer build() throws Exception {
final TServer server;
int poolSize = Runtime.getRuntime().availableProcessors() * 2;
poolSize = Math.max(poolSize, this.serverPoolSize);
AtomicInteger tpi = new AtomicInteger(1);
ThreadPoolExecutor tPool = new ThreadPoolExecutor(poolSize, poolSize, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), r -> {
Thread t = new Thread(r, "tServer-" + serverTPI.getAndIncrement() + "-" + tpi.getAndIncrement());
t.setDaemon(true);
return t;
});
tPool.allowCoreThreadTimeOut(true);
if (useTLS) {
// TLS server
TSSLTransportFactory.TSSLTransportParameters transportParams = new TSSLTransportFactory.TSSLTransportParameters();
transportParams.setKeyStore(ThriftServerFactory.class.getClassLoader().getResource(this.selfKeyStore).getPath(), this.selfKeyStorePw);
transportParams.requireClientAuth(this.isRequireClientAuth);
if (this.isRequireClientAuth)
transportParams.setTrustStore(ThriftServerFactory.class.getClassLoader().getResource(this.trustKeyStore).getPath(), this.trustKeyStorePw);
TServerSocket serverTransport = TSSLTransportFactory.getServerSocket(this.serverPort, this.clientTimeout, InetAddress.getByName(this.serverHost), transportParams);
server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(this.processor).protocolFactory(new TCompactProtocol.Factory()).executorService(tPool));
} else {
// Non security Server
TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(new InetSocketAddress(this.serverHost, this.serverPort), this.clientTimeout);
server = new THsHaServer(new THsHaServer.Args(serverTransport).processor(this.processor).protocolFactory(new TCompactProtocol.Factory()).transportFactory(new TFramedTransport.Factory(nonTLSServerMaxFrameSize)).executorService(tPool));
}
if (this.serverEventHandler != null) {
server.setServerEventHandler(this.serverEventHandler);
}
return server;
}
use of org.apache.thrift.transport.TServerSocket in project HackTutorial by linrongbin16.
the class Server method main.
public static void main(String[] args) throws Exception {
ServerSocket socket = new ServerSocket(30003);
TServerSocket serverTransport = new TServerSocket(socket);
Basic.BasicService.Processor processor = new Basic.BasicService.Processor(new BasicServiceImpl());
TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));
System.out.println("Server Starting...");
server.serve();
}
use of org.apache.thrift.transport.TServerSocket in project providence by morimekta.
the class RPCThriftSocketTest method setUp.
@Before
public void setUp() throws Exception {
Log.setLog(new NoLogging());
rc = copyResourceTo("/pvdrc", temp.getRoot());
copyResourceTo("/test.thrift", temp.getRoot());
impl = Mockito.mock(MyService.Iface.class);
TServerSocket transport = new TServerSocket(0);
server = new TSimpleServer(new TServer.Args(transport).protocolFactory(new TBinaryProtocol.Factory()).processor(new MyService.Processor<>(impl)));
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(server::serve);
Thread.sleep(1);
port = transport.getServerSocket().getLocalPort();
exitCode = 0;
rpc = new RPC(console.tty()) {
@Override
protected void exit(int i) {
exitCode = i;
}
};
}
Aggregations