Skip to content

Commit b153d83

Browse files
committed
remove custom DelegatingTaskExecutor
reason: better interop with Spring Boot conventions. Async-annotated methods in NotificationServiceForUser [1] are not executed by our customized "SteVe-TaskExecutor" but default Spring Boot task executor. this is because DelegatingTaskExecutor does not extend some necessary interfaces which Spring Boot uses to decide whether to create a default. getting rid ofthis wrapper since it was not useful anyways. then, using the conventions from Spring Boot to create and name a task executor [2]. [1] introduced in #1263 [2] https://docs.spring.io/spring-boot/reference/features/task-execution-and-scheduling.html
1 parent 12f4cea commit b153d83

File tree

6 files changed

+39
-86
lines changed

6 files changed

+39
-86
lines changed

src/main/java/de/rwth/idsg/steve/config/BeanConfiguration.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,17 @@ public DelegatingTaskScheduler asyncTaskScheduler() {
144144
return new DelegatingTaskScheduler(scheduler);
145145
}
146146

147-
@Bean(destroyMethod = "close")
148-
public DelegatingTaskExecutor asyncTaskExecutor() {
147+
@Bean
148+
@Primary
149+
public ThreadPoolTaskExecutor taskExecutor() {
149150
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
150151
executor.setCorePoolSize(5);
151152
executor.setThreadNamePrefix("SteVe-TaskExecutor-");
152153
executor.setWaitForTasksToCompleteOnShutdown(true);
153154
executor.setAwaitTerminationSeconds(30);
154155
executor.initialize();
155156

156-
return new DelegatingTaskExecutor(executor);
157+
return executor;
157158
}
158159

159160
/**

src/main/java/de/rwth/idsg/steve/config/DelegatingTaskExecutor.java

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/main/java/de/rwth/idsg/steve/ocpp/soap/MessageHeaderInterceptor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package de.rwth.idsg.steve.ocpp.soap;
2020

21-
import de.rwth.idsg.steve.config.DelegatingTaskExecutor;
2221
import de.rwth.idsg.steve.ocpp.OcppProtocol;
2322
import de.rwth.idsg.steve.repository.OcppServerRepository;
2423
import de.rwth.idsg.steve.repository.impl.ChargePointRepositoryImpl;
@@ -37,6 +36,7 @@
3736
import org.apache.cxf.ws.addressing.AddressingProperties;
3837
import org.apache.cxf.ws.addressing.ContextUtils;
3938
import org.apache.cxf.ws.addressing.EndpointReferenceType;
39+
import org.springframework.core.task.TaskExecutor;
4040
import org.springframework.stereotype.Component;
4141

4242
import javax.xml.namespace.QName;
@@ -61,18 +61,18 @@ public class MessageHeaderInterceptor extends AbstractPhaseInterceptor<Message>
6161

6262
private final OcppServerRepository ocppServerRepository;
6363
private final ChargePointRegistrationService chargePointRegistrationService;
64-
private final DelegatingTaskExecutor asyncTaskExecutor;
64+
private final TaskExecutor taskExecutor;
6565

6666
private static final String BOOT_OPERATION_NAME = "BootNotification";
6767
private static final String CHARGEBOX_ID_HEADER = "ChargeBoxIdentity";
6868

6969
public MessageHeaderInterceptor(OcppServerRepository ocppServerRepository,
7070
ChargePointRegistrationService chargePointRegistrationService,
71-
DelegatingTaskExecutor asyncTaskExecutor) {
71+
TaskExecutor taskExecutor) {
7272
super(Phase.PRE_INVOKE);
7373
this.ocppServerRepository = ocppServerRepository;
7474
this.chargePointRegistrationService = chargePointRegistrationService;
75-
this.asyncTaskExecutor = asyncTaskExecutor;
75+
this.taskExecutor = taskExecutor;
7676
}
7777

7878
@Override
@@ -97,7 +97,7 @@ public void handleMessage(Message message) throws Fault {
9797
// 2. update endpoint
9898
// -------------------------------------------------------------------------
9999

100-
asyncTaskExecutor.execute(() -> {
100+
taskExecutor.execute(() -> {
101101
try {
102102
String endpointAddress = getEndpointAddress(message);
103103
if (endpointAddress != null) {

src/main/java/de/rwth/idsg/steve/service/BackgroundService.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
*/
1919
package de.rwth.idsg.steve.service;
2020

21-
import de.rwth.idsg.steve.config.DelegatingTaskExecutor;
2221
import de.rwth.idsg.steve.repository.dto.ChargePointSelect;
2322
import lombok.AccessLevel;
2423
import lombok.RequiredArgsConstructor;
24+
import org.springframework.core.task.TaskExecutor;
2525

2626
import java.util.List;
2727
import java.util.function.Consumer;
@@ -33,10 +33,10 @@
3333
@RequiredArgsConstructor
3434
public class BackgroundService {
3535

36-
private final DelegatingTaskExecutor asyncTaskExecutor;
36+
private final TaskExecutor taskExecutor;
3737

38-
public static BackgroundService with(DelegatingTaskExecutor asyncTaskExecutor) {
39-
return new BackgroundService(asyncTaskExecutor);
38+
public static BackgroundService with(TaskExecutor taskExecutor) {
39+
return new BackgroundService(taskExecutor);
4040
}
4141

4242
public Runner forFirst(List<ChargePointSelect> list) {
@@ -57,7 +57,7 @@ private class BackgroundSingleRunner implements Runner {
5757

5858
@Override
5959
public void execute(Consumer<ChargePointSelect> consumer) {
60-
asyncTaskExecutor.execute(() -> consumer.accept(cps));
60+
taskExecutor.execute(() -> consumer.accept(cps));
6161
}
6262
}
6363

@@ -67,7 +67,7 @@ private class BackgroundListRunner implements Runner {
6767

6868
@Override
6969
public void execute(Consumer<ChargePointSelect> consumer) {
70-
asyncTaskExecutor.execute(() -> list.forEach(consumer));
70+
taskExecutor.execute(() -> list.forEach(consumer));
7171
}
7272
}
7373
}

src/main/java/de/rwth/idsg/steve/service/ChargePointServiceClient.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package de.rwth.idsg.steve.service;
2020

2121
import de.rwth.idsg.steve.SteveException;
22-
import de.rwth.idsg.steve.config.DelegatingTaskExecutor;
2322
import de.rwth.idsg.steve.ocpp.ChargePointServiceInvokerImpl;
2423
import de.rwth.idsg.steve.ocpp.OcppCallback;
2524
import de.rwth.idsg.steve.ocpp.task.CancelReservationTask;
@@ -73,6 +72,7 @@
7372
import ocpp.cp._2015._10.ChargingProfilePurposeType;
7473
import ocpp.cp._2015._10.GetCompositeScheduleResponse;
7574
import org.joda.time.DateTime;
75+
import org.springframework.core.task.TaskExecutor;
7676
import org.springframework.stereotype.Service;
7777

7878
import java.util.List;
@@ -90,7 +90,7 @@ public class ChargePointServiceClient {
9090
private final ReservationRepository reservationRepository;
9191
private final OcppTagService ocppTagService;
9292

93-
private final DelegatingTaskExecutor asyncTaskExecutor;
93+
private final TaskExecutor taskExecutor;
9494
private final TaskStore taskStore;
9595
private final ChargePointServiceInvokerImpl invoker;
9696

@@ -107,7 +107,7 @@ public final int changeAvailability(ChangeAvailabilityParams params,
107107
task.addCallback(callback);
108108
}
109109

110-
BackgroundService.with(asyncTaskExecutor)
110+
BackgroundService.with(taskExecutor)
111111
.forEach(task.getParams().getChargePointSelectList())
112112
.execute(c -> invoker.changeAvailability(c, task));
113113

@@ -123,7 +123,7 @@ public final int changeConfiguration(ChangeConfigurationParams params,
123123
task.addCallback(callback);
124124
}
125125

126-
BackgroundService.with(asyncTaskExecutor)
126+
BackgroundService.with(taskExecutor)
127127
.forEach(task.getParams().getChargePointSelectList())
128128
.execute(c -> invoker.changeConfiguration(c, task));
129129

@@ -139,7 +139,7 @@ public final int clearCache(MultipleChargePointSelect params,
139139
task.addCallback(callback);
140140
}
141141

142-
BackgroundService.with(asyncTaskExecutor)
142+
BackgroundService.with(taskExecutor)
143143
.forEach(task.getParams().getChargePointSelectList())
144144
.execute(c -> invoker.clearCache(c, task));
145145

@@ -155,7 +155,7 @@ public final int getDiagnostics(GetDiagnosticsParams params,
155155
task.addCallback(callback);
156156
}
157157

158-
BackgroundService.with(asyncTaskExecutor)
158+
BackgroundService.with(taskExecutor)
159159
.forEach(task.getParams().getChargePointSelectList())
160160
.execute(c -> invoker.getDiagnostics(c, task));
161161

@@ -171,7 +171,7 @@ public final int reset(ResetParams params,
171171
task.addCallback(callback);
172172
}
173173

174-
BackgroundService.with(asyncTaskExecutor)
174+
BackgroundService.with(taskExecutor)
175175
.forEach(task.getParams().getChargePointSelectList())
176176
.execute(c -> invoker.reset(c, task));
177177

@@ -187,7 +187,7 @@ public final int updateFirmware(UpdateFirmwareParams params,
187187
task.addCallback(callback);
188188
}
189189

190-
BackgroundService.with(asyncTaskExecutor)
190+
BackgroundService.with(taskExecutor)
191191
.forEach(task.getParams().getChargePointSelectList())
192192
.execute(c -> invoker.updateFirmware(c, task));
193193

@@ -217,7 +217,7 @@ public final int remoteStartTransaction(RemoteStartTransactionParams params,
217217
task.addCallback(callback);
218218
}
219219

220-
BackgroundService.with(asyncTaskExecutor)
220+
BackgroundService.with(taskExecutor)
221221
.forFirst(task.getParams().getChargePointSelectList())
222222
.execute(c -> invoker.remoteStartTransaction(c, task));
223223

@@ -233,7 +233,7 @@ public final int remoteStopTransaction(RemoteStopTransactionParams params,
233233
task.addCallback(callback);
234234
}
235235

236-
BackgroundService.with(asyncTaskExecutor)
236+
BackgroundService.with(taskExecutor)
237237
.forFirst(task.getParams().getChargePointSelectList())
238238
.execute(c -> invoker.remoteStopTransaction(c, task));
239239

@@ -249,7 +249,7 @@ public final int unlockConnector(UnlockConnectorParams params,
249249
task.addCallback(callback);
250250
}
251251

252-
BackgroundService.with(asyncTaskExecutor)
252+
BackgroundService.with(taskExecutor)
253253
.forFirst(task.getParams().getChargePointSelectList())
254254
.execute(c -> invoker.unlockConnector(c, task));
255255

@@ -269,7 +269,7 @@ public final int dataTransfer(DataTransferParams params,
269269
task.addCallback(callback);
270270
}
271271

272-
BackgroundService.with(asyncTaskExecutor)
272+
BackgroundService.with(taskExecutor)
273273
.forEach(task.getParams().getChargePointSelectList())
274274
.execute(c -> invoker.dataTransfer(c, task));
275275

@@ -285,7 +285,7 @@ public final int getConfiguration(GetConfigurationParams params,
285285
task.addCallback(callback);
286286
}
287287

288-
BackgroundService.with(asyncTaskExecutor)
288+
BackgroundService.with(taskExecutor)
289289
.forEach(task.getParams().getChargePointSelectList())
290290
.execute(c -> invoker.getConfiguration(c, task));
291291

@@ -301,7 +301,7 @@ public final int getLocalListVersion(MultipleChargePointSelect params,
301301
task.addCallback(callback);
302302
}
303303

304-
BackgroundService.with(asyncTaskExecutor)
304+
BackgroundService.with(taskExecutor)
305305
.forEach(task.getParams().getChargePointSelectList())
306306
.execute(c -> invoker.getLocalListVersion(c, task));
307307

@@ -317,7 +317,7 @@ public final int sendLocalList(SendLocalListParams params,
317317
task.addCallback(callback);
318318
}
319319

320-
BackgroundService.with(asyncTaskExecutor)
320+
BackgroundService.with(taskExecutor)
321321
.forEach(task.getParams().getChargePointSelectList())
322322
.execute(c -> invoker.sendLocalList(c, task));
323323

@@ -351,7 +351,7 @@ public final int reserveNow(ReserveNowParams params,
351351
task.addCallback(callback);
352352
}
353353

354-
BackgroundService.with(asyncTaskExecutor)
354+
BackgroundService.with(taskExecutor)
355355
.forFirst(task.getParams().getChargePointSelectList())
356356
.execute(c -> invoker.reserveNow(c, task));
357357

@@ -367,7 +367,7 @@ public final int cancelReservation(CancelReservationParams params,
367367
task.addCallback(callback);
368368
}
369369

370-
BackgroundService.with(asyncTaskExecutor)
370+
BackgroundService.with(taskExecutor)
371371
.forFirst(task.getParams().getChargePointSelectList())
372372
.execute(c -> invoker.cancelReservation(c, task));
373373

@@ -387,7 +387,7 @@ public final int triggerMessage(TriggerMessageParams params,
387387
task.addCallback(callback);
388388
}
389389

390-
BackgroundService.with(asyncTaskExecutor)
390+
BackgroundService.with(taskExecutor)
391391
.forEach(task.getParams().getChargePointSelectList())
392392
.execute(c -> invoker.triggerMessage(c, task));
393393

@@ -401,7 +401,7 @@ public final int setChargingProfile(SetChargingProfileTask task,
401401
task.addCallback(callback);
402402
}
403403

404-
BackgroundService.with(asyncTaskExecutor)
404+
BackgroundService.with(taskExecutor)
405405
.forEach(task.getParams().getChargePointSelectList())
406406
.execute(c -> invoker.setChargingProfile(c, task));
407407

@@ -427,7 +427,7 @@ public final int clearChargingProfile(ClearChargingProfileParams params,
427427
task.addCallback(callback);
428428
}
429429

430-
BackgroundService.with(asyncTaskExecutor)
430+
BackgroundService.with(taskExecutor)
431431
.forEach(task.getParams().getChargePointSelectList())
432432
.execute(c -> invoker.clearChargingProfile(c, task));
433433

@@ -443,7 +443,7 @@ public final int getCompositeSchedule(GetCompositeScheduleParams params,
443443
task.addCallback(callback);
444444
}
445445

446-
BackgroundService.with(asyncTaskExecutor)
446+
BackgroundService.with(taskExecutor)
447447
.forEach(task.getParams().getChargePointSelectList())
448448
.execute(c -> invoker.getCompositeSchedule(c, task));
449449

src/main/java/de/rwth/idsg/steve/service/MailServiceDefault.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020

2121
import com.google.common.base.Strings;
2222
import de.rwth.idsg.steve.SteveException;
23-
import de.rwth.idsg.steve.config.DelegatingTaskExecutor;
2423
import de.rwth.idsg.steve.repository.SettingsRepository;
2524
import de.rwth.idsg.steve.web.dto.SettingsForm.MailSettings;
2625
import lombok.RequiredArgsConstructor;
2726
import lombok.extern.slf4j.Slf4j;
27+
import org.springframework.core.task.TaskExecutor;
2828
import org.springframework.stereotype.Service;
2929

3030
import jakarta.mail.Authenticator;
@@ -50,7 +50,7 @@
5050
public class MailServiceDefault implements MailService {
5151

5252
private final SettingsRepository settingsRepository;
53-
private final DelegatingTaskExecutor asyncTaskExecutor;
53+
private final TaskExecutor taskExecutor;
5454

5555
@Override
5656
public MailSettings getSettings() {
@@ -68,7 +68,7 @@ public void sendTestMail() {
6868

6969
@Override
7070
public void sendAsync(String subject, String body) {
71-
asyncTaskExecutor.execute(() -> {
71+
taskExecutor.execute(() -> {
7272
try {
7373
send(subject, body);
7474
} catch (MessagingException e) {

0 commit comments

Comments
 (0)