如何在不重新启动程序的情况下禁用AspectJ?

发布于 2024-09-09 17:02:49 字数 102 浏览 3 评论 0原文

我有一个使用 AspectJ 和加载时间编织的应用程序来建议各种方法。我想在我的程序中放置一个开关来禁用该方面,而无需进行任何源代码更改或重新启动程序。关闭时它需要产生尽可能少的开销。谢谢!

I have an application using AspectJ with load time weaving to advise various methods. I would like to put a switch in my program to disable the aspect without having to make any source code changes or having to restart the program. It needs to incur as little overhead as possible while turned off. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不回头走下去 2024-09-16 17:02:49

据我所知,没有办法从字节码中编织出一些建议。如果您正在使用现有的增强字节码,我认为除了在不进行编织的情况下重新启动应用程序之外,没有任何方法可以将其删除。

如果您正在谈论设置一些东西以便可以将其删除 - 编织可能确实无法删除,但您当然可以添加一个全局 if (useWeavedCode)< /code> 检查所有内容,当然还添加该变量以及以适当方式修改它的方法(通过 JMX、新控制台命令、新管理 JSP 页面等公开)。然后,如果您想阻止这种新行为,可以使用这个新选项禁用它。

当然请注意,这实际上并没有删除代码,并且会产生布尔值的成本
禁用参数查找,但我认为不可能做得更好。

*严格来说,您需要再次加载类,因此您不需要重新启动应用程序,但实际上,这可能是您可用的最简单的选项,除非您之前已将挂钩放入类加载器中。

To my knowledge, there is no way to unweave some advice from bytecode. If you're working with an existing piece of augmented bytecode, I don't believe there's any way to remove it other than restarting the application without the weaving*.

If you're talking about setting things up so they can be removed - it may be true that the weaving can't be removed, but you could certainly add a global if (useWeavedCode) check around all of it, and of course add that variable as well as methods to modify it in an appropriate way (expose via JMX, new console command, new admin JSP page, etc.). Then if you want to prevent this new behaviour, you can disable it with this new option.

Note of course that this doesn't actually remove the code, and incurs the cost of a boolean
parameter lookup while it's disabled, but I don't think it's possible to do better than that.

*Strictly you need to get the class loaded again, so you don't need to restart the app, but in practice this is likely the most straightforward option available to you unless you've previously put hooks into the classloaders.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文