Skip to content

Commit 08f1418

Browse files
committed
Refactoring.
Hiding some internal handler implementation details in the plugin package. And renaming some classes to be a little more consistent. Signed-off-by: Hiram Chirino <hiram@hiramchirino.com>
1 parent 0a3f0c4 commit 08f1418

File tree

18 files changed

+527
-501
lines changed

18 files changed

+527
-501
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import java.util.List;
44

55
public interface Handler {
6+
/**
7+
* The default handler. It holds no state.
8+
*/
9+
Handler DEFAULT = new Handler() {};
610

711
default void log(LogLevel level, String message) throws WasmException {}
812

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
public final class ProxyWasm implements Closeable {
2323

2424
private final ABI abi;
25-
private final Handler pluginHandler;
2625
private final WasiPreview1 wasi;
2726

2827
private final AtomicInteger nextContextID = new AtomicInteger(1);
@@ -33,6 +32,7 @@ public final class ProxyWasm implements Closeable {
3332
private ProxyMap httpCallResponseHeaders;
3433
private ProxyMap httpCallResponseTrailers;
3534
private byte[] httpCallResponseBody;
35+
private Handler pluginHandler;
3636

3737
private ProxyWasm(Builder other) throws StartException {
3838
this.pluginHandler = Objects.requireNonNullElse(other.pluginHandler, new Handler() {});
@@ -52,6 +52,14 @@ private ProxyWasm(Builder other) throws StartException {
5252
}
5353
}
5454

55+
public Handler getPluginHandler() {
56+
return pluginHandler;
57+
}
58+
59+
public void setPluginHandler(Handler pluginHandler) {
60+
this.pluginHandler = pluginHandler;
61+
}
62+
5563
public void start() throws StartException {
5664
if (pluginContext != null) {
5765
return;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.roastedroot.proxywasm.plugin;
2+
3+
import io.roastedroot.proxywasm.ProxyMap;
4+
5+
public class HttpCallResponse {
6+
7+
public final int statusCode;
8+
public final ProxyMap headers;
9+
public final byte[] body;
10+
11+
public HttpCallResponse(int statusCode, ProxyMap headers, byte[] body) {
12+
this.statusCode = statusCode;
13+
this.headers = headers;
14+
this.body = body;
15+
}
16+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package io.roastedroot.proxywasm.plugin;
2+
3+
public interface HttpCallResponseHandler {
4+
void call(HttpCallResponse response);
5+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,11 @@ public SendResponse consumeSentHttpResponse() {
126126
}
127127

128128
class HandlerImpl extends ChainedHandler {
129+
private final Handler next = plugin.wasm.getPluginHandler();
129130

130131
@Override
131132
protected Handler next() {
132-
return plugin.handler;
133+
return next;
133134
}
134135

135136
public ProxyMap getHttpRequestHeaders() {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package io.roastedroot.proxywasm.plugin;
2+
3+
import io.roastedroot.proxywasm.MetricType;
4+
5+
public class Metric {
6+
7+
final int id;
8+
final MetricType type;
9+
final String name;
10+
long value;
11+
12+
public Metric(int id, MetricType type, String name) {
13+
this.id = id;
14+
this.type = type;
15+
this.name = name;
16+
}
17+
18+
public int id() {
19+
return id;
20+
}
21+
22+
public MetricType type() {
23+
return type;
24+
}
25+
26+
public String name() {
27+
return name;
28+
}
29+
30+
public long value() {
31+
return value;
32+
}
33+
}

0 commit comments

Comments
 (0)