提交 9b7af8b5 编写于 作者: J Juergen Hoeller

Polishing

上级 07b479e2
......@@ -19,6 +19,8 @@ package org.springframework.util.concurrent;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import org.springframework.util.Assert;
/**
* Extension of {@link CompletableFuture} which allows for cancelling
* a delegate along with the {@link CompletableFuture} itself.
......@@ -30,10 +32,13 @@ class DelegatingCompletableFuture<T> extends CompletableFuture<T> {
private final Future<T> delegate;
public DelegatingCompletableFuture(Future<T> delegate) {
Assert.notNull(delegate, "Delegate must not be null");
this.delegate = delegate;
}
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
boolean result = this.delegate.cancel(mayInterruptIfRunning);
......
......@@ -97,12 +97,10 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag
return this.receiveTimeout;
}
/**
* Set the name of the header used to determine the send timeout (if present).
* Default {@value #DEFAULT_SEND_TIMEOUT_HEADER}.
* The header is removed before sending the message to avoid propagation.
* @param sendTimeoutHeader the sendTimeoutHeader to set
* <p>The header is removed before sending the message to avoid propagation.
* @since 5.0
*/
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
*/
public String getSendTimeoutHeader() {
return sendTimeoutHeader;
return this.sendTimeoutHeader;
}
/**
* Set the name of the header used to determine the send timeout (if present).
* Default {@value #DEFAULT_RECEIVE_TIMEOUT_HEADER}.
* The header is removed before sending the message to avoid propagation.
* @param receiveTimeoutHeader the receiveTimeoutHeader to set
* @since 5.0
*/
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
*/
public String getReceiveTimeoutHeader() {
return receiveTimeoutHeader;
return this.receiveTimeoutHeader;
}
/**
......@@ -157,6 +154,7 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag
setDestinationResolver(new BeanFactoryMessageChannelDestinationResolver(beanFactory));
}
@Override
protected final void doSend(MessageChannel channel, Message<?> message) {
doSend(channel, message, sendTimeout(message));
......@@ -267,6 +265,7 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag
}
}
/**
* A temporary channel for receiving a single reply message.
*/
......
......@@ -391,9 +391,8 @@ you will be able to write your Kotlin beans without any additional `open` keywor
=== Using immutable class instances for persistence
In Kotlin, it is very convenient and considered best practice to declare
read-only properties within the primary constructor, as in the following
example:
In Kotlin, it is very convenient and considered best practice to declare read-only properties
within the primary constructor, as in the following example:
[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]
to make the compiler automatically derives the following members from all properties
declared in the primary constructor:
to make the compiler automatically derive the following members from all properties declared
in the primary constructor:
* equals()/hashCode() pair
* toString() of the form "User(name=John, age=42)"
* componentN() functions corresponding to the properties in their order of declaration
* copy() function
This allows to change easily just one of the properties even if `User` properties are read-only:
his allows us to write:
This allows for easy changes to individual properties even if `Person` properties are read-only:
[source,kotlin]
----
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)
----
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
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]
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
configure https://kotlinlang.org/docs/reference/compiler-plugins.html#how-to-use-no-arg-plugin[kotlin-noarg]
If you need to leverage this kind of mechanism for other persistence technologies, you can configure
the https://kotlinlang.org/docs/reference/compiler-plugins.html#how-to-use-no-arg-plugin[kotlin-noarg]
plugin.
[NOTE]
====
As of Kay release train, Spring Data supports Kotlin immutable class instances
and should not require `kotlin-noarg` plugin if the module leverages Spring Data object
mapping (like with MongoDB, Redis, Cassandra, etc.).
As of the Kay release train, Spring Data supports Kotlin immutable class instances and
does not require the `kotlin-noarg` plugin if the module leverages Spring Data object
mappings (like with MongoDB, Redis, Cassandra, etc).
====
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册