Skip to content

Commit b0cabb2

Browse files
committed
Polishing
1 parent 21d0696 commit b0cabb2

File tree

5 files changed

+41
-26
lines changed

5 files changed

+41
-26
lines changed

spring-tx/src/main/java/org/springframework/transaction/reactive/AbstractReactiveTransactionManager.java

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -196,7 +196,8 @@ private Mono<ReactiveTransaction> handleExistingTransaction(TransactionSynchroni
196196
return doBegin(synchronizationManager, transaction, definition).doOnSuccess(ignore ->
197197
prepareSynchronization(synchronizationManager, status, definition)).thenReturn(status)
198198
.onErrorResume(ErrorPredicates.RUNTIME_OR_ERROR, beginEx ->
199-
resumeAfterBeginException(synchronizationManager, transaction, suspendedResourcesHolder, beginEx).then(Mono.error(beginEx)));
199+
resumeAfterBeginException(synchronizationManager, transaction, suspendedResourcesHolder, beginEx)
200+
.then(Mono.error(beginEx)));
200201
});
201202
}
202203

@@ -281,7 +282,9 @@ private Mono<SuspendedResourcesHolder> suspend(TransactionSynchronizationManager
281282
if (synchronizationManager.isSynchronizationActive()) {
282283
Mono<List<TransactionSynchronization>> suspendedSynchronizations = doSuspendSynchronization(synchronizationManager);
283284
return suspendedSynchronizations.flatMap(synchronizations -> {
284-
Mono<Optional<Object>> suspendedResources = (transaction != null ? doSuspend(synchronizationManager, transaction).map(Optional::of).defaultIfEmpty(Optional.empty()) : Mono.just(Optional.empty()));
285+
Mono<Optional<Object>> suspendedResources = (transaction != null ?
286+
doSuspend(synchronizationManager, transaction).map(Optional::of).defaultIfEmpty(Optional.empty()) :
287+
Mono.just(Optional.empty()));
285288
return suspendedResources.map(it -> {
286289
String name = synchronizationManager.getCurrentTransactionName();
287290
synchronizationManager.setCurrentTransactionName(null);
@@ -293,12 +296,15 @@ private Mono<SuspendedResourcesHolder> suspend(TransactionSynchronizationManager
293296
synchronizationManager.setActualTransactionActive(false);
294297
return new SuspendedResourcesHolder(
295298
it.orElse(null), synchronizations, name, readOnly, isolationLevel, wasActive);
296-
}).onErrorResume(ErrorPredicates.RUNTIME_OR_ERROR, ex -> doResumeSynchronization(synchronizationManager, synchronizations).cast(SuspendedResourcesHolder.class));
299+
}).onErrorResume(ErrorPredicates.RUNTIME_OR_ERROR,
300+
ex -> doResumeSynchronization(synchronizationManager, synchronizations)
301+
.cast(SuspendedResourcesHolder.class));
297302
});
298303
}
299304
else if (transaction != null) {
300305
// Transaction active but no synchronization active.
301-
Mono<Optional<Object>> suspendedResources = doSuspend(synchronizationManager, transaction).map(Optional::of).defaultIfEmpty(Optional.empty());
306+
Mono<Optional<Object>> suspendedResources =
307+
doSuspend(synchronizationManager, transaction).map(Optional::of).defaultIfEmpty(Optional.empty());
302308
return suspendedResources.map(it -> new SuspendedResourcesHolder(it.orElse(null)));
303309
}
304310
else {
@@ -445,10 +451,12 @@ private Mono<Void> processCommit(TransactionSynchronizationManager synchronizati
445451
// Eclipse compiler with regard to inferred generics.
446452
Mono<Object> result = propagateException;
447453
if (ErrorPredicates.UNEXPECTED_ROLLBACK.test(ex)) {
448-
result = triggerAfterCompletion(synchronizationManager, status, TransactionSynchronization.STATUS_ROLLED_BACK).then(propagateException);
454+
result = triggerAfterCompletion(synchronizationManager, status, TransactionSynchronization.STATUS_ROLLED_BACK)
455+
.then(propagateException);
449456
}
450457
else if (ErrorPredicates.TRANSACTION_EXCEPTION.test(ex)) {
451-
result = triggerAfterCompletion(synchronizationManager, status, TransactionSynchronization.STATUS_UNKNOWN).then(propagateException);
458+
result = triggerAfterCompletion(synchronizationManager, status, TransactionSynchronization.STATUS_UNKNOWN)
459+
.then(propagateException);
452460
}
453461
else if (ErrorPredicates.RUNTIME_OR_ERROR.test(ex)) {
454462
Mono<Void> mono;
@@ -458,7 +466,8 @@ else if (ErrorPredicates.RUNTIME_OR_ERROR.test(ex)) {
458466
else {
459467
mono = Mono.empty();
460468
}
461-
result = mono.then(doRollbackOnCommitException(synchronizationManager, status, ex)).then(propagateException);
469+
result = mono.then(doRollbackOnCommitException(synchronizationManager, status, ex))
470+
.then(propagateException);
462471
}
463472

464473
return result;
@@ -573,9 +582,9 @@ private Mono<Void> triggerBeforeCommit(TransactionSynchronizationManager synchro
573582
if (status.isDebug()) {
574583
logger.trace("Triggering beforeCommit synchronization");
575584
}
576-
return TransactionSynchronizationUtils.triggerBeforeCommit(synchronizationManager.getSynchronizations(), status.isReadOnly());
585+
return TransactionSynchronizationUtils.triggerBeforeCommit(
586+
synchronizationManager.getSynchronizations(), status.isReadOnly());
577587
}
578-
579588
return Mono.empty();
580589
}
581590

@@ -593,7 +602,6 @@ private Mono<Void> triggerBeforeCompletion(TransactionSynchronizationManager syn
593602
}
594603
return TransactionSynchronizationUtils.triggerBeforeCompletion(synchronizationManager.getSynchronizations());
595604
}
596-
597605
return Mono.empty();
598606
}
599607

@@ -611,7 +619,6 @@ private Mono<Void> triggerAfterCommit(TransactionSynchronizationManager synchron
611619
}
612620
return TransactionSynchronizationUtils.invokeAfterCommit(synchronizationManager.getSynchronizations());
613621
}
614-
615622
return Mono.empty();
616623
}
617624

@@ -639,10 +646,10 @@ else if (!synchronizations.isEmpty()) {
639646
// Existing transaction that we participate in, controlled outside
640647
// of the scope of this Spring transaction manager -> try to register
641648
// an afterCompletion callback with the existing (JTA) transaction.
642-
return registerAfterCompletionWithExistingTransaction(synchronizationManager, status.getTransaction(), synchronizations);
649+
return registerAfterCompletionWithExistingTransaction(
650+
synchronizationManager, status.getTransaction(), synchronizations);
643651
}
644652
}
645-
646653
return Mono.empty();
647654
}
648655

@@ -690,7 +697,8 @@ private Mono<Void> cleanupAfterCompletion(TransactionSynchronizationManager sync
690697
logger.debug("Resuming suspended transaction after completion of inner transaction");
691698
}
692699
Object transaction = (status.hasTransaction() ? status.getTransaction() : null);
693-
return cleanup.then(resume(synchronizationManager, transaction, (SuspendedResourcesHolder) status.getSuspendedResources()));
700+
return cleanup.then(resume(synchronizationManager, transaction,
701+
(SuspendedResourcesHolder) status.getSuspendedResources()));
694702
}
695703
return cleanup;
696704
});
@@ -716,14 +724,16 @@ private Mono<Void> cleanupAfterCompletion(TransactionSynchronizationManager sync
716724
* returned transaction object.
717725
* @param synchronizationManager the synchronization manager bound to the current transaction
718726
* @return the current transaction object
719-
* @throws org.springframework.transaction.CannotCreateTransactionException if transaction support is not available
727+
* @throws org.springframework.transaction.CannotCreateTransactionException
728+
* if transaction support is not available
720729
* @throws TransactionException in case of lookup or system errors
721730
* @see #doBegin
722731
* @see #doCommit
723732
* @see #doRollback
724733
* @see GenericReactiveTransaction#getTransaction
725734
*/
726-
protected abstract Object doGetTransaction(TransactionSynchronizationManager synchronizationManager) throws TransactionException;
735+
protected abstract Object doGetTransaction(TransactionSynchronizationManager synchronizationManager)
736+
throws TransactionException;
727737

728738
/**
729739
* Check if the given transaction object indicates an existing transaction
@@ -775,7 +785,8 @@ protected abstract Mono<Void> doBegin(TransactionSynchronizationManager synchron
775785
* @param transaction the transaction object returned by {@code doGetTransaction}
776786
* @return an object that holds suspended resources
777787
* (will be kept unexamined for passing it into doResume)
778-
* @throws org.springframework.transaction.TransactionSuspensionNotSupportedException if suspending is not supported by the transaction manager implementation
788+
* @throws org.springframework.transaction.TransactionSuspensionNotSupportedException
789+
* if suspending is not supported by the transaction manager implementation
779790
* @throws TransactionException in case of system errors
780791
* @see #doResume
781792
*/
@@ -795,7 +806,8 @@ protected Mono<Object> doSuspend(TransactionSynchronizationManager synchronizati
795806
* @param transaction the transaction object returned by {@code doGetTransaction}
796807
* @param suspendedResources the object that holds suspended resources,
797808
* as returned by doSuspend
798-
* @throws org.springframework.transaction.TransactionSuspensionNotSupportedException if resuming is not supported by the transaction manager implementation
809+
* @throws org.springframework.transaction.TransactionSuspensionNotSupportedException
810+
* if suspending is not supported by the transaction manager implementation
799811
* @throws TransactionException in case of system errors
800812
* @see #doSuspend
801813
*/

spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpConnector.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* Reactor-Netty implementation of {@link ClientHttpConnector}.
3535
*
3636
* @author Brian Clozel
37+
* @author Rossen Stoyanchev
3738
* @since 5.0
3839
* @see reactor.netty.http.client.HttpClient
3940
*/

spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpRequest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,6 +38,7 @@
3838
* {@link ClientHttpRequest} implementation for the Reactor-Netty HTTP client.
3939
*
4040
* @author Brian Clozel
41+
* @author Rossen Stoyanchev
4142
* @since 5.0
4243
* @see reactor.netty.http.client.HttpClient
4344
*/

spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
* {@link ClientHttpResponse} implementation for the Reactor-Netty HTTP client.
4444
*
4545
* @author Brian Clozel
46+
* @author Rossen Stoyanchev
4647
* @since 5.0
4748
* @see reactor.netty.http.client.HttpClient
4849
*/
@@ -66,7 +67,7 @@ class ReactorClientHttpResponse implements ClientHttpResponse {
6667
/**
6768
* Constructor that matches the inputs from
6869
* {@link reactor.netty.http.client.HttpClient.ResponseReceiver#responseConnection(BiFunction)}.
69-
* @since 5.3
70+
* @since 5.2.8
7071
*/
7172
public ReactorClientHttpResponse(HttpClientResponse response, Connection connection) {
7273
this.response = response;
@@ -77,7 +78,7 @@ public ReactorClientHttpResponse(HttpClientResponse response, Connection connect
7778

7879
/**
7980
* Constructor with inputs extracted from a {@link Connection}.
80-
* @deprecated as of 5.2.8
81+
* @deprecated as of 5.2.8, in favor of {@link #ReactorClientHttpResponse(HttpClientResponse, Connection)}
8182
*/
8283
@Deprecated
8384
public ReactorClientHttpResponse(HttpClientResponse response, NettyInbound inbound, ByteBufAllocator alloc) {

spring-web/src/main/java/org/springframework/http/client/reactive/ReactorResourceFactory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
* and is expected typically to be declared as a Spring-managed bean.
3939
*
4040
* @author Rossen Stoyanchev
41+
* @author Brian Clozel
4142
* @since 5.1
4243
*/
4344
public class ReactorResourceFactory implements InitializingBean, DisposableBean {
@@ -97,8 +98,8 @@ public boolean isUseGlobalResources() {
9798
*/
9899
public void addGlobalResourcesConsumer(Consumer<HttpResources> consumer) {
99100
this.useGlobalResources = true;
100-
this.globalResourcesConsumer = this.globalResourcesConsumer != null ?
101-
this.globalResourcesConsumer.andThen(consumer) : consumer;
101+
this.globalResourcesConsumer = (this.globalResourcesConsumer != null ?
102+
this.globalResourcesConsumer.andThen(consumer) : consumer);
102103
}
103104

104105
/**
@@ -221,8 +222,7 @@ public void afterPropertiesSet() {
221222
@Override
222223
public void destroy() {
223224
if (this.useGlobalResources) {
224-
HttpResources.disposeLoopsAndConnectionsLater(
225-
this.shutdownQuietPeriod, this.shutdownTimeout).block();
225+
HttpResources.disposeLoopsAndConnectionsLater(this.shutdownQuietPeriod, this.shutdownTimeout).block();
226226
}
227227
else {
228228
try {

0 commit comments

Comments
 (0)