use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.
the class SubscriptionService method selectBoundedContext.
private BoundedContext selectBoundedContext(Subscription subscription) {
final TypeName typeName = TypeName.of(subscription.getTopic().getTarget().getType());
final TypeUrl type = typeName.toUrl();
final BoundedContext result = typeToContextMap.get(type);
return result;
}
use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.
the class Stand method update.
/**
* Updates the state of an entity inside of the current instance of {@code Stand}.
*
* <p>In case the entity update represents the new
* {@link io.spine.server.aggregate.Aggregate Aggregate} state,
* store the new value for the {@code Aggregate} to each of the configured instances of
* {@link StandStorage}.
*
* <p>Each {@code Aggregate} state value is stored as one-to-one to its
* {@link TypeUrl TypeUrl} obtained via {@link Any#getTypeUrl()}.
*
* <p>In case {@code Stand} already contains the state for this {@code Aggregate},
* the value will be replaced.
*
* <p>The state updates which are not originated from the {@code Aggregate} are not
* stored in the {@code Stand}.
*
* <p>In any case, the state update is then propagated to the callbacks.
* The set of matched callbacks is determined by filtering all the registered callbacks
* by the entity {@code TypeUrl}.
*
* <p>The matching callbacks are executed with the {@link #callbackExecutor}.
*
* @param envelope the updated entity state,
* packed as {@linkplain EntityStateEnvelope envelope}
*/
void update(final EntityStateEnvelope<?, ?> envelope) {
final EntityUpdateOperation op = new EntityUpdateOperation(envelope) {
@Override
public void run() {
final Object id = envelope.getEntityId();
final Message entityState = envelope.getMessage();
final Any packedState = AnyPacker.pack(entityState);
final TypeUrl entityTypeUrl = TypeUrl.of(entityState);
final boolean aggregateUpdate = typeRegistry.hasAggregateType(entityTypeUrl);
if (aggregateUpdate) {
final Optional<Version> entityVersion = envelope.getEntityVersion();
checkState(entityVersion.isPresent(), "The aggregate version must be set in order to update Stand. " + "Actual envelope: {}", envelope);
// checked above.
@SuppressWarnings("OptionalGetWithoutIsPresent") final Version versionValue = entityVersion.get();
final AggregateStateId aggregateStateId = AggregateStateId.of(id, entityTypeUrl);
final EntityRecord record = EntityRecord.newBuilder().setState(packedState).setVersion(versionValue).build();
storage.write(aggregateStateId, record);
}
notifyMatchingSubscriptions(id, packedState, entityTypeUrl);
}
};
op.execute();
}
use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.
the class AbstractTargetValidator method checkTargetSupported.
boolean checkTargetSupported(Target target) {
final TypeUrl typeUrl = getTypeOf(target);
final boolean result = typeRegistry.getTypes().contains(typeUrl);
return result;
}
use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.
the class AggregateStateIdStringifier method fromString.
@Override
protected AggregateStateId fromString(String s) {
checkNotNull(s);
final int typeUrlEndIndex = s.indexOf(DIVIDER);
checkArgument(typeUrlEndIndex > 0, "Passed string does not contain a type URL.");
final String typeUrlString = s.substring(0, typeUrlEndIndex);
final TypeUrl typeUrl = TypeUrl.parse(typeUrlString);
final int idTypeStartIndex = typeUrlEndIndex + 1;
final int idTypeEndIndex = s.indexOf(DIVIDER, idTypeStartIndex);
checkArgument(idTypeEndIndex > 0, "Passed string does not contain the ID type.");
final String idTypeString = s.substring(idTypeStartIndex, idTypeEndIndex);
final Class idType = idTypeFromString(idTypeString);
final String idStringValue = s.substring(idTypeEndIndex + 1);
final Object genericId = Stringifiers.fromString(idStringValue, idType);
final AggregateStateId result = AggregateStateId.of(genericId, typeUrl);
return result;
}
use of io.spine.type.TypeUrl in project core-java by SpineEventEngine.
the class StandShould method doCheckReadingCustomersById.
@CanIgnoreReturnValue
Stand doCheckReadingCustomersById(int numberOfCustomers) {
// Define the types and values used as a test data.
final TypeUrl customerType = TypeUrl.of(Customer.class);
final Map<CustomerId, Customer> sampleCustomers = fillSampleCustomers(numberOfCustomers);
// Prepare the stand and its storage to act.
final StandStorage standStorage = setupStandStorageWithCustomers(sampleCustomers, customerType);
final Stand stand = prepareStandWithAggregateRepo(standStorage);
triggerMultipleUpdates(sampleCustomers, stand);
final Query readMultipleCustomers = requestFactory.query().byIds(Customer.class, sampleCustomers.keySet());
final MemoizeQueryResponseObserver responseObserver = new MemoizeQueryResponseObserver();
stand.execute(readMultipleCustomers, responseObserver);
final List<Any> messageList = checkAndGetMessageList(responseObserver);
assertEquals(sampleCustomers.size(), messageList.size());
final Collection<Customer> allCustomers = sampleCustomers.values();
for (Any singleRecord : messageList) {
final Customer unpackedSingleResult = AnyPacker.unpack(singleRecord);
assertTrue(allCustomers.contains(unpackedSingleResult));
}
return stand;
}
Aggregations