/** * 设置服务端口 * @param servicePort * @return * @see ThriftServerConfig#setPort(int) */ public Builder setServerPort(int servicePort) { this.thriftServerConfig.setPort(servicePort); return this; }
ScribeCollector(Builder builder) { ScribeSpanConsumer scribe = new ScribeSpanConsumer(builder); ThriftServiceProcessor processor = new ThriftServiceProcessor(new ThriftCodecManager(), emptyList(), scribe); server = new ThriftServer(processor, new ThriftServerConfig().setPort(builder.port)); }
ScribeCollector(Builder builder, Lazy<AsyncSpanConsumer> consumer) { ScribeSpanConsumer scribe = new ScribeSpanConsumer(builder.category, consumer, builder.metrics); ThriftServiceProcessor processor = new ThriftServiceProcessor(new ThriftCodecManager(), emptyList(), scribe); server = new ThriftServer(processor, new ThriftServerConfig().setPort(builder.port)).start(); }
@Override protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException { TProcessor processor = new ThriftServiceProcessor(new ThriftCodecManager(), impl); final ThriftServer server = new ThriftServer(processor, new ThriftServerConfig().setPort(url.getPort())); server.start(); return new Runnable() { public void run() { try { server.close(); } catch (Throwable e) { logger.warn(e.getMessage(), e); } } }; }
.setPort(12345) .setMaxFrameSize(DataSize.valueOf("333kB")) .setBindAddress("127.0.0.1")
/** * 从配置文件中读取参数创建{@link ThriftServerConfig}实例 * @return */ public static ThriftServerConfig makeThriftServerConfig(){ ThriftServerConfig thriftServerConfig = new ThriftServerConfig(); CombinedConfiguration config = GlobalConfig.getConfig(); int intValue ; thriftServerConfig.setPort(config.getInt(SERVER_PORT,DEFAULT_PORT)); if((intValue = config.getInt(SERVER_CONNECTION_LIMIT,0)) >0){ thriftServerConfig.setConnectionLimit(intValue); } if((intValue = config.getInt(SERVER_IDLE_CONNECTION_TIMEMOUT,0))>0){ Duration timeout = new Duration(intValue,TimeUnit.SECONDS); thriftServerConfig.setIdleConnectionTimeout(timeout); } if((intValue = config.getInt(SERVER_WORKER_THREAD_COUNT,0))>0){ thriftServerConfig.setWorkerThreads(intValue); } return thriftServerConfig; } /**
public static void main(String ...args){ serviceConfig.parseCommandLine(args); // 设置slf4j记录日志,否则会有警告 InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory()); ThriftServerConfig config = new ThriftServerConfig() .setPort(serviceConfig.getServicePort()) .setWorkerThreads(serviceConfig.getWorkThreads()) .setConnectionLimit(serviceConfig.getConnectionLimit()) .setIdleConnectionTimeout(new Duration(serviceConfig.getIdleConnectionTimeout(),TimeUnit.SECONDS)); FaceApi faceapi = serviceConfig.getFaceapi(); ThriftServerService service = ThriftServerService.bulider() .withServices(new FaceApiThriftDecorator(faceapi)) .setThriftServerConfig(config) .build(); logger.info("FaceApi instance:{}",faceapi); service.startAsync(); }
@Test public void testDefaults() { ConfigAssertions.assertRecordedDefaults( ConfigAssertions.recordDefaults(ThriftServerConfig.class) .setBindAddress("localhost") .setAcceptBacklog(1024) .setMaxFrameSize(DataSize.valueOf("64MB")) .setPort(0) .setConnectionLimit(0) .setWorkerThreads(200) .setAcceptorThreadCount(1) .setIoThreadCount(2 * Runtime.getRuntime().availableProcessors()) .setIdleConnectionTimeout(Duration.valueOf("60s")) .setTransportName("framed") .setProtocolName("binary") .setWorkerExecutorKey(null) .setTaskExpirationTimeout(Duration.valueOf("5s")) .setQueueTimeout(null) .setMaxQueuedRequests(null) .setMaxQueuedResponsesPerConnection(16) .setTrafficClass(0) ); }