Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import reactor.core.publisher.FluxSink;
import reactor.core.publisher.Mono;
import reactor.core.publisher.ReplayProcessor;
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;

import java.io.IOException;
Expand Down Expand Up @@ -350,7 +351,11 @@ private synchronized Connection getOrCreateConnection() throws IOException {
connection = reactor.connectionToHost(handler.getHostname(), handler.getProtocolPort(), handler);

reactorExceptionHandler = new ReactorExceptionHandler();
executor = new ReactorExecutor(reactor, Schedulers.single(), connectionId,
// Use a new single-threaded scheduler for this connection as QPID's Reactor is not thread-safe.
// Using Schedulers.single() will use the same thread for all connections in this process which
// limits the scalability of the no. of concurrent connections a single process can have.
Scheduler scheduler = Schedulers.newSingle("reactor-executor");
executor = new ReactorExecutor(reactor, scheduler, connectionId,
reactorExceptionHandler, connectionOptions.getRetry().getTryTimeout(),
connectionOptions.getFullyQualifiedNamespace());

Expand Down Expand Up @@ -421,7 +426,6 @@ void dispose(ErrorCondition errorCondition) {
} else {
session.dispose();
}

subscription.dispose();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,6 @@ private void scheduleCompletePendingTasks() {
public void close() {
if (!isDisposed.getAndSet(true)) {
close(true, "ReactorExecutor.close() was called.");

try {
if (!disposeSemaphore.tryAcquire(timeout.toMillis(), TimeUnit.MILLISECONDS)) {
logger.info("Unable to acquire dispose reactor semaphore within timeout.");
}
} catch (InterruptedException e) {
logger.warning("Could not acquire semaphore to finish close operation.", e);
}
}
}

Expand All @@ -193,8 +185,16 @@ private void close(boolean isUserInitialized, String reason) {

if (isUserInitialized) {
scheduleCompletePendingTasks();
// wait for the scheduled pending tasks to complete
try {
if (!disposeSemaphore.tryAcquire(timeout.toMillis(), TimeUnit.MILLISECONDS)) {
logger.info("Unable to acquire dispose reactor semaphore within timeout.");
}
} catch (InterruptedException e) {
logger.warning("Could not acquire semaphore to finish close operation.", e);
}
}

exceptionHandler.onConnectionShutdown(new AmqpShutdownSignal(false, isUserInitialized, reason));
scheduler.dispose();
}
}