Search in sources :

Example 1 with EventClass

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);
}
Also used : EventClass(io.spine.type.EventClass) Message(com.google.protobuf.Message) IdSetEventFunction(io.spine.server.entity.idfunc.IdSetEventFunction)

Example 2 with EventClass

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);
}
Also used : EventClass(io.spine.type.EventClass) Message(com.google.protobuf.Message) IdSetEventFunction(io.spine.server.entity.idfunc.IdSetEventFunction)

Example 3 with EventClass

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;
}
Also used : EventClass(io.spine.type.EventClass) ConstraintViolation(io.spine.validate.ConstraintViolation)

Example 4 with EventClass

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();
}
Also used : EventClass(io.spine.type.EventClass) ImmutableSet(com.google.common.collect.ImmutableSet) EventFilter(io.spine.server.event.EventFilter)

Example 5 with EventClass

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);
    }
}
Also used : EventClass(io.spine.type.EventClass)

Aggregations

EventClass (io.spine.type.EventClass)7 Message (com.google.protobuf.Message)3 IdSetEventFunction (io.spine.server.entity.idfunc.IdSetEventFunction)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 EventFilter (io.spine.server.event.EventFilter)1 ConstraintViolation (io.spine.validate.ConstraintViolation)1