GithubHelp home page GithubHelp logo

方法功能增强问题 about jvm-sandbox HOT 1 CLOSED

ccpwcn avatar ccpwcn commented on July 26, 2024
方法功能增强问题

from jvm-sandbox.

Comments (1)

dongchenxu avatar dongchenxu commented on July 26, 2024

Q:我有一个问题提出来探讨一下,指定要修复的类名和方法名的时候,一般情况下,我个人感觉我们应该是比较明确的知道要去热替换哪个类的哪个方法的,用正则要解决什么问题呢?是要匹配一批量的类和方法吗?个人感觉用类和方法的全限定名是最简单易用的,只是用正则要匹配和满足其他需求的问题我还没有想到,所以提出来讨论。因为我碰到的问题都是我知道哪个方法有问题了,我要去替换了分析和排除故障的。

A:哈哈,非常欢迎这种讨论

  1. NameRegexFilter本意是一个Filter接口的Example,在ModuleEventWatcher的定义中,都是只定义了Filter类型的参数,没有写死必须要用NameRegexFilter

    因此你可以根据自己的实际需要去实现这个接口,从而让你更方便的匹配到你需要进行AOP的类和方法。

     // ModuleEventWatcher.java
    
     /**
      * 观察事件
      *
      * @param filter    观察类和方法过滤器
      *                  通过这个对象来告知{@code EventWatcher}观察的类和方法
      * @param listener  事件监听器
      *                  观察到的事件将会告知此事件监听器
      * @param eventType 观察事件类型
      * @return {@code watchId},本次观察的唯一编号,{@code watcherId}对象将会是整个操作的唯一KEY,后续删除观察事件的时候也需要通过同一个{@code watcherId}来完成
      */
     int watch(Filter filter, EventListener listener, Event.Type... eventType);
  2. 为什么不全部采用精确匹配而是考虑了可进行批量匹配的正则表达式呢?没错,我们的确是有场景需要匹配一批量的类和方法。

    在热修复场景中,类的确是越精确越好。但在更多的场景下(比如日志拦截),你可能要对一整个包下的类或者统一前后缀的类的指定方法进行拦截。此时正则表达式、通配符表达式在这种场合表现就非常灵活了

    # 匹配上所有对外开放API的出入参(用于业务日志记录、全链路跟踪埋点等)
    new NameRegexFilter(".*\\.ServiceImpl",".*");
    

from jvm-sandbox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.