Skip to content

Commit c5998fa

Browse files
author
Benny Bottema
committed
#558: Only close connection pool from batch-module, if batch-module has been included in the first place
1 parent 375bbd6 commit c5998fa

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

modules/batch-module/src/main/java/org/simplejavamail/internal/batchsupport/BatchSupport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ private void checkConfigureOAuth2Token(Session session) {
131131
*/
132132
@NotNull
133133
@Override
134-
public Future<?> shutdownConnectionPools(@NotNull Session session) {
134+
public Future<Void> shutdownConnectionPools(@NotNull Session session) {
135135
if (smtpConnectionPool == null) {
136136
LOGGER.warn("user requested connection pool shutdown, but there is no connection pool to shut down (yet)");
137137
return completedFuture(null);
138138
}
139139
return smtpConnectionPool.shutdownPool(session);
140140
}
141-
}
141+
}

modules/core-module/src/main/java/org/simplejavamail/api/mailer/Mailer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public interface Mailer extends AutoCloseable {
120120
* <p>
121121
* <strong>Note:</strong> this is only works in combination with the {@value org.simplejavamail.internal.modules.BatchModule#NAME}.
122122
*/
123-
Future<?> shutdownConnectionPool();
123+
Future<Void> shutdownConnectionPool();
124124

125125
/**
126126
* @return The server connection details. Will be {@code null} in case a custom fixed {@link Session} instance is used.

modules/core-module/src/main/java/org/simplejavamail/internal/modules/BatchModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ public interface BatchModule {
5757
* 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.
5858
*/
5959
@NotNull
60-
Future<?> shutdownConnectionPools(@NotNull Session session);
61-
}
60+
Future<Void> shutdownConnectionPools(@NotNull Session session);
61+
}

modules/simple-java-mail/src/main/java/org/simplejavamail/mailer/internal/MailerImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,14 @@ public boolean validate(@NotNull final Email email)
373373
* @see Mailer#shutdownConnectionPool()
374374
*/
375375
@Override
376-
public Future<?> shutdownConnectionPool() {
376+
public Future<Void> shutdownConnectionPool() {
377377
if (!operationalConfig.isExecutorServiceIsUserProvided()) {
378378
operationalConfig.getExecutorService().shutdown();
379379
}
380-
return ModuleLoader.loadBatchModule().shutdownConnectionPools(session);
380+
if (ModuleLoader.batchModuleAvailable()) {
381+
return ModuleLoader.loadBatchModule().shutdownConnectionPools(session);
382+
}
383+
return CompletableFuture.completedFuture(null);
381384
}
382385

383386
@Override
@@ -458,4 +461,4 @@ public EmailGovernance getEmailGovernance() {
458461
public void close() throws ExecutionException, InterruptedException {
459462
shutdownConnectionPool().get();
460463
}
461-
}
464+
}

0 commit comments

Comments
 (0)