Polishing

This commit is contained in:
Juergen Hoeller 2017-11-05 21:07:26 +01:00
parent 07b479e264
commit 9b7af8b5aa
3 changed files with 24 additions and 23 deletions

View File

@ -19,6 +19,8 @@ package org.springframework.util.concurrent;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import org.springframework.util.Assert;
/** /**
* Extension of {@link CompletableFuture} which allows for cancelling * Extension of {@link CompletableFuture} which allows for cancelling
* a delegate along with the {@link CompletableFuture} itself. * a delegate along with the {@link CompletableFuture} itself.
@ -30,10 +32,13 @@ class DelegatingCompletableFuture<T> extends CompletableFuture<T> {
private final Future<T> delegate; private final Future<T> delegate;
public DelegatingCompletableFuture(Future<T> delegate) { public DelegatingCompletableFuture(Future<T> delegate) {
Assert.notNull(delegate, "Delegate must not be null");
this.delegate = delegate; this.delegate = delegate;
} }
@Override @Override
public boolean cancel(boolean mayInterruptIfRunning) { public boolean cancel(boolean mayInterruptIfRunning) {
boolean result = this.delegate.cancel(mayInterruptIfRunning); boolean result = this.delegate.cancel(mayInterruptIfRunning);

View File

@ -97,12 +97,10 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag
return this.receiveTimeout; return this.receiveTimeout;
} }
/** /**
* Set the name of the header used to determine the send timeout (if present). * Set the name of the header used to determine the send timeout (if present).
* Default {@value #DEFAULT_SEND_TIMEOUT_HEADER}. * Default {@value #DEFAULT_SEND_TIMEOUT_HEADER}.
* The header is removed before sending the message to avoid propagation. * <p>The header is removed before sending the message to avoid propagation.
* @param sendTimeoutHeader the sendTimeoutHeader to set
* @since 5.0 * @since 5.0
*/ */
public void setSendTimeoutHeader(String sendTimeoutHeader) { public void setSendTimeoutHeader(String sendTimeoutHeader) {
@ -111,18 +109,17 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag
} }
/** /**
* @return the configured sendTimeoutHeader. * Return the configured send-timeout header.
* @since 5.0 * @since 5.0
*/ */
public String getSendTimeoutHeader() { public String getSendTimeoutHeader() {
return sendTimeoutHeader; return this.sendTimeoutHeader;
} }
/** /**
* Set the name of the header used to determine the send timeout (if present). * Set the name of the header used to determine the send timeout (if present).
* Default {@value #DEFAULT_RECEIVE_TIMEOUT_HEADER}. * Default {@value #DEFAULT_RECEIVE_TIMEOUT_HEADER}.
* The header is removed before sending the message to avoid propagation. * The header is removed before sending the message to avoid propagation.
* @param receiveTimeoutHeader the receiveTimeoutHeader to set
* @since 5.0 * @since 5.0
*/ */
public void setReceiveTimeoutHeader(String receiveTimeoutHeader) { public void setReceiveTimeoutHeader(String receiveTimeoutHeader) {
@ -131,11 +128,11 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag
} }
/** /**
* @return the configured receiveTimeoutHeader * Return the configured receive-timeout header.
* @since 5.0 * @since 5.0
*/ */
public String getReceiveTimeoutHeader() { public String getReceiveTimeoutHeader() {
return receiveTimeoutHeader; return this.receiveTimeoutHeader;
} }
/** /**
@ -157,6 +154,7 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag
setDestinationResolver(new BeanFactoryMessageChannelDestinationResolver(beanFactory)); setDestinationResolver(new BeanFactoryMessageChannelDestinationResolver(beanFactory));
} }
@Override @Override
protected final void doSend(MessageChannel channel, Message<?> message) { protected final void doSend(MessageChannel channel, Message<?> message) {
doSend(channel, message, sendTimeout(message)); doSend(channel, message, sendTimeout(message));
@ -267,6 +265,7 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag
} }
} }
/** /**
* A temporary channel for receiving a single reply message. * A temporary channel for receiving a single reply message.
*/ */

View File

@ -391,9 +391,8 @@ you will be able to write your Kotlin beans without any additional `open` keywor
=== Using immutable class instances for persistence === Using immutable class instances for persistence
In Kotlin, it is very convenient and considered best practice to declare In Kotlin, it is very convenient and considered best practice to declare read-only properties
read-only properties within the primary constructor, as in the following within the primary constructor, as in the following example:
example:
[source,kotlin] [source,kotlin]
---- ----
@ -401,41 +400,39 @@ class Person(val name: String, val age: Int)
---- ----
You can optionally add https://kotlinlang.org/docs/reference/data-classes.html[the `data` keyword] You can optionally add https://kotlinlang.org/docs/reference/data-classes.html[the `data` keyword]
to make the compiler automatically derives the following members from all properties to make the compiler automatically derive the following members from all properties declared
declared in the primary constructor: in the primary constructor:
* equals()/hashCode() pair * equals()/hashCode() pair
* toString() of the form "User(name=John, age=42)" * toString() of the form "User(name=John, age=42)"
* componentN() functions corresponding to the properties in their order of declaration * componentN() functions corresponding to the properties in their order of declaration
* copy() function * copy() function
This allows to change easily just one of the properties even if `User` properties are read-only: This allows for easy changes to individual properties even if `Person` properties are read-only:
his allows us to write:
[source,kotlin] [source,kotlin]
---- ----
data class Person(val name: String, val age: Int) data class Person(val name: String, val age: Int)
val jack = User(name = "Jack", age = 1) val jack = Person(name = "Jack", age = 1)
val olderJack = jack.copy(age = 2) val olderJack = jack.copy(age = 2)
---- ----
But some persistence technologies like JPA require a default constructor, preventing this Common persistence technologies such as JPA require a default constructor, preventing this
kind of design. Fortunately, there is now a workaround for this kind of design. Fortunately, there is now a workaround for this
https://stackoverflow.com/questions/32038177/kotlin-with-jpa-default-constructor-hell["default constructor hell"] https://stackoverflow.com/questions/32038177/kotlin-with-jpa-default-constructor-hell["default constructor hell"]
since Kotlin provides a https://kotlinlang.org/docs/reference/compiler-plugins.html#kotlin-jpa-compiler-plugin[kotlin-jpa] since Kotlin provides a https://kotlinlang.org/docs/reference/compiler-plugins.html#kotlin-jpa-compiler-plugin[kotlin-jpa]
plugin which generates synthetic no-arg constructor for classes annotated with JPA annotations. plugin which generates synthetic no-arg constructor for classes annotated with JPA annotations.
If you need to leverage this kind of mechanism for other persistence technologies, you can If you need to leverage this kind of mechanism for other persistence technologies, you can configure
configure https://kotlinlang.org/docs/reference/compiler-plugins.html#how-to-use-no-arg-plugin[kotlin-noarg] the https://kotlinlang.org/docs/reference/compiler-plugins.html#how-to-use-no-arg-plugin[kotlin-noarg]
plugin. plugin.
[NOTE] [NOTE]
==== ====
As of Kay release train, Spring Data supports Kotlin immutable class instances As of the Kay release train, Spring Data supports Kotlin immutable class instances and
and should not require `kotlin-noarg` plugin if the module leverages Spring Data object does not require the `kotlin-noarg` plugin if the module leverages Spring Data object
mapping (like with MongoDB, Redis, Cassandra, etc.). mappings (like with MongoDB, Redis, Cassandra, etc).
==== ====