use of io.spine.type.EventClass in project core-java by SpineEventEngine.
the class IdSetFunctions method put.
/**
* Puts a function into the map.
*
* @param eventClass the class of the event handled by the function
* @param func the function instance
* @param <E> the type of the event message
*/
public <E extends Message> void put(Class<E> eventClass, IdSetEventFunction<I, E> func) {
final EventClass clazz = EventClass.of(eventClass);
@SuppressWarnings("unchecked") final IdSetEventFunction<I, Message> // since we want to store {@code IdSetFunction}s for various event types.
casted = (IdSetEventFunction<I, Message>) func;
map.put(clazz, casted);
}
use of io.spine.type.EventClass in project core-java by SpineEventEngine.
the class IdSetFunctions method get.
/**
* Obtains a function for the passed event class.
*
* @param eventClass the class of the event message
* @param <E> the type of the event message
* @return the function wrapped into {@code Optional} or empty {@code Optional}
* if there is no matching function
*/
public <E extends Message> Optional<IdSetEventFunction<I, E>> get(Class<E> eventClass) {
final EventClass clazz = EventClass.of(eventClass);
final IdSetEventFunction<I, Message> func = map.get(clazz);
// we ensure the type when we put into the map.
@SuppressWarnings("unchecked") final IdSetEventFunction<I, E> result = (IdSetEventFunction<I, E>) func;
return Optional.fromNullable(result);
}
use of io.spine.type.EventClass in project core-java by SpineEventEngine.
the class EventBus method validateMessage.
@Override
protected boolean validateMessage(Message event, StreamObserver<Response> responseObserver) {
final EventClass eventClass = EventClass.of(event);
if (isUnsupportedEvent(eventClass)) {
final UnsupportedEventException unsupportedEvent = new UnsupportedEventException(event);
responseObserver.onError(invalidArgumentWithCause(unsupportedEvent, unsupportedEvent.getError()));
return false;
}
final List<ConstraintViolation> violations = eventValidator.validate(event);
if (!violations.isEmpty()) {
final InvalidEventException invalidEvent = InvalidEventException.onConstraintViolations(event, violations);
responseObserver.onError(invalidArgumentWithCause(invalidEvent, invalidEvent.getError()));
return false;
}
return true;
}
use of io.spine.type.EventClass in project core-java by SpineEventEngine.
the class ProjectionRepository method getEventFilters.
/**
* Obtains event filters for event classes handled by projections of this repository.
*/
private Set<EventFilter> getEventFilters() {
final ImmutableSet.Builder<EventFilter> builder = ImmutableSet.builder();
final Set<EventClass> eventClasses = getMessageClasses();
for (EventClass eventClass : eventClasses) {
final String typeName = TypeName.of(eventClass.value()).value();
builder.add(EventFilter.newBuilder().setEventType(typeName).build());
}
return builder.build();
}
use of io.spine.type.EventClass in project core-java by SpineEventEngine.
the class ProcessManagerRepository method checkEventClass.
private void checkEventClass(EventEnvelope eventEnvelope) throws IllegalArgumentException {
final EventClass eventClass = eventEnvelope.getMessageClass();
final Set<EventClass> classes = getMessageClasses();
if (!classes.contains(eventClass)) {
final String eventClassName = eventClass.value().getName();
throw newIllegalArgumentException("Unexpected event of class: %s", eventClassName);
}
}
Aggregations