private static int driftServerPort(DriftServer server) { return ((DriftNettyServerTransport) server.getServerTransport()).getPort(); }
public static void start(List<Module> extraModules) throws Exception { Bootstrap app = new Bootstrap( ImmutableList.<Module>builder() .add(new DriftNettyServerModule()) .add(new ThriftTpchServerModule()) .addAll(requireNonNull(extraModules, "extraModules is null")) .build()); app.strictConfig().initialize(); }
private static List<DriftServer> startThriftServers(int thriftServers, boolean enableIndexJoin) { List<DriftServer> servers = new ArrayList<>(thriftServers); for (int i = 0; i < thriftServers; i++) { ThriftTpchService service = enableIndexJoin ? new ThriftIndexedTpchService() : new ThriftTpchService(); DriftServer server = new DriftServer( new DriftNettyServerTransportFactory(new DriftNettyServerConfig()), CODEC_MANAGER, new NullMethodInvocationStatsFactory(), ImmutableSet.of(new DriftService(service)), ImmutableSet.of()); server.start(); servers.add(server); } return servers; }
private static int testMethodInvoker(ServerMethodInvoker methodInvoker, List<ToIntFunction<HostAndPort>> clients) { TestingPooledByteBufAllocator testingAllocator = new TestingPooledByteBufAllocator(); ServerTransport serverTransport = new DriftNettyServerTransportFactory(new DriftNettyServerConfig(), testingAllocator).createServerTransport(methodInvoker); try { serverTransport.start(); HostAndPort address = HostAndPort.fromParts("localhost", ((DriftNettyServerTransport) serverTransport).getPort()); int sum = 0; for (ToIntFunction<HostAndPort> client : clients) { sum += client.applyAsInt(address); } return sum; } finally { serverTransport.shutdown(); testingAllocator.close(); } }
private static int testDriftServer(ServerMethodInvoker methodInvoker, List<ToIntFunction<HostAndPort>> clients) { DriftNettyServerConfig config = new DriftNettyServerConfig() .setSslEnabled(true) .setTrustCertificate(ClientTestUtils.getCertificateChainFile()) .setKey(ClientTestUtils.getPrivateKeyFile()); TestingPooledByteBufAllocator testingAllocator = new TestingPooledByteBufAllocator(); ServerTransport serverTransport = new DriftNettyServerTransportFactory(config, testingAllocator).createServerTransport(methodInvoker); try { serverTransport.start(); HostAndPort address = HostAndPort.fromParts("localhost", ((DriftNettyServerTransport) serverTransport).getPort()); int sum = 0; for (ToIntFunction<HostAndPort> client : clients) { sum += client.applyAsInt(address); } return sum; } finally { serverTransport.shutdown(); testingAllocator.close(); } }
@Override protected void initChannel(SocketChannel channel) { ChannelPipeline pipeline = channel.pipeline(); if (sslContextSupplier.isPresent()) { if (allowPlainText) { pipeline.addLast(new OptionalSslHandler(sslContextSupplier.get().get())); } else { pipeline.addLast(sslContextSupplier.get().get().newHandler(channel.alloc())); } } pipeline.addLast(new ThriftProtocolDetection( new ThriftServerHandler(methodInvoker, requestTimeout, timeoutExecutor), maxFrameSize, assumeClientsSupportOutOfOrderResponses)); } }
@Override public ServerTransport createServerTransport(ServerMethodInvoker methodInvoker) { return new DriftNettyServerTransport(methodInvoker, config, allocator); } }
@Override public void channelRead(ChannelHandlerContext context, Object message) { if (message instanceof ThriftFrame) { messageReceived(context, (ThriftFrame) message); return; } context.fireChannelRead(message); }
private void switchToTransport(ChannelHandlerContext context, Transport transport, Optional<Protocol> protocol) { ChannelPipeline pipeline = context.pipeline(); transport.addFrameHandlers(pipeline, protocol, maxFrameSize, assumeClientsSupportOutOfOrderResponses); pipeline.addLast(new ResponseOrderingHandler()); pipeline.addLast(thriftServerHandler); // remove(this) must be last because it triggers downstream processing of the current message pipeline.remove(this); } }
private static int testMethodInvoker(ServerMethodInvoker methodInvoker, List<ToIntFunction<HostAndPort>> clients) { TestingPooledByteBufAllocator testingAllocator = new TestingPooledByteBufAllocator(); ServerTransport serverTransport = new DriftNettyServerTransportFactory(new DriftNettyServerConfig(), testingAllocator).createServerTransport(methodInvoker); try { serverTransport.start(); HostAndPort address = HostAndPort.fromParts("localhost", ((DriftNettyServerTransport) serverTransport).getPort()); int sum = 0; for (ToIntFunction<HostAndPort> client : clients) { sum += client.applyAsInt(address); } return sum; } finally { serverTransport.shutdown(); testingAllocator.close(); } }
private static void testDriftServer(DriftService service, Consumer<HostAndPort> task) { DriftNettyServerConfig config = new DriftNettyServerConfig() .setSslEnabled(true) .setTrustCertificate(ClientTestUtils.getCertificateChainFile()) .setKey(ClientTestUtils.getPrivateKeyFile()); TestingPooledByteBufAllocator testingAllocator = new TestingPooledByteBufAllocator(); DriftServer driftServer = new DriftServer( new DriftNettyServerTransportFactory(config, testingAllocator), CODEC_MANAGER, new NullMethodInvocationStatsFactory(), ImmutableSet.of(service), ImmutableSet.of()); try { driftServer.start(); HostAndPort address = HostAndPort.fromParts("localhost", ((DriftNettyServerTransport) driftServer.getServerTransport()).getPort()); task.accept(address); } finally { driftServer.shutdown(); testingAllocator.close(); } } }
private static int driftServerPort(DriftServer server) { return ((DriftNettyServerTransport) server.getServerTransport()).getPort(); }
@Override protected void initChannel(SocketChannel channel) { ChannelPipeline pipeline = channel.pipeline(); if (sslContextSupplier.isPresent()) { if (allowPlainText) { pipeline.addLast(new OptionalSslHandler(sslContextSupplier.get().get())); } else { pipeline.addLast(sslContextSupplier.get().get().newHandler(channel.alloc())); } } pipeline.addLast(new ThriftProtocolDetection( new ThriftServerHandler(methodInvoker, requestTimeout, timeoutExecutor), maxFrameSize, assumeClientsSupportOutOfOrderResponses)); } }
@Override public ServerTransport createServerTransport(ServerMethodInvoker methodInvoker) { return new DriftNettyServerTransport(methodInvoker, config, allocator); } }
@Override public void channelRead(ChannelHandlerContext context, Object message) { if (message instanceof ThriftFrame) { messageReceived(context, (ThriftFrame) message); return; } context.fireChannelRead(message); }
private void switchToTransport(ChannelHandlerContext context, Transport transport, Optional<Protocol> protocol) { ChannelPipeline pipeline = context.pipeline(); transport.addFrameHandlers(pipeline, protocol, maxFrameSize, assumeClientsSupportOutOfOrderResponses); pipeline.addLast(new ResponseOrderingHandler()); pipeline.addLast(thriftServerHandler); // remove(this) must be last because it triggers downstream processing of the current message pipeline.remove(this); } }
private static int testServerMethodInvoker(ServerMethodInvoker methodInvoker, boolean assumeClientsSupportOutOfOrderResponses, List<ToIntFunction<HostAndPort>> clients) { DriftNettyServerConfig config = new DriftNettyServerConfig() .setAssumeClientsSupportOutOfOrderResponses(assumeClientsSupportOutOfOrderResponses); TestingPooledByteBufAllocator testingAllocator = new TestingPooledByteBufAllocator(); ServerTransport serverTransport = new DriftNettyServerTransportFactory(config, testingAllocator).createServerTransport(methodInvoker); try { serverTransport.start(); HostAndPort address = HostAndPort.fromParts("localhost", ((DriftNettyServerTransport) serverTransport).getPort()); int sum = 0; for (ToIntFunction<HostAndPort> client : clients) { sum += client.applyAsInt(address); } return sum; } finally { serverTransport.shutdown(); testingAllocator.close(); } }
private static int testServerMethodInvoker(ServerMethodInvoker methodInvoker, boolean assumeClientsSupportOutOfOrderResponses, List<ToIntFunction<HostAndPort>> clients) { DriftNettyServerConfig config = new DriftNettyServerConfig() .setAssumeClientsSupportOutOfOrderResponses(assumeClientsSupportOutOfOrderResponses); TestingPooledByteBufAllocator testingAllocator = new TestingPooledByteBufAllocator(); ServerTransport serverTransport = new DriftNettyServerTransportFactory(config, testingAllocator).createServerTransport(methodInvoker); try { serverTransport.start(); HostAndPort address = HostAndPort.fromParts("localhost", ((DriftNettyServerTransport) serverTransport).getPort()); int sum = 0; for (ToIntFunction<HostAndPort> client : clients) { sum += client.applyAsInt(address); } return sum; } finally { serverTransport.shutdown(); testingAllocator.close(); } }