use of org.apache.thrift.transport.TServerSocket 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();
}
use of org.apache.thrift.transport.TServerSocket in project accumulo by apache.
the class TracerTest method testThrift.
@Test
public void testThrift() throws Exception {
TestReceiver tracer = new TestReceiver();
org.apache.htrace.Trace.addReceiver(tracer);
ServerSocket socket = new ServerSocket(0);
TServerSocket transport = new TServerSocket(socket);
transport.listen();
TThreadPoolServer.Args args = new TThreadPoolServer.Args(transport);
args.processor(new Processor<Iface>(TraceWrap.service(new Service())));
final TServer tserver = new TThreadPoolServer(args);
Thread t = new Thread() {
@Override
public void run() {
tserver.serve();
}
};
t.start();
TTransport clientTransport = new TSocket(new Socket("localhost", socket.getLocalPort()));
TestService.Iface client = new TestService.Client(new TBinaryProtocol(clientTransport), new TBinaryProtocol(clientTransport));
client = TraceWrap.client(client);
assertFalse(client.checkTrace(null, "test"));
Span start = Trace.on("start");
assertTrue(client.checkTrace(null, "my test"));
start.stop();
assertNotNull(tracer.traces.get(start.traceId()));
String[] traces = { "my test", "checkTrace", "client:checkTrace", "start" };
assertTrue(tracer.traces.get(start.traceId()).size() == traces.length);
for (int i = 0; i < traces.length; i++) assertEquals(traces[i], tracer.traces.get(start.traceId()).get(i).description);
tserver.stop();
t.join(100);
}
use of org.apache.thrift.transport.TServerSocket in project yyl_example by Relucent.
the class HelloServer method getPoolServer.
/**
* 线程池服务模型,使用标准的阻塞式IO,预先创建一组线程处理请求
*/
public static TServer getPoolServer(int port, HelloService.Processor<HelloServiceHandler> processor) throws TTransportException {
TServerTransport transport = new TServerSocket(port);
TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(transport).processor(processor));
return server;
}
use of org.apache.thrift.transport.TServerSocket in project hbase by apache.
the class ThriftServer method getTThreadPoolServer.
protected TServer getTThreadPoolServer(TProtocolFactory protocolFactory, TProcessor processor, TTransportFactory transportFactory, InetSocketAddress inetSocketAddress) throws Exception {
LOG.info("starting HBase ThreadPool Thrift server on " + inetSocketAddress.toString());
// Thrift's implementation uses '0' as a placeholder for 'use the default.'
int backlog = conf.getInt(BACKLOG_CONF_KEY, BACKLOG_CONF_DEAFULT);
int readTimeout = conf.getInt(THRIFT_SERVER_SOCKET_READ_TIMEOUT_KEY, THRIFT_SERVER_SOCKET_READ_TIMEOUT_DEFAULT);
TServerTransport serverTransport = new TServerSocket(new TServerSocket.ServerSocketTransportArgs().bindAddr(inetSocketAddress).backlog(backlog).clientTimeout(readTimeout));
TBoundedThreadPoolServer.Args serverArgs = new TBoundedThreadPoolServer.Args(serverTransport, conf);
serverArgs.processor(processor).transportFactory(transportFactory).protocolFactory(protocolFactory);
return new TBoundedThreadPoolServer(serverArgs, metrics);
}
use of org.apache.thrift.transport.TServerSocket in project zeppelin by apache.
the class RemoteInterpreterEventServer method start.
public void start() throws IOException {
Thread startingThread = new Thread() {
@Override
public void run() {
try (TServerSocket tSocket = new TServerSocket(RemoteInterpreterUtils.findAvailablePort(portRange))) {
port = tSocket.getServerSocket().getLocalPort();
host = RemoteInterpreterUtils.findAvailableHostAddress();
LOGGER.info("InterpreterEventServer is starting at {}:{}", host, port);
RemoteInterpreterEventService.Processor<RemoteInterpreterEventServer> processor = new RemoteInterpreterEventService.Processor<>(RemoteInterpreterEventServer.this);
thriftServer = new TThreadPoolServer(new TThreadPoolServer.Args(tSocket).processor(processor));
thriftServer.serve();
} catch (IOException | TTransportException e) {
throw new RuntimeException("Fail to create TServerSocket", e);
}
LOGGER.info("ThriftServer-Thread finished");
}
};
startingThread.start();
long start = System.currentTimeMillis();
while ((System.currentTimeMillis() - start) < 30 * 1000) {
if (thriftServer != null && thriftServer.isServing()) {
break;
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
throw new IOException(e);
}
}
if (thriftServer != null && !thriftServer.isServing()) {
throw new IOException("Fail to start InterpreterEventServer in 30 seconds.");
}
LOGGER.info("RemoteInterpreterEventServer is started");
runner = new AppendOutputRunner(listener);
appendFuture = appendService.scheduleWithFixedDelay(runner, 0, AppendOutputRunner.BUFFER_TIME_MS, TimeUnit.MILLISECONDS);
}
Aggregations