CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-io-grpc--grpc-netty-shaded

A shaded version of the Netty transport for gRPC-Java that includes relocated Netty dependencies to avoid version conflicts

Pending
Overview
Eval results
Files

transport-providers.mddocs/

Transport Providers

Automatic discovery and registration of Netty transport providers for gRPC, including Unix Domain Socket support and internal configuration APIs. The provider system enables automatic transport selection and configuration through Java's ServiceLoader mechanism.

Capabilities

NettyChannelProvider

Provider for Netty-based gRPC client channels with automatic discovery and configuration.

/**
 * Check if the Netty channel provider is available
 * @return true if Netty transport is available
 */
public boolean isAvailable();

/**
 * Get the priority of this provider (higher values have higher priority)
 * @return Provider priority value
 */
public int priority();

/**
 * Create a channel builder for the specified address
 * @param name Host name
 * @param port Port number
 * @return NettyChannelBuilder for the address
 */
public NettyChannelBuilder builderForAddress(String name, int port);

/**
 * Create a channel builder for the specified target
 * @param target Target string (e.g., "dns:///service.com:443")
 * @return NettyChannelBuilder for the target
 */
public NettyChannelBuilder builderForTarget(String target);

/**
 * Create a new channel builder with credentials
 * @param target Target string
 * @param creds Channel credentials
 * @return Result containing the channel builder
 */
public NewChannelBuilderResult newChannelBuilder(String target, ChannelCredentials creds);

Usage Example:

import io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider;

NettyChannelProvider provider = new NettyChannelProvider();

if (provider.isAvailable()) {
    NettyChannelBuilder builder = provider.builderForAddress("localhost", 9090);
    ManagedChannel channel = builder.build();
}

NettyServerProvider

Provider for Netty-based gRPC servers with automatic discovery and configuration.

/**
 * Check if the Netty server provider is available
 * @return true if Netty server transport is available
 */
protected boolean isAvailable();

/**
 * Get the priority of this provider (higher values have higher priority)
 * @return Provider priority value
 */
protected int priority();

/**
 * Create a server builder for the specified port
 * @param port Port number to listen on
 * @return NettyServerBuilder for the port
 */
protected NettyServerBuilder builderForPort(int port);

/**
 * Create a new server builder with credentials
 * @param port Port number to listen on
 * @param creds Server credentials
 * @return Result containing the server builder
 */
protected NewServerBuilderResult newServerBuilderForPort(int port, ServerCredentials creds);

Usage Example:

import io.grpc.netty.shaded.io.grpc.netty.NettyServerProvider;

NettyServerProvider provider = new NettyServerProvider();

if (provider.isAvailable()) {
    NettyServerBuilder builder = provider.builderForPort(9090);
    Server server = builder.addService(new MyServiceImpl()).build();
}

UdsNettyChannelProvider

Provider for Unix Domain Socket channels using Netty transport.

/**
 * Check if Unix Domain Socket transport is available
 * @return true if UDS transport is available
 */
public boolean isAvailable();

/**
 * Get the priority of this provider
 * @return Provider priority value
 */
public int priority();

/**
 * Create a channel builder for the specified address (UDS specific)
 * @param name Socket path or identifier
 * @param port Port number (may be ignored for UDS)
 * @return NettyChannelBuilder configured for UDS
 */
public NettyChannelBuilder builderForAddress(String name, int port);

/**
 * Create a channel builder for the specified target (UDS specific)
 * @param target Target string (e.g., "unix:///path/to/socket")
 * @return NettyChannelBuilder configured for UDS
 */
public NettyChannelBuilder builderForTarget(String target);

/**
 * Create a new UDS channel builder with credentials
 * @param target Target string
 * @param creds Channel credentials
 * @return Result containing the channel builder
 */
public NewChannelBuilderResult newChannelBuilder(String target, ChannelCredentials creds);

Usage Example:

import io.grpc.netty.shaded.io.grpc.netty.UdsNettyChannelProvider;

UdsNettyChannelProvider udsProvider = new UdsNettyChannelProvider();

if (udsProvider.isAvailable()) {
    NettyChannelBuilder builder = udsProvider.builderForTarget("unix:///tmp/grpc.sock");
    ManagedChannel channel = builder.build();
}

UdsNameResolverProvider

Name resolver provider for Unix Domain Socket addresses.

/**
 * Check if UDS name resolution is available
 * @return true if UDS name resolution is supported
 */
public boolean isAvailable();

/**
 * Get the priority of this name resolver provider
 * @return Provider priority value
 */
public int priority();

/**
 * Get the default URI scheme for UDS
 * @return Default scheme string (typically "unix")
 */
public String getDefaultScheme();

/**
 * Create a name resolver for the given URI
 * @param targetUri Target URI to resolve
 * @param args Name resolver arguments
 * @return NameResolver for the URI or null if not supported
 */
public NameResolver newNameResolver(URI targetUri, NameResolver.Args args);

Usage Example:

import io.grpc.netty.shaded.io.grpc.netty.UdsNameResolverProvider;
import java.net.URI;

UdsNameResolverProvider resolver = new UdsNameResolverProvider();

if (resolver.isAvailable()) {
    URI uri = URI.create("unix:///tmp/grpc.sock");
    NameResolver nameResolver = resolver.newNameResolver(uri, args);
}

Internal Provider APIs

InternalNettyChannelBuilder

Internal API for advanced channel builder configuration and transport factory creation.

/**
 * Disable authority checking for the channel
 * @param builder The NettyChannelBuilder to configure
 */
public static void disableCheckAuthority(NettyChannelBuilder builder);

/**
 * Enable authority checking for the channel
 * @param builder The NettyChannelBuilder to configure
 */
public static void enableCheckAuthority(NettyChannelBuilder builder);

/**
 * Set a protocol negotiator factory
 * @param builder The NettyChannelBuilder to configure
 * @param protocolNegotiator The protocol negotiator factory
 */
public static void setProtocolNegotiatorFactory(
    NettyChannelBuilder builder, 
    ProtocolNegotiatorFactory protocolNegotiator);

/**
 * Set statistics collection enabled/disabled
 * @param builder The NettyChannelBuilder to configure
 * @param value Whether to enable stats collection
 */
public static void setStatsEnabled(NettyChannelBuilder builder, boolean value);

/**
 * Set tracing enabled/disabled
 * @param builder The NettyChannelBuilder to configure
 * @param value Whether to enable tracing
 */
public static void setTracingEnabled(NettyChannelBuilder builder, boolean value);

/**
 * Build the underlying transport factory
 * @param builder The configured NettyChannelBuilder
 * @return ClientTransportFactory for the configuration
 */
public static ClientTransportFactory buildTransportFactory(NettyChannelBuilder builder);

InternalNettyServerBuilder

Internal API for advanced server builder configuration.

// Various internal configuration methods for advanced server setup
// (specific methods vary based on internal gRPC requirements)

Internal Credentials

Internal credential factories for custom protocol negotiators.

/**
 * Create channel credentials from a protocol negotiator factory
 * @param factory The protocol negotiator factory
 * @return ChannelCredentials using the factory
 */
public static ChannelCredentials create(ProtocolNegotiator.ClientFactory factory);

/**
 * Create server credentials from a protocol negotiator factory
 * @param factory The protocol negotiator factory
 * @return ServerCredentials using the factory
 */
public static ServerCredentials create(ProtocolNegotiator.ServerFactory factory);

Automatic Provider Discovery

The gRPC library automatically discovers and uses transport providers through Java's ServiceLoader mechanism. The Netty providers register themselves and are selected based on availability and priority.

Usage Example - Automatic Discovery:

import io.grpc.Grpc;
import io.grpc.InsecureChannelCredentials;
import io.grpc.InsecureServerCredentials;

// gRPC automatically selects the best available transport provider
// (will use Netty if available due to higher priority)

ManagedChannel channel = Grpc.newChannelBuilder(
    "localhost:9090", 
    InsecureChannelCredentials.create()
).build(); // Automatically uses NettyChannelBuilder

Server server = Grpc.newServerBuilderForPort(
    9090, 
    InsecureServerCredentials.create()
).build(); // Automatically uses NettyServerBuilder

Provider Priority System

Transport providers are ranked by priority, with higher values taking precedence:

  1. NettyChannelProvider - High priority for standard TCP connections
  2. UdsNettyChannelProvider - Specialized priority for Unix Domain Socket connections
  3. NettyServerProvider - High priority for standard TCP servers

The priority system ensures that:

  • Netty transport is preferred over other transports when available
  • UDS transport is used for unix:// URIs
  • Fallback to other transports occurs if Netty is unavailable

Provider Result Types

/**
 * Result of creating a new channel builder
 */
public static class NewChannelBuilderResult {
    private final ManagedChannelBuilder<?> channelBuilder;
    private final boolean intercepted;
    
    // Getters and construction methods
}

/**
 * Result of creating a new server builder  
 */
public static class NewServerBuilderResult {
    private final ServerBuilder<?> serverBuilder;
    private final boolean intercepted;
    
    // Getters and construction methods
}

Platform-Specific Considerations

Linux

  • Full support for epoll transport
  • Native TCP optimization
  • Unix Domain Socket support

macOS

  • kqueue transport support
  • Unix Domain Socket support
  • Native library compatibility

Windows

  • NIO transport (epoll/kqueue not available)
  • Named pipe support varies
  • TCP optimization through native libraries

The provider system automatically selects the best available transport for each platform.

Install with Tessl CLI

npx tessl i tessl/maven-io-grpc--grpc-netty-shaded

docs

channel-building.md

index.md

server-building.md

ssl-tls.md

transport-providers.md

tile.json