|
26 | 26 |
|
27 | 27 | import static java.lang.String.format;
|
28 | 28 | import static java.util.Objects.requireNonNull;
|
| 29 | +import static java.util.Optional.ofNullable; |
29 | 30 | import static java.util.concurrent.CompletableFuture.completedFuture;
|
30 | 31 | import static org.simplejavamail.internal.batchsupport.BatchException.ERROR_ACQUIRING_KEYED_POOLABLE;
|
31 | 32 | import static org.simplejavamail.internal.batchsupport.ClusterHelper.compareClusterConfig;
|
@@ -96,13 +97,20 @@ private void ensureClusterInitialized(@NotNull OperationalConfig operationalConf
|
96 | 97 | @Override
|
97 | 98 | @SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH", justification = "This is bullshit, Spotbugs. There's a requireNonNull() right in front of you, you numbnuts")
|
98 | 99 | public LifecycleDelegatingTransport acquireTransport(@NotNull final UUID clusterKey, @NotNull final Session session, boolean stickySession) {
|
| 100 | + val smtpConnectionPool = requireNonNull(this.smtpConnectionPool, "Connection pool used before it was initialized. This shouldn't be possible."); |
| 101 | + checkConfigureOAuth2Token(session); |
| 102 | + |
| 103 | + return ofNullable(getSessionTransportPoolableObject(smtpConnectionPool, clusterKey, session, stickySession)) |
| 104 | + .map(LifecycleDelegatingTransportImpl::new) |
| 105 | + .orElseThrow(() -> new BatchException(format(ERROR_ACQUIRING_KEYED_POOLABLE, session))); |
| 106 | + } |
| 107 | + |
| 108 | + @Nullable |
| 109 | + private PoolableObject<SessionTransport> getSessionTransportPoolableObject(SmtpConnectionPoolClustered smtpConnectionPool, UUID clusterKey, Session session, boolean stickySession) { |
99 | 110 | try {
|
100 |
| - requireNonNull(smtpConnectionPool, "Connection pool used before it was initialized. This shouldn't be possible."); |
101 |
| - checkConfigureOAuth2Token(session); |
102 |
| - final PoolableObject<SessionTransport> pooledTransport = stickySession |
| 111 | + return stickySession |
103 | 112 | ? smtpConnectionPool.claimResourceFromPool(new ResourceClusterAndPoolKey<>(clusterKey, session))
|
104 | 113 | : smtpConnectionPool.claimResourceFromCluster(clusterKey);
|
105 |
| - return new LifecycleDelegatingTransportImpl(pooledTransport); |
106 | 114 | } catch (InterruptedException e) {
|
107 | 115 | throw new BatchException(format(ERROR_ACQUIRING_KEYED_POOLABLE, session), e);
|
108 | 116 | }
|
|
0 commit comments