如何在我的框架中捕获连接请求?
我正在构建一个框架(类似 OSGi),其他方可以为其编写捆绑包。但我希望我的框架能够管理其他方将执行的连接请求的 QoS。
简单的解决方案是要求他们使用(或强制他们使用 - 尽管我不知道如何)框架的特定 ConnectionRequest 包。这种方法的问题在于,他们无法使用任何自己喜欢的依赖标准 Java 库来建立连接(请求)的库。
所以我想知道 Java 中是否有一种方法可以捕获所有请求的连接,以便我可以在将其发送到底层之前添加一些有关 QoS 处理的代码?
I'm building a framework (OSGi-like) where other parties can program a bundle for. But I want my framework to manage the QoS of the connection-requests that the other parties will do.
The easy solution would be to ask them to use (or enforce them to use - although I don't know how) a specific ConnectionRequest bundle of the framework. The problem with this approach is that they wouldn't be able to use any of their own preferred libraries that is counting on the standard Java libraries to make a connection(request).
So I wondered if there is a way in Java to catch all the requested connections, so I can add some code about my QoS handling, before its is sent of to the underlaying layer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我希望我正确理解你的问题。您可以做的是使用 Java 2 安全性并限制对 java.net.*(或任何其他库)的访问,然后提供一个包装器服务,该包装器服务提供功能并向其他服务实施您的 QoS 方案。但是,这些其他服务必须使用您的服务接口,并且不能再直接使用 java.net.*。
I hope I understand your problem correctly. What you can do is to use Java 2 Security and restrict the access to the java.net.* (or any other library), and then provide a wrapper service that provides the functionality and implements your QoS schemes to other services. These other services, though, must use your service interface and cannot use java.net.* directly anymore.
您可以使用 ProxySelector 类来“拦截”所有连接请求,但我不知道该 api 是否与您的使用相关。
http://java.sun.com/ j2se/1.5.0/docs/api/java/net/ProxySelector.html
You could use the ProxySelector class for 'intercepting' all connection requests, but i don't know if the api is relevant for your usage.
http://java.sun.com/j2se/1.5.0/docs/api/java/net/ProxySelector.html