You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/09/09 03:43:27 UTC

[GitHub] [apisix-java-plugin-runner] tzssangglass commented on a change in pull request #66: fix: reset vtable_start and vtable_size of conf request

tzssangglass commented on a change in pull request #66:
URL: https://github.com/apache/apisix-java-plugin-runner/pull/66#discussion_r704927477



##########
File path: runner-core/src/main/java/org/apache/apisix/plugin/runner/handler/A6ConfigHandler.java
##########
@@ -51,6 +52,15 @@ public void handle(A6Request request, A6Response response) {
         Req req = ((A6ConfigRequest) request).getReq();
         long token = ((A6ConfigResponse) response).getConfToken();
         PluginFilterChain chain = createFilterChain(req);
+        ByteBuffer bb = req.getByteBuffer();
+
+        /**
+        * to reset vtable_start and vtable_size of req,
+        * so that req can be reused after being got from the cache.
+        * {@link org.apache.apisix.plugin.runner.handler.A6HttpCallHandler#handle cache.getIfPresent()}
+        * @see <a href="Issues63"> https://github.com/apache/apisix-java-plugin-runner/issues/63</a>
+        * */
+        req.__init(bb.getInt(bb.position()) + bb.position(), bb);

Review comment:
       borrowed from here: https://github.com/api7/ext-plugin-proto/blob/c851b6c5f35c99b46218c1cd893a178ce64aa7b8/java/io.github.api7.A6/PrepareConf/Req.java#L14
   
   ```java
   public static Req getRootAsReq(ByteBuffer _bb, Req obj) {
      _bb.order(ByteOrder.LITTLE_ENDIAN); 
      return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); 
   }
   ```
   
   since I need to call `__init`, I need to know the first param `int _i`  of `__init`, from the `getRootAsReq` call `__assign`, we can see that `int _i` is `_bb.getInt(_bb.position()) + _bb.position()`
   
   ```
   public void __init(int _i, ByteBuffer _bb) {
      __reset(_i, _bb);
   }
   
   public Req __assign(int _i, ByteBuffer _bb) {
      __init(_i, _bb); 
      return this; 
   }
   ```
   
   > And is there a way to add a test?
   
   I have tried to write test cases. However, I have not found a suitable way to test this case, since the HeadByteBuffer is used automatically in the test case, but the DirectByteBuffer is used automatically in the runtime.
   I will work on how to write the test cases for this case when I have time.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org