Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Projection Catch-up #1221

Merged
merged 200 commits into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from 133 commits
Commits
Show all changes
200 commits
Select commit Hold shift + click to select a range
db495e2
Get rid of redundant synchronization.
armiol Nov 22, 2019
5c9e3cb
Rename the method.
armiol Nov 22, 2019
1a9d66e
Bump the version to `1.2.6`.
armiol Nov 22, 2019
f86a3d9
Extract and document some classes from `DeliveryTest`.
armiol Nov 26, 2019
7db54c1
Prepare the infrastructure for catch-up tests.
armiol Nov 26, 2019
d1937ec
Add an empty `catch-up` method to call from the tests.
armiol Nov 27, 2019
cbc68f9
Fix a typo.
armiol Nov 28, 2019
9e554e8
Simplify creating a set.
armiol Nov 28, 2019
6b87287
Address Protobuf message renaming.
armiol Nov 28, 2019
aa71c5e
Define catch-up process.
armiol Nov 28, 2019
8e2a5a1
Deal with the unchecked operation.
armiol Nov 28, 2019
cbd2b9d
Allow to set the limit for the `EventStreamQuery`.
armiol Nov 29, 2019
c6872b2
Implement catch-up process (in progress).
armiol Dec 3, 2019
701cedd
Migrate to an approach based upon `AbstractReactor`.
armiol Dec 5, 2019
872a1cb
Take care of the turbulence near the end of the catch-up.
armiol Dec 13, 2019
06ad4b1
Remove all the debug-logging messages.
armiol Dec 13, 2019
bd578e3
Move `CatchUp` to `ProjectionRepository`.
armiol Dec 14, 2019
716b7a7
Make the classes package-local.
armiol Dec 14, 2019
5744159
Fix the layout
armiol Dec 14, 2019
513dcd7
Fix the test.
armiol Dec 14, 2019
13a28aa
Adjust the documentation.
armiol Dec 26, 2019
3bff358
Split the delivery processing into stations which process the conveyor.
armiol Dec 31, 2019
23a255c
Merge remote-tracking branch 'origin/master' into catch-up
armiol Dec 31, 2019
3750501
Back-merge from the `master` and migrate to `1.3.1`.
armiol Dec 31, 2019
f20ef8a
Extract some classes out of `Delivery`. Remove the obsolete code.
armiol Dec 31, 2019
64c3611
Remove the redundant suppression.
armiol Dec 31, 2019
88e923b
Notify the endpoints of duplicates.
armiol Jan 1, 2020
0767a2c
Introduce a local cache of delivered messages.
armiol Jan 2, 2020
6ee3c1d
Document the delivery container.
armiol Jan 3, 2020
43b02ed
Do not take the events with the most recent timestamp into the account
armiol Jan 4, 2020
702ee9b
Address the issues reported by PMD.
armiol Jan 4, 2020
9b7f9e3
Support catching up of all Projection instances (in progress).
armiol Jan 7, 2020
bb8056d
Allow to manually trigger the delivery from a shard via an event.
armiol Jan 7, 2020
1fc7e49
Address the issues reported by PMD. Add more docs.
armiol Jan 8, 2020
f4bd902
Add the changes in the event routing to the catch-up-all test.
armiol Jan 8, 2020
7a89bda
Rename the process.
armiol Jan 8, 2020
80cae77
Add some concurrently dispatched commands along with the catching up …
armiol Jan 8, 2020
dfe24a5
Remove unused code and System.out usage.
armiol Jan 8, 2020
7507056
Split the catch-up tests from the delivery tests.
armiol Jan 8, 2020
1ef67ef
Simplify some methods.
armiol Jan 8, 2020
ae29aaa
Do not set the time provider for each thread.
armiol Jan 9, 2020
f5fe3d8
Merge remote-tracking branch 'origin/master' into catch-up
armiol Jan 9, 2020
f07c016
Remove the empty files.
armiol Jan 9, 2020
830535f
Update to `base` and `time` in `1.4.1`.
armiol Jan 9, 2020
046d763
Remove the unused methods.
armiol Jan 9, 2020
ffe7b11
Remove unused methods and rearrange those who survived.
armiol Jan 9, 2020
cde9d23
Document some of the methods.
armiol Jan 9, 2020
63680aa
Remove the unused variable.
armiol Jan 9, 2020
305ac72
Rename `SignalForShard` to `ShardEvent`.
armiol Jan 9, 2020
16fdfaf
Remove the unused method.
armiol Jan 9, 2020
d9aa93b
Document the class.
armiol Jan 9, 2020
309223a
Document `ConsecutiveProjection` and shorten its repository name.
armiol Jan 17, 2020
89b66bb
Repackage the catch-up messages.
armiol Jan 17, 2020
e69c987
Expose the repository index.
armiol Jan 20, 2020
0ddba80
Start catch-ups via a separate starter. Do not overinflate the `Proje…
armiol Jan 20, 2020
a7cab0a
Document more methods.
armiol Jan 20, 2020
57ca15f
Remove the unused nested interface.
armiol Jan 20, 2020
d129803
Suppress the complexity warnings.
armiol Jan 20, 2020
9bbef99
Document the field.
armiol Jan 20, 2020
e9159e4
Hide the method and make it static.
armiol Jan 20, 2020
87aa7db
Remember to describe the technical process.
armiol Jan 20, 2020
ff5bdc9
Use `eventStore()` from the Bounded Context upon the catch-up process…
armiol Jan 21, 2020
97e15f2
Get rid of the Projection's last handled event time.
armiol Jan 21, 2020
419619a
Use `null` to mark all instances as those to catch-up.
armiol Jan 21, 2020
2b65067
Create a common base for the event reactors with own state.
armiol Jan 21, 2020
b9993ab
Remove a redundant override and kill the debug logging.
armiol Jan 21, 2020
53eda0e
Document the interface.
armiol Jan 22, 2020
e199f4e
docum
armiol Jan 22, 2020
e5f08cf
Allow to configure the custom catch-up storage for the delivery.
armiol Jan 22, 2020
87e2d78
Add the missing test case.
armiol Jan 22, 2020
4356cbc
Set the `catchUpPageSize` properly.
armiol Jan 22, 2020
302f3ca
Use a static class instead of a helper method with an unnecessary lam…
armiol Jan 22, 2020
e53141a
Continue to clean up the catch-up test code by extracting the bits.
armiol Jan 30, 2020
ced3d3b
Simplify the `doDeliver` method by splitting and renaming its pieces.
armiol Feb 4, 2020
0e11980
Extract the creation of the shard index to the `DeliveryStrategy` and…
armiol Feb 4, 2020
61598c0
Reduce the method visibility.
armiol Feb 4, 2020
aec9063
Remove an obsolete `TODO` item.
armiol Feb 4, 2020
6379d7a
Remove another obsolete `TODO`.
armiol Feb 4, 2020
bac4c97
Make the turbulence period configurable.
armiol Feb 4, 2020
16c2f9a
Test more scenarios of the simultaneous start.
armiol Feb 5, 2020
075b8c3
Add even more tests for catch-up.
armiol Feb 5, 2020
04621c8
Test `DispatchingId`.
armiol Feb 5, 2020
71a59ee
Remove the `toString()` method previously used for debugging.
armiol Feb 5, 2020
48080ca
Remove the unused class.
armiol Feb 5, 2020
8a51af9
Extract the interface for the delivery action in order to customize i…
armiol Feb 6, 2020
22e7e92
Test the `CatchUpStation` behavior if an empty conveyor is passed.
armiol Feb 6, 2020
a094722
Test that the live messages are removed if the catch-up is started.
armiol Feb 6, 2020
3d86350
Test delivering the messages in `CATCH_UP` status.
armiol Feb 6, 2020
f1135a6
Shorten the test code. Cover the finalization stage.
armiol Feb 7, 2020
ed832d0
Test `CatchUp` job to `InboxMessage` matching.
armiol Feb 7, 2020
69d283e
Import the method statically.
armiol Feb 7, 2020
d5a9ec3
Add more tests of the `CatchUpStation` behavior.
armiol Feb 8, 2020
686b333
Do not mark duplicates as `DELIVERED`.
armiol Feb 8, 2020
d3d35e4
Test `LiveDeliveryStation`.
armiol Feb 8, 2020
c96e52c
Test `CleanupStation`.
armiol Feb 9, 2020
e064c2e
Remove an unused event.
armiol Feb 9, 2020
4d727c1
Do not check for `null` the object which cannot become `null`.
armiol Feb 9, 2020
2f30a99
Do not rely on the empty target list in case the catch up of all repo…
armiol Feb 9, 2020
cb3798f
Merge remote-tracking branch 'origin/master' into catch-up
armiol Feb 9, 2020
8a95e6e
Update to the latest changes from `master`.
armiol Feb 9, 2020
1f1a120
Extract a method.
armiol Feb 9, 2020
c1c82ae
Extend the description of the `Delivery` with new features (in progre…
armiol Feb 10, 2020
e387285
Plan another section.
armiol Feb 10, 2020
e9697ac
Add the `Catch-up` section.
armiol Feb 10, 2020
cba4400
Describe the conveyor and the stations.
armiol Feb 10, 2020
1b5886c
Briefly describe the need of the shard maintenance.
armiol Feb 10, 2020
95936cb
Document the `CatchUpStation`.
armiol Feb 10, 2020
427a3c9
Document `LiveDeliveryStation` and rename the conveyor method to be m…
armiol Feb 10, 2020
000f957
Document `CleanupStation`.
armiol Feb 10, 2020
bbde7a5
Add the missing bits to the `CatchUpStarter` documentation.
armiol Feb 10, 2020
9581d17
Document the conveyor.
armiol Feb 10, 2020
c761145
Document the `CatchUpProcess`.
armiol Feb 10, 2020
611c753
Suppress the warning and remove the obsolete `TODO` item.
armiol Feb 10, 2020
8423bf4
Add more docs.
armiol Feb 10, 2020
2efeb19
Document the events.
armiol Feb 10, 2020
d458fdf
Add more documentation for the Proto messages related to the catch-up.
armiol Feb 10, 2020
639fab6
Document the exception.
armiol Feb 10, 2020
7076689
Document and test `CatchUpMessages`.
armiol Feb 10, 2020
688dd41
Document the `CatchUpReadRequest`.
armiol Feb 10, 2020
68961f3
Document the method.
armiol Feb 10, 2020
6e976cd
Document the ctor.
armiol Feb 10, 2020
4a2e282
Document the `AbstractStatefulReactor`.
armiol Feb 10, 2020
7c7cf68
Remove an obsolete `TODO`.
armiol Feb 10, 2020
193ae5a
Remove an obsolete `TODO` and add more documentation.
armiol Feb 10, 2020
c81bce4
Remove an unused class.
armiol Feb 10, 2020
52f626d
Add a `throws` clause.
armiol Feb 10, 2020
73662ad
Rename a method.
armiol Feb 10, 2020
625a249
Document the class.
armiol Feb 10, 2020
0d1e0e2
Document the missing bits.
armiol Feb 10, 2020
9291ba1
Change minor bits in texts.
armiol Feb 10, 2020
0c9c551
Update the version to `1.4.5`.
armiol Feb 10, 2020
c2d8c22
Document the storage factory method.
armiol Feb 11, 2020
6c9626d
Do not throw NPE if it is impossible to execute `stopCaching()`.
armiol Feb 11, 2020
17379ee
Make the test data preparation more stable by removing the multi-thre…
armiol Feb 11, 2020
aa9645b
Document the `RepositoryCache` better.
armiol Feb 12, 2020
047204c
Remove `</li>` tags.
armiol Feb 12, 2020
e2db653
Remove an unused method.
armiol Feb 12, 2020
ff37737
Remove the second `@linkplain`.
armiol Feb 12, 2020
dbc6154
Move the `matches` method to the `CatchUpMixin`.
armiol Feb 12, 2020
ae8ca67
Reduce the visibility of the method.
armiol Feb 12, 2020
5355eb2
Extract the event factory.
armiol Feb 12, 2020
8214169
Remove the unused package.
armiol Feb 12, 2020
722f06c
Explain the turbulence.
armiol Feb 13, 2020
f888edc
Fix a typo.
armiol Feb 13, 2020
d5c7f17
Remove the unused API methods.
armiol Feb 13, 2020
ea470a7
Use the default turbulence period.
armiol Feb 13, 2020
e0bddd6
Import the enum constants statically.
armiol Feb 13, 2020
026ca8a
Use `@linkplain` with the proper caption.
armiol Feb 13, 2020
f70dd32
Fix the preposition.
armiol Feb 13, 2020
b09ec01
Reformat the code.
armiol Feb 13, 2020
60a9285
Improve the description.
armiol Feb 13, 2020
21be397
Document the process manager.
armiol Feb 13, 2020
57e81c2
Define the constraint better.
armiol Feb 13, 2020
2ee8e21
Remove an empty line.
armiol Feb 13, 2020
56fbf4f
Optimize the expression.
armiol Feb 13, 2020
09345a5
Fix the typo.
armiol Feb 13, 2020
ebce0fe
Rename the method and document it properly.
armiol Feb 13, 2020
0245ba7
Use "deduplication window" instead of "idempotence window".
armiol Feb 13, 2020
cfb08e1
Make the class `final`.
armiol Feb 13, 2020
98ca9e3
Update the copyright year.
armiol Feb 13, 2020
f8335cb
Comment of the `public` access level.
armiol Feb 13, 2020
ffd59ef
Turn the process into an event subscriber.
armiol Feb 13, 2020
0b05474
Remove a redundant annotation.
armiol Feb 13, 2020
d37a2a0
Remove a redundant annotation here as well.
armiol Feb 13, 2020
14648bf
Use a ternary operator.
armiol Feb 13, 2020
6b2da5a
Reduce the class visibility.
armiol Feb 13, 2020
59543f3
Make the class `final` and reduce its visibility.
armiol Feb 13, 2020
ad34026
Use backticks.
armiol Feb 13, 2020
6ed7b26
Remove a redundant empty line.
armiol Feb 13, 2020
97eb723
Remove a redundant empty line.
armiol Feb 13, 2020
f871c71
Improve the `DisplayName`s.
armiol Feb 13, 2020
6f70356
Simplify the constraint definition.
armiol Feb 13, 2020
44e2a02
Rename and document the `CatchUpProcessBuilder` API.
armiol Feb 13, 2020
b39842c
Mention that the `EntityStateChanged` events are not supported by the…
armiol Feb 13, 2020
1d45917
Document the handler in `Not started` status.
armiol Feb 14, 2020
39f5cdd
Rename `STARTED` status to `IN_PROGRESS`.
armiol Feb 14, 2020
ee39fc9
Improve the code layout.
armiol Feb 14, 2020
432e01f
Get rid of a redundant method parameter.
armiol Feb 14, 2020
f0e76a1
Remove unused message field.
armiol Feb 14, 2020
0abcea8
Reorder and document the sections.
armiol Feb 14, 2020
b357b56
Remove an unused method.
armiol Feb 14, 2020
4ddedf7
Use Guava's `ToStringHelper`.
armiol Feb 14, 2020
008e4f9
Merge remote-tracking branch 'origin/master' into catch-up
armiol Feb 15, 2020
d1b2921
Bump the version to `1.4.6`.
armiol Feb 15, 2020
2bf59b9
Tweak the documentation layout to use a proper title for `@linkplain`.
armiol Feb 15, 2020
0f477ca
Remove the method sections, as they don't work as expected.
armiol Feb 17, 2020
f8b708e
Re-structure and re-document the `CatchUpStation`.
armiol Feb 17, 2020
8318725
Re-structure and re-document the `LiveDeliveryStation`.
armiol Feb 17, 2020
6062ee8
Move the comparator to an upper level.
armiol Feb 17, 2020
015642c
Make the classes `final` and document the inner one.
armiol Feb 17, 2020
699357d
Introduce a constant.
armiol Feb 17, 2020
a2e2c34
Make an `EventComparator` an abstract class and document its implemen…
armiol Feb 17, 2020
c37356a
Reduce the visibility and annotate properly.
armiol Feb 17, 2020
4e36865
Annotate the whole interface as `@Internal`.
armiol Feb 17, 2020
78a0180
Reformat the code.
armiol Feb 17, 2020
85c30d6
Use `Comparator.comparing()`.
armiol Feb 17, 2020
2c46776
Extract, document and test `Turbulence`.
armiol Feb 17, 2020
8846cab
Remove the `lazyArg` lambda.
armiol Feb 17, 2020
8dbb2b1
Improve the documentation.
armiol Feb 17, 2020
2e2c105
Return the catch-up ID when starting.
armiol Feb 17, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config
96 changes: 48 additions & 48 deletions license-report.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ all modules and does not describe the project structure per-subproject.

<groupId>io.spine</groupId>
<artifactId>spine-core-java</artifactId>
<version>1.4.4</version>
<version>1.4.5</version>

<inceptionYear>2015</inceptionYear>

Expand Down
7 changes: 7 additions & 0 deletions server/src/main/java/io/spine/server/BoundedContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import io.spine.system.server.SystemContext;
import io.spine.system.server.SystemReadSide;
import io.spine.type.TypeName;
import io.spine.type.TypeUrl;

import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -357,6 +358,12 @@ public Optional<Repository> findRepository(Class<? extends EntityState> stateCla
return repository;
}

@Internal
public Optional<Repository> findRepository(TypeUrl stateType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document.

Optional<Repository> repository = guard.repositoryFor(stateType);
return repository;
}

/**
* Verifies if this Bounded Context contains entities of the passed class.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,9 @@ public BoundedContext build() {

registerRepositories(result);
registerDispatchers(result);
ServerEnvironment.instance()
.delivery()
.registerDispatchersIn(result);
return result;
}

Expand Down
23 changes: 23 additions & 0 deletions server/src/main/java/io/spine/server/VisibilityGuard.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.spine.server.entity.Repository;
import io.spine.server.entity.model.EntityClass;
import io.spine.type.TypeName;
import io.spine.type.TypeUrl;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -107,6 +108,12 @@ Optional<Repository> repositoryFor(Class<? extends EntityState> stateClass) {
return repositoryAccess.get();
}

Optional<Repository> repositoryFor(TypeUrl stateType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document.

checkNotNull(stateType);
RepositoryAccess repositoryAccess = findOrThrow(stateType);
return repositoryAccess.get();
}

private RepositoryAccess findOrThrow(Class<? extends EntityState> stateClass) {
RepositoryAccess repository = repositories.get(stateClass);
if (repository == null) {
Expand All @@ -118,6 +125,22 @@ private RepositoryAccess findOrThrow(Class<? extends EntityState> stateClass) {
return repository;
}

private RepositoryAccess findOrThrow(TypeUrl stateType) {
Optional<RepositoryAccess> result =
repositories.values()
.stream()
.filter((r) -> r.repository.entityStateType()
.equals(stateType))
.findFirst();
if (!result.isPresent()) {
throw newIllegalStateException(
"A repository for the state type `%s` is not registered.",
stateType
);
}
return result.get();
}

/**
* Obtains a set of entity type names by their visibility.
*/
Expand Down
30 changes: 30 additions & 0 deletions server/src/main/java/io/spine/server/catchup/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2019, TeamDev. All rights reserved.
*
* Redistribution and use in source and/or binary forms, with or without
* modification, must retain the above copyright notice and the following
* disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/**
* A package defining the catch-up related commands and events.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot find any generated code in this package. Is this really used?

*/
@ParametersAreNonnullByDefault
@CheckReturnValue
package io.spine.server.catchup;

import com.google.errorprone.annotations.CheckReturnValue;

import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2020, TeamDev. All rights reserved.
*
* Redistribution and use in source and/or binary forms, with or without
* modification, must retain the above copyright notice and the following
* disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package io.spine.server.delivery;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableSet;
import io.spine.type.TypeUrl;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.Set;

/**
* An exception telling that the projection catch-up cannot be started, since some of the requested
* entities are already catching up.
*/
public final class CatchUpAlreadyStartedException extends IllegalStateException {

private static final long serialVersionUID = 0L;

private final TypeUrl projectionStateType;
private final @Nullable ImmutableSet<Object> requestedIds;

CatchUpAlreadyStartedException(TypeUrl type, @Nullable Set<?> ids) {
super();
projectionStateType = type;
requestedIds = ids == null ? null : ImmutableSet.copyOf(ids);
}

@Override
public String getMessage() {
String message = String.format(
"Cannot start the catch-up for the `%s` Projection, `%s`. " +
"Another catch-up is already in progress.",
projectionStateType, targetsAsString());
return message;
}

/**
* Returns the type URL of the projection for which the catch-up was requested.
*/
public TypeUrl projectionStateType() {
return projectionStateType;
}

/**
* Returns the IDs of the targets which were asked to catch up.
*
* <p>If all the projection entities were specified as a target, returns an empty {@code Set}.
*/
public ImmutableSet<Object> requestedIds() {
return requestedIds == null? ImmutableSet.of() : requestedIds;
}

private String targetsAsString() {
if (requestedIds == null) {
return "[all instances]";
}
return Joiner.on(',')
.join(requestedIds);
}
}
128 changes: 128 additions & 0 deletions server/src/main/java/io/spine/server/delivery/CatchUpMessages.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Copyright 2020, TeamDev. All rights reserved.
*
* Redistribution and use in source and/or binary forms, with or without
* modification, must retain the above copyright notice and the following
* disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package io.spine.server.delivery;

import com.google.common.collect.ImmutableList;
import com.google.protobuf.ProtocolStringList;
import io.spine.server.delivery.event.CatchUpCompleted;
import io.spine.server.delivery.event.CatchUpStarted;
import io.spine.server.delivery.event.HistoryEventsRecalled;
import io.spine.server.delivery.event.HistoryFullyRecalled;
import io.spine.server.delivery.event.LiveEventsPickedUp;
import io.spine.server.delivery.event.ShardProcessingRequested;
import io.spine.server.event.EventFilter;
import io.spine.server.event.EventStreamQuery;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableList.toImmutableList;

/**
* A utility class producing the messages related to the {@code CatchUp} process.
*/
final class CatchUpMessages {

private CatchUpMessages() {
}

/**
* Creates a {@code CatchUpStarted} event messages with the specified ID.
*/
static CatchUpStarted started(CatchUpId id) {
checkNotNull(id);
return CatchUpStarted.newBuilder()
.setId(id)
.vBuild();
}

/**
* Creates a limit to be used in quering the {@link io.spine.server.event.EventStore
* EventStore}.
*/
static EventStreamQuery.Limit limitOf(int value) {
return EventStreamQuery.Limit.newBuilder()
.setValue(value)
.vBuild();
}

/**
* Creates a {@code HistoryEventsRecalled} event messages with the specified ID.
*/
static HistoryEventsRecalled recalled(CatchUpId id) {
checkNotNull(id);
return HistoryEventsRecalled.newBuilder()
.setId(id)
.vBuild();
}

/**
* Creates a {@code HistoryFullyRecalled} event messages with the specified ID.
*/
static HistoryFullyRecalled fullyRecalled(CatchUpId id) {
checkNotNull(id);
return HistoryFullyRecalled.newBuilder()
.setId(id)
.vBuild();
}

/**
* Wraps the passed list of {@code String}s into a list of {@code EventFilter}s.
*/
static ImmutableList<EventFilter> toFilters(ProtocolStringList rawEventTypes) {
checkNotNull(rawEventTypes);
return rawEventTypes.stream()
.map(type -> EventFilter
.newBuilder()
.setEventType(type)
.build())
.collect(toImmutableList());
}

/**
* Creates a {@code LiveEventsPickedUp} event messages with the specified ID.
*/
static LiveEventsPickedUp liveEventsPickedUp(CatchUpId id) {
checkNotNull(id);
return LiveEventsPickedUp.newBuilder()
.setId(id)
.vBuild();
}

/**
* Creates a {@code CatchUpCompleted} event messages with the specified ID.
*/
static CatchUpCompleted catchUpCompleted(CatchUpId id) {
checkNotNull(id);
return CatchUpCompleted.newBuilder()
.setId(id)
.vBuild();
}

/**
* Creates a {@code ShardProcessingRequested} event messages with the specified index.
*/
static ShardProcessingRequested shardProcessingRequested(ShardIndex shardIndex) {
checkNotNull(shardIndex);
return ShardProcessingRequested
.newBuilder()
.setId(shardIndex)
.vBuild();
}
}
28 changes: 28 additions & 0 deletions server/src/main/java/io/spine/server/delivery/CatchUpMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2020, TeamDev. All rights reserved.
*
* Redistribution and use in source and/or binary forms, with or without
* modification, must retain the above copyright notice and the following
* disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package io.spine.server.delivery;

/**
* A mixin for the state of the {@linkplain CatchUp catch-up} {@linkplain CatchUpProcess processes}.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd go with only one link. Probably, to the message itself.

*/
public interface CatchUpMixin {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this empty mixin?


}
Loading