本文整理汇总了Java中org.apache.thrift.transport.TNonblockingServerTransport类的典型用法代码示例。如果您正苦于以下问题:Java TNonblockingServerTransport类的具体用法?Java TNonblockingServerTransport怎么用?Java TNonblockingServerTransport使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TNonblockingServerTransport类属于org.apache.thrift.transport包,在下文中一共展示了TNonblockingServerTransport类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: nonBlockMode
import org.apache.thrift.transport.TNonblockingServerTransport; //导入依赖的package包/类
private void nonBlockMode() {
AskerHandler handler = new AskerHandler();
Asker.Processor processor = new Asker.Processor(handler);
try {
TNonblockingServerTransport transport = new TNonblockingServerSocket(port);
THsHaServer.Args arg = new THsHaServer.Args(transport);
arg.protocolFactory(new TCompactProtocol.Factory());
// arg.transportFactory(new TFramedTransport.Factory());
// arg.processorFactory(new TProcessorFactory(processor));
arg.processor(processor);
server = new THsHaServer(arg);
start.countDown();
System.out.println("Starting the nonBlock server...");
server.serve();
} catch (Exception e) {
e.printStackTrace();
}
}
示例2: ThriftTestingSource
import org.apache.thrift.transport.TNonblockingServerTransport; //导入依赖的package包/类
public ThriftTestingSource(String handlerName, int port, String protocol) throws Exception {
TNonblockingServerTransport serverTransport =
new TNonblockingServerSocket(new InetSocketAddress("0.0.0.0", port));
ThriftSourceProtocol.Iface handler = getHandler(handlerName);
TProtocolFactory transportProtocolFactory = null;
if (protocol != null && protocol == ThriftRpcClient.BINARY_PROTOCOL) {
transportProtocolFactory = new TBinaryProtocol.Factory();
} else {
transportProtocolFactory = new TCompactProtocol.Factory();
}
server = new THsHaServer(new THsHaServer.Args(serverTransport).processor(
new ThriftSourceProtocol.Processor(handler)).protocolFactory(
transportProtocolFactory));
Executors.newSingleThreadExecutor().submit(new Runnable() {
@Override
public void run() {
server.serve();
}
});
}
示例3: run
import org.apache.thrift.transport.TNonblockingServerTransport; //导入依赖的package包/类
public void run() {
try {
Scribe.Processor processor = new Scribe.Processor(new Receiver());
TNonblockingServerTransport transport = new TNonblockingServerSocket(port);
THsHaServer.Args args = new THsHaServer.Args(transport);
args.workerThreads(workers);
args.processor(processor);
args.transportFactory(new TFramedTransport.Factory(maxReadBufferBytes));
args.protocolFactory(new TBinaryProtocol.Factory(false, false));
args.maxReadBufferBytes = maxReadBufferBytes;
server = new THsHaServer(args);
LOG.info("Starting Scribe Source on port " + port);
server.serve();
} catch (Exception e) {
LOG.warn("Scribe failed", e);
}
}
示例4: startThreads
import org.apache.thrift.transport.TNonblockingServerTransport; //导入依赖的package包/类
@Override
protected boolean startThreads() {
try {
for (int i = 0; i < MAX_SELECTOR_THREADS; ++i) {
selectorThreads.add(new TrackingSelectorThread(ACCEPT_QUEUE_LEN));
}
acceptThread = new AcceptThread((TNonblockingServerTransport) serverTransport_,
createSelectorThreadLoadBalancer(selectorThreads));
selectorThreads.forEach(Thread::start);
acceptThread.start();
return true;
} catch (IOException e) {
log.error("Failed to start threads!", e);
return false;
}
}
示例5: hshaServer
import org.apache.thrift.transport.TNonblockingServerTransport; //导入依赖的package包/类
/**
* The function to create a thrift Half-Sync and Half-Async Server.
* @param processor
*/
public static void hshaServer(PacketStreamer.Processor<PacketStreamerHandler> processor) {
try {
TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(port);
THsHaServer.Args args = new THsHaServer.Args(serverTransport);
args.processor(processor);
args.transportFactory(new TFramedTransport.Factory());
args.protocolFactory(new TBinaryProtocol.Factory(true, true));
TServer server = new THsHaServer(args);
log.info("Starting the packetstreamer hsha server on port {} ...", port);
server.serve();
} catch (Exception e) {
e.printStackTrace();
}
}
示例6: hshaServer
import org.apache.thrift.transport.TNonblockingServerTransport; //导入依赖的package包/类
/**
* The function to create a thrift Half-Sync and Half-Async Server.
* @param processor
*/
public static void hshaServer(PacketStreamer.Processor<PacketStreamerHandler> processor) {
try {
TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(port);
THsHaServer.Args args = new THsHaServer.Args(serverTransport);
args.processor(processor);
args.transportFactory(new TFramedTransport.Factory());
args.protocolFactory(new TBinaryProtocol.Factory(true, true));
TServer server = new THsHaServer(args);
log.info("Starting the packetstreamer hsha server on port {} ...", port);
server.serve();
} catch (Exception e) {
e.printStackTrace();
}
}
示例7: startThreads
import org.apache.thrift.transport.TNonblockingServerTransport; //导入依赖的package包/类
/**
* Start the accept and selector threads running to deal with clients.
*
* @return true if everything went ok, false if we couldn't start for some
* reason.
*/
@Override
protected boolean startThreads() {
LOGGER.info("Starting {}", TThreadedSelectorServerWithFix.class.getSimpleName());
try {
for (int i = 0; i < args.selectorThreads; ++i) {
selectorThreads.add(new SelectorThread(args.acceptQueueSizePerThread));
}
acceptThread = new AcceptThread((TNonblockingServerTransport) serverTransport_,
createSelectorThreadLoadBalancer(selectorThreads));
stopped_ = false;
for (SelectorThread thread : selectorThreads) {
thread.start();
}
acceptThread.start();
return true;
} catch (IOException e) {
LOGGER.error("Failed to start threads!", e);
return false;
}
}
示例8: buildTServer
import org.apache.thrift.transport.TNonblockingServerTransport; //导入依赖的package包/类
public TServer buildTServer(Args args)
{
if (DatabaseDescriptor.getClientEncryptionOptions().enabled)
throw new RuntimeException("Client SSL is not supported for non-blocking sockets. Please remove client ssl from the configuration.");
final InetSocketAddress addr = args.addr;
TNonblockingServerTransport serverTransport;
try
{
serverTransport = new TCustomNonblockingServerSocket(addr, args.keepAlive, args.sendBufferSize, args.recvBufferSize);
}
catch (TTransportException e)
{
throw new RuntimeException(String.format("Unable to create thrift socket to %s:%s", addr.getAddress(), addr.getPort()), e);
}
// This is single threaded hence the invocation will be all
// in one thread.
TNonblockingServer.Args serverArgs = new TNonblockingServer.Args(serverTransport).inputTransportFactory(args.inTransportFactory)
.outputTransportFactory(args.outTransportFactory)
.inputProtocolFactory(args.tProtocolFactory)
.outputProtocolFactory(args.tProtocolFactory)
.processor(args.processor);
return new CustomTNonBlockingServer(serverArgs);
}
示例9: setUpServer
import org.apache.thrift.transport.TNonblockingServerTransport; //导入依赖的package包/类
@BeforeClass
public static void setUpServer() throws Exception {
setDefaultPollDelay(10, TimeUnit.MILLISECONDS);
serializer = new TBinaryProtocolSerializer();
factory = new TBinaryProtocol.Factory();
port = findFreePort();
impl = Mockito.mock(Iface.class);
TNonblockingServerTransport transport = new TNonblockingServerSocket(port);
server = new TNonblockingServer(
new TNonblockingServer.Args(transport)
.protocolFactory(factory)
.processor(new Processor<>(impl)));
executor = Executors.newSingleThreadExecutor();
executor.submit(server::serve);
address = new InetSocketAddress("localhost", port);
}
示例10: startThreads
import org.apache.thrift.transport.TNonblockingServerTransport; //导入依赖的package包/类
/**
* Start the accept and selector threads running to deal with clients.
*
* @return true if everything went ok, false if we couldn't start for some
* reason.
*/
@Override
protected boolean startThreads() {
try {
for (int i = 0; i < args.selectorThreads; ++i) {
selectorThreads.add(new SelectorThread(args.acceptQueueSizePerThread));
}
acceptThread = new AcceptThread((TNonblockingServerTransport) serverTransport_,
createSelectorThreadLoadBalancer(selectorThreads));
for (SelectorThread thread : selectorThreads) {
thread.start();
}
acceptThread.start();
return true;
} catch (IOException e) {
LOGGER.error("Failed to start threads!", e);
return false;
}
}
示例11: buildTServer
import org.apache.thrift.transport.TNonblockingServerTransport; //导入依赖的package包/类
@SuppressWarnings("resource")
public TServer buildTServer(Args args)
{
if (DatabaseDescriptor.getClientEncryptionOptions().enabled)
throw new RuntimeException("Client SSL is not supported for non-blocking sockets. Please remove client ssl from the configuration.");
final InetSocketAddress addr = args.addr;
TNonblockingServerTransport serverTransport;
try
{
serverTransport = new TCustomNonblockingServerSocket(addr, args.keepAlive, args.sendBufferSize, args.recvBufferSize);
}
catch (TTransportException e)
{
throw new RuntimeException(String.format("Unable to create thrift socket to %s:%s", addr.getAddress(), addr.getPort()), e);
}
// This is single threaded hence the invocation will be all
// in one thread.
TNonblockingServer.Args serverArgs = new TNonblockingServer.Args(serverTransport).inputTransportFactory(args.inTransportFactory)
.outputTransportFactory(args.outTransportFactory)
.inputProtocolFactory(args.tProtocolFactory)
.outputProtocolFactory(args.tProtocolFactory)
.processor(args.processor);
return new CustomTNonBlockingServer(serverArgs);
}
示例12: main
import org.apache.thrift.transport.TNonblockingServerTransport; //导入依赖的package包/类
public static void main(String[] args) {
try {
handler = new CalculatorHandler();
processor = new Calculator.Processor(handler);
try {
TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(9090);
TServer server = new TThreadedSelectorServer(
new TThreadedSelectorServer.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();
}
}
示例13: getTHsHaServer
import org.apache.thrift.transport.TNonblockingServerTransport; //导入依赖的package包/类
private static TServer getTHsHaServer(TProtocolFactory protocolFactory,
TProcessor processor, TTransportFactory transportFactory,
int workerThreads, int maxCallQueueSize,
InetSocketAddress inetSocketAddress, ThriftMetrics metrics)
throws TTransportException {
TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(inetSocketAddress);
log.info("starting HBase HsHA Thrift server on " + inetSocketAddress.toString());
THsHaServer.Args serverArgs = new THsHaServer.Args(serverTransport);
if (workerThreads > 0) {
// Could support the min & max threads, avoiding to preserve existing functionality.
serverArgs.minWorkerThreads(workerThreads).maxWorkerThreads(workerThreads);
}
ExecutorService executorService = createExecutor(
workerThreads, maxCallQueueSize, metrics);
serverArgs.executorService(executorService);
serverArgs.processor(processor);
serverArgs.transportFactory(transportFactory);
serverArgs.protocolFactory(protocolFactory);
return new THsHaServer(serverArgs);
}
示例14: getTThreadedSelectorServer
import org.apache.thrift.transport.TNonblockingServerTransport; //导入依赖的package包/类
private static TServer getTThreadedSelectorServer(TProtocolFactory protocolFactory,
TProcessor processor, TTransportFactory transportFactory,
int workerThreads, int selectorThreads, int maxCallQueueSize,
InetSocketAddress inetSocketAddress, ThriftMetrics metrics)
throws TTransportException {
TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(inetSocketAddress);
log.info("starting HBase ThreadedSelector Thrift server on " + inetSocketAddress.toString());
TThreadedSelectorServer.Args serverArgs = new TThreadedSelectorServer.Args(serverTransport);
if (workerThreads > 0) {
serverArgs.workerThreads(workerThreads);
}
if (selectorThreads > 0) {
serverArgs.selectorThreads(selectorThreads);
}
ExecutorService executorService = createExecutor(
workerThreads, maxCallQueueSize, metrics);
serverArgs.executorService(executorService);
serverArgs.processor(processor);
serverArgs.transportFactory(transportFactory);
serverArgs.protocolFactory(protocolFactory);
return new TThreadedSelectorServer(serverArgs);
}
示例15: createThreadedSelectorServer
import org.apache.thrift.transport.TNonblockingServerTransport; //导入依赖的package包/类
public static TServer createThreadedSelectorServer(TProcessorFactory processorFactory,
int port, int clientTimeoutMillisecs, int maxFrameSize, long maxReadBufferSize)
throws TTransportException {
int numThreads = Math.max(2, Runtime.getRuntime().availableProcessors());
int selectorThreads = Math.max(2, Runtime.getRuntime().availableProcessors() / 2);
TNonblockingServerTransport transport = new TNonblockingServerSocket(port,
clientTimeoutMillisecs);
TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
TTransportFactory transportFactory = new TFramedTransport.Factory(maxFrameSize);
TThreadedSelectorServer.Args args = new TThreadedSelectorServer.Args(transport)
.processorFactory(processorFactory).protocolFactory(protocolFactory)
.transportFactory(transportFactory).workerThreads(numThreads)
.acceptPolicy(AcceptPolicy.FAIR_ACCEPT).acceptQueueSizePerThread(10000)
.selectorThreads(selectorThreads);
args.maxReadBufferBytes = maxReadBufferSize;
TThreadedSelectorServer server = new TThreadedSelectorServer(args);
return server;
}