Skip to content

Commit c0e19a2

Browse files
Add AutoValue + small example
1 parent e8729ad commit c0e19a2

3 files changed

Lines changed: 41 additions & 43 deletions

File tree

databricks-sdk-java/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,18 @@
103103
<artifactId>jackson-datatype-jsr310</artifactId>
104104
<version>${jackson.version}</version>
105105
</dependency>
106+
<!-- Google Auto Value -->
107+
<dependency>
108+
<groupId>com.google.auto.value</groupId>
109+
<artifactId>auto-value</artifactId>
110+
<version>1.10.4</version>
111+
<scope>provided</scope>
112+
</dependency>
113+
<dependency>
114+
<groupId>com.google.auto.value</groupId>
115+
<artifactId>auto-value-annotations</artifactId>
116+
<version>1.10.4</version>
117+
<scope>provided</scope>
118+
</dependency>
106119
</dependencies>
107120
</project>

databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DataPlaneTokenSource.java

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,38 @@
11
package com.databricks.sdk.core.oauth;
22

33
import com.databricks.sdk.core.http.HttpClient;
4+
import com.google.auto.value.AutoValue;
45
import java.util.Objects;
56
import java.util.concurrent.ConcurrentHashMap;
67

78
/**
8-
* Manages and provides Databricks data plane tokens. This class is responsible for acquiring and
9-
* caching OAuth tokens that are specific to a particular Databricks data plane service endpoint and
10-
* a set of authorization details. It utilizes a {@link DatabricksOAuthTokenSource} for obtaining
11-
* control plane tokens, which may then be exchanged or used to authorize requests for data plane
12-
* tokens. Cached {@link EndpointTokenSource} instances are used to efficiently reuse tokens for
13-
* repeated requests to the same endpoint with the same authorization context.
9+
* Manages and provides Databricks data plane tokens. This class is responsible
10+
* for acquiring and caching OAuth tokens that are specific to a particular
11+
* Databricks data plane service endpoint and a set of authorization details.
12+
* It utilizes a {@link DatabricksOAuthTokenSource} for obtaining control plane
13+
* tokens, which may then be exchanged or used to authorize requests for data
14+
* plane tokens. Cached {@link EndpointTokenSource} instances are used to
15+
* efficiently reuse tokens for repeated requests to the same endpoint with the
16+
* same authorization context.
1417
*/
1518
public class DataPlaneTokenSource {
1619
private final HttpClient httpClient;
1720
private final TokenSource cpTokenSource;
1821
private final String host;
1922
private final ConcurrentHashMap<TokenSourceKey, EndpointTokenSource> sourcesCache;
23+
2024
/**
21-
* Caching key for {@link EndpointTokenSource}, based on endpoint and authorization details. This
22-
* is a value object that uniquely identifies a token source configuration.
25+
* Caching key for {@link EndpointTokenSource}, based on endpoint and
26+
* authorization details. This is a value object that uniquely identifies
27+
* a token source configuration.
2328
*/
24-
private static final class TokenSourceKey {
25-
/** The target service endpoint URL. */
26-
private final String endpoint;
27-
28-
/** Specific authorization details for the endpoint. */
29-
private final String authDetails;
30-
31-
/**
32-
* Constructs a TokenSourceKey.
33-
*
34-
* @param endpoint The target service endpoint URL.
35-
* @param authDetails Specific authorization details.
36-
*/
37-
public TokenSourceKey(String endpoint, String authDetails) {
38-
this.endpoint = endpoint;
39-
this.authDetails = authDetails;
40-
}
41-
42-
@Override
43-
public boolean equals(Object o) {
44-
if (this == o) {
45-
return true;
46-
}
47-
if (o == null || getClass() != o.getClass()) {
48-
return false;
49-
}
50-
TokenSourceKey that = (TokenSourceKey) o;
51-
return Objects.equals(endpoint, that.endpoint)
52-
&& Objects.equals(authDetails, that.authDetails);
53-
}
29+
@AutoValue
30+
static abstract class TokenSourceKey {
31+
abstract String endpoint();
32+
abstract String authDetails();
5433

55-
@Override
56-
public int hashCode() {
57-
return Objects.hash(endpoint, authDetails);
34+
static TokenSourceKey create(String endpoint, String authDetails) {
35+
return new AutoValue_DataPlaneTokenSource_TokenSourceKey(endpoint, authDetails);
5836
}
5937
}
6038

@@ -101,14 +79,14 @@ public Token getToken(String endpoint, String authDetails) {
10179
throw new IllegalArgumentException("Authorization details cannot be empty");
10280
}
10381

104-
TokenSourceKey key = new TokenSourceKey(endpoint, authDetails);
82+
TokenSourceKey key = TokenSourceKey.create(endpoint, authDetails);
10583

10684
EndpointTokenSource specificSource =
10785
sourcesCache.computeIfAbsent(
10886
key,
10987
k ->
11088
new EndpointTokenSource(
111-
this.cpTokenSource, k.authDetails, this.httpClient, this.host));
89+
this.cpTokenSource, k.authDetails(), this.httpClient, this.host));
11290

11391
return specificSource.getToken();
11492
}

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@
6767
<configuration>
6868
<source>8</source>
6969
<target>8</target>
70+
<annotationProcessorPaths>
71+
<path>
72+
<groupId>com.google.auto.value</groupId>
73+
<artifactId>auto-value</artifactId>
74+
<version>1.10.4</version>
75+
</path>
76+
</annotationProcessorPaths>
7077
</configuration>
7178
</plugin>
7279
<plugin>

0 commit comments

Comments
 (0)