Java Code Examples for io.netty.channel.kqueue.KQueue#isAvailable()
The following examples show how to use
io.netty.channel.kqueue.KQueue#isAvailable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KMSEncryptionProvider.java From credhub with Apache License 2.0 | 6 votes |
private void setChannelInfo() { if (Epoll.isAvailable()) { this.group = new EpollEventLoopGroup(); this.channelType = EpollDomainSocketChannel.class; LOGGER.info("Using epoll for Netty transport."); } else { if (!KQueue.isAvailable()) { throw new RuntimeException("Unsupported OS '" + System.getProperty("os.name") + "', only Unix and Mac are supported"); } this.group = new KQueueEventLoopGroup(); this.channelType = KQueueDomainSocketChannel.class; LOGGER.info("Using KQueue for Netty transport."); } }
Example 2
Source File: NettyDomainSocketClient.java From selenium with Apache License 2.0 | 6 votes |
public NettyDomainSocketClient(ClientConfig config) { super(config); URI uri = config.baseUri(); Require.argument("URI scheme", uri.getScheme()).equalTo("unix"); if (Epoll.isAvailable()) { this.eventLoopGroup = new EpollEventLoopGroup(); this.channelClazz = EpollDomainSocketChannel.class; } else if (KQueue.isAvailable()) { this.eventLoopGroup = new KQueueEventLoopGroup(); this.channelClazz = KQueueDomainSocketChannel.class; } else { throw new IllegalStateException("No native library for unix domain sockets is available"); } this.path = uri.getPath(); }
Example 3
Source File: GoogleAuthUtils.java From bazel with Apache License 2.0 | 6 votes |
private static NettyChannelBuilder newNettyChannelBuilder(String targetUrl, String proxy) throws IOException { if (Strings.isNullOrEmpty(proxy)) { return NettyChannelBuilder.forTarget(targetUrl).defaultLoadBalancingPolicy("round_robin"); } if (!proxy.startsWith("unix:")) { throw new IOException("Remote proxy unsupported: " + proxy); } DomainSocketAddress address = new DomainSocketAddress(proxy.replaceFirst("^unix:", "")); NettyChannelBuilder builder = NettyChannelBuilder.forAddress(address).overrideAuthority(targetUrl); if (KQueue.isAvailable()) { return builder .channelType(KQueueDomainSocketChannel.class) .eventLoopGroup(new KQueueEventLoopGroup()); } if (Epoll.isAvailable()) { return builder .channelType(EpollDomainSocketChannel.class) .eventLoopGroup(new EpollEventLoopGroup()); } throw new IOException("Unix domain sockets are unsupported on this platform"); }
Example 4
Source File: Connector.java From serve with Apache License 2.0 | 5 votes |
public static EventLoopGroup newEventLoopGroup(int threads) { if (useNativeIo && Epoll.isAvailable()) { return new EpollEventLoopGroup(threads); } else if (useNativeIo && KQueue.isAvailable()) { return new KQueueEventLoopGroup(threads); } NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup(threads); eventLoopGroup.setIoRatio(ConfigManager.getInstance().getIoRatio()); return eventLoopGroup; }
Example 5
Source File: KQueueSupport.java From qpid-jms with Apache License 2.0 | 5 votes |
public static boolean isAvailable(TransportOptions transportOptions) { try { return transportOptions.isUseKQueue() && KQueue.isAvailable(); } catch (NoClassDefFoundError ncdfe) { LOG.debug("Unable to check for KQueue support due to missing class definition", ncdfe); return false; } }
Example 6
Source File: CheckDependencies.java From activemq-artemis with Apache License 2.0 | 5 votes |
public static final boolean isKQueueAvailable() { try { return Env.isMacOs() && KQueue.isAvailable(); } catch (NoClassDefFoundError noClassDefFoundError) { ActiveMQClientLogger.LOGGER.unableToCheckKQueueAvailabilityNoClass(); return false; } catch (Throwable e) { ActiveMQClientLogger.LOGGER.unableToCheckKQueueAvailability(e); return false; } }
Example 7
Source File: Client.java From java-dcp-client with Apache License 2.0 | 5 votes |
private static EventLoopGroup newEventLoopGroup() { if (Epoll.isAvailable()) { LOGGER.info("Using Netty epoll native transport."); return new EpollEventLoopGroup(threadFactory); } if (KQueue.isAvailable()) { LOGGER.info("Using Netty kqueue native transport."); return new KQueueEventLoopGroup(threadFactory); } LOGGER.info("Using Netty NIO transport."); return new NioEventLoopGroup(threadFactory); }
Example 8
Source File: HttpBlobStore.java From bazel-buildfarm with Apache License 2.0 | 5 votes |
public static HttpBlobStore create( DomainSocketAddress domainSocketAddress, URI uri, int timeoutMillis, int remoteMaxConnections, @Nullable final Credentials creds) throws ConfigurationException, URISyntaxException, SSLException { if (KQueue.isAvailable()) { return new HttpBlobStore( KQueueEventLoopGroup::new, KQueueDomainSocketChannel.class, uri, timeoutMillis, remoteMaxConnections, creds, domainSocketAddress); } else if (Epoll.isAvailable()) { return new HttpBlobStore( EpollEventLoopGroup::new, EpollDomainSocketChannel.class, uri, timeoutMillis, remoteMaxConnections, creds, domainSocketAddress); } else { throw new ConfigurationException("Unix domain sockets are unsupported on this platform"); } }
Example 9
Source File: Connector.java From multi-model-server with Apache License 2.0 | 5 votes |
public Class<? extends Channel> getClientChannel() { if (useNativeIo && Epoll.isAvailable()) { return uds ? EpollDomainSocketChannel.class : EpollSocketChannel.class; } else if (useNativeIo && KQueue.isAvailable()) { return uds ? KQueueDomainSocketChannel.class : KQueueSocketChannel.class; } return NioSocketChannel.class; }
Example 10
Source File: Connector.java From multi-model-server with Apache License 2.0 | 5 votes |
public Class<? extends ServerChannel> getServerChannel() { if (useNativeIo && Epoll.isAvailable()) { return uds ? EpollServerDomainSocketChannel.class : EpollServerSocketChannel.class; } else if (useNativeIo && KQueue.isAvailable()) { return uds ? KQueueServerDomainSocketChannel.class : KQueueServerSocketChannel.class; } return NioServerSocketChannel.class; }
Example 11
Source File: RequestResponseCloseHandlerTest.java From servicetalk with Apache License 2.0 | 5 votes |
private void expectToFailIfNotOnLinux(Runnable call) { // TODO(scott) Windows doesn't propagate the exception. Some times an unhandled exception in pipeline. if (cChannel instanceof EpollSocketChannel || (!KQueue.isAvailable() && !Epoll.isAvailable())) { call.run(); } else { try { call.run(); fail("Should fail"); } catch (ChannelException e) { // Expected } } }
Example 12
Source File: Connector.java From serve with Apache License 2.0 | 5 votes |
public Class<? extends Channel> getClientChannel() { if (useNativeIo && Epoll.isAvailable()) { return uds ? EpollDomainSocketChannel.class : EpollSocketChannel.class; } else if (useNativeIo && KQueue.isAvailable()) { return uds ? KQueueDomainSocketChannel.class : KQueueSocketChannel.class; } return NioSocketChannel.class; }
Example 13
Source File: Connector.java From multi-model-server with Apache License 2.0 | 4 votes |
public Connector(int port) { this(port, useNativeIo && (Epoll.isAvailable() || KQueue.isAvailable())); }
Example 14
Source File: NetworkUtils.java From CloudNet with Apache License 2.0 | 4 votes |
public static EventLoopGroup eventLoopGroup(int threads, ThreadFactory threadFactory) { return EPOLL ? new EpollEventLoopGroup(threads, threadFactory) : KQueue.isAvailable() ? new KQueueEventLoopGroup(threads, threadFactory) : new NioEventLoopGroup( threads, threadFactory); }
Example 15
Source File: NetworkUtils.java From CloudNet with Apache License 2.0 | 4 votes |
public static Class<? extends ServerSocketChannel> serverSocketChannel() { return EPOLL ? EpollServerSocketChannel.class : KQueue.isAvailable() ? KQueueServerSocketChannel.class : NioServerSocketChannel.class; }
Example 16
Source File: NetworkUtils.java From CloudNet with Apache License 2.0 | 4 votes |
public static Class<? extends SocketChannel> socketChannel() { return EPOLL ? EpollSocketChannel.class : KQueue.isAvailable() ? KQueueSocketChannel.class : NioSocketChannel.class; }
Example 17
Source File: NativeSupport.java From Jupiter with Apache License 2.0 | 4 votes |
/** * The native socket transport for BSD systems such as MacOS using JNI. */ public static boolean isNativeKQueueAvailable() { return KQueue.isAvailable(); }
Example 18
Source File: NettyClientTest.java From selenium with Apache License 2.0 | 4 votes |
@Before public void setupUnixDomainSocketServer() throws IOException, URISyntaxException { Class<? extends ServerDomainSocketChannel> channelType = null; if (Epoll.isAvailable()) { group = new EpollEventLoopGroup(2); channelType = EpollServerDomainSocketChannel.class; } else if (KQueue.isAvailable()) { group = new KQueueEventLoopGroup(2); channelType = KQueueServerDomainSocketChannel.class; } assumeThat(group).isNotNull(); assumeThat(channelType).isNotNull(); ServerBootstrap bootstrap = new ServerBootstrap() .group(group) .option(ChannelOption.SO_BACKLOG, 1024) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .channel(channelType) .childHandler(new ChannelInitializer<DomainSocketChannel>() { @Override protected void initChannel(DomainSocketChannel ch) { ch.pipeline() .addLast("http-codec", new HttpServerCodec()) .addLast("http-keep-alive", new HttpServerKeepAliveHandler()) .addLast("http-aggregator", new HttpObjectAggregator(Integer.MAX_VALUE)) .addLast(new SimpleChannelInboundHandler<FullHttpRequest>() { @Override protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest req) { byte[] bytes = responseText.get().getBytes(UTF_8); ByteBuf text = Unpooled.wrappedBuffer(bytes); FullHttpResponse res = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, text); res.headers().set(CONTENT_TYPE, MediaType.PLAIN_TEXT_UTF_8.toString()); res.headers().set(CONTENT_LENGTH, bytes.length); ctx.writeAndFlush(res); } }); } }); Path temp = Files.createTempFile("domain-socket-test", "socket"); Files.deleteIfExists(temp); SocketAddress address = new DomainSocketAddress(temp.toFile()); future = bootstrap.bind(address); socket = new URI("unix", null, null, 0, temp.toString(), null, null); }
Example 19
Source File: Connector.java From serve with Apache License 2.0 | 4 votes |
public Connector(int port) { this(port, useNativeIo && (Epoll.isAvailable() || KQueue.isAvailable())); }
Example 20
Source File: NettyIoExecutors.java From servicetalk with Apache License 2.0 | 3 votes |
/** * Create a new {@link EventLoopGroup}. * * @param ioThreads number of threads * @param threadFactory the {@link ThreadFactory} to use. * @return The created {@link IoExecutor} */ public static EventLoopGroup createEventLoopGroup(int ioThreads, ThreadFactory threadFactory) { validateIoThreads(ioThreads); return Epoll.isAvailable() ? new EpollEventLoopGroup(ioThreads, threadFactory) : KQueue.isAvailable() ? new KQueueEventLoopGroup(ioThreads, threadFactory) : new NioEventLoopGroup(ioThreads, threadFactory); }