本文整理汇总了Java中org.apache.thrift.server.TThreadPoolServer.serve方法的典型用法代码示例。如果您正苦于以下问题:Java TThreadPoolServer.serve方法的具体用法?Java TThreadPoolServer.serve怎么用?Java TThreadPoolServer.serve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.thrift.server.TThreadPoolServer
的用法示例。
在下文中一共展示了TThreadPoolServer.serve方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.thrift.server.TThreadPoolServer; //导入方法依赖的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();
}
}
示例2: init
import org.apache.thrift.server.TThreadPoolServer; //导入方法依赖的package包/类
protected void init() throws Exception {
TServerTransport serverTransport = new TServerSocket( PORT );
TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory();
server = new TThreadPoolServer(
new TThreadPoolServer.Args( serverTransport )
.inputProtocolFactory( bFactory )
.outputProtocolFactory( bFactory )
.inputTransportFactory( getTransportFactory() )
.outputTransportFactory( getTransportFactory() )
.processor( getProcessor() ) );
Thread startTread = new Thread() {
@Override
public void run() {
server.serve();
}
};
startTread.setName( "thrift-server" );
startTread.start();
while( !server.isServing() ) {
Thread.sleep( 100 );
}
protocol = ExtensionLoader.getExtensionLoader(Protocol.class)
.getExtension( ThriftProtocol.NAME );
invoker = protocol.refer( getInterface(), getUrl() );
}
示例3: main
import org.apache.thrift.server.TThreadPoolServer; //导入方法依赖的package包/类
public static void main(String[] args)
throws TTransportException, IOException {
TradeHistory.Processor proc =
new TradeHistory.Processor(new TradeHistoryHandler());
TServerSocket trans_svr =
new TServerSocket(9090);
TThreadPoolServer server =
new TThreadPoolServer(new TThreadPoolServer.Args(trans_svr)
.protocolFactory(new TJSONProtocol.Factory())
.processor(proc));
System.out.println("[Server] listening of port 9090");
server.serve();
}
示例4: main
import org.apache.thrift.server.TThreadPoolServer; //导入方法依赖的package包/类
public static void main(String[] args)
throws TTransportException, IOException {
TradeHistory.Processor proc =
new TradeHistory.Processor(new TradeHistoryHandler());
TServerSocket trans_svr =
new TServerSocket(9090);
TThreadPoolServer server =
new TThreadPoolServer(new TThreadPoolServer.Args(trans_svr).processor(proc));
System.out.println("[Server] listening of port 9090");
server.serve();
}
示例5: run
import org.apache.thrift.server.TThreadPoolServer; //导入方法依赖的package包/类
@Override
public void run() {
LOG.info("Initializing Thrift Service for Bootstrap Server....");
LOG.info("thrift host: {}", thriftHost);
LOG.info("thrift port: {}", thriftPort);
try {
TMultiplexedProcessor processor = new TMultiplexedProcessor();
BootstrapThriftService.Processor<BootstrapThriftService.Iface> bootstrapProcessor = new BootstrapThriftService.Processor<BootstrapThriftService.Iface>(
bootstrapThriftService);
processor.registerProcessor(KaaThriftService.BOOTSTRAP_SERVICE.getServiceName(), bootstrapProcessor);
TServerTransport serverTransport = new TServerSocket(new InetSocketAddress(thriftHost, thriftPort));
server = new TThreadPoolServer(new Args(serverTransport).processor(processor));
LOG.info("Bootstrap test Server {}:{} Started.", thriftHost, thriftPort);
synchronized (startSync) {
startComplete = true;
startSync.notify();
}
server.serve();
LOG.info("Bootstrap test Server {}:{} Stopped.", thriftHost, thriftPort);
} catch (TTransportException e) {
LOG.error("TTransportException", e);
} finally {
synchronized (stopSync) {
stopComplete = true;
bootstrapThriftService.reset();
stopSync.notify();
}
}
}
示例6: init
import org.apache.thrift.server.TThreadPoolServer; //导入方法依赖的package包/类
protected void init() throws Exception {
TServerTransport serverTransport = new TServerSocket(PORT);
TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory();
server = new TThreadPoolServer(
new TThreadPoolServer.Args(serverTransport)
.inputProtocolFactory(bFactory)
.outputProtocolFactory(bFactory)
.inputTransportFactory(getTransportFactory())
.outputTransportFactory(getTransportFactory())
.processor(getProcessor()));
Thread startTread = new Thread() {
@Override
public void run() {
server.serve();
}
};
startTread.setName("thrift-server");
startTread.start();
while (!server.isServing()) {
Thread.sleep(100);
}
protocol = ExtensionLoader.getExtensionLoader(Protocol.class)
.getExtension(ThriftProtocol.NAME);
invoker = protocol.refer(getInterface(), getUrl());
}
示例7: startWaggleDance
import org.apache.thrift.server.TThreadPoolServer; //导入方法依赖的package包/类
/**
* Start Metastore based on a passed {@link HadoopThriftAuthBridge}
*
* @param bridge
* @param startLock
* @param startCondition
* @param startedServing
* @throws Throwable
*/
private void startWaggleDance(
HadoopThriftAuthBridge bridge,
Lock startLock,
Condition startCondition,
AtomicBoolean startedServing)
throws Throwable {
try {
// Server will create new threads up to max as necessary. After an idle
// period, it will destory threads to keep the number of threads in the
// pool to min.
int minWorkerThreads = hiveConf.getIntVar(ConfVars.METASTORESERVERMINTHREADS);
int maxWorkerThreads = hiveConf.getIntVar(ConfVars.METASTORESERVERMAXTHREADS);
boolean tcpKeepAlive = hiveConf.getBoolVar(ConfVars.METASTORE_TCP_KEEP_ALIVE);
boolean useFramedTransport = hiveConf.getBoolVar(ConfVars.METASTORE_USE_THRIFT_FRAMED_TRANSPORT);
boolean useSSL = hiveConf.getBoolVar(ConfVars.HIVE_METASTORE_USE_SSL);
TServerSocket serverSocket = createServerSocket(useSSL, waggleDanceConfiguration.getPort());
if (tcpKeepAlive) {
serverSocket = new TServerSocketKeepAlive(serverSocket);
}
TTransportFactory transFactory = useFramedTransport ? new TFramedTransport.Factory() : new TTransportFactory();
LOG.info("Starting WaggleDance Server");
TThreadPoolServer.Args args = new TThreadPoolServer.Args(serverSocket)
.processorFactory(tSetIpAddressProcessorFactory)
.transportFactory(transFactory)
.protocolFactory(new TBinaryProtocol.Factory())
.minWorkerThreads(minWorkerThreads)
.maxWorkerThreads(maxWorkerThreads)
.stopTimeoutVal(waggleDanceConfiguration.getThriftServerStopTimeoutValInSeconds())
.requestTimeout(waggleDanceConfiguration.getThriftServerRequestTimeout())
.requestTimeoutUnit(waggleDanceConfiguration.getThriftServerRequestTimeoutUnit());
tServer = new TThreadPoolServer(args);
LOG.info("Started the new WaggleDance on port [" + waggleDanceConfiguration.getPort() + "]...");
LOG.info("Options.minWorkerThreads = " + minWorkerThreads);
LOG.info("Options.maxWorkerThreads = " + maxWorkerThreads);
LOG.info("TCP keepalive = " + tcpKeepAlive);
if (startLock != null) {
signalOtherThreadsToStart(tServer, startLock, startCondition, startedServing);
}
tServer.serve();
} catch (Throwable x) {
LOG.error(StringUtils.stringifyException(x));
throw x;
}
LOG.info("Waggle Dance has stopped");
}
示例8: beforeTest
import org.apache.thrift.server.TThreadPoolServer; //导入方法依赖的package包/类
/**
* Before test.
*
* @throws Exception the exception
*/
@Before
public void beforeTest() throws Exception {
if (!thriftServerStarted) {
CliThriftService.Processor<CliThriftService.Iface> cliProcessor = new CliThriftService.Processor<CliThriftService.Iface>(
new TestCliThriftService(THRIFT_SERVER_SHORT_NAME));
TMultiplexedProcessor processor = new TMultiplexedProcessor();
processor.registerProcessor(KaaThriftService.KAA_NODE_SERVICE.getServiceName(), cliProcessor);
TServerTransport serverTransport = new TServerSocket(
new InetSocketAddress(HOST, PORT));
server = new TThreadPoolServer(
new Args(serverTransport).processor(processor));
thriftServerThread = new Thread(new Runnable() {
@Override
public void run() {
LOG.info("Thrift Server started.");
server.serve();
LOG.info("Thrift Server stopped.");
}
});
thriftServerThread.start();
Thread.sleep(100);
thriftServerStarted = true;
}
cliSession = new CliSessionState();
cliSession.in = System.in;
systemOut = new ByteArrayOutputStream();
PrintStream out = new PrintStream(systemOut, true, "UTF-8");
System.setOut(out);
systemErr = new ByteArrayOutputStream();
PrintStream err = new PrintStream(systemErr, true, "UTF-8");
System.setErr(err);
cliSession.out = System.out;
cliSession.err = System.err;
CliSessionState.start(cliSession);
}
示例9: run
import org.apache.thrift.server.TThreadPoolServer; //导入方法依赖的package包/类
@Override
public void run() {
LOG.info("Initializing Thrift Service for Operations Server....");
LOG.info("thrift host: {}", thriftHost);
LOG.info("thrift port: {}", thriftPort);
registerZK();
try {
TMultiplexedProcessor processor = new TMultiplexedProcessor();
OperationsThriftService.Processor<OperationsThriftService.Iface> operationsProcessor = new OperationsThriftService.Processor<OperationsThriftService.Iface>(
operationsThriftService);
processor.registerProcessor(KaaThriftService.OPERATIONS_SERVICE.getServiceName(), operationsProcessor);
TServerTransport serverTransport = new TServerSocket(new InetSocketAddress(thriftHost, thriftPort));
server = new TThreadPoolServer(new Args(serverTransport).processor(processor));
LOG.info("Operations Server {}:{} Started.", thriftHost, thriftPort);
server.serve();
LOG.info("Operations Server {}:{} Stopped.", thriftHost, thriftPort);
} catch (TTransportException e) {
LOG.error("TTransportException", e);
}
}
示例10: init
import org.apache.thrift.server.TThreadPoolServer; //导入方法依赖的package包/类
protected void init() throws Exception {
TServerTransport serverTransport = new TServerSocket( PORT );
DubboDemoImpl impl = new DubboDemoImpl();
$__DemoStub.Processor processor = new $__DemoStub.Processor( impl );
// for test
Field field = processor.getClass().getSuperclass().getDeclaredField( "processMap" );
field.setAccessible( true );
Object obj = field.get( processor );
if ( obj instanceof Map ) {
( ( Map ) obj ).remove( "echoString" );
}
// ~
TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory();
MultiServiceProcessor wrapper = new MultiServiceProcessor();
wrapper.addProcessor( Demo.class, processor );
server = new TThreadPoolServer(
new TThreadPoolServer.Args( serverTransport )
.inputProtocolFactory( bFactory )
.outputProtocolFactory( bFactory )
.inputTransportFactory( getTransportFactory() )
.outputTransportFactory( getTransportFactory() )
.processor( wrapper ) );
Thread startTread = new Thread() {
@Override
public void run() {
server.serve();
}
};
startTread.start();
while ( !server.isServing() ) {
Thread.sleep( 100 );
}
}
示例11: init
import org.apache.thrift.server.TThreadPoolServer; //导入方法依赖的package包/类
protected void init() throws Exception {
TServerTransport serverTransport = new TServerSocket(PORT);
DubboDemoImpl impl = new DubboDemoImpl();
$__DemoStub.Processor processor = new $__DemoStub.Processor(impl);
// for test
Field field = processor.getClass().getSuperclass().getDeclaredField("processMap");
field.setAccessible(true);
Object obj = field.get(processor);
if (obj instanceof Map) {
((Map) obj).remove("echoString");
}
// ~
TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory();
MultiServiceProcessor wrapper = new MultiServiceProcessor();
wrapper.addProcessor(Demo.class, processor);
server = new TThreadPoolServer(
new TThreadPoolServer.Args(serverTransport)
.inputProtocolFactory(bFactory)
.outputProtocolFactory(bFactory)
.inputTransportFactory(getTransportFactory())
.outputTransportFactory(getTransportFactory())
.processor(wrapper));
Thread startTread = new Thread() {
@Override
public void run() {
server.serve();
}
};
startTread.start();
while (!server.isServing()) {
Thread.sleep(100);
}
}