Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2137f4f073 | ||
|
|
826014d618 | ||
|
|
8b1e76b526 |
@ -20,6 +20,7 @@ The code will scan all requests from methods that are inside the specified packa
|
|||||||
|
|
||||||
```
|
```
|
||||||
@Around("@annotation(org.springframework.amqp.rabbit.annotation.RabbitListener) || "
|
@Around("@annotation(org.springframework.amqp.rabbit.annotation.RabbitListener) || "
|
||||||
|
+ "@annotation(com.knecon.fforesight.lifecyclecommons.LifecycleMonitor) || "
|
||||||
+ "@annotation(org.springframework.web.bind.annotation.GetMapping) || "
|
+ "@annotation(org.springframework.web.bind.annotation.GetMapping) || "
|
||||||
+ "@annotation(org.springframework.web.bind.annotation.PostMapping) || "
|
+ "@annotation(org.springframework.web.bind.annotation.PostMapping) || "
|
||||||
+ "@annotation(org.springframework.web.bind.annotation.PutMapping) || "
|
+ "@annotation(org.springframework.web.bind.annotation.PutMapping) || "
|
||||||
@ -34,5 +35,6 @@ So any method that has one of the annotations present there, if it's being execu
|
|||||||
executing it will decrement the ongoing tasks. If at any point a shutdown is initiated and the amount of ongoing tasks is not 0, the termination process will wait until all ongoing
|
executing it will decrement the ongoing tasks. If at any point a shutdown is initiated and the amount of ongoing tasks is not 0, the termination process will wait until all ongoing
|
||||||
tasks are completed. It will also not allow new tasks to be started, throwing back an exception.
|
tasks are completed. It will also not allow new tasks to be started, throwing back an exception.
|
||||||
|
|
||||||
If you want to monitor and keep track of other methods you can add annotations in the `@Around` part. You can even create a custom annotation and add it here, then whenever you
|
If you want to monitor and keep track of other methods you can add annotations in the `@Around` part.
|
||||||
annotate a method with that annotations it will keep track of its tasks in event of a shutdown.
|
|
||||||
|
The `LifecycleMonitor` annotation is provided with the library, all methods that are annotated with this annotations will be monitored during a shutdown to make sure it finishes execution.
|
||||||
@ -6,11 +6,13 @@ import org.aspectj.lang.annotation.Aspect;
|
|||||||
import org.springframework.amqp.AmqpRejectAndDontRequeueException;
|
import org.springframework.amqp.AmqpRejectAndDontRequeueException;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@Aspect
|
@Aspect
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class LifecycleAspect {
|
public class LifecycleAspect {
|
||||||
|
|
||||||
private final LifecycleManager lifecycleManager;
|
private final LifecycleManager lifecycleManager;
|
||||||
@ -18,14 +20,6 @@ public class LifecycleAspect {
|
|||||||
private final LifecycleProperties lifecycleProperties;
|
private final LifecycleProperties lifecycleProperties;
|
||||||
|
|
||||||
|
|
||||||
public LifecycleAspect(LifecycleManager lifecycleManager, LifecycleProperties lifecycleProperties) {
|
|
||||||
|
|
||||||
this.lifecycleManager = lifecycleManager;
|
|
||||||
this.lifecycleProperties = lifecycleProperties;
|
|
||||||
log.info("Initializing LifecycleAspect with basePackage: {}", lifecycleProperties.getBasePackage());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Around("@annotation(org.springframework.amqp.rabbit.annotation.RabbitListener) || "
|
@Around("@annotation(org.springframework.amqp.rabbit.annotation.RabbitListener) || "
|
||||||
+ "@annotation(com.knecon.fforesight.lifecyclecommons.LifecycleMonitor) || "
|
+ "@annotation(com.knecon.fforesight.lifecyclecommons.LifecycleMonitor) || "
|
||||||
+ "@annotation(org.springframework.web.bind.annotation.GetMapping) || "
|
+ "@annotation(org.springframework.web.bind.annotation.GetMapping) || "
|
||||||
@ -36,7 +30,7 @@ public class LifecycleAspect {
|
|||||||
public Object checkLifecycle(ProceedingJoinPoint joinPoint) throws Throwable {
|
public Object checkLifecycle(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||||
|
|
||||||
String targetClassName = joinPoint.getTarget().getClass().getPackageName();
|
String targetClassName = joinPoint.getTarget().getClass().getPackageName();
|
||||||
if (!targetClassName.startsWith(lifecycleProperties.getBasePackage())) {
|
if (targetClassName == null || lifecycleProperties.getBasePackage() == null || !targetClassName.startsWith(lifecycleProperties.getBasePackage())) {
|
||||||
return joinPoint.proceed();
|
return joinPoint.proceed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user