use of org.apache.thrift.server.TServer in project accumulo by apache.
the class TServerUtilsTest method testStartServerUsedPortWithSearch.
@Test
public void testStartServerUsedPortWithSearch() throws Exception {
TServer server = null;
int[] port = findTwoFreeSequentialPorts(1024);
// Bind to the port
InetAddress addr = InetAddress.getByName("localhost");
((ConfigurationCopy) factory.getSystemConfiguration()).set(Property.TSERV_CLIENTPORT, Integer.toString(port[0]));
((ConfigurationCopy) factory.getSystemConfiguration()).set(Property.TSERV_PORTSEARCH, "true");
try (ServerSocket s = new ServerSocket(port[0], 50, addr)) {
ServerAddress address = startServer();
assertNotNull(address);
server = address.getServer();
assertNotNull(server);
assertEquals(port[1], address.getAddress().getPort());
} finally {
if (null != server) {
TServerUtils.stopTServer(server);
}
}
}
use of org.apache.thrift.server.TServer in project accumulo by apache.
the class TServerUtilsTest method testStartServerPortRangeFirstPortUsed.
@Test
public void testStartServerPortRangeFirstPortUsed() throws Exception {
TServer server = null;
InetAddress addr = InetAddress.getByName("localhost");
int[] port = findTwoFreeSequentialPorts(1024);
String portRange = Integer.toString(port[0]) + "-" + Integer.toString(port[1]);
// Bind to the port
((ConfigurationCopy) factory.getSystemConfiguration()).set(Property.TSERV_CLIENTPORT, portRange);
try (ServerSocket s = new ServerSocket(port[0], 50, addr)) {
ServerAddress address = startServer();
assertNotNull(address);
server = address.getServer();
assertNotNull(server);
assertTrue(port[1] == address.getAddress().getPort());
} finally {
if (null != server) {
TServerUtils.stopTServer(server);
}
}
}
use of org.apache.thrift.server.TServer 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.server.TServer 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.server.TServer in project accumulo by apache.
the class TestThrift1474 method test.
@Test
public void test() throws IOException, TException, InterruptedException {
TServerSocket serverTransport = new TServerSocket(0);
serverTransport.listen();
int port = serverTransport.getServerSocket().getLocalPort();
TestServer handler = new TestServer();
ThriftTest.Processor<ThriftTest.Iface> processor = new ThriftTest.Processor<>(handler);
TThreadPoolServer.Args args = new TThreadPoolServer.Args(serverTransport);
args.stopTimeoutVal = 10;
args.stopTimeoutUnit = TimeUnit.MILLISECONDS;
final TServer server = new TThreadPoolServer(args.processor(processor));
Thread thread = new Thread() {
@Override
public void run() {
server.serve();
}
};
thread.start();
while (!server.isServing()) {
sleepUninterruptibly(10, TimeUnit.MILLISECONDS);
}
TTransport transport = new TSocket("localhost", port);
transport.open();
TProtocol protocol = new TBinaryProtocol(transport);
ThriftTest.Client client = new ThriftTest.Client(protocol);
assertTrue(client.success());
assertFalse(client.fails());
try {
client.throwsError();
fail("no exception thrown");
} catch (ThriftSecurityException ex) {
// expected
}
server.stop();
thread.join();
}
Aggregations