Search in sources :

Example 1 with DefaultConcurrencyResolver

use of com.kloia.eventapis.cassandra.DefaultConcurrencyResolver in project eventapis by kloiasoft.

the class CommandExecutionInterceptor method recordCommand.

private CommandRecord recordCommand(JoinPoint jp, CommandHandler commandHandler, Command command) throws ConcurrentEventException, EventStoreException {
    EventRepository eventRepository;
    CommandDto commandDto = null;
    CommandRecord commandRecord = new CommandRecord();
    commandRecord.setEventName(commandHandler.getClass().getSimpleName());
    for (int i = 0; i < jp.getArgs().length; i++) {
        Object arg = jp.getArgs()[i];
        commandRecord.getParameters().put(i, arg);
    }
    // }
    try {
        Field declaredField = commandHandler.getClass().getDeclaredField(command.eventRepository());
        if (!declaredField.isAccessible())
            declaredField.setAccessible(true);
        eventRepository = (EventRepository) declaredField.get(commandHandler);
    } catch (IllegalAccessException | NoSuchFieldException e) {
        log.error("Error while accessing EventRecorder(" + command.eventRepository() + ") of Command:" + commandHandler.getClass().getSimpleName() + " message: " + e.getMessage(), e);
        return null;
    }
    if (eventRepository != null) {
        eventRepository.getEventRecorder().recordEntityEvent(commandRecord, System.currentTimeMillis(), Optional.empty(), entityEvent -> new DefaultConcurrencyResolver());
    } else
        log.error("Error while accessing EventRecorder(" + command.eventRepository() + " is null ) of Command:" + commandHandler.getClass().getSimpleName());
    return commandRecord;
}
Also used : Field(java.lang.reflect.Field) DefaultConcurrencyResolver(com.kloia.eventapis.cassandra.DefaultConcurrencyResolver) EventRepository(com.kloia.eventapis.api.EventRepository) CommandDto(com.kloia.eventapis.api.CommandDto) CommandRecord(com.kloia.eventapis.pojos.CommandRecord) JoinPoint(org.aspectj.lang.JoinPoint)

Aggregations

CommandDto (com.kloia.eventapis.api.CommandDto)1 EventRepository (com.kloia.eventapis.api.EventRepository)1 DefaultConcurrencyResolver (com.kloia.eventapis.cassandra.DefaultConcurrencyResolver)1 CommandRecord (com.kloia.eventapis.pojos.CommandRecord)1 Field (java.lang.reflect.Field)1 JoinPoint (org.aspectj.lang.JoinPoint)1