Class ChannelManager

java.lang.Object
ai.pipestream.dynamic.grpc.client.ChannelManager

@ApplicationScoped public class ChannelManager extends Object
Manages gRPC Channels for services.

Channels are cached with Caffeine and automatically evicted after an idle TTL. On eviction or application shutdown, channels are shut down gracefully.

  • Constructor Details

    • ChannelManager

      public ChannelManager()
      Default constructor for CDI frameworks.
  • Method Details

    • getOrCreateChannel

      public io.smallrye.mutiny.Uni<io.grpc.Channel> getOrCreateChannel(String serviceName, List<io.smallrye.stork.api.ServiceInstance> instances)
      Gets or creates a gRPC Channel for the given service. Reuses a cached channel when available, otherwise creates a new Stork-backed channel.
      Parameters:
      serviceName - the logical service name used for discovery and caching
      instances - the list of discovered service instances (must be non-empty)
      Returns:
      a Uni that emits the Channel when ready or fails with Status.UNAVAILABLE when no instances are provided
    • evictChannel

      public void evictChannel(String serviceName)
      Manually evicts a channel for a service from the cache.
      Parameters:
      serviceName - the service whose channel should be removed
    • getCacheStats

      public String getCacheStats()
      Gets cache statistics for monitoring.
      Returns:
      a human-readable summary of cache size, hits, misses, hit rate, and evictions
    • getActiveServiceCount

      public int getActiveServiceCount()
      Gets the number of active services with cached channels.
      Returns:
      approximate count of active services (based on cache size)