Skip to content

Commit b22fd05

Browse files
mp911dechristophstrobl
authored andcommitted
DATAMONGO-1667 - Rename @infinitestream to @Tailable.
Rename InfiniteStream annotation to Tailable to reflect the related MongoDB approach used for repository query methods returning an infinite stream. InfiniteStream is the high-level concept that is achieved by using tailable cursors. Original Pull Request: spring-projects#458
1 parent 42672a6 commit b22fd05

File tree

5 files changed

+34
-33
lines changed

5 files changed

+34
-33
lines changed
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
import org.springframework.data.annotation.QueryAnnotation;
2525

2626
/**
27-
* Annotation to declare an infinite stream using repository query methods. An infinite stream uses MongoDB's
28-
* {@link com.mongodb.CursorType#TailableAwait tailable} cursors to retrieve data from a capped collection and stream
29-
* data as it is inserted into the collection. An infinite stream can only be used with streams that emit more than one
30-
* element, such as {@link reactor.core.publisher.Flux} or {@link rx.Observable}.
27+
* Annotation to declare an infinite stream using MongoDB's {@link com.mongodb.CursorType#TailableAwait tailable}
28+
* cursors. An infinite stream can only be used with capped collections. Objects are emitted through the stream as data
29+
* is inserted into the collection. An infinite stream can only be used with streams that emit more than one element,
30+
* such as {@link reactor.core.publisher.Flux}.
3131
* <p>
3232
* The stream may become dead, or invalid, if either the query returns no match or the cursor returns the document at
3333
* the "end" of the collection and then the application deletes that document.
@@ -37,11 +37,12 @@
3737
*
3838
* @author Mark Paluch
3939
* @see <a href="https://docs.mongodb.com/manual/core/tailable-cursors/">Tailable Cursors</a>
40+
* @since 2.0
4041
*/
4142
@Retention(RetentionPolicy.RUNTIME)
4243
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
4344
@Documented
4445
@QueryAnnotation
45-
public @interface InfiniteStream {
46+
public @interface Tailable {
4647

4748
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/AbstractReactiveMongoQuery.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 the original author or authors.
2+
* Copyright 2016-2017 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.
@@ -130,7 +130,7 @@ private ReactiveMongoQueryExecution getExecutionToWrap(MongoParameterAccessor ac
130130
return new DeleteExecution(operations, method);
131131
} else if (method.isGeoNearQuery()) {
132132
return new GeoNearExecution(operations, accessor, method.getReturnType());
133-
} else if (isInfiniteStream(method)) {
133+
} else if (isTailable(method)) {
134134
return new TailExecution(operations, accessor.getPageable());
135135
} else if (method.isCollectionQuery()) {
136136
return new CollectionExecution(operations, accessor.getPageable());
@@ -139,8 +139,8 @@ private ReactiveMongoQueryExecution getExecutionToWrap(MongoParameterAccessor ac
139139
}
140140
}
141141

142-
private boolean isInfiniteStream(MongoQueryMethod method) {
143-
return method.getInfiniteStreamAnnotation() != null;
142+
private boolean isTailable(MongoQueryMethod method) {
143+
return method.getTailableAnnotation() != null;
144144
}
145145

146146
Query applyQueryMetaAttributesWhenPresent(Query query) {

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryMethod.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2016 the original author or authors.
2+
* Copyright 2011-2017 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.
@@ -29,9 +29,9 @@
2929
import org.springframework.data.mapping.context.MappingContext;
3030
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
3131
import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
32-
import org.springframework.data.mongodb.repository.InfiniteStream;
3332
import org.springframework.data.mongodb.repository.Meta;
3433
import org.springframework.data.mongodb.repository.Query;
34+
import org.springframework.data.mongodb.repository.Tailable;
3535
import org.springframework.data.projection.ProjectionFactory;
3636
import org.springframework.data.repository.core.RepositoryMetadata;
3737
import org.springframework.data.repository.query.QueryMethod;
@@ -44,7 +44,7 @@
4444

4545
/**
4646
* Mongo specific implementation of {@link QueryMethod}.
47-
*
47+
*
4848
* @author Oliver Gierke
4949
* @author Christoph Strobl
5050
* @author Mark Paluch
@@ -61,7 +61,7 @@ public class MongoQueryMethod extends QueryMethod {
6161

6262
/**
6363
* Creates a new {@link MongoQueryMethod} from the given {@link Method}.
64-
*
64+
*
6565
* @param method must not be {@literal null}.
6666
* @param metadata must not be {@literal null}.
6767
* @param projectionFactory must not be {@literal null}.
@@ -89,7 +89,7 @@ protected MongoParameters createParameters(Method method) {
8989

9090
/**
9191
* Returns whether the method has an annotated query.
92-
*
92+
*
9393
* @return
9494
*/
9595
public boolean hasAnnotatedQuery() {
@@ -99,7 +99,7 @@ public boolean hasAnnotatedQuery() {
9999
/**
100100
* Returns the query string declared in a {@link Query} annotation or {@literal null} if neither the annotation found
101101
* nor the attribute was specified.
102-
*
102+
*
103103
* @return
104104
*/
105105
String getAnnotatedQuery() {
@@ -110,7 +110,7 @@ String getAnnotatedQuery() {
110110

111111
/**
112112
* Returns the field specification to be used for the query.
113-
*
113+
*
114114
* @return
115115
*/
116116
String getFieldSpecification() {
@@ -119,7 +119,7 @@ String getFieldSpecification() {
119119
return StringUtils.hasText(value) ? value : null;
120120
}
121121

122-
/*
122+
/*
123123
* (non-Javadoc)
124124
* @see org.springframework.data.repository.query.QueryMethod#getEntityInformation()
125125
*/
@@ -165,7 +165,7 @@ public MongoParameters getParameters() {
165165

166166
/**
167167
* Returns whether the query is a geo near query.
168-
*
168+
*
169169
* @return
170170
*/
171171
public boolean isGeoNearQuery() {
@@ -192,7 +192,7 @@ private boolean isGeoNearQuery(Method method) {
192192

193193
/**
194194
* Returns the {@link Query} annotation that is applied to the method or {@code null} if none available.
195-
*
195+
*
196196
* @return
197197
*/
198198
Query getQueryAnnotation() {
@@ -213,7 +213,7 @@ public boolean hasQueryMetaAttributes() {
213213

214214
/**
215215
* Returns the {@link Meta} annotation that is applied to the method or {@code null} if not available.
216-
*
216+
*
217217
* @return
218218
* @since 1.6
219219
*/
@@ -222,18 +222,18 @@ Meta getMetaAnnotation() {
222222
}
223223

224224
/**
225-
* Returns the {@link InfiniteStream} annotation that is applied to the method or {@code null} if not available.
225+
* Returns the {@link Tailable} annotation that is applied to the method or {@code null} if not available.
226226
*
227227
* @return
228228
* @since 2.0
229229
*/
230-
InfiniteStream getInfiniteStreamAnnotation() {
231-
return AnnotatedElementUtils.findMergedAnnotation(method, InfiniteStream.class);
230+
Tailable getTailableAnnotation() {
231+
return AnnotatedElementUtils.findMergedAnnotation(method, Tailable.class);
232232
}
233233

234234
/**
235235
* Returns the {@link org.springframework.data.mongodb.core.query.Meta} attributes to be applied.
236-
*
236+
*
237237
* @return never {@literal null}.
238238
* @since 1.6
239239
*/

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/ReactiveMongoRepositoryTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public void shouldFindByLastNameAndSort() {
170170
}
171171

172172
@Test // DATAMONGO-1444
173-
public void shouldUseInfiniteStream() throws Exception {
173+
public void shouldUseTailableCursor() throws Exception {
174174

175175
StepVerifier
176176
.create(template.dropCollection(Capped.class) //
@@ -195,7 +195,7 @@ public void shouldUseInfiniteStream() throws Exception {
195195
}
196196

197197
@Test // DATAMONGO-1444
198-
public void shouldUseInfiniteStreamWithProjection() throws Exception {
198+
public void shouldUseTailableCursorWithProjection() throws Exception {
199199

200200
StepVerifier
201201
.create(template.dropCollection(Capped.class) //
@@ -329,10 +329,10 @@ interface ReactivePersonRepository extends ReactiveMongoRepository<Person, Strin
329329

330330
interface ReactiveCappedCollectionRepository extends Repository<Capped, String> {
331331

332-
@InfiniteStream
332+
@Tailable
333333
Flux<Capped> findByKey(String key);
334334

335-
@InfiniteStream
335+
@Tailable
336336
Flux<CappedProjection> findProjectionByKey(String key);
337337
}
338338

src/main/asciidoc/reference/reactive-mongo-repositories.adoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,25 +188,25 @@ public interface PersonRepository extends ReactiveMongoRepository<Person, String
188188
----
189189

190190
[[mongo.reactive.repositories.infinite-streams]]
191-
== Infinite Streams
191+
== Infinite Streams with Tailable Cursors
192192

193-
By default, MongoDB will automatically close a cursor when the client has exhausted all results in the cursor. Closing a cursors turns a Stream into a finite stream. However, for capped collections you may use a https://docs.mongodb.com/manual/core/tailable-cursors/[Tailable Cursor] that remains open after the client exhausts the results in the initial cursor. Using Tailable Cursors with a reactive approach allows construction of infinite streams. A Tailable Cursor remains open until it's closed. It emits data as data arrives in a capped collection. Using Tailable Cursors with Collections is not possible as its result would never complete.
193+
By default, MongoDB will automatically close a cursor when the client has exhausted all results in the cursor. Closing a cursors turns a Stream into a finite stream. However, for capped collections you may use a https://docs.mongodb.com/manual/core/tailable-cursors/[Tailable Cursor] that remains open after the client exhausts the results in the initial cursor. Using tailable Cursors with a reactive approach allows construction of infinite streams. A tailable Cursor remains open until it's closed. It emits data as data arrives in a capped collection. Using Tailable Cursors with Collections is not possible as its result would never complete.
194194

195-
Spring Data MongoDB Reactive Repository support supports infinite streams by annotating a query method with `@InfiniteStream`. This works for methods returning `Flux` or `Observable` wrapper types.
195+
Spring Data MongoDB Reactive Repository support supports infinite streams by annotating a query method with `@TailableCursor`. This works for methods returning `Flux` or `Observable` wrapper types.
196196

197197
[source,java]
198198
----
199199
200200
public interface PersonRepository extends ReactiveMongoRepository<Person, String> {
201201
202-
@InfiniteStream
202+
@Tailable
203203
Flux<Person> findByFirstname(String firstname);
204204
205205
}
206206
207207
Flux<Person> stream = repository.findByFirstname("Joe");
208208
209-
Disposable subscription = stream.doOnNext(person -> System.out.println(person)).subscribe();
209+
Disposable subscription = stream.doOnNext(System.out::println).subscribe();
210210
211211
// …
212212

0 commit comments

Comments
 (0)