Skip to content

Commit c65e753

Browse files
committed
feat: reactify-core
1 parent d7deb80 commit c65e753

File tree

107 files changed

+4068
-1092
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+4068
-1092
lines changed

reactify-cache/src/main/java/com/reactify/cache/CacheUtils.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,16 @@
2424

2525
/**
2626
* <p>
27-
* CacheUtils class.
27+
* The CacheUtils class provides utility methods for working with caching
28+
* functionality in the application. It contains methods to invoke
29+
* cached methods dynamically at runtime, allowing for efficient cache
30+
* management and retrieval.
31+
* </p>
32+
*
33+
* <p>
34+
* This class is particularly useful for autoloading cache entries based
35+
* on the methods annotated with {@link LocalCache} and managing their
36+
* execution in a reactive manner using Project Reactor.
2837
* </p>
2938
*
3039
* @author hoangtien2k3
@@ -36,11 +45,14 @@ public class CacheUtils {
3645

3746
/**
3847
* <p>
39-
* invokeMethod.
48+
* Invokes the specified method and subscribes to its result, enabling
49+
* the execution of the method in a reactive context. This method
50+
* retrieves the bean instance of the declaring class from the Spring
51+
* application context and calls the specified method.
4052
* </p>
4153
*
42-
* @param method
43-
* a {@link Method} object
54+
* @param method a {@link Method} object representing the method to be
55+
* invoked
4456
*/
4557
public static void invokeMethod(Method method) {
4658
try {

reactify-core/pom.xml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
<version>3.3.5</version>
99
<relativePath/>
1010
</parent>
11-
<groupId>io.github.hoangtien2k3</groupId>
11+
<groupId>com.ezbuy.platform</groupId>
1212
<artifactId>reactify-core</artifactId>
13-
<version>1.1.7</version>
13+
<version>1.0-SNAPSHOT</version>
1414
<name>reactify-core</name>
1515
<description>Java library for developing backend with reactive programming</description>
1616
<url>https://github.com/hoangtien2k3/reactify</url>
17-
1817
<licenses>
1918
<license>
2019
<name>Apache License, Version 2.0</name>
@@ -44,8 +43,8 @@
4443
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
4544
</repository>
4645
</distributionManagement>
47-
4846
<properties>
47+
<revision>1.0-SNAPSHOT</revision>
4948
<java.version>21</java.version>
5049
<micrometer.tracing.version>1.3.1</micrometer.tracing.version>
5150
<micrometer.registry.version>1.13.1</micrometer.registry.version>
@@ -72,7 +71,6 @@
7271
<sonar.organization>hoangtien2k3</sonar.organization>
7372
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
7473
</properties>
75-
7674
<dependencyManagement>
7775
<dependencies>
7876
<dependency>
@@ -84,7 +82,6 @@
8482
</dependency>
8583
</dependencies>
8684
</dependencyManagement>
87-
8885
<dependencies>
8986
<dependency>
9087
<groupId>org.springframework.boot</groupId>
@@ -102,6 +99,10 @@
10299
<groupId>org.springframework.boot</groupId>
103100
<artifactId>spring-boot-starter-aop</artifactId>
104101
</dependency>
102+
<dependency>
103+
<groupId>org.springframework.boot</groupId>
104+
<artifactId>spring-boot-configuration-processor</artifactId>
105+
</dependency>
105106
<dependency>
106107
<groupId>org.springframework.boot</groupId>
107108
<artifactId>spring-boot-starter-oauth2-client</artifactId>
@@ -236,7 +237,6 @@
236237
<version>${modelmapper.version}</version>
237238
</dependency>
238239
</dependencies>
239-
240240
<build>
241241
<plugins>
242242
<plugin>
@@ -388,5 +388,4 @@
388388
</plugin>
389389
</plugins>
390390
</build>
391-
392391
</project>

reactify-core/src/main/java/com/reactify/annotations/LocalCache.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
* This annotation should be applied to methods that return a result that can
4141
* benefit from caching.
4242
*
43-
* <h3>Usage Example:</h3>
43+
* <h2>Usage Example:</h2>
4444
*
4545
* <pre>
4646
* &#64;LocalCache(durationInMinute = 10, maxRecord = 500, autoCache = true)
@@ -49,7 +49,9 @@
4949
* }
5050
* </pre>
5151
*
52-
* <h3>Annotation Properties:</h3>
52+
* <h2>Annotation Properties:</h2> <!-- Changed
53+
* <h3>to
54+
* <h2>-->
5355
* <dl>
5456
* <dt>durationInMinute</dt>
5557
* <dd>The time period in minutes for which the cached data is valid. Default is
@@ -68,13 +70,33 @@
6870
* This annotation is intended for use in performance-sensitive applications
6971
* where reducing latency and resource consumption is critical.
7072
* </p>
73+
*
74+
* @author hoangtien2k3
7175
*/
7276
@Target(ElementType.METHOD)
7377
@Retention(RetentionPolicy.RUNTIME)
7478
public @interface LocalCache {
79+
/**
80+
* Specifies the duration (in minutes) for which the cache entry is valid.
81+
* Default value is 120 minutes.
82+
*
83+
* @return the duration in minutes
84+
*/
7585
int durationInMinute() default 120;
7686

87+
/**
88+
* Specifies the maximum number of records that can be stored in the cache.
89+
* Default value is 1000 records.
90+
*
91+
* @return the maximum number of records
92+
*/
7793
int maxRecord() default 1000;
7894

95+
/**
96+
* Indicates whether the caching should be enabled automatically. Default value
97+
* is false.
98+
*
99+
* @return true if auto-cache is enabled, false otherwise
100+
*/
79101
boolean autoCache() default false;
80102
}

reactify-core/src/main/java/com/reactify/annotations/LogPerformance.java

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,72 @@
2222

2323
/**
2424
* <p>
25-
* LogPerformance class.
25+
* Indicates that performance logging should be applied to a method or a class.
26+
* This annotation can be used to track the execution time and other performance
27+
* metrics of the annotated method or class, which is useful for monitoring and
28+
* optimizing application performance.
29+
* </p>
30+
*
31+
* <p>
32+
* This annotation supports various logging configurations such as specifying
33+
* the type of log, whether to log input parameters, output results, and a title
34+
* for the log entry.
35+
* </p>
36+
*
37+
* <p>
38+
* <strong>Usage Example:</strong>
39+
* </p>
40+
*
41+
* <pre>
42+
* &#64;LogPerformance(logType = "INFO", actionType = "DATABASE_OPERATION", logOutput = true)
43+
* public void fetchData() {
44+
* // Method implementation
45+
* }
46+
* </pre>
47+
*
48+
* <p>
49+
* <strong>Note:</strong> The actual logging mechanism must be configured
50+
* separately in the application.
2651
* </p>
2752
*
2853
* @author hoangtien2k3
54+
* @version 1.0
2955
*/
3056
@Target({ElementType.METHOD, ElementType.TYPE})
3157
@Retention(RetentionPolicy.RUNTIME)
3258
public @interface LogPerformance {
59+
/**
60+
* The type of log for categorizing the log entries.
61+
*
62+
* @return the log type as a string
63+
*/
3364
String logType() default "";
3465

66+
/**
67+
* The type of action that the log entry is recording.
68+
*
69+
* @return the action type as a string
70+
*/
3571
String actionType() default "";
3672

73+
/**
74+
* Specifies whether to log the output or not.
75+
*
76+
* @return true if output logging is enabled, false otherwise
77+
*/
3778
boolean logOutput() default true;
3879

80+
/**
81+
* Specifies whether to log the input or not.
82+
*
83+
* @return true if input logging is enabled, false otherwise
84+
*/
3985
boolean logInput() default true;
4086

87+
/**
88+
* The title for the performance log entry.
89+
*
90+
* @return the title as a string
91+
*/
4192
String title() default "";
4293
}

reactify-core/src/main/java/com/reactify/annotations/Loggable.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,34 @@
2222

2323
/**
2424
* <p>
25-
* Loggable class.
25+
* Indicates that a method should be logged when it is executed. This annotation
26+
* can be used to track method calls, parameters, and return values, which is
27+
* useful for debugging and monitoring application behavior.
28+
* </p>
29+
*
30+
* <p>
31+
* This annotation is typically processed by an aspect-oriented programming
32+
* (AOP) framework that intercepts method calls and performs the logging.
33+
* </p>
34+
*
35+
* <p>
36+
* <strong>Usage Example:</strong>
37+
* </p>
38+
*
39+
* <pre>
40+
* &#64;Loggable
41+
* public void performAction(String parameter) {
42+
* // Method implementation
43+
* }
44+
* </pre>
45+
*
46+
* <p>
47+
* <strong>Note:</strong> The actual logging behavior must be configured
48+
* separately in the application, depending on the logging framework in use.
2649
* </p>
2750
*
2851
* @author hoangtien2k3
52+
* @version 1.0
2953
*/
3054
@Retention(RetentionPolicy.RUNTIME)
3155
@Target(ElementType.METHOD)

reactify-core/src/main/java/com/reactify/annotations/cache/CacheAspect.java

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
package com.reactify.annotations.cache;
1717

1818
import com.github.benmanes.caffeine.cache.Cache;
19-
import java.util.Objects;
20-
import java.util.Optional;
2119
import lombok.extern.slf4j.Slf4j;
2220
import org.aspectj.lang.ProceedingJoinPoint;
2321
import org.aspectj.lang.annotation.Around;
@@ -30,9 +28,29 @@
3028
import reactor.core.publisher.Mono;
3129
import reactor.core.publisher.Signal;
3230

31+
import java.util.Objects;
32+
import java.util.Optional;
33+
3334
/**
3435
* <p>
35-
* CacheAspect class.
36+
* The {@code CacheAspect} class provides caching functionality for methods
37+
* annotated with {@link com.reactify.annotations.LocalCache}. This aspect
38+
* intercepts method calls, checks the cache for existing results, and returns
39+
* cached results if available. If no cached result is found, the method is
40+
* executed and the result is stored in the cache for future calls.
41+
* </p>
42+
*
43+
* <p>
44+
* This class uses Spring AOP (Aspect-Oriented Programming) features to
45+
* implement caching logic around method executions, providing a way to enhance
46+
* performance by avoiding redundant computations or data retrievals.
47+
* </p>
48+
*
49+
* <p>
50+
* The class is annotated with {@link Aspect} and
51+
* {@link Configuration}, making it a
52+
* Spring managed bean that can intercept method calls. The logging is managed
53+
* using the Lombok {@link Slf4j} annotation.
3654
* </p>
3755
*
3856
* @author hoangtien2k3
@@ -42,19 +60,37 @@
4260
@Slf4j
4361
public class CacheAspect {
4462

63+
/**
64+
* Constructs a new instance of {@code CacheAspect}.
65+
*/
66+
public CacheAspect() {}
67+
68+
/**
69+
* <p>
70+
* Pointcut that matches methods annotated with
71+
* {@link com.reactify.annotations.LocalCache}.
72+
* </p>
73+
*/
4574
@Pointcut("@annotation(com.reactify.annotations.LocalCache)")
4675
private void processAnnotation() {}
4776

4877
/**
4978
* <p>
50-
* aroundAdvice.
79+
* Around advice that intercepts method calls annotated with
80+
* {@link com.reactify.annotations.LocalCache}. This method checks for a cached
81+
* result using the generated key based on the method arguments. If a cached
82+
* result is found, it is returned; otherwise, the method is executed, and the
83+
* result is stored in the cache.
5184
* </p>
5285
*
5386
* @param joinPoint
54-
* a {@link ProceedingJoinPoint} object
55-
* @return a {@link Object} object
87+
* a {@link ProceedingJoinPoint} object representing
88+
* the method execution context.
89+
* @return an {@link Object} that is the result of the method
90+
* execution or the cached result.
5691
* @throws Throwable
57-
* if any.
92+
* if any exception occurs during method execution or while
93+
* accessing the cache.
5894
*/
5995
@Around("processAnnotation()")
6096
public Object aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {

0 commit comments

Comments
 (0)