forked from roastedroot/proxy-wasm-java-host
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContext.java
More file actions
65 lines (52 loc) · 1.65 KB
/
Context.java
File metadata and controls
65 lines (52 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package io.roastedroot.proxywasm.v1;
import java.io.Closeable;
public abstract class Context implements Closeable {
ProxyWasm proxyWasm;
final int id;
boolean closeDone;
boolean closeStarted;
Context(ProxyWasm proxyWasm) {
this.proxyWasm = proxyWasm;
this.id = proxyWasm.nextContextID();
}
abstract Handler handler();
public int id() {
return id;
}
public void close() {
if (closeStarted) {
return;
}
closeStarted = true;
if (!closeDone) {
// the plugin may want to finish closing later...
if (proxyWasm.abi().proxyOnDone(id)) {
// close now...
finishClose();
}
}
}
// plugin is indicating it wants to finish closing
WasmResult done() {
if (!closeStarted) {
// spec says: return NOT_FOUND when active context was not pending finalization.
return WasmResult.NOT_FOUND;
}
if (!closeDone) {
finishClose();
}
return WasmResult.OK;
}
protected void finishClose() {
closeDone = true;
proxyWasm.abi().proxyOnLog(id);
proxyWasm.contexts().remove(id);
// todo: we likely need to callback to user code to allow cleaning up resources like http
// connections.
// I think we should allways be the current context...
assert proxyWasm.getActiveContext() == this : "we are the active context";
// unset active context so that callbacks don't try to use us.
proxyWasm.setActiveContext(null);
proxyWasm.abi().proxyOnDelete(id);
}
}