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

upgrade to java 11 #2

Merged
merged 1 commit into from
Mar 4, 2024
Merged
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
4 changes: 2 additions & 2 deletions concurrency-loadbalancer-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -48,7 +48,7 @@
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<artifactId>powermock-api-mockito2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
* </p>
* Example:
* <pre>
* {@code
* ArrayList<String> entries = new ArrayList<String>() {{add("a"); add("b");}};
*
* ArrayConcurrencyLoadBalancer<String> loadBalancer = ArrayConcurrencyLoadBalancer.newBuilder()
* .withTasks(entries)
* .build();
* loadBalancer.next();
* }
* </pre>
*
* @param <T> the type parameter
*/
public final class ArrayConcurrencyLoadBalancer<T> extends AbstractConcurrencyLoadBalancer<T> {
private static final TaskConcurrency LEAST_TASK_CONCURRENCY = new TaskConcurrency.Noop(Integer.MAX_VALUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* </P>
* Example:
* <pre>
* {@code
* ArrayList<String> urls = new ArrayList<String>() {{add("http://192.168.0.1:80"); add("http://192.168.0.2:80");}};
*
* HeapConcurrencyLoadBalancer<String> loadBalancer = HeapConcurrencyLoadBalancer.newBuilder()
Expand All @@ -37,9 +38,8 @@
* CompletableTask<String> url = loadBalancer.next();
* boolean succeed = doPost(url.getTask()); //make rest call with url.getTask()
* url.complete(succeed); //finish the task
*
* }
* </pre>
* @param <T> the type parameter
*/
public final class HeapConcurrencyLoadBalancer<T> extends AbstractConcurrencyLoadBalancer<T> {
private final TaskConcurrencyQueue<T> taskConcurrencyQueue;
Expand Down Expand Up @@ -75,10 +75,12 @@ TaskConcurrencyQueue<T> getTaskConcurrencyQueue() {
*
* To prevent surge of failure, specify timeout to treat failure as timeout
* <pre>
* {@code
* HeapConcurrencyLoadBalancer<String> loadBalancer = HeapConcurrencyLoadBalancer.newBuilder(String.class)
* .withTasks(entries)
* .withTimeout(Duration.ofSeconds(10))
* .build();
* }
* </pre>
* @param <T> the type parameter
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.ImmutableList;

import javax.annotation.concurrent.ThreadSafe;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
Expand All @@ -12,18 +13,18 @@
* interaction evenly across all entities with index
*
* Example:
* {@code
* String[] tasks = new String[]{"a", "b", "c", "d", "e"};
*
* RoundRobinLoadBalancer lb = RoundRobinLoadBalancer
* .newBuilder()
* .withTasks(Arrays.asList(tasks))
* .build();
* return lb.next();
*
* @ThreadSafe
*
* }
* @param <T> the type parameter
*/
@ThreadSafe
public final class RoundRobinLoadBalancer<T> implements LoadBalancer<T> {
private final ImmutableList<T> tasks;
private final AtomicInteger index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public interface TaskConcurrency<T> extends Comparable<TaskConcurrency> {

/**
* Acquire task
*
* @return concurrency
*/
default void acquire() {
acquire(1);
Expand All @@ -29,7 +27,6 @@ default void acquire() {
*
* @param succeed the result
* @param latency the latency
* @return concurrency
*/
default void complete(boolean succeed, Duration latency) {
complete(1, latency);
Expand All @@ -39,7 +36,6 @@ default void complete(boolean succeed, Duration latency) {
* Acquire tasks in batch
*
* @param n number of requests processed
* @return the int
*/
void acquire(int n);

Expand All @@ -48,7 +44,6 @@ default void complete(boolean succeed, Duration latency) {
*
* @param n number of requests
* @param latency total duration
* @return concurrency
*/
void complete(int n, Duration latency);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Ticker;

import javax.annotation.concurrent.ThreadSafe;
import java.time.Duration;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Consumer;
Expand All @@ -21,22 +22,23 @@
* for this case .check() @12s will call consumer.accept(2)
* Example:
* <pre>
* {@code
* WindowScheduledCounter scheduledCounter = WindowScheduledCounter.newBuilder()
* .withMaxDelay(Duration.ofSeconds(30))
* .withNumWindow(100)
* .of(consumer);
* scheduledCounter.schedule(1, Duration.ofMillis(delayMs));
* scheduledCounter.check() //check and push count to consumer
* }
* </pre>
*
* <p>
* Performance related
* more windows indicates higher precision but also more CPU cost
* ScheduledCounter use the number of window as its concurrency limit, when the limit reached
* </p>
*
* @TheadSafe
*/
@ThreadSafe
public class WindowScheduledCounter implements ScheduledCounter {
final LifespanTracker lifespanTracker;
private final Consumer<Long> consumer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.Set;

/**
* HashIndexedPriorityQueue implemented both interfaces of Queue<> and Set<>
* HashIndexedPriorityQueue implemented both interfaces of Queue and Set
* Comparing with {@link java.util.PriorityQueue}, HashIndexedPriorityQueue
* - reduced contains(obj)/remove(obj) complexity from O(n) to O(logN)
* - offer(obj)/add(obj) ensures uniqueness
Expand All @@ -31,6 +31,7 @@
*
* Example: Suppose class Entity.value is Integer
* <pre>
* {@code
* class Entity {
* int value;
* Entity(int v) {
Expand All @@ -42,6 +43,7 @@
* //add entities into queue
* entity1.value+=1; //change order of entity
* queue.offer(entity1) //if entity1 is not in the queue, it will be added. otherwise order of entity1 will be in-place adjusted
* }
* </pre>
*
* @param <E> the type parameter
Expand Down Expand Up @@ -73,7 +75,7 @@ public HashIndexedPriorityQueue(Comparator<E> comparator) {

/**
* Instantiates a new Hash indexed priority queue.
* use (e1, e2) -> e1.compareTo(e2) as default comparator
* use {@code(e1, e2) -> e1.compareTo(e2)} as default comparator
*/
public HashIndexedPriorityQueue() {
this(null);
Expand All @@ -94,7 +96,7 @@ public int size() {
* 2. adjust order in-place with O(logn) complexity, if obj exist.
*
* @param e entity to add or update order
* @return
* @return true indicates element added successfully
*/
@Override
public boolean offer(E e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
*
* Example:
* <pre>
* {@code
* ReservoirSampler<Entity> sampler = new ReservoirSampler();
* for(Entity e : entities) {
* sampler.sample(e);
* }
* Entity selected = sampler.get();
* }
* </pre>
* @param <T> the entity type
*/
Expand Down
4 changes: 2 additions & 2 deletions concurrency-loadbalancer-m3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -57,7 +57,7 @@
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<artifactId>powermock-api-mockito2</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
* usage:
* <pre>
* {@code
* TallyMetricsTaskListener listener = TallyMetricsTaskListener.newBuilder(String.class)
* .withName("my-loadBalancer")
* .build(mockScope);
Expand All @@ -25,6 +26,7 @@
* .withTasks(entries)
* .withTaskListener(listener)
* .build();
* }
* </pre>
* @param <T> the type parameter
*/
Expand Down
4 changes: 2 additions & 2 deletions concurrency-loadbalancer-tracing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -49,7 +49,7 @@
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<artifactId>powermock-api-mockito2</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*
* Usage:
* <pre>
* {@code
* TracingTaskListener<String> listener = TracingTaskListener.newBuilder(String.class)
* .withName("a-loadBalancer")
* .withTaskNameMapper(o->o+"Name")
Expand All @@ -19,8 +20,8 @@
* .withTasks(entries)
* .withTaskListener(listener)
* .build();
* }
* </pre>
* @param <T> the type parameter
*/
public class TracingTaskListener<T> implements CompletableTask.Listener<T> {
private static final Function<Object, String> DEFAULT_TASK_NAME_MAPPER = o->o.toString();
Expand Down
54 changes: 47 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,25 @@

<properties>
<concurrency-loadbalancer.version>0.1-SNAPSHOT</concurrency-loadbalancer.version>
<jdk.version>1.8</jdk.version>
<jdk.version>11</jdk.version>
<guava.version>30.1-jre</guava.version>
<io.dropwizard.metrics.version>3.1.1</io.dropwizard.metrics.version>
<commons-math3.version>3.4.1</commons-math3.version>
<commons-lang3.version>3.5</commons-lang3.version>
<junit.version>4.13.1</junit.version>
<mockito.version>1.10.19</mockito.version>
<powermock.version>1.6.4</powermock.version>
<mockito.version>2.23.4</mockito.version>
<powermock.version>2.0.2</powermock.version>
<opentracing.version>0.32.0</opentracing.version>
<tally.core.version>0.3.1</tally.core.version>
<checkstyle.version>2.17</checkstyle.version>
<checkstyle.config.location>checkstyles/uber_checks.xml</checkstyle.config.location>
<pmd.version>3.14.0</pmd.version>
<spotbugs.version>3.1.0-RC6</spotbugs.version>
<spotbugs.version>3.1.10</spotbugs.version>
<findbugs.version>3.0.0</findbugs.version>
<jacoco.version>0.8.6</jacoco.version>
<javadoc.version>2.10.4</javadoc.version>
<javadoc.version>3.2.0</javadoc.version>
<surefire.version>2.18.1</surefire.version>
<source.plugin.version>2.1.2</source.plugin.version>
</properties>
<dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -87,7 +88,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
</dependency>
<dependency>
Expand All @@ -103,7 +104,7 @@
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<artifactId>powermock-api-mockito2</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
Expand Down Expand Up @@ -142,6 +143,11 @@
<artifactId>maven-javadoc-plugin</artifactId>
<version>${javadoc.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${source.plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
Expand All @@ -155,6 +161,40 @@
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<phase>deploy</phase>
<goals><goal>jar-no-fork</goal></goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<source>1.8</source>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>deploy</phase>
<goals><goal>jar</goal></goals>
</execution>
</executions>
</plugin>
<plugin>
<!-- explicitly define maven-deploy-plugin after other to force exec order -->
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<id>deploy</id>
<phase>deploy</phase>
<goals><goal>deploy</goal></goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Loading