本文整理汇总了Java中org.apache.thrift.transport.TNonblockingServerSocket类的典型用法代码示例。如果您正苦于以下问题:Java TNonblockingServerSocket类的具体用法?Java TNonblockingServerSocket怎么用?Java TNonblockingServerSocket使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TNonblockingServerSocket类属于org.apache.thrift.transport包,在下文中一共展示了TNonblockingServerSocket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.thrift.transport.TNonblockingServerSocket; //导入依赖的package包/类
public static void main(String[] args) throws TTransportException, IOException, InterruptedException {
TNonblockingServerSocket trans_svr = new TNonblockingServerSocket(9090);
TMultiplexedProcessor proc = new TMultiplexedProcessor();
proc.registerProcessor("Message", new Message.Processor<>(new MessageHandler()));
proc.registerProcessor("ServerTime", new ServerTime.Processor<>(new ServerTimeHandler()));
TServer server = new TThreadedSelectorServer(
new TThreadedSelectorServer.Args(trans_svr)
.processor(proc)
.protocolFactory(new TJSONProtocol.Factory())
.workerThreads(6)
.selectorThreads(3));
Thread server_thread = new Thread(new RunnableServer(server), "server_thread");
server_thread.start();
System.out.println("[Server] press enter to shutdown> ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
br.readLine();
System.out.println("[Server] shutting down...");
server.stop();
server_thread.join();
System.out.println("[Server] down, exiting");
}
示例2: nonBlockMode
import org.apache.thrift.transport.TNonblockingServerSocket; //导入依赖的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();
}
}
示例3: ThriftTestingSource
import org.apache.thrift.transport.TNonblockingServerSocket; //导入依赖的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();
}
});
}
示例4: run
import org.apache.thrift.transport.TNonblockingServerSocket; //导入依赖的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);
}
}
示例5: hshaServer
import org.apache.thrift.transport.TNonblockingServerSocket; //导入依赖的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: main
import org.apache.thrift.transport.TNonblockingServerSocket; //导入依赖的package包/类
public static void main(String[] args){
ExecutorService es = Executors.newFixedThreadPool(2);
for(int i=0; i<ports.length; i++){
final int index = i;
es.execute(new Runnable() {
@Override
public void run() {
try{
TNonblockingServerSocket socket = new TNonblockingServerSocket(ports[index]);
TestThriftJ.Processor processor = new TestThriftJ.Processor(new QueryImp());
TNonblockingServer.Args arg = new TNonblockingServer.Args(socket);
arg.protocolFactory(new TBinaryProtocol.Factory());
arg.transportFactory(new TFramedTransport.Factory());
arg.processorFactory(new TProcessorFactory(processor));
TServer server = new TNonblockingServer (arg);
logger.info("127.0.0.1:" + ports[index] + " start");
server.serve();
}catch(Exception e){
logger.error("127.0.0.1:" + ports[index] + " error");
}
}
});
}
}
示例7: main
import org.apache.thrift.transport.TNonblockingServerSocket; //导入依赖的package包/类
public static void main(String[] args){
ExecutorService es = Executors.newFixedThreadPool(2);
for(int i=0; i<ports.length; i++){
final int index = i;
es.execute(new Runnable() {
@Override
public void run() {
try{
TNonblockingServerSocket socket = new TNonblockingServerSocket(ports[index]);
TestThriftJ.Processor processor = new TestThriftJ.Processor(new QueryImp());
TNonblockingServer.Args arg = new TNonblockingServer.Args(socket);
arg.protocolFactory(new TBinaryProtocol.Factory());
arg.transportFactory(new TFramedTransport.Factory());
arg.processorFactory(new TProcessorFactory(processor));
TServer server = new TNonblockingServer(arg);
logger.info("127.0.0.1:" + ports[index] + " start");
server.serve();
}catch(Exception e){
logger.error("127.0.0.1:" + ports[index] + " error");
}
}
});
}
}
示例8: startRPCServer2
import org.apache.thrift.transport.TNonblockingServerSocket; //导入依赖的package包/类
public static void startRPCServer2(leafServer leafserver , String ip , int port) throws Exception
{
//关联处理器leafrpc的实现
TProcessor processor = new leafrpc.Processor<leafrpc.Iface>(new RPCService(leafserver));
//传输通道,非阻塞模式
InetSocketAddress address = new InetSocketAddress(InetAddress.getByName(ip),port);
TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(address,10000);
//多线程半同步半异步
TThreadedSelectorServer.Args tArgs = new TThreadedSelectorServer.Args(serverTransport);
tArgs.processor(processor);
//二进制协议
tArgs.protocolFactory(new TBinaryProtocol.Factory());
//多线程半同步半异步的服务模型
TServer server = new TThreadedSelectorServer(tArgs);
LOG.info("leaf RPCServer(type:TThreadedSelectorServer) start at ip:port : "+ ip +":" + port );
server.serve();
}
示例9: start
import org.apache.thrift.transport.TNonblockingServerSocket; //导入依赖的package包/类
public void start(CountDownLatch latch, int port) {
try {
TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(port);
//异步IO,需要使用TFramedTransport,它将分块缓存读取。
TTransportFactory transportFactory = new TFramedTransport.Factory();
//使用高密度二进制协议
TProtocolFactory proFactory = new TBinaryProtocol.Factory();
//发布多个服务
TMultiplexedProcessor processor = new TMultiplexedProcessor();
processor.registerProcessor(ClassNameUtils.getClassName(Hello.class), new Hello.Processor<>(new HelloServer()));
TServer server = new TThreadedSelectorServer(new
TThreadedSelectorServer.Args(serverTransport)
.transportFactory(transportFactory)
.protocolFactory(proFactory)
.processor(processor)
);
System.out.println("Starting the hello server...");
latch.countDown();
server.serve();
} catch (Exception e) {
e.printStackTrace();
}
}
示例10: hshaServer
import org.apache.thrift.transport.TNonblockingServerSocket; //导入依赖的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();
}
}
示例11: createThrift
import org.apache.thrift.transport.TNonblockingServerSocket; //导入依赖的package包/类
private static boolean createThrift() {
String flag = getClassName() + ".createThrift";
try {
TProcessor tProcessor = new FrcService.Processor<FrcService.Iface>(theInstance);
TNonblockingServerSocket tnbSocketTransport = new TNonblockingServerSocket(thrift_port);
TNonblockingServer.Args tnbArgs = new TNonblockingServer.Args(tnbSocketTransport);
tnbArgs.maxReadBufferBytes = DefaultValues.THRIFT_MAX_READ_BUF;
tnbArgs.processor(tProcessor);
// tnbArgs.transportFactory(new LCQTFramedTransport.Factory());
tnbArgs.transportFactory(new TFramedTransport.Factory());
tnbArgs.protocolFactory(new TBinaryProtocol.Factory());
server = new TNonblockingServer(tnbArgs);
// server.setServerEventHandler(new LCQTServerEventHandler());
return true;
} catch (Exception e) {
FRCLogger.getInstance().warn(-100, flag, "exception", e);
return false;
}
}
示例12: setUp
import org.apache.thrift.transport.TNonblockingServerSocket; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
rc = copyResourceTo("/pvdrc", temp.getRoot());
copyResourceTo("/test.thrift", temp.getRoot());
impl = Mockito.mock(MyService.Iface.class);
TNonblockingServerSocket transport = new TNonblockingServerSocket(0);
server = new TNonblockingServer(new TNonblockingServer.Args(transport).protocolFactory(new TBinaryProtocol.Factory())
.processor(new MyService.Processor<>(impl)));
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(server::serve);
Thread.sleep(1);
port = transport.getPort();
exitCode = 0;
rpc = new RPC(console.tty()) {
@Override
protected void exit(int i) {
exitCode = i;
}
};
}
示例13: setUpServer
import org.apache.thrift.transport.TNonblockingServerSocket; //导入依赖的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);
}
示例14: initHandlerServer
import org.apache.thrift.transport.TNonblockingServerSocket; //导入依赖的package包/类
private THsHaServer initHandlerServer(Map conf, final Drpc service) throws Exception {
int port = JStormUtils.parseInt(conf.get(Config.DRPC_PORT));
int workerThreadNum = JStormUtils.parseInt(conf.get(Config.DRPC_WORKER_THREADS));
int queueSize = JStormUtils.parseInt(conf.get(Config.DRPC_QUEUE_SIZE));
TNonblockingServerSocket socket = new TNonblockingServerSocket(port);
THsHaServer.Args targs = new THsHaServer.Args(socket);
targs.workerThreads(64);
targs.protocolFactory(new TBinaryProtocol.Factory());
targs.processor(new DistributedRPC.Processor<DistributedRPC.Iface>(service));
ThreadPoolExecutor executor = new ThreadPoolExecutor(workerThreadNum, workerThreadNum, 60, TimeUnit.SECONDS, new ArrayBlockingQueue(queueSize));
targs.executorService(executor);
THsHaServer handlerServer = new THsHaServer(targs);
LOG.info("Successfully init Handler Server " + port);
return handlerServer;
}
示例15: initThrift
import org.apache.thrift.transport.TNonblockingServerSocket; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private void initThrift(Map conf) throws TTransportException {
Integer thrift_port = JStormUtils.parseInt(conf.get(Config.NIMBUS_THRIFT_PORT));
TNonblockingServerSocket socket = new TNonblockingServerSocket(thrift_port);
Integer maxReadBufSize = JStormUtils.parseInt(conf.get(Config.NIMBUS_THRIFT_MAX_BUFFER_SIZE));
THsHaServer.Args args = new THsHaServer.Args(socket);
args.workerThreads(ServiceHandler.THREAD_NUM);
args.protocolFactory(new TBinaryProtocol.Factory(false, true, maxReadBufSize, -1));
args.processor(new Nimbus.Processor<Iface>(serviceHandler));
args.maxReadBufferBytes = maxReadBufSize;
thriftServer = new THsHaServer(args);
LOG.info("Successfully started nimbus: started Thrift server...");
thriftServer.serve();
}