Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[METRICS] rewrite BeanQuery by java 17 record #1700

Merged
merged 1 commit into from
May 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 9 additions & 32 deletions common/src/main/java/org/astraea/common/metrics/BeanQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
* BeanQuery.all("java.*")
* }</pre>
*/
public interface BeanQuery {
public record BeanQuery(String domainName, Map<String, String> properties, ObjectName objectName) {

static BeanQuery fromObjectName(ObjectName objectName) {
return BeanQuery.builder()
Expand All @@ -63,7 +63,7 @@ static BeanQuery fromObjectName(ObjectName objectName) {
.build();
}

static Builder builder() {
public static Builder builder() {
return new Builder();
}

Expand All @@ -72,7 +72,7 @@ static Builder builder() {
*
* @return a {@link BeanQuery} object that target all MBeans under every domain name
*/
static BeanQuery all() {
public static BeanQuery all() {
return builder().propertyListPattern(true).build();
}

Expand All @@ -82,17 +82,11 @@ static BeanQuery all() {
* @param domainName the domain name to query
* @return a {@link BeanQuery} object that target all MBeans under specific domain name
*/
static BeanQuery all(String domainName) {
public static BeanQuery all(String domainName) {
return builder().domainName(domainName).propertyListPattern(true).build();
}

String domainName();

Map<String, String> properties();

ObjectName objectName();

class Builder {
public static class Builder {

private String domainName = "*";
private final Map<String, String> properties = new HashMap<>();
Expand Down Expand Up @@ -162,9 +156,9 @@ public Builder propertyListPattern(boolean propertyListPattern) {
* previous calling to {@link Builder#property(String, String)}.
*/
public BeanQuery build() {
var domainName = Objects.requireNonNull(this.domainName);
var properties = Map.copyOf(Objects.requireNonNull(this.properties));
var objectName =
return new BeanQuery(
Objects.requireNonNull(domainName),
Map.copyOf(Objects.requireNonNull(properties)),
Utils.packException(
() -> {
if (propertyListPattern) {
Expand All @@ -176,24 +170,7 @@ public BeanQuery build() {
domainName + ":" + propertyList + ((properties.isEmpty()) ? "*" : ",*"));
}
return ObjectName.getInstance(domainName, new Hashtable<>(this.properties));
});
return new BeanQuery() {

@Override
public String domainName() {
return domainName;
}

@Override
public Map<String, String> properties() {
return properties;
}

@Override
public ObjectName objectName() {
return objectName;
}
};
}));
}
}
}