Skip to content

Commit ccf60c8

Browse files
committed
Documentation
Signed-off-by: Hendrik Ebbers <[email protected]>
1 parent 025e364 commit ccf60c8

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

hiero-enterprise-base/src/main/java/com/openelements/hiero/base/interceptors/ReceiveRecordInterceptor.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,36 @@
66
import java.util.Objects;
77
import org.jspecify.annotations.NonNull;
88

9+
/**
10+
* First simple interceptor for receiving a record. This interceptor is used to intercept the call for receiving a
11+
* record for a transaction. Frameworks like Spring can use this interceptor to add functionalities like metrics,
12+
* tracing, or logging to the calls.
13+
*/
914
@FunctionalInterface
1015
public interface ReceiveRecordInterceptor {
1116

17+
/**
18+
* Default interceptor that does nothing.
19+
*/
1220
ReceiveRecordInterceptor DEFAULT_INTERCEPTOR = data -> data.handle();
1321

22+
/**
23+
* Intercept the call for receiving a record for a transaction.
24+
*
25+
* @param handler the handler that will be used to receive the record
26+
* @return the record for the transaction
27+
* @throws Exception if the interceptor fails
28+
*/
1429
@NonNull
1530
TransactionRecord getRecordFor(@NonNull ReceiveRecordHandler handler) throws Exception;
1631

32+
/**
33+
* Handler for receiving a record for a transaction.
34+
*
35+
* @param transaction the transaction for which the record is received
36+
* @param receipt the receipt for the transaction
37+
* @param function the function that will be used to receive the record
38+
*/
1739
record ReceiveRecordHandler(@NonNull Transaction transaction, @NonNull TransactionReceipt receipt,
1840
@NonNull ReceiveRecordFunction function) {
1941

@@ -23,14 +45,31 @@ record ReceiveRecordHandler(@NonNull Transaction transaction, @NonNull Transacti
2345
Objects.requireNonNull(function, "handler must not be null");
2446
}
2547

48+
/**
49+
* Handle the call for receiving a record for a transaction.
50+
*
51+
* @return the record for the transaction
52+
* @throws Exception if the interceptor fails
53+
*/
2654
@NonNull
2755
public TransactionRecord handle() throws Exception {
2856
return function.handle(receipt);
2957
}
3058
}
3159

60+
/**
61+
* Function that will be used to receive the record for a transaction.
62+
*/
3263
@FunctionalInterface
3364
interface ReceiveRecordFunction {
65+
66+
/**
67+
* Handle the call for receiving a record for a transaction.
68+
*
69+
* @param receipt the receipt for the transaction
70+
* @return the record for the transaction
71+
* @throws Exception if the interceptor fails
72+
*/
3473
@NonNull
3574
TransactionRecord handle(@NonNull TransactionReceipt receipt) throws Exception;
3675
}

hiero-enterprise-spring-sample/src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ spring.hiero.network.name=${HEDERA_NETWORK:hedera-testnet}
55
logging.level.com.openelements=DEBUG
66
logging.pattern.console=%d{HH:mm:ss.SSS} %logger{36} - %msg%n
77
server.port=${SERVER_PORT:8080}
8+
# Needs to be done to activate the actuator endpoints (for metrics)
89
management.endpoints.web.exposure.include=*

hiero-enterprise-spring/src/main/java/com/openelements/hiero/spring/implementation/MicrometerSupportConfig.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
1616
import org.springframework.context.annotation.Bean;
1717

18+
/**
19+
* Micrometer support for Hiero. This configuration class is used to create a {@link ReceiveRecordInterceptor} that will
20+
* measure metrics for Hiero transactions. The config is only loaded if the {@code spring.hiero.metrics.enabled}
21+
* property is set to {@code true} or not set at all. Next to that, the {@code MetricsAutoConfiguration} configuration
22+
* must be on the classpath.
23+
*/
1824
@AutoConfiguration
1925
@ConditionalOnProperty(name = "spring.hiero.metrics.enabled", havingValue = "true", matchIfMissing = true)
2026
@ConditionalOnClass(name = "org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration")
@@ -25,6 +31,12 @@ public class MicrometerSupportConfig {
2531
public static final String TIMER_NAME = "hiero.transaction.record.time";
2632
public static final String COUNTER_NAME = "hiero.transaction.record";
2733

34+
/**
35+
* Creates a {@link ReceiveRecordInterceptor} that will measure metrics for Hiero transactions.
36+
*
37+
* @param meterRegistry the {@link MeterRegistry} to use for metrics
38+
* @return the {@link ReceiveRecordInterceptor} to use for metrics
39+
*/
2840
@Bean
2941
@NonNull
3042
public ReceiveRecordInterceptor interceptRecordReceive(@NonNull final MeterRegistry meterRegistry) {

0 commit comments

Comments
 (0)