Class ChannelManager
java.lang.Object
ai.pipestream.dynamic.grpc.client.ChannelManager
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidevictChannel(String serviceName) Manually evicts a channel for a service from the cache.intGets the number of active services with cached channels.Gets cache statistics for monitoring.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.
-
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 cachinginstances- 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
Manually evicts a channel for a service from the cache.- Parameters:
serviceName- the service whose channel should be removed
-
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)
-