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

Java 21 upgrade #52

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion drift-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
</dependency>

<dependency>
<groupId>io.airlift</groupId>
<groupId>com.facebook.airlift</groupId>
<artifactId>units</artifactId>
</dependency>

Expand All @@ -97,6 +97,11 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.gaul</groupId>
<artifactId>modernizer-maven-annotations</artifactId>
</dependency>

<!-- for testing -->
<dependency>
<groupId>com.facebook.airlift</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import io.airlift.units.Duration;
import org.gaul.modernizer_maven_annotations.SuppressModernizer;

import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;
Expand Down Expand Up @@ -148,6 +149,7 @@ private DriftMethodInvocation(
}, directExecutor());
}

@SuppressModernizer
private synchronized void nextAttempt(boolean noConnectDelay)
{
try {
Expand All @@ -157,29 +159,30 @@ private synchronized void nextAttempt(boolean noConnectDelay)
}

Optional<A> address = addressSelector.selectAddress(addressSelectionContext, attemptedAddresses);
if (!address.isPresent()) {
if (address.isEmpty()) {
fail("No hosts available");
return;
}
A addr = address.get();

if (invocationAttempts > 0) {
stat.recordRetry();
}

if (noConnectDelay) {
invoke(address.get());
invoke(addr);
return;
}

int connectionFailuresCount = failedConnectionAttempts.count(address.get());
int connectionFailuresCount = failedConnectionAttempts.count(addr);
if (connectionFailuresCount == 0) {
invoke(address.get());
invoke(addr);
return;
}

Duration connectDelay = retryPolicy.getBackoffDelay(connectionFailuresCount);
log.debug("Failed connection to %s with attempt %s, will retry in %s", address.get(), connectionFailuresCount, connectDelay);
schedule(connectDelay, () -> invoke(address.get()));
log.debug("Failed connection to %s with attempt %s, will retry in %s", addr, connectionFailuresCount, connectDelay);
schedule(connectDelay, () -> invoke(addr));
}
catch (Throwable t) {
// this should never happen, but ensure that invocation always finishes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,10 @@ public ExceptionClassification toExceptionClassification()
@SuppressWarnings("OptionalIsPresent")
public static Optional<Boolean> mergeRetry(Optional<Boolean> oldRetry, Optional<Boolean> newRetry)
{
if (!oldRetry.isPresent()) {
return newRetry;
}
if (!newRetry.isPresent()) {
return oldRetry;
}
return Optional.of(oldRetry.get() && newRetry.get());
return oldRetry.map(oldOne ->
newRetry.map(newOne -> oldOne && newOne)
.orElse(false))
.or(() -> newRetry);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ public void testGuiceClient()
LifeCycleManager lifeCycleManager = null;
try {
Injector injector = app
.strictConfig()
.doNotInitializeLogging()
.initialize();
lifeCycleManager = injector.getInstance(LifeCycleManager.class);
Expand Down Expand Up @@ -238,7 +237,6 @@ public void testGuiceClientFilter()
LifeCycleManager lifeCycleManager = null;
try {
Injector injector = app
.strictConfig()
.doNotInitializeLogging()
.initialize();
lifeCycleManager = injector.getInstance(LifeCycleManager.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ private static void testAddressSelector(
try {
Injector injector = app
.setRequiredConfigurationProperties(configurationProperties)
.strictConfig()
.doNotInitializeLogging()
.initialize();
lifeCycleManager = injector.getInstance(LifeCycleManager.class);
Expand Down
4 changes: 3 additions & 1 deletion drift-codec-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<dependency>
<groupId>com.facebook.drift</groupId>
<artifactId>drift-api</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
Expand All @@ -38,7 +39,7 @@
</dependency>

<dependency>
<groupId>io.airlift</groupId>
<groupId>com.facebook.airlift</groupId>
<artifactId>units</artifactId>
</dependency>

Expand All @@ -60,6 +61,7 @@
</dependency>

<!-- for testing -->

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
Expand Down
7 changes: 6 additions & 1 deletion drift-codec/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<dependency>
<groupId>com.facebook.airlift</groupId>
<artifactId>bytecode</artifactId>
<version>1.3</version>
<version>1.4-SNAPSHOT</version>
</dependency>

<dependency>
Expand All @@ -56,6 +56,11 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.gaul</groupId>
<artifactId>modernizer-maven-annotations</artifactId>
</dependency>

<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.facebook.drift.protocol.TProtocolReader;
import com.facebook.drift.protocol.TProtocolWriter;
import com.google.common.reflect.TypeToken;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.lang.reflect.Type;

Expand All @@ -35,6 +36,7 @@ public class DelegateCodec<T>
private final ThriftCodecManager codecManager;
private final TypeToken<T> typeToken;

@SuppressFBWarnings("EI_EXPOSE_REP2")
public DelegateCodec(ThriftCodecManager codecManager, Type javaType)
{
this.codecManager = codecManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.TypeToken;
import com.google.inject.Inject;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import javax.annotation.concurrent.ThreadSafe;

Expand Down Expand Up @@ -286,6 +287,7 @@ private void addBuiltinCodec(ThriftCodec<?> codec)
typeCodecs.put(codec.getType(), codec);
}

@SuppressFBWarnings("EI_EXPOSE_REP")
public ThriftCatalog getCatalog()
{
return catalog;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.inject.Module;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.util.Objects;

Expand All @@ -41,11 +42,13 @@ public ThriftCodecModule()
this(ThriftCodecModule.class.getClassLoader());
}

@SuppressFBWarnings("EI_EXPOSE_REP2")
public ThriftCodecModule(ClassLoader parent)
{
this.parent = parent;
}

@SuppressFBWarnings("EI_EXPOSE_REP2")
@Override
public void configure(Binder binder)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.facebook.drift.protocol.TSet;
import com.facebook.drift.protocol.TStruct;
import com.facebook.drift.protocol.TType;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import javax.annotation.concurrent.NotThreadSafe;

Expand All @@ -37,6 +38,7 @@ public class ProtocolWriter
{
private final TProtocolWriter protocol;

@SuppressFBWarnings("EI_EXPOSE_REP2")
public ProtocolWriter(TProtocolWriter protocol)
{
this.protocol = protocol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ public void write(Optional<T> value, TProtocolWriter protocol)
requireNonNull(protocol, "protocol is null");
// write can not be called with a missing value, and instead the write should be skipped
// after check the result from isNull
if (!value.isPresent()) {
throw new IllegalArgumentException("value is not present");
}
elementCodec.write(value.get(), protocol);
elementCodec.write(value.orElseThrow(() -> new IllegalArgumentException("value is not present")), protocol);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.facebook.drift.codec.metadata.TypeCoercion;
import com.facebook.drift.protocol.TProtocolReader;
import com.facebook.drift.protocol.TProtocolWriter;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import javax.annotation.concurrent.Immutable;

Expand All @@ -35,6 +36,7 @@ public class CoercionThriftCodec<T>
private final TypeCoercion typeCoercion;
private final ThriftType thriftType;

@SuppressFBWarnings("EI_EXPOSE_REP2")
public CoercionThriftCodec(ThriftCodec<?> codec, TypeCoercion typeCoercion)
{
this.codec = (ThriftCodec<Object>) codec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@

import javax.annotation.concurrent.Immutable;

import java.security.AccessController;
import java.security.PrivilegedAction;

/**
* Creates Thrift codecs directly in byte code.
*/
Expand All @@ -46,13 +43,13 @@ public CompilerThriftCodecFactory(@ForCompiler ClassLoader parent)

public CompilerThriftCodecFactory(boolean debug)
{
this(debug, getPrivilegedClassLoader(CompilerThriftCodecFactory.class.getClassLoader()));
this(debug, new DynamicClassLoader(CompilerThriftCodecFactory.class.getClassLoader()));
}

public CompilerThriftCodecFactory(boolean debug, ClassLoader parent)
{
this.debug = debug;
this.classLoader = getPrivilegedClassLoader(parent);
this.classLoader = new DynamicClassLoader(parent);
}

@Override
Expand All @@ -65,9 +62,4 @@ public ThriftCodec<?> generateThriftTypeCodec(ThriftCodecManager codecManager, T
debug);
return generator.getThriftCodec();
}

private static DynamicClassLoader getPrivilegedClassLoader(ClassLoader parent)
{
return AccessController.doPrivileged((PrivilegedAction<DynamicClassLoader>) () -> new DynamicClassLoader(parent));
}
}
Loading
Loading