CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-io-grpc--grpc-inprocess

High-performance in-process transport implementation for gRPC Java that enables direct communication between client and server within the same JVM process

Pending
Overview
Eval results
Files

channel-builder.mddocs/

Channel Building

The InProcessChannelBuilder provides a fluent API for creating in-process channels that connect to servers within the same JVM process. It extends the standard gRPC channel builder with in-process specific optimizations.

Capabilities

Factory Methods

Create channel builders for different connection patterns.

/**
 * Create a channel builder that will connect to the server with the given name.
 * @param name the identity of the server to connect to
 * @return a new builder
 */
public static InProcessChannelBuilder forName(String name);

/**
 * Create a channel builder that will connect to the server referenced by the given target URI.
 * Only intended for use with a custom name resolver.
 * @param target the identity of the server to connect to
 * @return a new builder
 */
public static InProcessChannelBuilder forTarget(String target);

/**
 * Create a channel builder that will connect to the server referenced by the given address.
 * @param address the address of the server to connect to
 * @return a new builder
 */
public static InProcessChannelBuilder forAddress(SocketAddress address);

Usage Examples:

// Connect to named server
InProcessChannelBuilder builder1 = InProcessChannelBuilder.forName("test-server");

// Connect using target URI (for custom name resolvers)
InProcessChannelBuilder builder2 = InProcessChannelBuilder.forTarget("inprocess://my-service");

// Connect using socket address
InProcessSocketAddress address = new InProcessSocketAddress("service-name");
InProcessChannelBuilder builder3 = InProcessChannelBuilder.forAddress(address);

Message Size Configuration

Configure message size limits and assumptions for performance optimization.

/**
 * Sets the maximum size of inbound messages. Currently not enforced for in-process transport.
 * @param max the maximum message size in bytes
 * @return this builder
 */
public InProcessChannelBuilder maxInboundMessageSize(int max);

/**
 * Sets the maximum size of metadata allowed to be received.
 * @param bytes the maximum size of received metadata
 * @return this builder
 * @throws IllegalArgumentException if bytes is non-positive
 */
public InProcessChannelBuilder maxInboundMetadataSize(int bytes);

/**
 * Assumes RPC messages are the specified size to avoid serialization for metrics.
 * @param assumedMessageSize length of InProcess transport's messageSize
 * @return this builder
 * @throws IllegalArgumentException if assumedMessageSize is negative
 */
public InProcessChannelBuilder assumedMessageSize(long assumedMessageSize);

Security Configuration

Security configuration methods (no-ops for in-process transport).

/**
 * Does nothing for in-process transport.
 * @return this builder
 */
public InProcessChannelBuilder useTransportSecurity();

/**
 * Does nothing for in-process transport.
 * @return this builder
 */
public InProcessChannelBuilder usePlaintext();

Keep-Alive Configuration

Keep-alive configuration methods (no-ops for in-process transport).

/**
 * Does nothing for in-process transport.
 * @param keepAliveTime keep alive time value
 * @param timeUnit time unit for keep alive time
 * @return this builder
 */
public InProcessChannelBuilder keepAliveTime(long keepAliveTime, TimeUnit timeUnit);

/**
 * Does nothing for in-process transport.
 * @param keepAliveTimeout keep alive timeout value
 * @param timeUnit time unit for keep alive timeout
 * @return this builder
 */
public InProcessChannelBuilder keepAliveTimeout(long keepAliveTimeout, TimeUnit timeUnit);

/**
 * Does nothing for in-process transport.
 * @param enable whether to enable keep alive without calls
 * @return this builder
 */
public InProcessChannelBuilder keepAliveWithoutCalls(boolean enable);

Executor Configuration

Configure custom executor services for the channel.

/**
 * Provides a custom scheduled executor service.
 * @param scheduledExecutorService the scheduled executor service to use
 * @return this builder
 */
public InProcessChannelBuilder scheduledExecutorService(
    ScheduledExecutorService scheduledExecutorService);

Debugging and Error Handling

Configure debugging and error propagation behavior.

/**
 * Sets whether to include the cause with the status that is propagated forward.
 * By default, this is set to false for consistency with other transports.
 * @param enable whether to include cause in status
 * @return this builder
 */
public InProcessChannelBuilder propagateCauseWithStatus(boolean enable);

Usage Example:

String serverName = "test-server";

Channel channel = InProcessChannelBuilder.forName(serverName)
    .maxInboundMetadataSize(4096)
    .assumedMessageSize(1024)
    .propagateCauseWithStatus(true) // For debugging
    .directExecutor() // Use direct executor for testing
    .build();

// Use the channel with gRPC stubs
MyServiceGrpc.MyServiceBlockingStub stub = 
    MyServiceGrpc.newBlockingStub(channel);

Error Handling

  • IllegalArgumentException - Thrown for invalid parameter values (negative sizes, null arguments)
  • UnsupportedOperationException - Thrown when calling deprecated forAddress(String, int) method

Thread Safety

InProcessChannelBuilder instances are not thread-safe during configuration. Each builder instance should be used by a single thread during the building phase. However, the resulting ManagedChannel instances are fully thread-safe and can be used concurrently by multiple threads.

Performance Considerations

  • Use assumedMessageSize() when you know typical message sizes to skip serialization for metrics
  • The in-process transport automatically disables stats recording for optimal performance
  • Custom executor services can be shared across multiple channels for resource efficiency

Install with Tessl CLI

npx tessl i tessl/maven-io-grpc--grpc-inprocess

docs

channel-builder.md

index.md

server-builder.md

socket-addresses.md

tile.json