Skip to content

Commit

Permalink
fix: Create ocpp services at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
juherr committed Aug 29, 2023
1 parent de29db8 commit 697d909
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/main/java/de/rwth/idsg/steve/config/OcppConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.ContextStartedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.Collections;
Expand All @@ -56,10 +60,24 @@ public class OcppConfiguration {
LogUtils.setLoggerClass(Slf4jLogger.class);
}

private final CentralSystemService ocpp12Server;
private final ocpp.cs._2012._06.CentralSystemService ocpp15Server;
private final ocpp.cs._2015._10.CentralSystemService ocpp16Server;
private final List<Interceptor<? extends Message>> interceptors;
private final List<Feature> logging;
private final String routerEndpointPath;

public OcppConfiguration(CentralSystemService ocpp12Server, ocpp.cs._2012._06.CentralSystemService ocpp15Server, ocpp.cs._2015._10.CentralSystemService ocpp16Server, @Qualifier("MessageHeaderInterceptor") PhaseInterceptor<Message> messageHeaderInterceptor) {
List<Interceptor<? extends Message>> interceptors = asList(new MessageIdInterceptor(), messageHeaderInterceptor);
List<Feature> logging = singletonList(LoggingFeatureProxy.INSTANCE.get());
this.ocpp12Server = ocpp12Server;
this.ocpp15Server = ocpp15Server;
this.ocpp16Server = ocpp16Server;
this.interceptors = asList(new MessageIdInterceptor(), messageHeaderInterceptor);
this.logging = singletonList(LoggingFeatureProxy.INSTANCE.get());
this.routerEndpointPath = CONFIG.getRouterEndpointPath();
}

@EventListener
public void afterStart(ContextRefreshedEvent event) {
createOcppService(ocpp12Server, "/CentralSystemServiceOCPP12", interceptors, logging);
createOcppService(ocpp15Server, "/CentralSystemServiceOCPP15", interceptors, logging);
createOcppService(ocpp16Server, "/CentralSystemServiceOCPP16", interceptors, logging);
Expand All @@ -68,7 +86,7 @@ public OcppConfiguration(CentralSystemService ocpp12Server, ocpp.cs._2012._06.Ce
// one to be created, since in MediatorInInterceptor we go over created/registered services and build a map.
//
List<Interceptor<? extends Message>> mediator = singletonList(new MediatorInInterceptor(springBus()));
createOcppService(ocpp12Server, CONFIG.getRouterEndpointPath(), mediator, Collections.emptyList());
createOcppService(ocpp12Server, routerEndpointPath, mediator, Collections.emptyList());
}

@Bean(name = Bus.DEFAULT_BUS_ID, destroyMethod = "shutdown")
Expand Down

0 comments on commit 697d909

Please sign in to comment.