Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

事件观察者超时或中断机制 #421

Open
ThreefLi opened this issue Apr 26, 2023 · 1 comment
Open

事件观察者超时或中断机制 #421

ThreefLi opened this issue Apr 26, 2023 · 1 comment
Assignees

Comments

@ThreefLi
Copy link

com.alibaba.jvm.sandbox.core.manager.impl.DefaultModuleEventWatcher#watch
事件观察者watch之后有没有超时或中断机制,比如类表达式增强的类过多,会导致cpu持续飙高,但是没法强制停止

@oldmanpushcart
Copy link
Collaborator

首现报个歉,虽然可以终止掉一次watch的行为,但这个能力没有开出来,我会考虑在下个版本中增加。

我先给你简单介绍下如何感知到watch的进程,后续的终止代码我可能会在这个类上进行完善。

com.alibaba.jvm.sandbox.api.resource.ModuleEventWatcher这个类中

/**
 * 事件观察者
 *
 * @author [email protected]
 */
public interface ModuleEventWatcher {

    /**
     * 观察事件
     *
     * @param filter    观察类和方法过滤器
     *                  通过这个对象来告知{@code EventWatcher}观察的类和方法
     * @param listener  事件监听器
     *                  观察到的事件将会告知此事件监听器
     * @param progress  观察渲染进度报告
     * @param eventType 观察事件类型
     * @return {@code watchId},本次观察的唯一编号,{@code watcherId}对象将会是整个操作的唯一KEY,后续删除观察事件的时候也需要通过同一个{@code watcherId}来完成
     */
    int watch(Filter filter, EventListener listener, Progress progress, Event.Type... eventType);

}

这里有一个Progress的类,这个类中可以感知到字节码增强的进度、时间

    /**
     * 进度报告
     * <p>
     * 观察类是需要对类进行增强,有时候需要对大量的类进行渲染,耗时比较长。
     * 通过这样的报告方式可以让外部感知到当前渲染的进度。
     * 在渲染完成之前,事件是不会触发给到{@link EventListener}的
     * </p>
     */
    interface Progress {

        /**
         * 进度开始
         *
         * @param total 总共需要渲染类的总数
         */
        void begin(int total);

        /**
         * 进度报告(成功)
         *
         * @param clazz 当前进行行变的类
         * @param index 当前形变类的序号,从0开始
         */
        void progressOnSuccess(Class<?> clazz, int index);

        /**
         * 进度报告(失败)
         *
         * @param clazz 当前进行行变的类
         * @param index 当前形变类的序号,从0开始
         * @param cause 失败异常
         */
        void progressOnFailed(Class<?> clazz, int index, Throwable cause);

        /**
         * 进度结束
         * <p>如果是add方法,则影响的数量是递增;</p>
         * <p>如果是remove方法,则影响的数量是递减;</p>
         * <p>当彻remove完成之后,cCnt = mCnt = 0;</p>
         *
         * @param cCnt 影响类总数
         * @param mCnt 影响方法总数
         */
        void finish(int cCnt, int mCnt);

    }

@oldmanpushcart oldmanpushcart self-assigned this May 12, 2023
oldmanpushcart pushed a commit that referenced this issue May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants