4444/**
4545 * A {@link SotwConfigSourceSubscriptionFactory} that reads xDS resources from
4646 * Spring {@link Environment} properties. Each resource name is mapped to a
47- * property key using a configurable prefix, and the property value is parsed
48- * as the proto type corresponding to the subscribed {@link XdsType}.
49- *
50- * <p>Example properties:
51- * <pre>{@code
52- * armeria.xds.my-cluster: |
53- * name: my-cluster
54- * type: STATIC
55- * load_assignment:
56- * cluster_name: my-cluster
57- * endpoints:
58- * - lb_endpoints:
59- * - endpoint:
60- * address:
61- * socket_address:
62- * address: 127.0.0.1
63- * port_value: 8080
64- *
65- * armeria.xds.my-listener: |
66- * name: my-listener
67- * address:
68- * socket_address:
69- * address: 0.0.0.0
70- * port_value: 8080
71- * }</pre>
47+ * property key of the form {@code <prefix>.<resource-name>}, and the property
48+ * value is parsed as the type corresponding to the subscribed {@link XdsType}.
7249 *
7350 * <p>The property key prefix is configured via a {@link SpringConfigSource}
7451 * packed into the {@code typed_config} field of the bootstrap's
75- * {@code custom_config_source}.
52+ * {@code custom_config_source}. The default prefix is {@code armeria.xds.}.
7653 *
7754 * <p>Call {@link #refresh()} to re-read properties and push updated resources
7855 * to subscribers (e.g. from a Spring Cloud Config {@code EnvironmentChangeEvent}).
56+ *
57+ * @see SpringXdsAutoConfiguration
7958 */
8059@ UnstableApi
8160public final class SpringConfigSourceFactory implements SotwConfigSourceSubscriptionFactory {
@@ -85,11 +64,6 @@ public final class SpringConfigSourceFactory implements SotwConfigSourceSubscrip
8564 */
8665 public static final String NAME = "armeria.config_source.spring" ;
8766
88- /**
89- * The default prefix prepended to resource names to form property keys.
90- */
91- public static final String DEFAULT_PREFIX = "armeria.xds." ;
92-
9367 private static final Object SIGNAL = new Object ();
9468
9569 private final Environment environment ;
@@ -98,7 +72,11 @@ public final class SpringConfigSourceFactory implements SotwConfigSourceSubscrip
9872 /**
9973 * Creates a new factory backed by the given Spring {@link Environment}.
10074 */
101- public SpringConfigSourceFactory (Environment environment ) {
75+ public static SpringConfigSourceFactory of (Environment environment ) {
76+ return new SpringConfigSourceFactory (environment );
77+ }
78+
79+ private SpringConfigSourceFactory (Environment environment ) {
10280 this .environment = requireNonNull (environment , "environment" );
10381 }
10482
@@ -111,10 +89,10 @@ public String name() {
11189 public SnapshotStream <DiscoveryResponse > create (ConfigSource configSource ,
11290 FactoryContext factoryContext ,
11391 SnapshotStream <InterestedResources > interestedResources ) {
114- final String rawPrefix = factoryContext . validator ()
115- .unpack (configSource .getCustomConfigSource ().getTypedConfig (),
116- SpringConfigSource .class )
117- .getPrefix ();
92+ final SpringConfigSource springConfigSource =
93+ factoryContext . validator () .unpack (configSource .getCustomConfigSource ().getTypedConfig (),
94+ SpringConfigSource .class );
95+ final String rawPrefix = springConfigSource .getPrefix ();
11896 final String prefix = rawPrefix .endsWith ("." ) ? rawPrefix : rawPrefix + '.' ;
11997 final Map <XdsType , InterestedResources > accumulated = new EnumMap <>(XdsType .class );
12098 final SnapshotStream <Map <XdsType , InterestedResources >> allInterests =
0 commit comments