You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by mm...@apache.org on 2021/03/04 12:28:09 UTC
[accumulo] branch main updated: Clean up CompactionDirectives
default impl (#1950)
This is an automated email from the ASF dual-hosted git repository.
mmiller pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/main by this push:
new 3bbc77d Clean up CompactionDirectives default impl (#1950)
3bbc77d is described below
commit 3bbc77de13aa6cf0b849f7b28ec08cb6e6b843e9
Author: Mike Miller <mm...@apache.org>
AuthorDate: Thu Mar 4 07:27:58 2021 -0500
Clean up CompactionDirectives default impl (#1950)
* Created CompactionDirectivesBuilder class for builder logic
Co-authored-by: Keith Turner <kt...@apache.org>
---
.../core/spi/compaction/CompactionDirectives.java | 17 +++--
...tives.java => CompactionDirectivesBuilder.java} | 38 +++++-----
...rectives.java => CompactionDirectivesImpl.java} | 32 ++++----
.../spi/compaction/CompactionsDirectiveImpl.java | 85 ----------------------
.../spi/compaction/SimpleCompactionDispatcher.java | 8 +-
5 files changed, 48 insertions(+), 132 deletions(-)
diff --git a/core/src/main/java/org/apache/accumulo/core/spi/compaction/CompactionDirectives.java b/core/src/main/java/org/apache/accumulo/core/spi/compaction/CompactionDirectives.java
index e3370eb..6991fc6 100644
--- a/core/src/main/java/org/apache/accumulo/core/spi/compaction/CompactionDirectives.java
+++ b/core/src/main/java/org/apache/accumulo/core/spi/compaction/CompactionDirectives.java
@@ -32,17 +32,24 @@ public interface CompactionDirectives {
CompactionServiceId getService();
/**
+ * Required for CompactionDirectives
+ *
* @since 2.1.0
*/
- public static interface Builder {
- Builder setService(CompactionServiceId service);
+ interface ServiceBuilder {
+ Builder toService(CompactionServiceId service);
- Builder setService(String compactionServiceId);
+ Builder toService(String compactionServiceId);
+ }
+ /**
+ * @since 2.1.0
+ */
+ interface Builder {
CompactionDirectives build();
}
- public static Builder builder() {
- return CompactionsDirectiveImpl.DEFAULT_BUILDER;
+ static ServiceBuilder builder() {
+ return new CompactionDirectivesBuilder();
}
}
diff --git a/core/src/main/java/org/apache/accumulo/core/spi/compaction/CompactionDirectives.java b/core/src/main/java/org/apache/accumulo/core/spi/compaction/CompactionDirectivesBuilder.java
similarity index 55%
copy from core/src/main/java/org/apache/accumulo/core/spi/compaction/CompactionDirectives.java
copy to core/src/main/java/org/apache/accumulo/core/spi/compaction/CompactionDirectivesBuilder.java
index e3370eb..c542699 100644
--- a/core/src/main/java/org/apache/accumulo/core/spi/compaction/CompactionDirectives.java
+++ b/core/src/main/java/org/apache/accumulo/core/spi/compaction/CompactionDirectivesBuilder.java
@@ -18,31 +18,31 @@
*/
package org.apache.accumulo.core.spi.compaction;
+import java.util.Objects;
+
/**
- * The directions of a {@link CompactionDispatcher}
- *
- * @since 2.1.0
- * @see org.apache.accumulo.core.spi.compaction
+ * This class intentionally package private.
*/
-public interface CompactionDirectives {
-
- /**
- * @return The service where a compaction should run.
- */
- CompactionServiceId getService();
+class CompactionDirectivesBuilder
+ implements CompactionDirectives.Builder, CompactionDirectives.ServiceBuilder {
- /**
- * @since 2.1.0
- */
- public static interface Builder {
- Builder setService(CompactionServiceId service);
+ private CompactionServiceId service;
- Builder setService(String compactionServiceId);
+ @Override
+ public CompactionDirectives.Builder toService(CompactionServiceId service) {
+ this.service = Objects.requireNonNull(service, "CompactionServiceId cannot be null");
+ return this;
+ }
- CompactionDirectives build();
+ @Override
+ public CompactionDirectives.Builder toService(String compactionServiceId) {
+ this.service = CompactionServiceId.of(compactionServiceId);
+ return this;
}
- public static Builder builder() {
- return CompactionsDirectiveImpl.DEFAULT_BUILDER;
+ @Override
+ public CompactionDirectives build() {
+ return new CompactionDirectivesImpl(service);
}
+
}
diff --git a/core/src/main/java/org/apache/accumulo/core/spi/compaction/CompactionDirectives.java b/core/src/main/java/org/apache/accumulo/core/spi/compaction/CompactionDirectivesImpl.java
similarity index 61%
copy from core/src/main/java/org/apache/accumulo/core/spi/compaction/CompactionDirectives.java
copy to core/src/main/java/org/apache/accumulo/core/spi/compaction/CompactionDirectivesImpl.java
index e3370eb..fe2a833 100644
--- a/core/src/main/java/org/apache/accumulo/core/spi/compaction/CompactionDirectives.java
+++ b/core/src/main/java/org/apache/accumulo/core/spi/compaction/CompactionDirectivesImpl.java
@@ -19,30 +19,24 @@
package org.apache.accumulo.core.spi.compaction;
/**
- * The directions of a {@link CompactionDispatcher}
- *
- * @since 2.1.0
- * @see org.apache.accumulo.core.spi.compaction
+ * This class intentionally package private. It is immutable and provides default allocation for
+ * {@code CompactionDirectives}.
*/
-public interface CompactionDirectives {
-
- /**
- * @return The service where a compaction should run.
- */
- CompactionServiceId getService();
+class CompactionDirectivesImpl implements CompactionDirectives {
- /**
- * @since 2.1.0
- */
- public static interface Builder {
- Builder setService(CompactionServiceId service);
+ private final CompactionServiceId service;
- Builder setService(String compactionServiceId);
+ public CompactionDirectivesImpl(CompactionServiceId service) {
+ this.service = service;
+ }
- CompactionDirectives build();
+ @Override
+ public CompactionServiceId getService() {
+ return service;
}
- public static Builder builder() {
- return CompactionsDirectiveImpl.DEFAULT_BUILDER;
+ @Override
+ public String toString() {
+ return "service=" + service;
}
}
diff --git a/core/src/main/java/org/apache/accumulo/core/spi/compaction/CompactionsDirectiveImpl.java b/core/src/main/java/org/apache/accumulo/core/spi/compaction/CompactionsDirectiveImpl.java
deleted file mode 100644
index ae0e0ca..0000000
--- a/core/src/main/java/org/apache/accumulo/core/spi/compaction/CompactionsDirectiveImpl.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.accumulo.core.spi.compaction;
-
-import java.util.Objects;
-
-import org.apache.accumulo.core.spi.compaction.CompactionDirectives.Builder;
-
-import com.google.common.base.Preconditions;
-
-/**
- * This class intentionally package private. This implementation is odd because it supports zero
- * object allocations for {@code CompactionDirectives.builder().build()}.
- */
-class CompactionsDirectiveImpl implements Builder, CompactionDirectives {
-
- private static final CompactionDirectives DEFAULT =
- new CompactionsDirectiveImpl().setService(CompactionServiceId.of("default")).build();
-
- static final Builder DEFAULT_BUILDER = new Builder() {
- @Override
- public Builder setService(CompactionServiceId service) {
- return new CompactionsDirectiveImpl().setService(service);
- }
-
- @Override
- public Builder setService(String compactionServiceId) {
- return new CompactionsDirectiveImpl().setService(compactionServiceId);
- }
-
- @Override
- public CompactionDirectives build() {
- return DEFAULT;
- }
- };
-
- boolean built = false;
- private CompactionServiceId service;
-
- @Override
- public Builder setService(CompactionServiceId service) {
- Objects.requireNonNull(service);
- Preconditions.checkState(!built);
- this.service = service;
- return this;
- }
-
- @Override
- public Builder setService(String compactionServiceId) {
- return setService(CompactionServiceId.of(compactionServiceId));
- }
-
- @Override
- public CompactionServiceId getService() {
- Preconditions.checkState(built);
- return service;
- }
-
- @Override
- public CompactionDirectives build() {
- built = true;
- return this;
- }
-
- @Override
- public String toString() {
- return "service=" + service;
- }
-}
diff --git a/core/src/main/java/org/apache/accumulo/core/spi/compaction/SimpleCompactionDispatcher.java b/core/src/main/java/org/apache/accumulo/core/spi/compaction/SimpleCompactionDispatcher.java
index c985714..e572373 100644
--- a/core/src/main/java/org/apache/accumulo/core/spi/compaction/SimpleCompactionDispatcher.java
+++ b/core/src/main/java/org/apache/accumulo/core/spi/compaction/SimpleCompactionDispatcher.java
@@ -72,11 +72,11 @@ public class SimpleCompactionDispatcher implements CompactionDispatcher {
public void init(InitParameters params) {
services = new EnumMap<>(CompactionKind.class);
- var defaultService = CompactionDirectives.builder().build();
+ var defaultService = CompactionDirectives.builder().toService("default").build();
if (params.getOptions().containsKey("service")) {
defaultService =
- CompactionDirectives.builder().setService(params.getOptions().get("service")).build();
+ CompactionDirectives.builder().toService(params.getOptions().get("service")).build();
}
for (CompactionKind ctype : CompactionKind.values()) {
@@ -84,7 +84,7 @@ public class SimpleCompactionDispatcher implements CompactionDispatcher {
if (service == null)
services.put(ctype, defaultService);
else
- services.put(ctype, CompactionDirectives.builder().setService(service).build());
+ services.put(ctype, CompactionDirectives.builder().toService(service).build());
}
if (params.getOptions().isEmpty()) {
@@ -94,7 +94,7 @@ public class SimpleCompactionDispatcher implements CompactionDispatcher {
params.getOptions().forEach((k, v) -> {
if (k.startsWith("service.user.")) {
String type = k.substring("service.user.".length());
- tmpUS.put(type, CompactionDirectives.builder().setService(v).build());
+ tmpUS.put(type, CompactionDirectives.builder().toService(v).build());
}
});