@@ -0,0 +1,2269 @@
+package com.github.aureliano.evtbridge.core.register;%0A%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0Aimport com.github.aureliano.evtbridge.core.agent.IAgent;%0Aimport com.github.aureliano.evtbridge.core.config.IConfiguration;%0Aimport com.github.aureliano.evtbridge.core.exception.EventBridgeException;%0Aimport com.github.aureliano.evtbridge.core.helper.ReflectionHelper;%0Aimport com.github.aureliano.evtbridge.core.helper.StringHelper;%0A%0Apublic final class ApiServiceRegistrator %7B%0A%0A%09private static ApiServiceRegistrator instance;%0A%09%0A%09private Map%3CString, ServiceRegistration%3E registrations;%0A%09%0A%09private ApiServiceRegistrator() %7B%0A%09%09this.registrations = new HashMap%3CString, ServiceRegistration%3E();%0A%09%7D%0A%09%0A%09public void registrate(Class%3C? extends IConfiguration%3E configuration, Class%3C? extends IAgent%3E executor) %7B%0A%09%09this.registrate(this.createService(configuration, executor));%0A%09%7D%0A%09%0A%09public void registrate(ServiceRegistration registration) %7B%0A%09%09if (StringHelper.isEmpty(registration.getId())) %7B%0A%09%09%09if (registration.getConfiguration() != null) %7B%0A%09%09%09%09IConfiguration configuration = (IConfiguration) ReflectionHelper.newInstance(registration.getConfiguration());%0A%09%09%09%09registration.withId(configuration.id());%0A%09%09%09%7D else %7B%0A%09%09%09%09throw new EventBridgeException(%22Service registration expected to get a valid id but got an empty value.%22);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A%09%09this.registrations.put(registration.getId(), registration);%0A%09%7D%0A%09%0A%09public IAgent createExecutor(IConfiguration configuration) %7B%0A%09%09ServiceRegistration registration = this.registrations.get(configuration.id());%0A%09%09%0A%09%09if ((registration == null) %7C%7C (registration.getExecutor() == null)) %7B%0A%09%09%09throw new EventBridgeException(%22There isn't an executor (reader/writer) registered with ID %22 + configuration.id());%0A%09%09%7D%0A%09%09%0A%09%09IAgent executor = (IAgent) ReflectionHelper.newInstance(registration.getExecutor());%0A%09%09return executor.withConfiguration(configuration);%0A%09%7D%0A%09%0A%09public static ApiServiceRegistrator instance() %7B%0A%09%09if (instance == null) %7B%0A%09%09%09instance = new ApiServiceRegistrator();%0A%09%09%7D%0A%09%09%0A%09%09return instance;%0A%09%7D%0A%09%0A%09private ServiceRegistration createService(Class%3C? extends IConfiguration%3E configuration,%0A%09%09%09Class%3C? extends IAgent%3E executor) %7B%0A%09%09%0A%09%09return new ServiceRegistration()%0A%09%09%09.withConfiguration(configuration)%0A%09%09%09.withExecutor(executor);%0A%09%7D%0A%7D

Create API service registrator.