|
12 | 12 | import io.roastedroot.proxywasm.v1.LogLevel; |
13 | 13 | import io.roastedroot.proxywasm.v1.MapType; |
14 | 14 | import io.roastedroot.proxywasm.v1.MetricType; |
| 15 | +import io.roastedroot.proxywasm.v1.QueueName; |
15 | 16 | import io.roastedroot.proxywasm.v1.StreamType; |
16 | 17 | import io.roastedroot.proxywasm.v1.WasmException; |
17 | 18 | import io.roastedroot.proxywasm.v1.WasmResult; |
@@ -1002,4 +1003,77 @@ int proxySetSharedData(int keyDataPtr, int keySize, int valueDataPtr, int valueS |
1002 | 1003 | return e.result().getValue(); |
1003 | 1004 | } |
1004 | 1005 | } |
| 1006 | + |
| 1007 | + @WasmExport |
| 1008 | + int proxyRegisterSharedQueue(int queueNameDataPtr, int queueNameSize, int returnQueueId) { |
| 1009 | + try { |
| 1010 | + // Get queue name from memory |
| 1011 | + String queueName = string(readMemory(queueNameDataPtr, queueNameSize)); |
| 1012 | + |
| 1013 | + var vmId = handler.getProperty("vm_id"); |
| 1014 | + |
| 1015 | + // Register shared queue using handler |
| 1016 | + int queueId = handler.registerSharedQueue(new QueueName(vmId, queueName)); |
| 1017 | + putUint32(returnQueueId, queueId); |
| 1018 | + return WasmResult.OK.getValue(); |
| 1019 | + |
| 1020 | + } catch (WasmException e) { |
| 1021 | + return e.result().getValue(); |
| 1022 | + } |
| 1023 | + } |
| 1024 | + |
| 1025 | + @WasmExport |
| 1026 | + int proxyResolveSharedQueue( |
| 1027 | + int vmIdDataPtr, |
| 1028 | + int vmIdSize, |
| 1029 | + int queueNameDataPtr, |
| 1030 | + int queueNameSize, |
| 1031 | + int returnQueueId) { |
| 1032 | + try { |
| 1033 | + // Get vm id from memory |
| 1034 | + String vmId = string(readMemory(vmIdDataPtr, vmIdSize)); |
| 1035 | + // Get queue name from memory |
| 1036 | + String queueName = string(readMemory(queueNameDataPtr, queueNameSize)); |
| 1037 | + |
| 1038 | + // Resolve shared queue using handler |
| 1039 | + int queueId = handler.resolveSharedQueue(new QueueName(vmId, queueName)); |
| 1040 | + putUint32(returnQueueId, queueId); |
| 1041 | + return WasmResult.OK.getValue(); |
| 1042 | + |
| 1043 | + } catch (WasmException e) { |
| 1044 | + return e.result().getValue(); |
| 1045 | + } |
| 1046 | + } |
| 1047 | + |
| 1048 | + @WasmExport |
| 1049 | + int proxyEnqueueSharedQueue(int queueId, int valueDataPtr, int valueSize) { |
| 1050 | + try { |
| 1051 | + // Get value from memory |
| 1052 | + byte[] value = readMemory(valueDataPtr, valueSize); |
| 1053 | + |
| 1054 | + // Enqueue shared queue using handler |
| 1055 | + WasmResult result = handler.enqueueSharedQueue(queueId, value); |
| 1056 | + return result.getValue(); |
| 1057 | + |
| 1058 | + } catch (WasmException e) { |
| 1059 | + return e.result().getValue(); |
| 1060 | + } |
| 1061 | + } |
| 1062 | + |
| 1063 | + @WasmExport |
| 1064 | + int proxyDequeueSharedQueue(int queueId, int returnValueData, int returnValueSize) { |
| 1065 | + try { |
| 1066 | + // Dequeue shared queue using handler |
| 1067 | + byte[] value = handler.dequeueSharedQueue(queueId); |
| 1068 | + if (value == null) { |
| 1069 | + return WasmResult.EMPTY.getValue(); |
| 1070 | + } |
| 1071 | + |
| 1072 | + copyIntoInstance(value, returnValueData, returnValueSize); |
| 1073 | + return WasmResult.OK.getValue(); |
| 1074 | + |
| 1075 | + } catch (WasmException e) { |
| 1076 | + return e.result().getValue(); |
| 1077 | + } |
| 1078 | + } |
1005 | 1079 | } |
0 commit comments