11package io .opentelemetry .opamp .client .internal ;
22
33import com .github .f4b6a3 .uuid .UuidCreator ;
4+ import com .google .errorprone .annotations .CanIgnoreReturnValue ;
45import io .opentelemetry .opamp .client .internal .impl .OpampClientImpl ;
56import io .opentelemetry .opamp .client .internal .impl .OpampClientState ;
67import io .opentelemetry .opamp .client .internal .request .service .HttpRequestService ;
1314import java .util .List ;
1415import java .util .Map ;
1516import java .util .UUID ;
17+ import javax .annotation .Nullable ;
1618import opamp .proto .AgentCapabilities ;
1719import opamp .proto .AgentDescription ;
1820import opamp .proto .AnyValue ;
2628 * <p>Builds an {@link OpampClient} instance.
2729 */
2830public final class OpampClientBuilder {
29- private final Map <String , String > identifyingAttributes = new HashMap <>();
30- private final Map <String , String > nonIdentifyingAttributes = new HashMap <>();
31- private byte [] instanceUid ;
31+ private final Map <String , AnyValue > identifyingAttributes = new HashMap <>();
32+ private final Map <String , AnyValue > nonIdentifyingAttributes = new HashMap <>();
3233 private long capabilities = 0 ;
33- private State .EffectiveConfig effectiveConfigState ;
34- private RequestService service ;
34+ @ Nullable private byte [] instanceUid ;
35+ @ Nullable private State .EffectiveConfig effectiveConfigState ;
36+ @ Nullable private RequestService service ;
3537
3638 OpampClientBuilder () {}
3739
@@ -43,6 +45,7 @@ public final class OpampClientBuilder {
4345 * @param service The request service implementation.
4446 * @return this
4547 */
48+ @ CanIgnoreReturnValue
4649 public OpampClientBuilder setRequestService (RequestService service ) {
4750 this .service = service ;
4851 return this ;
@@ -56,6 +59,7 @@ public OpampClientBuilder setRequestService(RequestService service) {
5659 * @param value The AgentToServer.instance_uid value.
5760 * @return this
5861 */
62+ @ CanIgnoreReturnValue
5963 public OpampClientBuilder setInstanceUid (byte [] value ) {
6064 this .instanceUid = value ;
6165 return this ;
@@ -70,8 +74,9 @@ public OpampClientBuilder setInstanceUid(byte[] value) {
7074 * @param value The attribute value.
7175 * @return this
7276 */
77+ @ CanIgnoreReturnValue
7378 public OpampClientBuilder setIdentifyingAttribute (String key , String value ) {
74- identifyingAttributes .put (key , value );
79+ identifyingAttributes .put (key , createStringValue ( value ) );
7580 return this ;
7681 }
7782
@@ -84,8 +89,9 @@ public OpampClientBuilder setIdentifyingAttribute(String key, String value) {
8489 * @param value The attribute value.
8590 * @return this
8691 */
92+ @ CanIgnoreReturnValue
8793 public OpampClientBuilder setNonIdentifyingAttribute (String key , String value ) {
88- nonIdentifyingAttributes .put (key , value );
94+ nonIdentifyingAttributes .put (key , createStringValue ( value ) );
8995 return this ;
9096 }
9197
@@ -96,6 +102,7 @@ public OpampClientBuilder setNonIdentifyingAttribute(String key, String value) {
96102 *
97103 * @return this
98104 */
105+ @ CanIgnoreReturnValue
99106 public OpampClientBuilder enableRemoteConfig () {
100107 capabilities =
101108 capabilities
@@ -111,6 +118,7 @@ public OpampClientBuilder enableRemoteConfig() {
111118 *
112119 * @return this
113120 */
121+ @ CanIgnoreReturnValue
114122 public OpampClientBuilder enableEffectiveConfigReporting () {
115123 capabilities =
116124 capabilities | AgentCapabilities .AgentCapabilities_ReportsEffectiveConfig .getValue ();
@@ -125,6 +133,7 @@ public OpampClientBuilder enableEffectiveConfigReporting() {
125133 * @param effectiveConfigState The state implementation.
126134 * @return this
127135 */
136+ @ CanIgnoreReturnValue
128137 public OpampClientBuilder setEffectiveConfigState (State .EffectiveConfig effectiveConfigState ) {
129138 this .effectiveConfigState = effectiveConfigState ;
130139 return this ;
@@ -163,20 +172,22 @@ public OpampClient build() {
163172 return OpampClientImpl .create (service , state );
164173 }
165174
166- private State .EffectiveConfig createEffectiveConfigNoop () {
175+ private static State .EffectiveConfig createEffectiveConfigNoop () {
167176 return new State .EffectiveConfig () {
177+ @ Nullable
168178 @ Override
169179 public opamp .proto .EffectiveConfig get () {
170180 return null ;
171181 }
172182 };
173183 }
174184
175- private KeyValue createKeyValue (String key , String value ) {
176- return new KeyValue .Builder ()
177- .key (key )
178- .value (new AnyValue .Builder ().string_value (value ).build ())
179- .build ();
185+ private static AnyValue createStringValue (String value ) {
186+ return new AnyValue .Builder ().string_value (value ).build ();
187+ }
188+
189+ private static KeyValue createKeyValue (String key , AnyValue value ) {
190+ return new KeyValue .Builder ().key (key ).value (value ).build ();
180191 }
181192
182193 public static byte [] createRandomInstanceUid () {
0 commit comments