use of io.spine.server.integration.ExternalMessageClass in project core-java by SpineEventEngine.
the class AggregateRepository method onRegistered.
/**
* {@inheritDoc}
*
* <p>{@linkplain io.spine.server.commandbus.CommandBus#register(
* io.spine.server.bus.MessageDispatcher) Registers} itself with the {@code CommandBus} of the
* parent {@code BoundedContext}.
*/
@Override
public void onRegistered() {
super.onRegistered();
final BoundedContext boundedContext = getBoundedContext();
final Set<CommandClass> commandClasses = getMessageClasses();
final DelegatingEventDispatcher<I> eventDispatcher;
eventDispatcher = DelegatingEventDispatcher.of(this);
final Set<EventClass> eventClasses = eventDispatcher.getMessageClasses();
final ExternalMessageDispatcher<I> extEventDispatcher;
extEventDispatcher = eventDispatcher.getExternalDispatcher();
final Set<ExternalMessageClass> extEventClasses = extEventDispatcher.getMessageClasses();
final DelegatingRejectionDispatcher<I> rejectionDispatcher;
rejectionDispatcher = DelegatingRejectionDispatcher.of(this);
final Set<RejectionClass> rejectionClasses = rejectionDispatcher.getMessageClasses();
final ExternalMessageDispatcher<I> extRejectionDispatcher;
extRejectionDispatcher = rejectionDispatcher.getExternalDispatcher();
final Set<ExternalMessageClass> extRejectionClasses = extRejectionDispatcher.getMessageClasses();
if (commandClasses.isEmpty() && eventClasses.isEmpty() && rejectionClasses.isEmpty() && extEventClasses.isEmpty() && extRejectionClasses.isEmpty()) {
throw newIllegalStateException("Aggregates of the repository %s neither handle commands" + " nor react on events or rejections.", this);
}
registerInCommandBus(boundedContext, commandClasses);
registerInEventBus(boundedContext, eventDispatcher, eventClasses);
registerInRejectionBus(boundedContext, rejectionDispatcher, rejectionClasses);
registerExtMessageDispatcher(boundedContext, extEventDispatcher, extEventClasses);
registerExtMessageDispatcher(boundedContext, extRejectionDispatcher, extRejectionClasses);
this.commandErrorHandler = CommandErrorHandler.with(boundedContext.getRejectionBus());
}
use of io.spine.server.integration.ExternalMessageClass in project core-java by SpineEventEngine.
the class DelegatingEventDispatcher method getExternalDispatcher.
/**
* Wraps this dispatcher to an external event dispatcher.
*
* @return the external rejection dispatcher proxying calls to the underlying instance
*/
public ExternalMessageDispatcher<I> getExternalDispatcher() {
return new ExternalMessageDispatcher<I>() {
@Override
public Set<ExternalMessageClass> getMessageClasses() {
final Set<EventClass> eventClasses = delegate.getExternalEventClasses();
return ExternalMessageClass.fromEventClasses(eventClasses);
}
@Override
public Set<I> dispatch(ExternalMessageEnvelope envelope) {
final EventEnvelope eventEnvelope = asEventEnvelope(envelope);
final Set<I> ids = delegate.dispatchEvent(eventEnvelope);
return ids;
}
@Override
public void onError(ExternalMessageEnvelope envelope, RuntimeException exception) {
final EventEnvelope eventEnvelope = asEventEnvelope(envelope);
delegate.onError(eventEnvelope, exception);
}
};
}
use of io.spine.server.integration.ExternalMessageClass in project core-java by SpineEventEngine.
the class DelegatingRejectionDispatcher method getExternalDispatcher.
/**
* Wraps this dispatcher to an external rejection dispatcher.
*
* @return the external rejection dispatcher proxying calls to the underlying instance
*/
public ExternalMessageDispatcher<I> getExternalDispatcher() {
return new ExternalMessageDispatcher<I>() {
@Override
public Set<ExternalMessageClass> getMessageClasses() {
final Set<RejectionClass> rejectionClasses = delegate.getExternalRejectionClasses();
return ExternalMessageClass.fromRejectionClasses(rejectionClasses);
}
@Override
public Set<I> dispatch(ExternalMessageEnvelope envelope) {
final ExternalMessage externalMessage = envelope.getOuterObject();
final Rejection rejection = unpack(externalMessage.getOriginalMessage());
final Set<I> ids = delegate.dispatchRejection(RejectionEnvelope.of(rejection));
return ids;
}
@Override
public void onError(ExternalMessageEnvelope envelope, RuntimeException exception) {
final MessageClass messageClass = envelope.getMessageClass();
final String messageId = Stringifiers.toString(envelope.getId());
final String errorMessage = format("Error dispatching external rejection (class: %s, id: %s)", messageClass, messageId);
log().error(errorMessage, exception);
}
};
}
Aggregations