private static int testApacheServer(List<MethodInvocationFilter> filters) throws Exception { ScribeService scribeService = new ScribeService(); TProcessor processor = new scribe.Processor<>(scribeService); int invocationCount = 0; for (boolean secure : ImmutableList.of(true, false)) { for (Transport transport : Transport.values()) { for (Protocol protocol : Protocol.values()) { invocationCount += testApacheServer(secure, transport, protocol, processor, ImmutableList.<ToIntFunction<HostAndPort>>builder() .addAll(legacyApacheThriftTestClients(filters, transport, protocol, secure)) .addAll(driftNettyTestClients(filters, transport, protocol, secure)) .addAll(apacheThriftTestClients(filters, transport, protocol, secure)) .build()); } } } assertEquals(scribeService.getMessages(), newArrayList(concat(nCopies(invocationCount, MESSAGES)))); return invocationCount; }
/** * @Title: startSchedulerThriftService * @Description: 开启scheduler 同步、异步调用服务 * @return void 返回类型 */ private static void startSchedulerThriftService() { LOG.info("start scheduler thrift service...."); new Thread() { @Override public void run(){ try { SchedulerServiceImpl schedulerServiceImpl = SpringUtil.getBean(SchedulerServiceImpl.class); TProcessor tprocessor = new SchedulerService.Processor<SchedulerService.Iface>(schedulerServiceImpl); TServerSocket serverTransport = new TServerSocket(PropertyLoader.THRIFT_SCHEDULER_PORT); TThreadPoolServer.Args ttpsArgs = new TThreadPoolServer.Args(serverTransport); ttpsArgs.processor(tprocessor); ttpsArgs.protocolFactory(new TBinaryProtocol.Factory()); //线程池服务模型,使用标准的阻塞式IO,预先创建一组线程处理请求。 TServer server = new TThreadPoolServer(ttpsArgs); server.serve(); } catch (Exception e) { LOG.error("start scheduler thrift service error,msg:"+ExceptionUtil.getStackTraceAsString(e)); } } }.start(); LOG.info("start scheduler thrift server success!"); }
public static void startRPCServer(leafServer leafserver , String ip , int port) throws Exception { ServerSocket serverSocket = new ServerSocket(port,10000, InetAddress.getByName(ip)); TServerSocket serverTransport = new TServerSocket(serverSocket); //设置协议工厂为TBinaryProtocolFactory Factory proFactory = new TBinaryProtocol.Factory(); //关联处理器leafrpc的实现 TProcessor processor = new leafrpc.Processor<leafrpc.Iface>(new RPCService(leafserver)); TThreadPoolServer.Args args2 = new TThreadPoolServer.Args(serverTransport); args2.processor(processor); args2.protocolFactory(proFactory); TServer server = new TThreadPoolServer(args2); LOG.info("leaf RPCServer(type:TThreadPoolServer) start at ip:port : "+ ip +":" + port ); server.serve(); }
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(); }
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); }
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); }
/** * {@inheritDoc} */ @Override public TProcessor getProcessor() { return new ThriftHiveMetastore.Processor<>( new CatalogThriftHiveMetastore(config, hiveConverters, metacatV1, partitionV1, catalogName, registry) ); }
protected ClientProcessData(GfxdTSocket socket, int connectionNumber, TProcessor proc, TTransport in, TTransport out, TProtocol inp, TProtocol outp, TServerEventHandler eventHandler) { this.clientSocket = socket; this.connectionNumber = connectionNumber; this.processor = proc; this.inputTransport = in; this.outputTransport = out; this.inputProtocol = inp; this.outputProtocol = outp; this.eventHandler = eventHandler; if (eventHandler != null) { this.connectionContext = eventHandler.createContext(inp, outp); } else { this.connectionContext = null; } this.idle = true; }
@Test public void testAysncServiceImpl() { int serverPort = 49001; TProcessor p = new ServiceProcessor(new TestThriftServiceImpl1()); thriftServerConfiguration.setProcessorFactory(new TProcessorFactory(p)); Factory factory = new GeneralFactory(thriftServerConfiguration); ThriftServer thriftServer = factory.getThriftServer(serverPort, new TestThriftServiceImpl1()); thriftServer.run(); try { AsyncService service = factory.getAsyncService(new TNonblockingSocket(LOCAL_HOST, serverPort)); Thread.sleep(500); TestCallback1 callback = new TestCallback1(); service.get(testString1, callback); Thread.sleep(1000); } catch (Exception e) { fail(); } finally { thriftServer.stop(); } }
@Test public void testMultiplexedThriftServerImpl() { int serverPort = 39101; Map<String, TProcessor> processorMap = new HashMap<>(); processorMap.put("testServer", new ThriftSimpleService.Processor<Iface>(new ThriftSimpleServiceImpl())); MultiplexedProcessor processor = new MultiplexedProcessor(processorMap); ThriftServer defaultThriftServer = new DefaultThriftServerImpl(serverName, serverPort, configuration, processor); assertEquals(defaultThriftServer.getServerName(), serverName); assertEquals(defaultThriftServer.getServerPort(), serverPort); assertEquals(defaultThriftServer.getThriftServerConfiguration(), configuration); defaultThriftServer.run(); try (ThriftClient thriftClient = factory.getThriftClient(LOCAL_HOST, serverPort); TTransport transport = thriftClient.getTransport()) { Thread.sleep(500); transport.open(); ThriftSimpleService.Client client = new ThriftSimpleService.Client( thriftClient.getProtocol(transport, "testServer")); assertEquals(testString, client.get(testString)); } catch (Exception e) { fail(); } finally { defaultThriftServer.stop(); } }
@SuppressWarnings("unchecked") private TProcessor createProcessor(final Class<T> handlerType, Class<I> serviceType) { // Pick the Iface inner interface and the Processor class Class<? extends TProcessor> processorType = null; Class<?> ifaceType = null; for (Class<?> clz : serviceType.getDeclaredClasses()) { if (TProcessor.class.isAssignableFrom(clz)) { processorType = (Class<? extends TProcessor>) clz; } else if (clz.isInterface() && "Iface".equals(clz.getSimpleName())) { ifaceType = clz; } } Preconditions.checkArgument(processorType != null, "Missing TProcessor, %s is not a valid thrift service.", serviceType.getName()); Preconditions.checkArgument(ifaceType != null, "Missing Iface, %s is not a valid thrift service.", serviceType.getName()); // If handler already implements the Iface, simply delegate if (ifaceType.isAssignableFrom(handlerType)) { return createProxyProcessor(handlerType, processorType, ifaceType); } throw new IllegalArgumentException("Unsupported handler type."); }
/** * 根据refImpl来获取相应的TProcessor,然后构造一个对象 * * @return */ private TProcessor getProcessorIface(Class iface) { if (iface == null) { LOGGER.error("refImpl is not thrift implement class instance."); throw new OureaException("invalid null refImpl params"); } String parentClazzName = StringUtils.substringBeforeLast(iface.getCanonicalName(), ".Iface"); String processorClazzName = parentClazzName + "$Processor"; try { Class clazz = Class.forName(processorClazzName); if (clazz.isMemberClass() && !clazz.isInterface()) { @SuppressWarnings("unchecked") Class<TProcessor> processorClazz = (Class<TProcessor>) clazz; return processorClazz.getConstructor(iface).newInstance(refImpl); } return null; } catch (Exception e) { LOGGER.error("get thrift Porcessor class from Iface class fail.e:", e); throw new OureaException("invalid iface class params maybe not thrift class."); } }
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; } }
public ThriftServerThread(InetAddress listenAddr, int listenPort, int listenBacklog, TProcessor processor, TTransportFactory transportFactory) { // now we start listening for clients logger.info(String.format("Binding thrift service to %s:%s", listenAddr, listenPort)); TServerFactory.Args args = new TServerFactory.Args(); args.tProtocolFactory = new TBinaryProtocol.Factory(true, true); args.addr = new InetSocketAddress(listenAddr, listenPort); args.listenBacklog = listenBacklog; args.processor = processor; args.keepAlive = DatabaseDescriptor.getRpcKeepAlive(); args.sendBufferSize = DatabaseDescriptor.getRpcSendBufferSize(); args.recvBufferSize = DatabaseDescriptor.getRpcRecvBufferSize(); args.inTransportFactory = transportFactory; args.outTransportFactory = transportFactory; serverEngine = new TServerCustomFactory(DatabaseDescriptor.getRpcServerType()).buildTServer(args); }
public ThriftServerThread(InetAddress listenAddr, int listenPort, CassandraServer server, TProcessor processor, TTransportFactory transportFactory) { // now we start listening for clients logger.info(String.format("Binding thrift service to %s:%s", listenAddr, listenPort)); TServerFactory.Args args = new TServerFactory.Args(); args.tProtocolFactory = new TBinaryProtocol.Factory(true, true); args.addr = new InetSocketAddress(listenAddr, listenPort); args.cassandraServer = server; args.processor = processor; args.keepAlive = DatabaseDescriptor.getRpcKeepAlive(); args.sendBufferSize = DatabaseDescriptor.getRpcSendBufferSize(); args.recvBufferSize = DatabaseDescriptor.getRpcRecvBufferSize(); args.inTransportFactory = transportFactory; args.outTransportFactory = transportFactory; serverEngine = new TServerCustomFactory(DatabaseDescriptor.getRpcServerType()).buildTServer(args); }
private static TServer startSimpleServer(final TServerTransport transport, final TProcessor processor, Properties properties) throws Exception { TServer.AbstractServerArgs<?> serverArgs; if (properties == null) { serverArgs = new TServer.Args(transport).processor(processor); } else { serverArgs = ThriftUtils.getServerArgs(transport, properties).processor(processor); } final TServer server = new TSimpleServer(serverArgs); new Thread(new Runnable() { @Override public void run() { server.serve(); } }).start(); return server; }
private static TServer startThreadedPoolServer(final TServerTransport transport, final TProcessor processor, Properties properties) throws Exception { TThreadPoolServer.Args serverArgs; if (properties == null) { serverArgs = new TThreadPoolServer.Args(transport).processor(processor); } else { serverArgs = (TThreadPoolServer.Args) ThriftUtils.getServerArgs(transport, properties).processor( processor); } final TServer server = new TThreadPoolServer(serverArgs); new Thread(new Runnable() { @Override public void run() { server.serve(); } }).start(); return server; }
@VisibleForTesting public static TServer startHshaServer(TProcessor processor, int portNumber) throws Exception { final TNonblockingServerSocket socket = new TNonblockingServerSocket(portNumber); final THsHaServer.Args serverArgs = new THsHaServer.Args(socket); serverArgs.processor(processor); serverArgs.inputProtocolFactory(new TCompactProtocol.Factory()); serverArgs.outputProtocolFactory(new TCompactProtocol.Factory()); final TServer server = new THsHaServer(serverArgs); final Thread t = new Thread(new Runnable() { @Override public void run() { server.serve(); } }); t.start(); return server; }
@Override public TServer getServer(TProcessor processor) throws IOException, TTransportException { int port = type.getPort(storm_conf); TTransportFactory serverTransportFactory = getServerTransportFactory(); TServerSocket serverTransport = new TServerSocket(port); int numWorkerThreads = type.getNumThreads(storm_conf); Integer queueSize = type.getQueueSize(storm_conf); TThreadPoolServer.Args server_args = new TThreadPoolServer.Args(serverTransport).processor(new TUGIWrapProcessor(processor)).minWorkerThreads(numWorkerThreads) .maxWorkerThreads(numWorkerThreads).protocolFactory(new TBinaryProtocol.Factory(false, true)); if (serverTransportFactory != null) { server_args.transportFactory(serverTransportFactory); } BlockingQueue workQueue = new SynchronousQueue(); if (queueSize != null) { workQueue = new ArrayBlockingQueue(queueSize); } ThreadPoolExecutor executorService = new ExtendedThreadPoolExecutor(numWorkerThreads, numWorkerThreads, 60, TimeUnit.SECONDS, workQueue); server_args.executorService(executorService); return new TThreadPoolServer(server_args); }
@Override public TServer getServer(TProcessor processor) throws IOException, TTransportException { int port = type.getPort(storm_conf); TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(port); int numWorkerThreads = type.getNumThreads(storm_conf); int maxBufferSize = type.getMaxBufferSize(storm_conf); Integer queueSize = type.getQueueSize(storm_conf); THsHaServer.Args server_args = new THsHaServer.Args(serverTransport).processor(new SimpleWrapProcessor(processor)).workerThreads(numWorkerThreads) .protocolFactory(new TBinaryProtocol.Factory(false, true, maxBufferSize, -1)); if (queueSize != null) { server_args.executorService(new ThreadPoolExecutor(numWorkerThreads, numWorkerThreads, 60, TimeUnit.SECONDS, new ArrayBlockingQueue(queueSize))); } // construct THsHaServer return new THsHaServer(server_args); }
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); }
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); }
private TServer getServer(int workerThreads, int selectorThreads, int maxCallQueueSize, int readTimeout, int backlog, boolean nonblocking, boolean hsha, boolean selector, ThriftMetrics metrics, TProtocolFactory protocolFactory, TProcessor processor, TTransportFactory transportFactory, InetSocketAddress inetSocketAddress) throws TTransportException { TServer server; if (nonblocking) { server = getTNonBlockingServer(protocolFactory, processor, transportFactory, inetSocketAddress); } else if (hsha) { server = getTHsHaServer(protocolFactory, processor, transportFactory, workerThreads, maxCallQueueSize, inetSocketAddress, metrics); } else if (selector) { server = getTThreadedSelectorServer(protocolFactory, processor, transportFactory, workerThreads, selectorThreads, maxCallQueueSize, inetSocketAddress, metrics); } else { server = getTThreadPoolServer(protocolFactory, processor, transportFactory, workerThreads, inetSocketAddress, backlog, readTimeout, metrics); } return server; }
public static void main(String[] args) throws TTransportException, IOException, InterruptedException { FloorBroker floor = new FloorBroker(); (new Thread(floor)).start(); TProcessor proc = new TradeReporting.TradeHistory.AsyncProcessor( new AsyncTradeHistoryHandler(floor.getQ())); TNonblockingServerSocket trans_svr = new TNonblockingServerSocket(9090); TServer server = new THsHaServer(new THsHaServer.Args(trans_svr) .processor(proc) .protocolFactory(new TBinaryProtocol.Factory()) .minWorkerThreads(4) .maxWorkerThreads(4)); System.out.println("[Server] listening of port 9090"); server.serve(); }
public TServer getServer(int port, TProcessor processor) throws IOException, TTransportException { TTransportFactory serverTransportFactory = getServerTransportFactory(); //define THsHaServer args //original: THsHaServer + TNonblockingServerSocket //option: TThreadPoolServer + TServerSocket TServerSocket serverTransport = new TServerSocket(port); TThreadPoolServer.Args server_args = new TThreadPoolServer.Args(serverTransport). processor(new TUGIWrapProcessor(processor)). minWorkerThreads(64). maxWorkerThreads(64). protocolFactory(new TBinaryProtocol.Factory()); if (serverTransportFactory != null) server_args.transportFactory(serverTransportFactory); //construct THsHaServer return new TThreadPoolServer(server_args); }
public static void main(String [] args) throws TTransportException, IOException, InterruptedException { Properties port_cfg = new Properties(); InputStream input = new FileInputStream("../config.properties"); port_cfg.load(input); String port_str = port_cfg.getProperty("CA_PORT"); Integer port = Integer.valueOf(port_str); TProcessor proc = new LucidaService.AsyncProcessor( new CAServiceHandler.AsyncCAServiceHandler()); TNonblockingServerTransport transport = new TNonblockingServerSocket(port); TThreadedSelectorServer.Args arguments = new TThreadedSelectorServer.Args(transport) .processor(proc) .protocolFactory(new TBinaryProtocol.Factory()) .transportFactory(new TFramedTransport.Factory()); final TThreadedSelectorServer server = new TThreadedSelectorServer(arguments); System.out.println("CA at port " + port_str); server.serve(); }
/** * Entry point for question-answer. * @param args the argument list. Provide port numbers * for both sirius and qa. */ public static void main(String [] args) throws TTransportException, IOException, InterruptedException { Properties port_cfg = new Properties(); InputStream input = new FileInputStream("../../config.properties"); port_cfg.load(input); String port_str = port_cfg.getProperty("QA_PORT"); Integer port = Integer.valueOf(port_str); TProcessor proc = new LucidaService.AsyncProcessor( new QAServiceHandler.AsyncQAServiceHandler()); TNonblockingServerTransport transport = new TNonblockingServerSocket(port); TThreadedSelectorServer.Args arguments = new TThreadedSelectorServer.Args(transport) .processor(proc) .protocolFactory(new TBinaryProtocol.Factory()) .transportFactory(new TFramedTransport.Factory()); final TThreadedSelectorServer server = new TThreadedSelectorServer(arguments); System.out.println("QA at port " + port_str); server.serve(); }
public ThriftServerThread(InetAddress listenAddr, int listenPort, int listenBacklog, CassandraServer server, TProcessor processor, TTransportFactory transportFactory) { // now we start listening for clients logger.info(String.format("Binding thrift service to %s:%s", listenAddr, listenPort)); TServerFactory.Args args = new TServerFactory.Args(); args.tProtocolFactory = new TBinaryProtocol.Factory(true, true); args.addr = new InetSocketAddress(listenAddr, listenPort); args.listenBacklog = listenBacklog; args.cassandraServer = server; args.processor = processor; args.keepAlive = DatabaseDescriptor.getRpcKeepAlive(); args.sendBufferSize = DatabaseDescriptor.getRpcSendBufferSize(); args.recvBufferSize = DatabaseDescriptor.getRpcRecvBufferSize(); args.inTransportFactory = transportFactory; args.outTransportFactory = transportFactory; serverEngine = new TServerCustomFactory(DatabaseDescriptor.getRpcServerType()).buildTServer(args); }
@Override protected TServer getServer(TProcessor processor) throws TTransportException { LOGGER.debug("Setting Secured Server on port {} and keystore", remotePort, keystoreFile); TSSLTransportFactory.TSSLTransportParameters params = new TSSLTransportFactory.TSSLTransportParameters(); params.setKeyStore(keystoreFile, keystorePass); TServerSocket serverTransport; try { serverTransport = TSSLTransportFactory.getServerSocket(remotePort, 1000, InetAddress.getByName("localhost"), params); } catch (UnknownHostException e) { throw new TTransportException(e); } return new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor)); }
public ThriftServer(QueueService.Iface queueService, ServerConfig serverConfig, ThriftServerStats stats) throws TTransportException { this.queueService = queueService; this.serverConfig = serverConfig; this.stats = stats; // assemble thrift server TProcessor tprocessor = new QueueService.Processor(this.queueService); TNonblockingServerSocket tnbSocketTransport = new TNonblockingServerSocket(serverConfig.getPort()); TNonblockingServer.Args tnbArgs = new TNonblockingServer.Args(tnbSocketTransport); tnbArgs.processor(tprocessor); // Nonblocking server mode must use TFramedTransport tnbArgs.transportFactory(new TFramedTransport.Factory()); tnbArgs.protocolFactory(new TBinaryProtocol.Factory()); this.server = new TNonblockingServer(tnbArgs); // THsHaServer.Args thhArgs = new THsHaServer.Args(tnbSocketTransport); // thhArgs.processor(tprocessor); // // Nonblocking server mode must use TFramedTransport // thhArgs.transportFactory(new TFramedTransport.Factory()); // thhArgs.protocolFactory(new TBinaryProtocol.Factory()); // // this.server = new THsHaServer(thhArgs); this.serverThread = new ServerThread(this.server); }
private String thriftRequest(byte[] input){ try{ //Input TMemoryBuffer inbuffer = new TMemoryBuffer(input.length); inbuffer.write(input); TProtocol inprotocol = new TJSONProtocol(inbuffer); //Output TMemoryBuffer outbuffer = new TMemoryBuffer(100); TProtocol outprotocol = new TJSONProtocol(outbuffer); TProcessor processor = new Calculator.Processor(new CalculatorHandler()); processor.process(inprotocol, outprotocol); byte[] output = new byte[outbuffer.length()]; outbuffer.readAll(output, 0, output.length); return new String(output,"UTF-8"); }catch(Throwable t){ return "Error:"+t.getMessage(); } }
@Override public void startServer(final TProcessor processor, final TProtocolFactory protoFactory) throws Exception { serverThread = new Thread() { public void run() { try { // Transport TServerSocket socket = new TServerSocket(PORT); TTransportFactory factory = new TSaslServerTransport.Factory( WRAPPED_MECHANISM, SERVICE, HOST, WRAPPED_PROPS, new TestSaslCallbackHandler(PASSWORD)); server = new TSimpleServer(new Args(socket).processor(processor).transportFactory(factory).protocolFactory(protoFactory)); // Run it LOGGER.debug("Starting the server on port {}", PORT); server.serve(); } catch (Exception e) { e.printStackTrace(); fail(); } } }; serverThread.start(); Thread.sleep(1000); }
@Override public void startServer(final TProcessor processor, final TProtocolFactory protoFactory) throws Exception { serverThread = new Thread() { public void run() { try { TServerTransport serverTransport = TSSLTransportFactory.getServerSocket(PORT); server = new TSimpleServer(new Args(serverTransport).processor(processor)); server.serve(); } catch (TTransportException e) { e.printStackTrace(); assert false; } } }; serverThread.start(); Thread.sleep(1000); }
@Override public void startServer(final TProcessor processor, final TProtocolFactory protoFactory) throws Exception { serverThread = new Thread() { public void run() { try { // Transport TNonblockingServerSocket tServerSocket = new TNonblockingServerSocket(PORT); server = getServer(processor, tServerSocket, protoFactory); // Run it System.out.println("Starting the server on port " + PORT + "..."); server.serve(); } catch (Exception e) { e.printStackTrace(); fail(); } } }; serverThread.start(); Thread.sleep(1000); }