Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
douglascraigschmidt committed Mar 31, 2023
1 parent a7e2549 commit 3d346ae
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 354 deletions.
10 changes: 5 additions & 5 deletions Reactor/ex2/src/main/java/ex2.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import common.Options;
import common.PrimeUtils;
import utils.PrimeUtils;
import org.reactivestreams.Subscriber;
import publisher.Publisher;
import reactor.core.Disposable;
Expand All @@ -16,9 +16,9 @@
import static publisher.Publisher.sPendingItemCount;

/**
* This program applies Project Reactor features to check the primality
* of randomly generate {@link Integer} objects via a publisher and
* a subscriber that (conditionally) run in different threads/schedulers.
* This program applies Project Reactor features to check the primality
* of randomly generate {@link Integer} objects via a publisher and
* a subscriber that (conditionally) run in different threads/schedulers.
*/
public class ex2 {
/**
Expand Down Expand Up @@ -156,7 +156,7 @@ static public void main(String[] argv) {
Mono<PrimeUtils.Result>> makePrimeCheckFunction
(Function<Integer, Integer> primeChecker) {
return number -> Mono
.fromCallable(() -> number)
.fromSupplier(() -> number)

// Subscriber may run in different thread(s).
.publishOn(mSubscriberScheduler)
Expand Down
4 changes: 2 additions & 2 deletions Reactor/ex2/src/main/java/publisher/Emitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import java.util.function.Consumer;

/**
* This Java utility class defines static methods that emit random {@link Integer}s
* with either backpressure enabled or disabled.
* This Java utility class defines static methods that emit
* random {@link Integer} objects with backpressure disabled.
*/
public final class Emitter {
/**
Expand Down
10 changes: 7 additions & 3 deletions Reactor/ex2/src/main/java/subscriber/BlockingSubscriber.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
import reactor.core.publisher.Flux;
import utils.ExceptionUtils;
import common.Options;
import common.PrimeUtils;
import utils.PrimeUtils;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;

/**
* A {@link Flux} {@link Subscriber} that blocks the caller.
* A {@link Flux} {@link Subscriber} that consumes random large
* Integer objects from the publisher and allows the subscriber
* thread to block.
*/
@SuppressWarnings("ReactiveStreamsSubscriberImplementation")
public class BlockingSubscriber
implements Subscriber<PrimeUtils.Result>,
Disposable {
Expand Down Expand Up @@ -88,7 +91,8 @@ public void onNext(PrimeUtils.Result result) {
// Store the current pending item count.
int pendingItems = mPendingItemCount.decrementAndGet();

Options.debug(TAG, "subscriber pending items: " + pendingItems);
Options.debug(TAG, "subscriber pending items: "
+ pendingItems);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package common;
package utils;

import common.Options;
import reactor.core.publisher.Flux;

import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package edu.vandy.lockmanager.common;

import java.util.Objects;
import java.util.concurrent.ArrayBlockingQueue;

/**
* This class is used to keep track of allocated {@link LockManager}
* objects.
* This class is used to keep track of allocated
* {@link ArrayBlockingQueue} objects.
*/
public class LockManager {
/**
Expand All @@ -17,23 +18,21 @@ public class LockManager {
*/
public Integer permitCount;

/**
* @return The unique name of the {@link LockManager}
*
public String getName() {
return mName;
}
*/

/**
* Set the unique name of the {@link LockManager}.
*
* @param name The unique name of the {@link LockManager}
* @param name The unique name of this {@link LockManager}
*/
public LockManager(String name) {
this.name = name;
}

/**
* Constructor initializes the name of the {@link LockManager}.
*
* @param name The unique name of this {@link LockManager}
* @param permitCount The number of permits managed
*/
public LockManager(String name,
Integer permitCount) {
this.name = name + ":[" + permitCount + "]";
Expand Down Expand Up @@ -64,6 +63,7 @@ public String toString() {
*/
@Override
public boolean equals(Object object) {
// Fun use of a recent Java feature.
return object instanceof LockManager other
&& this.name.equals(other.name);
}
Expand Down
Loading

0 comments on commit 3d346ae

Please sign in to comment.