Skip to content

Commit

Permalink
#558: Only close connection pool from batch-module, if batch-module h…
Browse files Browse the repository at this point in the history
…as been included in the first place
  • Loading branch information
Benny Bottema committed Dec 12, 2024
1 parent 375bbd6 commit c5998fa
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ private void checkConfigureOAuth2Token(Session session) {
*/
@NotNull
@Override
public Future<?> shutdownConnectionPools(@NotNull Session session) {
public Future<Void> shutdownConnectionPools(@NotNull Session session) {
if (smtpConnectionPool == null) {
LOGGER.warn("user requested connection pool shutdown, but there is no connection pool to shut down (yet)");
return completedFuture(null);
}
return smtpConnectionPool.shutdownPool(session);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public interface Mailer extends AutoCloseable {
* <p>
* <strong>Note:</strong> this is only works in combination with the {@value org.simplejavamail.internal.modules.BatchModule#NAME}.
*/
Future<?> shutdownConnectionPool();
Future<Void> shutdownConnectionPool();

/**
* @return The server connection details. Will be {@code null} in case a custom fixed {@link Session} instance is used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ public interface BatchModule {
* Shuts down connection pool(s) and closes remaining open connections. Waits until all connections still in use become available again to deallocate them as well.
*/
@NotNull
Future<?> shutdownConnectionPools(@NotNull Session session);
}
Future<Void> shutdownConnectionPools(@NotNull Session session);
}
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,14 @@ public boolean validate(@NotNull final Email email)
* @see Mailer#shutdownConnectionPool()
*/
@Override
public Future<?> shutdownConnectionPool() {
public Future<Void> shutdownConnectionPool() {
if (!operationalConfig.isExecutorServiceIsUserProvided()) {
operationalConfig.getExecutorService().shutdown();
}
return ModuleLoader.loadBatchModule().shutdownConnectionPools(session);
if (ModuleLoader.batchModuleAvailable()) {
return ModuleLoader.loadBatchModule().shutdownConnectionPools(session);
}
return CompletableFuture.completedFuture(null);
}

@Override
Expand Down Expand Up @@ -458,4 +461,4 @@ public EmailGovernance getEmailGovernance() {
public void close() throws ExecutionException, InterruptedException {
shutdownConnectionPool().get();
}
}
}

0 comments on commit c5998fa

Please sign in to comment.