Skip to content

Commit

Permalink
Adds TransportClientFactories as required parameter to DiscoveryClient.
Browse files Browse the repository at this point in the history
Removes deprecated DiscoveryClient constructors.
  • Loading branch information
spencergibb committed Nov 15, 2022
1 parent 46dc731 commit 3b73bdb
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public abstract class AbstractDiscoveryClientOptionalArgs<T> {

TransportClientFactory transportClientFactory;

TransportClientFactories transportClientFactories;

private Set<EurekaEventListener> eventListeners;

private Optional<SSLContext> sslContext = Optional.empty();
Expand Down Expand Up @@ -82,16 +80,6 @@ public void setAdditionalFilters(Collection<T> additionalFilters) {
this.additionalFilters = additionalFilters;
}

public TransportClientFactories getTransportClientFactories() {
return transportClientFactories;
}

// @Inject
public void setTransportClientFactories(TransportClientFactories transportClientFactories) {
this.transportClientFactories = transportClientFactories;
}


public TransportClientFactory getTransportClientFactory() {
return transportClientFactory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,16 @@ public class DiscoveryClient implements EurekaClient {
protected final EurekaClientConfig clientConfig;
protected final EurekaTransportConfig transportConfig;

@SuppressWarnings("rawtypes")
protected final TransportClientFactories transportClientFactories;

private final long initTimestampMs;
private final int initRegistrySize;

private final Stats stats = new Stats();

private static final class EurekaTransport {
@SuppressWarnings("rawtypes")
private ClosableResolver bootstrapResolver;
private TransportClientFactory transportClientFactory;

Expand Down Expand Up @@ -228,34 +232,19 @@ void shutdown() {
}
}

/**
* Assumes applicationInfoManager is already initialized
*
* @deprecated use constructor that takes ApplicationInfoManager instead of InstanceInfo directly
*/
@Deprecated
public DiscoveryClient(InstanceInfo myInfo, EurekaClientConfig config) {
this(myInfo, config, null);
}

/**
* @deprecated use constructor that takes ApplicationInfoManager instead of InstanceInfo directly
*/
@Deprecated
public DiscoveryClient(InstanceInfo myInfo, EurekaClientConfig config, AbstractDiscoveryClientOptionalArgs args) {
this(ApplicationInfoManager.getInstance(), config, args);
}

public DiscoveryClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig config) {
this(applicationInfoManager, config, null);
@SuppressWarnings("rawtypes")
public DiscoveryClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig config, TransportClientFactories transportClientFactories) {
this(applicationInfoManager, config, transportClientFactories, null);
}

public DiscoveryClient(ApplicationInfoManager applicationInfoManager, final EurekaClientConfig config, AbstractDiscoveryClientOptionalArgs args) {
this(applicationInfoManager, config, args, ResolverUtils::randomize);
@SuppressWarnings("rawtypes")
public DiscoveryClient(ApplicationInfoManager applicationInfoManager, final EurekaClientConfig config, TransportClientFactories transportClientFactories, AbstractDiscoveryClientOptionalArgs args) {
this(applicationInfoManager, config, transportClientFactories, args, ResolverUtils::randomize);
}

public DiscoveryClient(ApplicationInfoManager applicationInfoManager, final EurekaClientConfig config, AbstractDiscoveryClientOptionalArgs args, EndpointRandomizer randomizer) {
this(applicationInfoManager, config, args, new Provider<BackupRegistry>() {
@SuppressWarnings("rawtypes")
public DiscoveryClient(ApplicationInfoManager applicationInfoManager, final EurekaClientConfig config, TransportClientFactories transportClientFactories, AbstractDiscoveryClientOptionalArgs args, EndpointRandomizer randomizer) {
this(applicationInfoManager, config, transportClientFactories, args, new Provider<BackupRegistry>() {
private volatile BackupRegistry backupRegistryInstance;

@Override
Expand Down Expand Up @@ -286,17 +275,8 @@ public synchronized BackupRegistry get() {
}, randomizer);
}

/**
* @deprecated Use {@link #DiscoveryClient(ApplicationInfoManager, EurekaClientConfig, AbstractDiscoveryClientOptionalArgs, Provider<BackupRegistry>, EndpointRandomizer)}
*/
@Deprecated
DiscoveryClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig config, AbstractDiscoveryClientOptionalArgs args,
Provider<BackupRegistry> backupRegistryProvider) {
this(applicationInfoManager, config, args, backupRegistryProvider, ResolverUtils::randomize);
}

@Inject
DiscoveryClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig config, AbstractDiscoveryClientOptionalArgs args,
DiscoveryClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig config, TransportClientFactories transportClientFactories, AbstractDiscoveryClientOptionalArgs args,
Provider<BackupRegistry> backupRegistryProvider, EndpointRandomizer endpointRandomizer) {
if (args != null) {
this.healthCheckHandlerProvider = args.healthCheckHandlerProvider;
Expand All @@ -308,7 +288,7 @@ public synchronized BackupRegistry get() {
this.healthCheckHandlerProvider = null;
this.preRegistrationHandler = null;
}

this.transportClientFactories = transportClientFactories;
this.applicationInfoManager = applicationInfoManager;
InstanceInfo myInfo = applicationInfoManager.getInfo();

Expand Down Expand Up @@ -468,6 +448,7 @@ public synchronized BackupRegistry get() {
initTimestampMs, initRegistrySize);
}

@SuppressWarnings("unchecked")
private void scheduleServerEndpointTask(EurekaTransport eurekaTransport,
AbstractDiscoveryClientOptionalArgs args) {

Expand All @@ -476,13 +457,6 @@ private void scheduleServerEndpointTask(EurekaTransport eurekaTransport,
? Collections.emptyList()
: args.additionalFilters;

@SuppressWarnings("rawtypes")
// Ignore the raw types warnings since the client filter interface changed between jersey 1/2
TransportClientFactories transportClientFactories = null;
if (args != null && args.getTransportClientFactories() != null) {
transportClientFactories = args.getTransportClientFactories();
}

if (transportClientFactories == null) {
throw new IllegalArgumentException("transportClientFactories may not be null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import com.netflix.appinfo.ApplicationInfoManager;
import com.netflix.appinfo.EurekaInstanceConfig;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.shared.LookupService;
import com.netflix.discovery.shared.transport.jersey.TransportClientFactories;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -80,20 +80,14 @@ public void setEurekaInstanceConfig(EurekaInstanceConfig eurekaInstanceConfig) {
* @param eurekaConfig the eureka client configuration of the instance.
*/
public void initComponent(EurekaInstanceConfig config,
EurekaClientConfig eurekaConfig, AbstractDiscoveryClientOptionalArgs args) {
EurekaClientConfig eurekaConfig, TransportClientFactories transportClientFactories, AbstractDiscoveryClientOptionalArgs args) {
this.eurekaInstanceConfig = config;
this.eurekaClientConfig = eurekaConfig;
if (ApplicationInfoManager.getInstance().getInfo() == null) {
// Initialize application info
ApplicationInfoManager.getInstance().initComponent(config);
}
InstanceInfo info = ApplicationInfoManager.getInstance().getInfo();
discoveryClient = new DiscoveryClient(info, eurekaConfig, args);
}

public void initComponent(EurekaInstanceConfig config,
EurekaClientConfig eurekaConfig) {
initComponent(config, eurekaConfig, null);
discoveryClient = new DiscoveryClient(ApplicationInfoManager.getInstance(), eurekaConfig, transportClientFactories, args);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ public Name getName() {

backupRegistry = new MockBackupRegistry();
setupBackupMock();
Jersey3DiscoveryClientOptionalArgs args = new Jersey3DiscoveryClientOptionalArgs();
args.setTransportClientFactories(Jersey3TransportClientFactories.getInstance());
client = new DiscoveryClient(
applicationInfoManager,
new DefaultEurekaClientConfig(),
args,
Jersey3TransportClientFactories.getInstance(),
null,
() -> backupRegistry,
ResolverUtils::randomize
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.netflix.appinfo.InstanceInfo;
import com.netflix.appinfo.MyDataCenterInstanceConfig;
import com.netflix.config.ConfigurationManager;
import com.netflix.discovery.shared.transport.jersey3.Jersey3TransportClientFactories;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -42,7 +43,7 @@ public Name getName() {
});

ApplicationInfoManager applicationInfoManager = new ApplicationInfoManager(new MyDataCenterInstanceConfig(), builder.build());
client = new DiscoveryClient(applicationInfoManager, new DefaultEurekaClientConfig());
client = new DiscoveryClient(applicationInfoManager, new DefaultEurekaClientConfig(), Jersey3TransportClientFactories.getInstance());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public void testDoNotUnregisterOnShutdown() throws Exception {

private Jersey3DiscoveryClientOptionalArgs getOptionalArgs() {
Jersey3DiscoveryClientOptionalArgs optionalArgs = new Jersey3DiscoveryClientOptionalArgs();
optionalArgs.setTransportClientFactories(Jersey3TransportClientFactories.getInstance());
return optionalArgs;
}

Expand All @@ -171,7 +170,7 @@ private static <T> T getLast(List<T> list) {
private static class TestClient extends DiscoveryClient {

public TestClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig config, AbstractDiscoveryClientOptionalArgs optionalArgs) {
super(applicationInfoManager, config, optionalArgs);
super(applicationInfoManager, config, Jersey3TransportClientFactories.getInstance(), optionalArgs);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.netflix.discovery.DiscoveryClient;
import com.netflix.discovery.EurekaClientConfig;
import com.netflix.discovery.Jersey3DiscoveryClientOptionalArgs;
import com.netflix.discovery.shared.transport.jersey.TransportClientFactories;
import com.netflix.discovery.shared.transport.jersey3.Jersey3TransportClientFactories;
import com.netflix.eureka.cluster.Jersey3PeerEurekaNodes;
import com.netflix.eureka.cluster.PeerEurekaNodes;
Expand Down Expand Up @@ -44,10 +45,14 @@ protected PeerEurekaNodes getPeerEurekaNodes(PeerAwareInstanceRegistry registry,
@Override
protected AbstractDiscoveryClientOptionalArgs<?> getDiscoveryClientOptionalArgs() {
Jersey3DiscoveryClientOptionalArgs jersey3DiscoveryClientOptionalArgs = new Jersey3DiscoveryClientOptionalArgs();
jersey3DiscoveryClientOptionalArgs.setTransportClientFactories(Jersey3TransportClientFactories.getInstance());
return jersey3DiscoveryClientOptionalArgs;
}

@Override
protected TransportClientFactories getTransportClientFactories() {
return Jersey3TransportClientFactories.getInstance();
}

@Override
protected EurekaServerHttpClientFactory getEurekaServerHttpClientFactory() {
return new Jersey3EurekaServerHttpClientFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.netflix.eureka;

import com.netflix.discovery.AbstractDiscoveryClientOptionalArgs;
import com.netflix.discovery.shared.transport.jersey.TransportClientFactories;
import com.netflix.eureka.transport.EurekaServerHttpClientFactory;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletContextEvent;
Expand Down Expand Up @@ -168,7 +169,8 @@ protected void initEurekaServerContext() throws Exception {
instanceConfig, new EurekaConfigBasedInstanceInfoProvider(instanceConfig).get());

EurekaClientConfig eurekaClientConfig = new DefaultEurekaClientConfig();
eurekaClient = new DiscoveryClient(applicationInfoManager, eurekaClientConfig, getDiscoveryClientOptionalArgs());
eurekaClient = new DiscoveryClient(applicationInfoManager, eurekaClientConfig, getTransportClientFactories(),
getDiscoveryClientOptionalArgs());
} else {
applicationInfoManager = eurekaClient.getApplicationInfoManager();
}
Expand Down Expand Up @@ -227,6 +229,8 @@ protected AbstractDiscoveryClientOptionalArgs<?> getDiscoveryClientOptionalArgs(
return null;
}

protected abstract TransportClientFactories getTransportClientFactories();

protected abstract EurekaServerHttpClientFactory getEurekaServerHttpClientFactory();

protected abstract PeerEurekaNodes getPeerEurekaNodes(PeerAwareInstanceRegistry registry, EurekaServerConfig eurekaServerConfig, EurekaClientConfig eurekaClientConfig, ServerCodecs serverCodecs, ApplicationInfoManager applicationInfoManager);
Expand Down
2 changes: 1 addition & 1 deletion eureka-examples/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'application'

dependencies {
implementation project(':eureka-client')
implementation project(':eureka-client-jersey3')
implementation files('conf')
implementation 'jakarta.inject:jakarta.inject-api:2.0.1'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.netflix.discovery.DiscoveryClient;
import com.netflix.discovery.EurekaClient;
import com.netflix.discovery.EurekaClientConfig;
import com.netflix.discovery.shared.transport.jersey3.Jersey3TransportClientFactories;

/**
* Sample Eureka client that discovers the example service using Eureka and sends requests.
Expand All @@ -57,7 +58,7 @@ private static synchronized ApplicationInfoManager initializeApplicationInfoMana

private static synchronized EurekaClient initializeEurekaClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig clientConfig) {
if (eurekaClient == null) {
eurekaClient = new DiscoveryClient(applicationInfoManager, clientConfig);
eurekaClient = new DiscoveryClient(applicationInfoManager, clientConfig, Jersey3TransportClientFactories.getInstance());
}

return eurekaClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.discovery.DefaultEurekaClientConfig;
import com.netflix.discovery.EurekaClientConfig;
import com.netflix.discovery.shared.transport.jersey3.Jersey3TransportClientFactories;

/**
* Sample Eureka service that registers with Eureka to receive and process requests.
Expand All @@ -49,7 +50,7 @@ private static synchronized ApplicationInfoManager initializeApplicationInfoMana

private static synchronized EurekaClient initializeEurekaClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig clientConfig) {
if (eurekaClient == null) {
eurekaClient = new DiscoveryClient(applicationInfoManager, clientConfig);
eurekaClient = new DiscoveryClient(applicationInfoManager, clientConfig, Jersey3TransportClientFactories.getInstance());
}

return eurekaClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ public EurekaClient getClient() {
EurekaClientConfig clientConfig = createEurekaClientConfig();

Jersey3DiscoveryClientOptionalArgs args = new Jersey3DiscoveryClientOptionalArgs();
args.setTransportClientFactories(new Jersey3TransportClientFactories()); eventBus = new EventBusImpl();
eventBus = new EventBusImpl();
args.setEventBus(eventBus);

client = new DiscoveryClient(applicationInfoManager, clientConfig, args);
client = new DiscoveryClient(applicationInfoManager, clientConfig, Jersey3TransportClientFactories.getInstance(), args);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -253,9 +253,7 @@ public static EurekaClient setupDiscoveryClient(InstanceInfo clientInstanceInfo)
ApplicationInfoManager applicationInfoManager = new ApplicationInfoManager(new MyDataCenterInstanceConfig(), clientInstanceInfo);

DiscoveryManager.getInstance().setEurekaClientConfig(config);
Jersey3DiscoveryClientOptionalArgs args = new Jersey3DiscoveryClientOptionalArgs();
args.setTransportClientFactories(new Jersey3TransportClientFactories());
EurekaClient client = new DiscoveryClient(applicationInfoManager, config, args);
EurekaClient client = new DiscoveryClient(applicationInfoManager, config, Jersey3TransportClientFactories.getInstance());
return client;
}

Expand All @@ -265,10 +263,8 @@ public static EurekaClient setupInjector(InstanceInfo clientInstanceInfo) {
DefaultEurekaClientConfig config = new DefaultEurekaClientConfig();
// setup config in advance, used in initialize converter
DiscoveryManager.getInstance().setEurekaClientConfig(config);
Jersey3DiscoveryClientOptionalArgs args = new Jersey3DiscoveryClientOptionalArgs();
args.setTransportClientFactories(new Jersey3TransportClientFactories());
EurekaClient client = new DiscoveryClient(clientInstanceInfo, config, args);
ApplicationInfoManager.getInstance().initComponent(new MyDataCenterInstanceConfig());
ApplicationInfoManager applicationInfoManager1 = new ApplicationInfoManager(new MyDataCenterInstanceConfig(), clientInstanceInfo);
EurekaClient client = new DiscoveryClient(applicationInfoManager1, config, Jersey3TransportClientFactories.getInstance());
return client;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ public void setUp() throws Exception {
InstanceInfo instanceInfo = builder.build();
ApplicationInfoManager applicationInfoManager = new ApplicationInfoManager(new MyDataCenterInstanceConfig(), instanceInfo);

Jersey3DiscoveryClientOptionalArgs args = new Jersey3DiscoveryClientOptionalArgs();
args.setTransportClientFactories(new Jersey3TransportClientFactories());
client = new DiscoveryClient(applicationInfoManager, clientConfig, args);
client = new DiscoveryClient(applicationInfoManager, clientConfig, Jersey3TransportClientFactories.getInstance());

ServerCodecs serverCodecs = new DefaultServerCodecs(serverConfig);
EurekaServerHttpClientFactory eurekaServerHttpClientFactory = new Jersey3EurekaServerHttpClientFactory();
Expand Down

0 comments on commit 3b73bdb

Please sign in to comment.