Skip to content

Commit 96fa052

Browse files
committed
Add more javadoc.
Signed-off-by: Hiram Chirino <hiram@hiramchirino.com>
1 parent 26e9ad3 commit 96fa052

File tree

25 files changed

+738
-137
lines changed

25 files changed

+738
-137
lines changed

pom.xml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
<surefire-plugin.version>3.5.2</surefire-plugin.version>
4646
<failsafe-plugin.version>${surefire-plugin.version}</failsafe-plugin.version>
4747
<jandex.version>3.2.7</jandex.version>
48-
<maven.javadoc.version>3.11.2</maven.javadoc.version>
48+
<javadoc-plugin.version>3.11.2</javadoc-plugin.version>
49+
<dependency-plugin.version>3.8.1</dependency-plugin.version>
4950

5051
<!-- test time versions -->
5152
<junit.version>5.12.0</junit.version>
@@ -210,17 +211,6 @@
210211
</configuration>
211212
</plugin>
212213

213-
<plugin>
214-
<groupId>org.apache.maven.plugins</groupId>
215-
<artifactId>maven-javadoc-plugin</artifactId>
216-
<version>${maven.javadoc.version}</version>
217-
<configuration>
218-
<sourceFileExcludes>
219-
<sourceFileExclude>**/internal/**</sourceFileExclude>
220-
</sourceFileExcludes>
221-
</configuration>
222-
</plugin>
223-
224214
</plugins>
225215

226216
</pluginManagement>

proxy-wasm-java-host/pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,21 @@
100100
</configuration>
101101
</plugin>
102102

103+
<plugin>
104+
<groupId>org.apache.maven.plugins</groupId>
105+
<artifactId>maven-javadoc-plugin</artifactId>
106+
<version>${javadoc-plugin.version}</version>
107+
<configuration>
108+
<sourceFileExcludes>
109+
<sourceFileExclude>**/internal/**</sourceFileExclude>
110+
</sourceFileExcludes>
111+
<links>
112+
<link>https://www.javadoc.io/doc/com.dylibso.chicory/wasm/${chicory.version}/</link>
113+
<link>https://www.javadoc.io/doc/com.dylibso.chicory/runtime/${chicory.version}/</link>
114+
</links>
115+
</configuration>
116+
</plugin>
117+
103118
</plugins>
104119
</build>
105120
</project>
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.roastedroot.proxywasm;
22

3-
public interface ForeignFunction {
4-
byte[] apply(byte[] data);
5-
}
3+
/**
4+
* A functional interface that represents a foreign function call in the Proxy-Wasm.
5+
*/
6+
public interface ForeignFunction extends java.util.function.Function<byte[], byte[]> {}

proxy-wasm-java-host/src/main/java/io/roastedroot/proxywasm/LogHandler.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,35 @@
11
package io.roastedroot.proxywasm;
22

3+
/**
4+
* Interface for handling logging sent form the guest of Proxy-WASM environment.
5+
* <p>
6+
* This interface provides methods to log messages at different levels and to retrieve the current
7+
* log level.
8+
*/
39
public interface LogHandler {
410

5-
LogHandler DEFAULT = new LogHandler() {};
11+
/**
12+
* A default, no-operation {@code LogHandler}.
13+
* It ignores all log messages and reports {@link LogLevel#CRITICAL} as the current log level,
14+
* effectively disabling logging.
15+
*
16+
* <p>Useful as a placeholder or when logging is explicitly disabled.
17+
*/
18+
LogHandler DEFAULT =
19+
new LogHandler() {
20+
@Override
21+
public LogLevel getLogLevel() throws WasmException {
22+
// since we are not logging anything, we can return the highest log level
23+
return LogLevel.CRITICAL;
24+
}
25+
};
626

27+
/**
28+
* A simple {@code LogHandler} that logs all messages to {@link System#out}.
29+
* Messages are prefixed with their corresponding {@link LogLevel}.
30+
* The effective log level for this handler is {@link LogLevel#TRACE},
31+
* meaning all messages will be printed.
32+
*/
733
LogHandler SYSTEM =
834
new LogHandler() {
935
@Override
@@ -12,8 +38,21 @@ public void log(LogLevel level, String message) throws WasmException {
1238
}
1339
};
1440

41+
/**
42+
* Logs a message at the specified log level.
43+
*
44+
* @param level the log level
45+
* @param message the message to log
46+
* @throws WasmException the result to provide the plugin
47+
*/
1548
default void log(LogLevel level, String message) throws WasmException {}
1649

50+
/**
51+
* Gets the current log level.
52+
*
53+
* @return the current log level
54+
* @throws WasmException the result to provide the plugin
55+
*/
1756
default LogLevel getLogLevel() throws WasmException {
1857
return LogLevel.TRACE;
1958
}

proxy-wasm-java-host/src/main/java/io/roastedroot/proxywasm/LogLevel.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,57 @@
11
package io.roastedroot.proxywasm;
22

33
/**
4-
* Represents log levels for proxy WASM.
5-
* Converted from Go's LogLevel type.
4+
* Represents log levels used within the Proxy-WASM ABI specification.
5+
* These levels correspond to the values expected by the host environment
6+
* when logging messages from a WASM module.
7+
* <p>
8+
* Converted from Go's LogLevel type in the proxy-wasm-go-sdk.
69
*/
710
public enum LogLevel {
8-
// The values follow the same order as in the Go code using iota (0-based incrementing)
11+
12+
/** Trace log level. Value: 0 */
913
TRACE(0),
14+
/** Debug log level. Value: 1 */
1015
DEBUG(1),
16+
/** Info log level. Value: 2 */
1117
INFO(2),
18+
/** Warn log level. Value: 3 */
1219
WARN(3),
20+
/** Error log level. Value: 4 */
1321
ERROR(4),
22+
/** Critical log level. Value: 5 */
1423
CRITICAL(5);
1524

25+
/** The integer representation of the log level, as defined by the Proxy-WASM ABI. */
1626
private final int value;
1727

1828
/**
1929
* Constructor for LogLevel enum.
2030
*
21-
* @param value The integer value of the log level
31+
* @param value The integer value corresponding to the log level in the ABI.
2232
*/
2333
LogLevel(int value) {
2434
this.value = value;
2535
}
2636

2737
/**
28-
* Get the integer value of this log level.
38+
* Get the integer value of this log level as defined by the Proxy-WASM ABI.
2939
*
30-
* @return The integer value
40+
* @return The integer value representing the log level.
3141
*/
3242
public int value() {
3343
return value;
3444
}
3545

3646
/**
37-
* Convert an integer value to a LogLevel.
47+
* Convert an integer value to its corresponding LogLevel enum constant.
48+
* This is useful for interpreting log level values received from the host
49+
* or specified in configurations.
3850
*
39-
* @param value The integer value to convert
40-
* @return The corresponding LogLevel, or null if not found
51+
* @param value The integer value to convert.
52+
* @return The corresponding LogLevel enum constant.
53+
* @throws IllegalArgumentException if the provided integer value does not
54+
* match any known LogLevel.
4155
*/
4256
public static LogLevel fromInt(int value) {
4357
for (LogLevel level : values()) {

proxy-wasm-java-host/src/main/java/io/roastedroot/proxywasm/MetricType.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,54 @@
11
package io.roastedroot.proxywasm;
22

33
/**
4-
* Represents the type of metric in proxy WASM.
4+
* Represents the types of metrics that can be defined and manipulated
5+
* via the Proxy-WASM ABI.
56
*/
67
public enum MetricType {
8+
/**
9+
* A metric that only increments.
10+
* Value: 0
11+
*/
712
COUNTER(0),
13+
/**
14+
* A metric that can be arbitrarily set.
15+
* Value: 1
16+
*/
817
GAUGE(1),
18+
/**
19+
* A metric that accumulates observations into predefined buckets
20+
* and a sum of observations.
21+
* Value: 2
22+
*/
923
HISTOGRAM(2);
1024

25+
/** The integer representation of the metric type, as defined by the Proxy-WASM ABI. */
1126
private final int value;
1227

1328
/**
1429
* Constructor for MetricType enum.
1530
*
16-
* @param value The integer value of the metric type
31+
* @param value The integer value corresponding to the metric type in the ABI.
1732
*/
1833
MetricType(int value) {
1934
this.value = value;
2035
}
2136

2237
/**
23-
* Get the integer value of this metric type.
38+
* Get the integer value of this metric type as defined by the Proxy-WASM ABI.
2439
*
25-
* @return The integer value
40+
* @return The integer value representing the metric type.
2641
*/
2742
public int getValue() {
2843
return value;
2944
}
3045

3146
/**
32-
* Convert an integer value to a MetricType.
47+
* Convert an integer value to its corresponding MetricType enum constant.
3348
*
34-
* @param value The integer value to convert
35-
* @return The corresponding MetricType or null if the value doesn't match any MetricType
49+
* @param value The integer value to convert.
50+
* @return The corresponding MetricType enum constant, or {@code null} if the
51+
* provided integer value does not match any known MetricType.
3652
*/
3753
public static MetricType fromInt(int value) {
3854
for (MetricType type : values()) {

proxy-wasm-java-host/src/main/java/io/roastedroot/proxywasm/MetricsHandler.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,78 @@
22

33
import io.roastedroot.proxywasm.internal.WasmResult;
44

5+
/**
6+
* Defines the contract for handling metrics operations initiated by a Proxy-WASM module.
7+
* Implementations of this interface are responsible for interacting with the underlying
8+
* metrics system of the host environment (Prometheus etc.).
9+
*
10+
* <p>The host environment provides implementations of these methods to allow WASM modules
11+
* to define, manipulate, and retrieve metric values.
12+
*/
513
public interface MetricsHandler {
614

15+
/**
16+
* A default, non-functional instance of {@code MetricsHandler}.
17+
* This instance throws {@link WasmException} with {@link WasmResult#UNIMPLEMENTED}
18+
* for methods that define or retrieve metrics, and returns {@link WasmResult#UNIMPLEMENTED}
19+
* for methods that modify or remove metrics.
20+
* Useful as a placeholder or base when only a subset of metrics functionality is needed.
21+
*/
722
MetricsHandler DEFAULT = new MetricsHandler() {};
823

24+
/**
25+
* Defines a new metric.
26+
*
27+
* @param metricType The type of the metric (e.g., Counter, Gauge, Histogram).
28+
* @param name The name of the metric.
29+
* @return A unique identifier (metric ID) for the newly defined metric.
30+
* @throws WasmException If the metric cannot be defined (e.g., name conflict, unsupported type,
31+
* or if the operation is unimplemented by the host).
32+
*/
933
default int defineMetric(MetricType metricType, String name) throws WasmException {
1034
throw new WasmException(WasmResult.UNIMPLEMENTED);
1135
}
1236

37+
/**
38+
* Removes or deletes a previously defined metric.
39+
*
40+
* @param metricId The unique identifier of the metric to remove.
41+
* @return A {@link WasmResult} indicating the outcome of the operation (e.g., OK, NOT_FOUND, UNIMPLEMENTED).
42+
*/
1343
default WasmResult removeMetric(int metricId) {
1444
return WasmResult.UNIMPLEMENTED;
1545
}
1646

47+
/**
48+
* Records a value for a metric (typically used for Gauges or Histograms).
49+
*
50+
* @param metricId The unique identifier of the metric.
51+
* @param value The value to record.
52+
* @return A {@link WasmResult} indicating the outcome of the operation (e.g., OK, BAD_ARGUMENT, UNIMPLEMENTED).
53+
*/
1754
default WasmResult recordMetric(int metricId, long value) {
1855
return WasmResult.UNIMPLEMENTED;
1956
}
2057

58+
/**
59+
* Increments a metric's value (typically used for Counters).
60+
*
61+
* @param metricId The unique identifier of the metric.
62+
* @param value The amount to increment by (can be negative to decrement, although convention is usually positive).
63+
* @return A {@link WasmResult} indicating the outcome of the operation (e.g., OK, BAD_ARGUMENT, UNIMPLEMENTED).
64+
*/
2165
default WasmResult incrementMetric(int metricId, long value) {
2266
return WasmResult.UNIMPLEMENTED;
2367
}
2468

69+
/**
70+
* Retrieves the current value of a metric.
71+
*
72+
* @param metricId The unique identifier of the metric.
73+
* @return The current value of the metric.
74+
* @throws WasmException If the metric cannot be retrieved (e.g., metric not found, type mismatch,
75+
* or if the operation is unimplemented by the host).
76+
*/
2577
default long getMetric(int metricId) throws WasmException {
2678
throw new WasmException(WasmResult.UNIMPLEMENTED);
2779
}

0 commit comments

Comments
 (0)