排队方法调用 - 知道怎么做吗?
我编写了一个高度异步的应用程序。
我正在寻找一种对方法调用进行排队的方法,类似于 BeginInvoke / EndInvoke 所做的......但在我自己的队列上。原因是我拥有自己的优化消息队列系统,使用线程池,但同时确保每个组件在请求中都是单线程的(即一个线程仅处理组件的消息)。
我有很多来回的消息。对于有限的使用,我真的很希望能够使用参数对消息调用进行排队,而不是为了执行大量管理调用而必须定义自己的参数、方法包装/展开。我也不总是想绕过队列,并且我绝对不希望发送服务等待其他服务响应。
有人知道拦截方法调用的方法吗?有什么方法可以利用透明代理/虚拟代理来实现此目的? ;) 服务组件?我希望开销尽可能小;)
I write a heavily asynchronseous application.
I am looking for a way to queue method calls, similar to what BeginInvoke / EndInvoke does.... but on my OWN queue. The reaqson is that I am having my own optimized message queueing system using a threadpool but at the same time making sure every component is single threaded in the requests (i.e. one thread only handles messages for a component).
I Have a lot of messages going back and forth. For limited use, I would really love to be able to just queue a message call with parameters, instead of having to define my own parameter, method wrapping / unwrapping just for the sake of doing a lot of admnistrative calls. I also do not always want to bypass the queue, and I definitely do not want the sending service to wait for the other service to respond.
Anyone knows of a way to intercept a method call? Some way to utilize TransparentProxy / Virtual Proxy for this? ;) ServicedComponent? I would like this to be as little overhead as possible ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 lambda 怎么样?
我的意思是,为什么你不创建一些队列,并以类似的方式处理它们,
你可以非常简单地添加操作:
这只是一个提示,我不确定是否有一些队列类,但它应该非常简单自己创建一个(并且是线程安全的!)。
解决方法可以(而且应该)更加明智,但要点就在那里。如果您想咨询请写信给我。
Pz,TaskConnect 开发人员
How about using lambdas?
I mean, why don't you create some Queue, and process them in manner like
You can add actions very simply:
This is just a tip, I'm not sure if there is some Queue class, but it should be pretty straightforward to create one (and threadsafe!) by yourself.
The workaround could (and should) be much wiser, but the main point is there. Write me if you want to consult.
Pz, the TaskConnect developer
创建 MethodInvoker 的队列
稍后将项目添加到您的队列
然后一次调用您的函数:
以安全的方式调用所有函数(这也会将它们从队列中删除,使队列为空并调用所有函数)
要全部调用它们,只需使用
InvokeAll();
或在需要时一次调用它们:Create a queue of MethodInvoker's
Later add items to your Queue
Then call your functions one at a time:
to call all of your functions in a safe way (this will also remove them all from the queue leaving the queue empty and all the functions called)
to call them all just use
InvokeAll();
or to call them one a time whenever you want:作为 Castle 项目一部分的 DynamicProxy 允许对象成员拦截,而无需一些典型的编组痛苦
http:// /www.castleproject.org/projects/dynamicproxy/
您可以使用它来拦截您的方法调用,然后对它们执行您想要的操作。
The DynamicProxy that is part of the Castle project allows object member interception without some of the typical Marshalling pain
http://www.castleproject.org/projects/dynamicproxy/
You could use this to intercept your methods calls and then do with them what you want.