Skip to content

Commit

Permalink
Apply modernizer-maven-plugin to managed-ledger module. (apache#16363)
Browse files Browse the repository at this point in the history
To encourage the use of modern & jdk builtin APIs.
  • Loading branch information
MarvinCai authored Aug 8, 2022
1 parent d8a9a9e commit 40f0438
Show file tree
Hide file tree
Showing 30 changed files with 150 additions and 133 deletions.
18 changes: 18 additions & 0 deletions managed-ledger/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,24 @@

<build>
<plugins>
<plugin>
<groupId>org.gaul</groupId>
<artifactId>modernizer-maven-plugin</artifactId>
<configuration>
<failOnViolations>true</failOnViolations>
<javaVersion>17</javaVersion>
</configuration>
<executions>
<execution>
<id>modernizer</id>
<phase>verify</phase>
<goals>
<goal>modernizer</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.apache.bookkeeper.mledger;

import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.base.Charsets;
import java.nio.charset.StandardCharsets;
import java.time.Clock;
import java.util.Arrays;
import java.util.Map;
Expand Down Expand Up @@ -68,7 +68,7 @@ public class ManagedLedgerConfig {
private long readEntryTimeoutSeconds = 120;
private long addEntryTimeoutSeconds = 120;
private DigestType digestType = DigestType.CRC32C;
private byte[] password = "".getBytes(Charsets.UTF_8);
private byte[] password = "".getBytes(StandardCharsets.UTF_8);
private boolean unackedRangesOpenCacheSetEnabled = true;
private Class<? extends EnsemblePlacementPolicy> bookKeeperEnsemblePlacementPolicyClassName;
private Map<String, Object> bookKeeperEnsemblePlacementPolicyProperties;
Expand Down Expand Up @@ -271,7 +271,7 @@ public byte[] getPassword() {
* the password to set
*/
public ManagedLedgerConfig setPassword(String password) {
this.password = password.getBytes(Charsets.UTF_8);
this.password = password.getBytes(StandardCharsets.UTF_8);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.bookkeeper.mledger.impl;

import com.google.common.collect.ImmutableMap;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import org.apache.bookkeeper.client.EnsemblePlacementPolicy;
Expand Down Expand Up @@ -53,7 +52,7 @@ public final class LedgerMetadataUtils {
* @return an immutable map which describes a ManagedLedger
*/
static Map<String, byte[]> buildBaseManagedLedgerMetadata(String name) {
return ImmutableMap.of(
return Map.of(
METADATA_PROPERTY_APPLICATION, METADATA_PROPERTY_APPLICATION_PULSAR,
METADATA_PROPERTY_COMPONENT, METADATA_PROPERTY_COMPONENT_MANAGED_LEDGER,
METADATA_PROPERTY_MANAGED_LEDGER_NAME, name.getBytes(StandardCharsets.UTF_8));
Expand All @@ -67,7 +66,7 @@ static Map<String, byte[]> buildBaseManagedLedgerMetadata(String name) {
* @see #buildBaseManagedLedgerMetadata(java.lang.String)
*/
static Map<String, byte[]> buildAdditionalMetadataForCursor(String name) {
return ImmutableMap.of(METADATA_PROPERTY_CURSOR_NAME, name.getBytes(StandardCharsets.UTF_8));
return Map.of(METADATA_PROPERTY_CURSOR_NAME, name.getBytes(StandardCharsets.UTF_8));
}

/**
Expand All @@ -79,7 +78,7 @@ static Map<String, byte[]> buildAdditionalMetadataForCursor(String name) {
*/
public static Map<String, byte[]> buildMetadataForCompactedLedger(String compactedTopic,
byte[] compactedToMessageId) {
return ImmutableMap.of(
return Map.of(
METADATA_PROPERTY_APPLICATION, METADATA_PROPERTY_APPLICATION_PULSAR,
METADATA_PROPERTY_COMPONENT, METADATA_PROPERTY_COMPONENT_COMPACTED_LEDGER,
METADATA_PROPERTY_COMPACTEDTOPIC, compactedTopic.getBytes(StandardCharsets.UTF_8),
Expand All @@ -94,7 +93,7 @@ public static Map<String, byte[]> buildMetadataForCompactedLedger(String compact
* @return an immutable map which describes the schema
*/
public static Map<String, byte[]> buildMetadataForSchema(String schemaId) {
return ImmutableMap.of(
return Map.of(
METADATA_PROPERTY_APPLICATION, METADATA_PROPERTY_APPLICATION_PULSAR,
METADATA_PROPERTY_COMPONENT, METADATA_PROPERTY_COMPONENT_SCHEMA,
METADATA_PROPERTY_SCHEMAID, schemaId.getBytes(StandardCharsets.UTF_8)
Expand All @@ -117,7 +116,7 @@ static Map<String, byte[]> buildMetadataForPlacementPolicyConfig(
Class<? extends EnsemblePlacementPolicy> className, Map<String, Object> properties)
throws EnsemblePlacementPolicyConfig.ParseEnsemblePlacementPolicyConfigException {
EnsemblePlacementPolicyConfig config = new EnsemblePlacementPolicyConfig(className, properties);
return ImmutableMap.of(EnsemblePlacementPolicyConfig.ENSEMBLE_PLACEMENT_POLICY_CONFIG, config.encode());
return Map.of(EnsemblePlacementPolicyConfig.ENSEMBLE_PLACEMENT_POLICY_CONFIG, config.encode());
}

private LedgerMetadataUtils() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
*/
package org.apache.bookkeeper.mledger.impl;

import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.Lists;
import static java.util.Objects.requireNonNull;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
Expand Down Expand Up @@ -75,7 +74,7 @@ public ManagedCursorContainer(CursorType cursorType) {
private final CursorType cursorType;

// Used to keep track of slowest cursor. Contains all of all active cursors.
private final ArrayList<Item> heap = Lists.newArrayList();
private final ArrayList<Item> heap = new ArrayList();

// Maps a cursor to its position in the heap
private final ConcurrentMap<String, Item> cursors = new ConcurrentSkipListMap<>();
Expand Down Expand Up @@ -157,7 +156,7 @@ public void removeCursor(String name) {
* update).
*/
public Pair<PositionImpl, PositionImpl> cursorUpdated(ManagedCursor cursor, Position newPosition) {
checkNotNull(cursor);
requireNonNull(cursor);

long stamp = rwLock.writeLock();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.apache.bookkeeper.mledger.impl;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import static org.apache.bookkeeper.mledger.ManagedLedgerException.getManagedLedgerException;
import static org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.DEFAULT_LEDGER_DELETE_BACKOFF_TIME_SEC;
import static org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.DEFAULT_LEDGER_DELETE_RETRIES;
Expand All @@ -31,16 +31,16 @@
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Range;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.RateLimiter;
import com.google.protobuf.InvalidProtocolBufferException;
import java.time.Clock;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -370,7 +370,7 @@ public boolean putProperty(String key, Long value) {
if (lastMarkDeleteEntry != null) {
LAST_MARK_DELETE_ENTRY_UPDATER.updateAndGet(this, last -> {
Map<String, Long> properties = last.properties;
Map<String, Long> newProperties = properties == null ? Maps.newHashMap() : Maps.newHashMap(properties);
Map<String, Long> newProperties = properties == null ? new HashMap<>() : new HashMap<>(properties);
newProperties.put(key, value);

MarkDeleteEntry newLastMarkDeleteEntry = new MarkDeleteEntry(last.newPosition, newProperties,
Expand Down Expand Up @@ -417,7 +417,7 @@ public void operationComplete(ManagedCursorInfo info, Stat stat) {
Map<String, String> recoveredCursorProperties = Collections.emptyMap();
if (info.getCursorPropertiesCount() > 0) {
// Recover properties map
recoveredCursorProperties = Maps.newHashMap();
recoveredCursorProperties = new HashMap<>();
for (int i = 0; i < info.getCursorPropertiesCount(); i++) {
StringProperty property = info.getCursorProperties(i);
recoveredCursorProperties.put(property.getName(), property.getValue());
Expand All @@ -437,7 +437,7 @@ public void operationComplete(ManagedCursorInfo info, Stat stat) {
Map<String, Long> recoveredProperties = Collections.emptyMap();
if (info.getPropertiesCount() > 0) {
// Recover properties map
recoveredProperties = Maps.newHashMap();
recoveredProperties = new HashMap<>();
for (int i = 0; i < info.getPropertiesCount(); i++) {
LongProperty property = info.getProperties(i);
recoveredProperties.put(property.getName(), property.getValue());
Expand Down Expand Up @@ -525,7 +525,7 @@ protected void recoverFromLedger(final ManagedCursorInfo info, final VoidCallbac
Map<String, Long> recoveredProperties = Collections.emptyMap();
if (positionInfo.getPropertiesCount() > 0) {
// Recover properties map
recoveredProperties = Maps.newHashMap();
recoveredProperties = new HashMap<>();
for (int i = 0; i < positionInfo.getPropertiesCount(); i++) {
LongProperty property = positionInfo.getProperties(i);
recoveredProperties.put(property.getName(), property.getValue());
Expand Down Expand Up @@ -1379,7 +1379,7 @@ public Set<? extends Position> asyncReplayEntries(Set<? extends Position> positi
}

// filters out messages which are already acknowledged
Set<Position> alreadyAcknowledgedPositions = Sets.newHashSet();
Set<Position> alreadyAcknowledgedPositions = new HashSet<>();
lock.readLock().lock();
try {
positions.stream()
Expand Down Expand Up @@ -1492,7 +1492,7 @@ public void markDelete(Position position) throws InterruptedException, ManagedLe
@Override
public void markDelete(Position position, Map<String, Long> properties)
throws InterruptedException, ManagedLedgerException {
checkNotNull(position);
requireNonNull(position);
checkArgument(position instanceof PositionImpl);

class Result {
Expand Down Expand Up @@ -1792,7 +1792,7 @@ public void asyncMarkDelete(final Position position, final MarkDeleteCallback ca
@Override
public void asyncMarkDelete(final Position position, Map<String, Long> properties,
final MarkDeleteCallback callback, final Object ctx) {
checkNotNull(position);
requireNonNull(position);
checkArgument(position instanceof PositionImpl);

if (isClosed()) {
Expand Down Expand Up @@ -2032,7 +2032,7 @@ public void asyncDelete(Position pos, final AsyncCallbacks.DeleteCallback callba

@Override
public void delete(Iterable<Position> positions) throws InterruptedException, ManagedLedgerException {
checkNotNull(positions);
requireNonNull(positions);

class Result {
ManagedLedgerException exception = null;
Expand Down Expand Up @@ -2098,7 +2098,7 @@ public void asyncDelete(Iterable<Position> positions, AsyncCallbacks.DeleteCallb
}

for (Position pos : positions) {
PositionImpl position = (PositionImpl) checkNotNull(pos);
PositionImpl position = (PositionImpl) requireNonNull(pos);
if (((PositionImpl) ledger.getLastConfirmedEntry()).compareTo(position) < 0) {
if (log.isDebugEnabled()) {
log.debug(
Expand Down Expand Up @@ -2707,7 +2707,7 @@ private static List<LongProperty> buildPropertiesMap(Map<String, Long> propertie
return Collections.emptyList();
}

List<LongProperty> longProperties = Lists.newArrayList();
List<LongProperty> longProperties = new ArrayList<>();
properties.forEach((name, value) -> {
LongProperty lp = LongProperty.newBuilder().setName(name).setValue(value).build();
longProperties.add(lp);
Expand All @@ -2721,7 +2721,7 @@ private static List<StringProperty> buildStringPropertiesMap(Map<String, String>
return Collections.emptyList();
}

List<StringProperty> stringProperties = Lists.newArrayList();
List<StringProperty> stringProperties = new ArrayList<>();
properties.forEach((name, value) -> {
StringProperty sp = StringProperty.newBuilder().setName(name).setValue(value).build();
stringProperties.add(sp);
Expand All @@ -2741,7 +2741,7 @@ private List<MLDataFormats.MessageRange> buildIndividualDeletedMessageRanges() {
.newBuilder();
MLDataFormats.MessageRange.Builder messageRangeBuilder = MLDataFormats.MessageRange.newBuilder();
AtomicInteger acksSerializedSize = new AtomicInteger(0);
List<MessageRange> rangeList = Lists.newArrayList();
List<MessageRange> rangeList = new ArrayList<>();
individualDeletedMessages.forEach((positionRange) -> {
PositionImpl p = positionRange.lowerEndpoint();
nestedPositionBuilder.setLedgerId(p.getLedgerId());
Expand Down Expand Up @@ -2775,7 +2775,7 @@ private List<MLDataFormats.BatchedEntryDeletionIndexInfo> buildBatchEntryDeletio
.newBuilder();
MLDataFormats.BatchedEntryDeletionIndexInfo.Builder batchDeletedIndexInfoBuilder = MLDataFormats
.BatchedEntryDeletionIndexInfo.newBuilder();
List<MLDataFormats.BatchedEntryDeletionIndexInfo> result = Lists.newArrayList();
List<MLDataFormats.BatchedEntryDeletionIndexInfo> result = new ArrayList<>();
Iterator<Map.Entry<PositionImpl, BitSetRecyclable>> iterator = batchDeletedIndexes.entrySet().iterator();
while (iterator.hasNext() && result.size() < config.getMaxBatchDeletedIndexToPersist()) {
Map.Entry<PositionImpl, BitSetRecyclable> entry = iterator.next();
Expand Down Expand Up @@ -2811,7 +2811,7 @@ void persistPositionToLedger(final LedgerHandle lh, MarkDeleteEntry mdEntry, fin
position);
}

checkNotNull(lh);
requireNonNull(lh);
byte[] data = pi.toByteArray();
lh.asyncAddEntry(data, (rc, lh1, entryId, ctx) -> {
if (rc == BKException.Code.OK) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
Expand Down Expand Up @@ -693,7 +694,7 @@ public void operationComplete(MLDataFormats.ManagedLedgerInfo pbInfo, Stat stat)
}

if (pbInfo.getPropertiesCount() > 0) {
info.properties = Maps.newTreeMap();
info.properties = new TreeMap();
for (int i = 0; i < pbInfo.getPropertiesCount(); i++) {
MLDataFormats.KeyValue property = pbInfo.getProperties(i);
info.properties.put(property.getKey(), property.getValue());
Expand Down Expand Up @@ -744,7 +745,7 @@ public void operationComplete(ManagedCursorInfo pbCursorInfo, Stat stat) {
}

if (pbCursorInfo.getPropertiesCount() > 0) {
cursorInfo.properties = Maps.newTreeMap();
cursorInfo.properties = new TreeMap();
for (int i = 0; i < pbCursorInfo.getPropertiesCount(); i++) {
LongProperty property = pbCursorInfo.getProperties(i);
cursorInfo.properties.put(property.getName(), property.getValue());
Expand Down
Loading

0 comments on commit 40f0438

Please sign in to comment.