Skip to content

Commit

Permalink
Merge branch 'main' of github.com:spring-cloud/spring-cloud-commons
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanjbaxter committed Sep 4, 2024
2 parents c2707f8 + 5412d6d commit 9bbed9f
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 14 deletions.
16 changes: 16 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ updates:
target-branch: "4.0.x" # oldest OSS supported branch
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"
directory: "/"
target-branch: "4.1.x"
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"
directory: "/"
target-branch: "main"
Expand Down Expand Up @@ -37,6 +42,17 @@ updates:
update-types:
- version-update:semver-major
- version-update:semver-minor
- package-ecosystem: maven
directory: /
schedule:
interval: daily
target-branch: 4.1.x
ignore:
# only upgrade patch versions for maintenance branch
- dependency-name: "*"
update-types:
- version-update:semver-major
- version-update:semver-minor
- package-ecosystem: maven
directory: /
schedule:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name: Build

on:
push:
branches: [ main, 4.1.x, 4.0.x, 3.1.x ]
branches: [ main, 4.1.x ]
pull_request:
branches: [ main, 4.1.x, 4.0.x, 3.1.x ]
branches: [ main, 4.1.x ]

jobs:
build:
Expand Down
6 changes: 6 additions & 0 deletions spring-cloud-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,11 @@
<artifactId>micrometer-observation-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.16.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,11 +29,13 @@
import org.springframework.cloud.client.loadbalancer.EmptyResponse;
import org.springframework.cloud.client.loadbalancer.Request;
import org.springframework.cloud.client.loadbalancer.Response;
import org.springframework.util.function.SingletonSupplier;

/**
* A random-based implementation of {@link ReactorServiceInstanceLoadBalancer}.
*
* @author Olga Maciaszek-Sharma
* @author Nan Chiu
* @since 2.2.7
*/
public class RandomLoadBalancer implements ReactorServiceInstanceLoadBalancer {
Expand All @@ -42,7 +44,7 @@ public class RandomLoadBalancer implements ReactorServiceInstanceLoadBalancer {

private final String serviceId;

private ObjectProvider<ServiceInstanceListSupplier> serviceInstanceListSupplierProvider;
private final SingletonSupplier<ServiceInstanceListSupplier> serviceInstanceListSingletonSupplier;

/**
* @param serviceInstanceListSupplierProvider a provider of
Expand All @@ -52,14 +54,14 @@ public class RandomLoadBalancer implements ReactorServiceInstanceLoadBalancer {
public RandomLoadBalancer(ObjectProvider<ServiceInstanceListSupplier> serviceInstanceListSupplierProvider,
String serviceId) {
this.serviceId = serviceId;
this.serviceInstanceListSupplierProvider = serviceInstanceListSupplierProvider;
this.serviceInstanceListSingletonSupplier = SingletonSupplier
.of(() -> serviceInstanceListSupplierProvider.getIfAvailable(NoopServiceInstanceListSupplier::new));
}

@SuppressWarnings("rawtypes")
@Override
public Mono<Response<ServiceInstance>> choose(Request request) {
ServiceInstanceListSupplier supplier = serviceInstanceListSupplierProvider
.getIfAvailable(NoopServiceInstanceListSupplier::new);
ServiceInstanceListSupplier supplier = serviceInstanceListSingletonSupplier.obtain();
return supplier.get(request)
.next()
.map(serviceInstances -> processInstanceResponse(supplier, serviceInstances));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,13 +30,15 @@
import org.springframework.cloud.client.loadbalancer.EmptyResponse;
import org.springframework.cloud.client.loadbalancer.Request;
import org.springframework.cloud.client.loadbalancer.Response;
import org.springframework.util.function.SingletonSupplier;

/**
* A Round-Robin-based implementation of {@link ReactorServiceInstanceLoadBalancer}.
*
* @author Spencer Gibb
* @author Olga Maciaszek-Sharma
* @author Zhuozhi JI
* @author Nan Chiu
*/
public class RoundRobinLoadBalancer implements ReactorServiceInstanceLoadBalancer {

Expand All @@ -46,7 +48,7 @@ public class RoundRobinLoadBalancer implements ReactorServiceInstanceLoadBalance

final String serviceId;

ObjectProvider<ServiceInstanceListSupplier> serviceInstanceListSupplierProvider;
private final SingletonSupplier<ServiceInstanceListSupplier> serviceInstanceListSingletonSupplier;

/**
* @param serviceInstanceListSupplierProvider a provider of
Expand All @@ -67,7 +69,8 @@ public RoundRobinLoadBalancer(ObjectProvider<ServiceInstanceListSupplier> servic
public RoundRobinLoadBalancer(ObjectProvider<ServiceInstanceListSupplier> serviceInstanceListSupplierProvider,
String serviceId, int seedPosition) {
this.serviceId = serviceId;
this.serviceInstanceListSupplierProvider = serviceInstanceListSupplierProvider;
this.serviceInstanceListSingletonSupplier = SingletonSupplier
.of(() -> serviceInstanceListSupplierProvider.getIfAvailable(NoopServiceInstanceListSupplier::new));
this.position = new AtomicInteger(seedPosition);
}

Expand All @@ -77,8 +80,7 @@ public RoundRobinLoadBalancer(ObjectProvider<ServiceInstanceListSupplier> servic
// https://github.com/Netflix/ocelli/blob/master/ocelli-core/
// src/main/java/netflix/ocelli/loadbalancer/RoundRobinLoadBalancer.java
public Mono<Response<ServiceInstance>> choose(Request request) {
ServiceInstanceListSupplier supplier = serviceInstanceListSupplierProvider
.getIfAvailable(NoopServiceInstanceListSupplier::new);
ServiceInstanceListSupplier supplier = serviceInstanceListSingletonSupplier.obtain();
return supplier.get(request)
.next()
.map(serviceInstances -> processInstanceResponse(supplier, serviceInstances));
Expand Down
4 changes: 2 additions & 2 deletions spring-cloud-test-support/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<name>spring-cloud-test-support</name>
<description>Spring Cloud Test Support</description>
<properties>
<maven.version>3.9.5</maven.version>
<maven-resolver.version>1.9.16</maven-resolver.version>
<maven.version>3.9.9</maven.version>
<maven-resolver.version>1.9.22</maven-resolver.version>
</properties>
<dependencies>
<dependency>
Expand Down

0 comments on commit 9bbed9f

Please sign in to comment.