本文整理匯總了Java中org.apache.thrift.transport.TServerTransport類的典型用法代碼示例。如果您正苦於以下問題:Java TServerTransport類的具體用法?Java TServerTransport怎麽用?Java TServerTransport使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TServerTransport類屬於org.apache.thrift.transport包,在下文中一共展示了TServerTransport類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: poolServer
import org.apache.thrift.transport.TServerTransport; //導入依賴的package包/類
@Bean(name = "pool-server")
public TServer poolServer() throws Exception {
TServerTransport transport = new TServerSocket(this.port());
TThreadPoolServer.Args args = new TThreadPoolServer.Args(transport);
args.transportFactory(new TTransportFactory());
args.protocolFactory(new TBinaryProtocol.Factory());
args.processor(this.processor());
args.executorService(new ThreadPoolExecutor(env.getProperty(
"rpc.server.min.worker.threads", Integer.class, 512), env
.getProperty("rpc.server.max.worker.threads", Integer.class,
65535), env.getProperty(
"rpc.server.thread.keep.alive.time", Long.class, 600l),
TimeUnit.SECONDS, new SynchronousQueue<Runnable>()));
return new TThreadPoolServer(args);
}
示例2: getSSLServerTransport
import org.apache.thrift.transport.TServerTransport; //導入依賴的package包/類
private TServerTransport getSSLServerTransport() {
try {
TServerTransport transport;
TSSLTransportFactory.TSSLTransportParameters params =
new TSSLTransportFactory.TSSLTransportParameters();
params.setKeyStore(keystore, keystorePassword, getkeyManagerAlgorithm(), keystoreType);
transport = TSSLTransportFactory.getServerSocket(
port, 120000, InetAddress.getByName(bindAddress), params);
ServerSocket serverSock = ((TServerSocket) transport).getServerSocket();
if (serverSock instanceof SSLServerSocket) {
SSLServerSocket sslServerSock = (SSLServerSocket) serverSock;
List<String> enabledProtocols = new ArrayList<String>();
for (String protocol : sslServerSock.getEnabledProtocols()) {
if (!excludeProtocols.contains(protocol)) {
enabledProtocols.add(protocol);
}
}
sslServerSock.setEnabledProtocols(enabledProtocols.toArray(new String[0]));
}
return transport;
} catch (Throwable throwable) {
throw new FlumeException("Cannot start Thrift source.", throwable);
}
}
示例3: ServerThread
import org.apache.thrift.transport.TServerTransport; //導入依賴的package包/類
ServerThread() throws TTransportException {
TMultiplexedProcessor processor = new TMultiplexedProcessor();
for (String beanName : serviceMap.keySet()) {
IThriftServerService serverService = (IThriftServerService) serviceMap.getService(beanName);
String processorName = serverService.getName();
TProcessor tProcessor = serverService.getProcessor(serverService);
processor.registerProcessor(processorName, tProcessor);
logger.info("Register a processorName {} processorImpl {}", processorName, tProcessor);
}
logger.info("init default TServerTransport in addr {} port {}", applicationProperties.getAddr(), applicationProperties.getPort());
TServerTransport tServerTransport = new TServerSocket(new InetSocketAddress(applicationProperties.getAddr(),
applicationProperties.getPort()));
TThreadPoolServer.Args args = new TThreadPoolServer.Args(tServerTransport);
args.processor(processor);
args.protocolFactory(tProtocolFactory);
server = new TThreadPoolServer(args);
}
示例4: getTThreadPoolServer
import org.apache.thrift.transport.TServerTransport; //導入依賴的package包/類
private static TServer getTThreadPoolServer(TProtocolFactory protocolFactory,
TProcessor processor,
TTransportFactory transportFactory,
int workerThreads,
InetSocketAddress inetSocketAddress,
int backlog,
int clientTimeout)
throws TTransportException {
TServerTransport serverTransport = new TServerSocket(
new TServerSocket.ServerSocketTransportArgs().
bindAddr(inetSocketAddress).backlog(backlog).
clientTimeout(clientTimeout));
log.info("starting HBase ThreadPool Thrift server on " + inetSocketAddress.toString());
TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport);
serverArgs.processor(processor);
serverArgs.transportFactory(transportFactory);
serverArgs.protocolFactory(protocolFactory);
if (workerThreads > 0) {
serverArgs.maxWorkerThreads(workerThreads);
}
return new TThreadPoolServer(serverArgs);
}
示例5: start
import org.apache.thrift.transport.TServerTransport; //導入依賴的package包/類
/**
* Server initialization.
*
* @throws Exception error
*/
public void start() throws Exception {
log.info("initializing thrift server {}", getServerName());
final ThreadFactory threadFactory = new ThreadFactoryBuilder()
.setNameFormat(threadPoolNameFormat)
.setUncaughtExceptionHandler((t, e) -> log.error("Uncaught exception in thread: {}", t.getName(), e))
.build();
final ExecutorService executorService = new ThreadPoolExecutor(
Math.min(2, config.getThriftServerMaxWorkerThreads()),
config.getThriftServerMaxWorkerThreads(),
60L,
TimeUnit.SECONDS,
new SynchronousQueue<>(),
threadFactory
);
RegistryUtil.registerThreadPool(registry, threadPoolNameFormat, (ThreadPoolExecutor) executorService);
final int timeout = config.getThriftServerSocketClientTimeoutInSeconds() * 1000;
final TServerTransport serverTransport = new TServerSocket(portNumber, timeout);
startServing(executorService, serverTransport);
}
示例6: main
import org.apache.thrift.transport.TServerTransport; //導入依賴的package包/類
public static void main(String[] args) {
try {
userProfileServerHandler = new UserProfileServerHandler();
userProfileProcessor = new UserProfileService.Processor(userProfileServerHandler);
TMultiplexedProcessor airavataServerProcessor = new TMultiplexedProcessor();
airavataServerProcessor.registerProcessor("UserProfileService", userProfileProcessor);
TServerTransport serverTransport = new TServerSocket(9190);
TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(airavataServerProcessor));
System.out.println("Starting User Profile server...");
server.serve();
} catch (Exception x) {
x.printStackTrace();
}
}
示例7: HadoopThriftServer
import org.apache.thrift.transport.TServerTransport; //導入依賴的package包/類
/**
* Constrcts a server object
*/
public HadoopThriftServer(String [] args) {
if (args.length > 0) {
serverPort = new Integer(args[0]);
}
try {
ServerSocket ssock = createServerSocket(serverPort);
TServerTransport serverTransport = new TServerSocket(ssock);
Iface handler = new HadoopThriftHandler("hdfs-thrift-dhruba");
ThriftHadoopFileSystem.Processor processor = new ThriftHadoopFileSystem.Processor(handler);
TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport);
serverArgs.minWorkerThreads = 10;
serverArgs.processor(processor);
serverArgs.transportFactory(new TTransportFactory());
serverArgs.protocolFactory(new TBinaryProtocol.Factory());
server = new TThreadPoolServer(serverArgs);
System.out.println("Starting the hadoop thrift server on port [" + serverPort + "]...");
HadoopThriftHandler.LOG.info("Starting the hadoop thrift server on port [" +serverPort + "]...");
System.out.flush();
} catch (Exception x) {
x.printStackTrace();
}
}
示例8: startServer2
import org.apache.thrift.transport.TServerTransport; //導入依賴的package包/類
public void startServer2() throws Exception
{
AwesomeService.Processor<AwesomeService.Iface> processor = new AwesomeService.Processor<>(referenceServer);
TServerTransport serverTransport = new TServerSocket(9090);
TServer server = new TSimpleServer(new TSimpleServer.Args(serverTransport).processor(processor));
ServerRunner serverRunner = new ServerRunner(server);
Thread serverThread = new Thread(serverRunner);
serverThread.start();
logger.info("Started binary interface");
joinMethods.add(() -> {
try {
serverThread.join();
} catch (InterruptedException ignored) {
}
});
}
示例9: main
import org.apache.thrift.transport.TServerTransport; //導入依賴的package包/類
public static void main(String[] args) {
try {
handler = new CalculatorHandler();
processor = new Calculator.Processor(handler);
try {
TServerTransport serverTransport = new TServerSocket(9090);
TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));
System.out.println("Starting the server...");
server.serve();
} catch (TTransportException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (Exception x) {
x.printStackTrace();
}
}
示例10: main
import org.apache.thrift.transport.TServerTransport; //導入依賴的package包/類
public static void main(String[] args)
throws TTransportException, UnsupportedEncodingException {
final String msg = "Hello Thrift!\n";
final String stop_cmd = "STOP";
final int buf_size = 1024*8;
byte[] buf = new byte[buf_size];
final int port = 9090;
TServerTransport acceptor = new TServerSocket(9090);
acceptor.listen();
System.out.println("[Server] listening on port: " + port);
String input;
do {
TTransport trans = acceptor.accept();
int len = trans.read(buf, 0, buf_size);
input = new String(buf, 0, len,"UTF-8");
System.out.println("[Server] handling request: " + input);
trans.write(msg.getBytes());
trans.flush();
trans.close();
} while (! stop_cmd.regionMatches(0, input, 0, 4));
System.out.println("[Server] exiting");
acceptor.close();
}
示例11: main
import org.apache.thrift.transport.TServerTransport; //導入依賴的package包/類
public static void main(String[] args) {
int port = 9090;
try {
TServerTransport serverTransport = new TServerSocket(port);
Args processor = new TThreadPoolServer.Args(serverTransport)
.inputTransportFactory(new TFramedTransport.Factory())
.outputTransportFactory(new TFramedTransport.Factory())
.processor(new Processor<>(new TestThriftServiceHandler()));
// processor.maxWorkerThreads = 20;
TThreadPoolServer server = new TThreadPoolServer(processor);
System.out.println("Starting the server...");
server.serve();
} catch (Exception e) {
e.printStackTrace();
}
}
示例12: setUp
import org.apache.thrift.transport.TServerTransport; //導入依賴的package包/類
@BeforeClass
public static void setUp() {
int port = 9090;
try {
TServerTransport serverTransport = new TServerSocket(port);
Args processor = new TThreadPoolServer.Args(serverTransport)
.inputTransportFactory(new TFramedTransport.Factory())
.outputTransportFactory(new TFramedTransport.Factory())
.processor(new Processor<>(new TestThriftServiceHandler()));
// processor.maxWorkerThreads = 20;
TThreadPoolServer server = new TThreadPoolServer(processor);
logger.info("Starting test server...");
new Thread(server::serve).start();
Thread.sleep(1000); // waiting server init
} catch (Exception e) {
e.printStackTrace();
}
}
示例13: createServerSocket
import org.apache.thrift.transport.TServerTransport; //導入依賴的package包/類
/**
* Creates the server socket.
*
* @return the t server transport
* @throws TTransportException the t transport exception
*/
public TServerTransport createServerSocket() throws TTransportException {
return new TServerSocket(
new InetSocketAddress(getNodeConfig().getThriftHost(), getNodeConfig().getThriftPort())) {
@Override
protected TSocket acceptImpl() throws TTransportException {
ServerSocket serverSocket = getServerSocket();
if (serverSocket == null) {
throw new TTransportException(
TTransportException.NOT_OPEN,
"No underlying server socket."
);
}
try {
Socket result = serverSocket.accept();
TSocketWrapper result2 = new TSocketWrapper(result);
result2.setTimeout(0);
openedSockets.add(result2);
return result2;
} catch (IOException iox) {
throw new TTransportException(iox);
}
}
};
}
示例14: testKaaNodeInitializationServiceStart
import org.apache.thrift.transport.TServerTransport; //導入依賴的package包/類
/**
* Test kaa node initialization service start.
*
* @throws Exception the exception
*/
@Test
public void testKaaNodeInitializationServiceStart() throws Exception {
KaaNodeInitializationService kaaNodeInitializationService = kaaNodeInitializationServiceSpy();
TThreadPoolServer server = Mockito.mock(TThreadPoolServer.class);
Mockito.doNothing().when(server).serve();
Mockito.doReturn(server).when(kaaNodeInitializationService).createServer(Mockito.any(TServerTransport.class),
Mockito.any(TMultiplexedProcessor.class));
kaaNodeInitializationService.start();
Mockito.verify(controlInitializationService).start();
Mockito.verify(bootstrapInitializationService).start();
Mockito.verify(operationsInitializationService).start();
}
示例15: testKaaNodeInitializationServiceStartTransportException
import org.apache.thrift.transport.TServerTransport; //導入依賴的package包/類
/**
* Test kaa node initialization service start with transport exception.
*
* @throws Exception the exception
*/
@Test
public void testKaaNodeInitializationServiceStartTransportException() throws Exception {
KaaNodeInitializationService kaaNodeInitializationService = kaaNodeInitializationServiceSpy();
TThreadPoolServer server = Mockito.mock(TThreadPoolServer.class);
Mockito.doThrow(TTransportException.class).when(server).serve();
Mockito.doReturn(server).when(kaaNodeInitializationService).createServer(Mockito.any(TServerTransport.class),
Mockito.any(TMultiplexedProcessor.class));
kaaNodeInitializationService.start();
Mockito.verify(controlInitializationService).start();
Mockito.verify(bootstrapInitializationService).start();
Mockito.verify(operationsInitializationService).start();
}