Skip to content

Commit

Permalink
Merge pull request #1152 from SpineEventEngine/import-3d-party-events
Browse files Browse the repository at this point in the history
Import third-party events
  • Loading branch information
dmdashenkov authored Sep 4, 2019
2 parents 9b537f0 + e0f85cb commit 21a252e
Show file tree
Hide file tree
Showing 34 changed files with 1,117 additions and 120 deletions.
1 change: 0 additions & 1 deletion .idea/dictionaries/common.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions license-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Sun Sep 01 13:04:20 EEST 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Wed Sep 04 14:39:07 EEST 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).



Expand Down Expand Up @@ -865,7 +865,7 @@ This report was generated on **Sun Sep 01 13:04:20 EEST 2019** using [Gradle-Lic
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Sun Sep 01 13:04:20 EEST 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Wed Sep 04 14:39:08 EEST 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).



Expand Down Expand Up @@ -1321,7 +1321,7 @@ This report was generated on **Sun Sep 01 13:04:20 EEST 2019** using [Gradle-Lic
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Sun Sep 01 13:04:21 EEST 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Wed Sep 04 14:39:09 EEST 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).



Expand Down Expand Up @@ -1939,7 +1939,7 @@ This report was generated on **Sun Sep 01 13:04:21 EEST 2019** using [Gradle-Lic
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Sun Sep 01 13:04:22 EEST 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Wed Sep 04 14:39:10 EEST 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).



Expand Down Expand Up @@ -2461,7 +2461,7 @@ This report was generated on **Sun Sep 01 13:04:22 EEST 2019** using [Gradle-Lic
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Sun Sep 01 13:04:23 EEST 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Wed Sep 04 14:39:11 EEST 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).



Expand Down Expand Up @@ -2993,7 +2993,7 @@ This report was generated on **Sun Sep 01 13:04:23 EEST 2019** using [Gradle-Lic
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Sun Sep 01 13:04:23 EEST 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Wed Sep 04 14:39:11 EEST 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).



Expand Down Expand Up @@ -3533,7 +3533,7 @@ This report was generated on **Sun Sep 01 13:04:23 EEST 2019** using [Gradle-Lic
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Sun Sep 01 13:04:24 EEST 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Wed Sep 04 14:39:12 EEST 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).



Expand Down Expand Up @@ -4119,4 +4119,4 @@ This report was generated on **Sun Sep 01 13:04:24 EEST 2019** using [Gradle-Lic
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Sun Sep 01 13:04:25 EEST 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Wed Sep 04 14:39:13 EEST 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
30 changes: 28 additions & 2 deletions server/src/main/java/io/spine/server/BoundedContextBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import io.spine.server.event.EventDispatcher;
import io.spine.server.event.EventEnricher;
import io.spine.server.integration.IntegrationBus;
import io.spine.server.security.Security;
import io.spine.server.stand.Stand;
import io.spine.server.tenant.TenantIndex;
import io.spine.server.type.CommandEnvelope;
Expand Down Expand Up @@ -100,7 +101,7 @@ public final class BoundedContextBuilder implements Logging {
private final Collection<Repository<?, ?>> repositories = new ArrayList<>();

/**
* Prevents direct instantiation.
* Creates a new builder with the given spec.
*
* @param spec
* the context spec for the built context
Expand All @@ -112,10 +113,12 @@ public final class BoundedContextBuilder implements Logging {
}

/**
* Prevents direct instantiation.
* Creates a new builder with the given spec and system features.
*
* @param spec
* the context spec for the built context
* @param systemFeatures
* system feature flags; can be changed later via {@link #systemFeatures()}
* @see BoundedContext#singleTenant
* @see BoundedContext#multitenant
*/
Expand Down Expand Up @@ -145,6 +148,29 @@ public static BoundedContextBuilder assumingTests() {
return assumingTests(false);
}

/**
* Creates a new builder for a Bounded Context which does not store its events.
*
* <p>Such a Bounded Context should not be used general case. This method throws
* a {@link SecurityException} if called outside the framework core. Please use static factory
* methods in {@link BoundedContext} to create an instance of builder.
*/
@Internal
public static BoundedContextBuilder notStoringEvents(String name, boolean multitenant) {
checkNotNull(name);
Security.allowOnlyFrameworkServer();

ContextSpec spec = multitenant
? multitenant(name)
: singleTenant(name);
BoundedContextBuilder builder = new BoundedContextBuilder(spec.notStoringEvents());
builder.systemFeatures()
.forgetEvents()
.disableAggregateQuerying()
.disableCommandLog();
return builder;
}

/**
* Obtains the context spec.
*/
Expand Down
1 change: 0 additions & 1 deletion server/src/main/java/io/spine/server/aggregate/Apply.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,3 @@
*/
boolean allowImport() default false;
}

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.spine.server.type.EventEnvelope;
import io.spine.type.TypeName;

import static io.spine.core.EventValidationError.UNSUPPORTED_EVENT_VALUE;
import static io.spine.server.event.EventException.eventTypeAttribute;
import static java.lang.String.format;

Expand Down Expand Up @@ -71,7 +72,7 @@ private static Error unsupportedImportEvent(Message eventMessage, String errorMe
Error result = Error
.newBuilder()
.setType(UnsupportedImportEventException.class.getName())
.setCode(-1)
.setCode(UNSUPPORTED_EVENT_VALUE)
.setMessage(errorMessage)
.putAllAttributes(eventTypeAttribute(eventMessage))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
*
* <p>An entity column can be of any type. Most common types are already supported if an existing
* implementation of the {@link io.spine.server.storage.Storage Spine Storage} is used.
* However, their behavior can be overriden using {@link ColumnTypeRegistry}.
* However, their behavior can be overridden using {@link ColumnTypeRegistry}.
*
* <p>To handle column types not supported by default implement the {@link ColumnType}
* interface, register it in a {@link ColumnTypeRegistry} and pass the instance of the registry
Expand Down
3 changes: 2 additions & 1 deletion server/src/main/java/io/spine/server/event/EventBus.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ protected EventEnvelope toEnvelope(Event message) {
public EventStore eventStore() {
checkNotNull(
eventStore,
"`EventStore` is not initialized. Please call `EventBus.init(BoundedContext)`."
"`EventStore` is not initialized. " +
"Please call `EventBus.registerWith(BoundedContext)`."
);
return eventStore;
}
Expand Down
19 changes: 19 additions & 0 deletions server/src/main/java/io/spine/server/event/EventFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.protobuf.Timestamp;
import io.spine.base.EventMessage;
import io.spine.base.RejectionMessage;
import io.spine.core.ActorContext;
import io.spine.core.Event;
import io.spine.core.EventContext;
import io.spine.core.EventId;
Expand Down Expand Up @@ -73,6 +74,24 @@ public static EventFactory on(MessageEnvelope origin, Any producerId) {
return new EventFactory(eventOrigin, producerId);
}

/**
* Creates a new event factory for producing events to be imported into a Bounced Context.
*
* @param actorContext
* the description of the actor who imports the events
* @param producerId
* the ID of the system which produced the events
* @return new event factory
*/
public static EventFactory forImport(ActorContext actorContext, Any producerId) {
checkNotNull(actorContext);
checkNotNull(producerId);
checkValid(actorContext);

EventOrigin origin = EventOrigin.forImport(actorContext);
return new EventFactory(origin, producerId);
}

/**
* Creates an event for the passed event message.
*
Expand Down
4 changes: 2 additions & 2 deletions server/src/main/java/io/spine/server/event/React.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
* <ul>
* <li>be annotated with {@link React @React};
* <li>have package-private visibility;
* <li>accept an event message (derived from {@link io.spine.base.EventMessage
* EventMessage}) as the first parameter;
* <li>accept an event message (derived from {@link io.spine.base.EventMessage EventMessage})
* as the first parameter;
* <li>return an event message derived from {@link io.spine.base.EventMessage Message}
* <strong>or</strong> several event messages returned as an {@code Iterable}.
* </ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ abstract class EventAcceptingSignature<H extends HandlerMethod<?, ?, EventEnvelo

/**
* This field is also is used by {@link SubscriberSignature} to avoid repeated scanning in
* the overriden {@link #paramSpecs()}.
* the overridden {@link #paramSpecs()}.
*/
static final ImmutableSet<EventAcceptingMethodParams>
PARAM_SPEC = ImmutableSet.copyOf(EventAcceptingMethodParams.values());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import io.spine.core.BoundedContextName;
import io.spine.server.transport.Publisher;

import java.util.Set;

import static com.google.common.base.Preconditions.checkNotNull;
import static io.spine.base.Identifier.newUuid;
import static io.spine.base.Identifier.pack;
Expand All @@ -40,7 +38,7 @@ final class ConfigurationBroadcast {
private final BoundedContextName contextName;
private final Publisher needsPublisher;

private ImmutableSet<ExternalMessageType> knownNeeds = ImmutableSet.of();
private ImmutableSet<ExternalMessageType> requestedTypes = ImmutableSet.of();

ConfigurationBroadcast(BoundedContextName contextName, Publisher publisher) {
this.contextName = checkNotNull(contextName);
Expand All @@ -50,17 +48,15 @@ final class ConfigurationBroadcast {
/**
* Notifies other Bounded contexts about a change in the requested messages.
*
* <p>If the given {@code needs} are the same as previous ones, i.e. the needs did not change,
* the request is not sent.
* <p>If the given {@code types} are the same as previous ones, the request is not sent.
*
* @param needs
* the new needs of current context
* @param types
* the types
*/
synchronized void onNeedsUpdated(Set<ExternalMessageType> needs) {
checkNotNull(needs);
ImmutableSet<ExternalMessageType> newNeeds = ImmutableSet.copyOf(needs);
if (!knownNeeds.equals(newNeeds)) {
knownNeeds = newNeeds;
synchronized void onTypesChanged(ImmutableSet<ExternalMessageType> types) {
checkNotNull(types);
if (!requestedTypes.equals(types)) {
requestedTypes = types;
send();
}
}
Expand All @@ -71,7 +67,7 @@ synchronized void onNeedsUpdated(Set<ExternalMessageType> needs) {
synchronized void send() {
RequestForExternalMessages request = RequestForExternalMessages
.newBuilder()
.addAllRequestedMessageType(knownNeeds)
.addAllRequestedMessageType(requestedTypes)
.buildPartial();
ExternalMessage externalMessage = ExternalMessages.of(request, contextName);
needsPublisher.publish(pack(newUuid()), externalMessage);
Expand Down
Loading

0 comments on commit 21a252e

Please sign in to comment.