diff --git a/spring-grpc-core/src/main/java/org/springframework/grpc/client/DefaultGrpcChannelFactory.java b/spring-grpc-core/src/main/java/org/springframework/grpc/client/DefaultGrpcChannelFactory.java
index b0a57b9a..7bbf3739 100644
--- a/spring-grpc-core/src/main/java/org/springframework/grpc/client/DefaultGrpcChannelFactory.java
+++ b/spring-grpc-core/src/main/java/org/springframework/grpc/client/DefaultGrpcChannelFactory.java
@@ -29,6 +29,15 @@
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
+/**
+ * Default implementation of {@link GrpcChannelFactory} for creating and managing gRPC
+ * channels.
+ *
+ * Implements {@link DisposableBean} to shut down channels when no longer needed
+ *
+ * @author David Syer
+ * @author Chris Bono
+ */
public class DefaultGrpcChannelFactory implements GrpcChannelFactory, DisposableBean {
private final Map> builders = new ConcurrentHashMap<>();
@@ -71,6 +80,13 @@ public ManagedChannelBuilder> createChannel(String authority) {
}
+ /**
+ * Creates a new {@link ManagedChannelBuilder} instance for the given target path and
+ * credentials.
+ * @param path the target path for the channel
+ * @param creds the credentials for the channel
+ * @return a new {@link ManagedChannelBuilder} for the given path and credentials
+ */
protected ManagedChannelBuilder> newChannel(String path, ChannelCredentials creds) {
return Grpc.newChannelBuilder(path, creds);
}
@@ -82,6 +98,10 @@ public void destroy() {
}
}
+ /**
+ * A {@link ManagedChannelBuilder} wrapper that ensures the created channel is
+ * disposed of when no longer needed.
+ */
class DisposableChannelBuilder extends ForwardingChannelBuilder2 {
private final ManagedChannelBuilder> delegate;
diff --git a/spring-grpc-core/src/main/java/org/springframework/grpc/client/GrpcChannelConfigurer.java b/spring-grpc-core/src/main/java/org/springframework/grpc/client/GrpcChannelConfigurer.java
index 05748a68..86a8cfdd 100644
--- a/spring-grpc-core/src/main/java/org/springframework/grpc/client/GrpcChannelConfigurer.java
+++ b/spring-grpc-core/src/main/java/org/springframework/grpc/client/GrpcChannelConfigurer.java
@@ -18,9 +18,22 @@
import io.grpc.ManagedChannelBuilder;
+/**
+ * A functional interface for configuring a {@link ManagedChannelBuilder} for a specific
+ * authority.
+ *
+ * @author Dave Syer
+ * @author Chris Bono
+ * @see ManagedChannelBuilder
+ */
@FunctionalInterface
public interface GrpcChannelConfigurer {
+ /**
+ * Configures the given {@link ManagedChannelBuilder} for the specified authority.
+ * @param authority the target authority for the channel
+ * @param builder the builder to configure
+ */
void configure(String authority, ManagedChannelBuilder> builder);
}
diff --git a/spring-grpc-core/src/main/java/org/springframework/grpc/client/GrpcChannelFactory.java b/spring-grpc-core/src/main/java/org/springframework/grpc/client/GrpcChannelFactory.java
index 9fbfac7f..0f2b1066 100644
--- a/spring-grpc-core/src/main/java/org/springframework/grpc/client/GrpcChannelFactory.java
+++ b/spring-grpc-core/src/main/java/org/springframework/grpc/client/GrpcChannelFactory.java
@@ -18,8 +18,20 @@
import io.grpc.ManagedChannelBuilder;
+/**
+ * Factory interface for creating {@link ManagedChannelBuilder} instances for a given
+ * authority.
+ *
+ * @author Dave Syer
+ * @see ManagedChannelBuilder
+ */
public interface GrpcChannelFactory {
+ /**
+ * Creates a {@link ManagedChannelBuilder} for the given authority.
+ * @param authority the target authority for the channel
+ * @return a {@link ManagedChannelBuilder} configured for the given authority
+ */
ManagedChannelBuilder> createChannel(String authority);
}