-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Removal of COMThread broke simplification usecase of the COM.util package #651
Comments
…a asserts The custom thread instantiated in the c.s.j.p.w.C.util.ProxyObject and then used as a dispatch for COM calls is a bootleneck and not following COM convention. If COM is initialized for a thread as COINIT_MULTITHREADED there is no reason to force dispatch through a central thread and if it is COINIT_APARTMENTTHREADED a message queue is needed: https://msdn.microsoft.com/de-de/library/windows/desktop/ms695279%28v=vs.85%29.aspx The change introduced here removes the dispatcher thread and the initialization routines from COMBindingBaseObject. In their place asserts are placed, that enforce correct COM initialization. The tests were adjusted accordingly.
Thanks for starting this discussion - indeed I failed to explain why I went ahead and removed the COMThread. While it looked like a good idea when looking at it at first, I became less enthusiastic at that time. Basicly the util classes have a different approach to the basic COM classes, that uses much less boiler plate code and move the common code into the basic module (wrapping, dispatch handling, memory handling) and this can now used at the price, that you need to initialize COM in the threads that access the COM methods. While I see that this is break in the API (a massive one), I consider it worth it. The proxy approach can now be used in MTA and STA mode, provided the user prepares the environment correctly (that would be calling the CoInitializeEx/CoUninitialize pair). In fact the save part of the current api could be reimplemented see: https://gist.github.com/matthiasblaesing/72c0b4751d52ebfd4406a72e5c7fe6d0 The idea, layer a single threaded factory on top of the basic factory. This factory wraps the COM objects into a layer, that pushes them into the thread executor. I still would strongly advice against using callbacks in this scenario, but for a basic usecase this might be ok. At first I tried to stay with the single thread approach, but then I tried to enhance it and uglyness entered. To be able to handle callbacks, I introduces a "COM initialized" flag, that would allow the callback and the factory to be used in the callback thread (which is by definition COM initialized), but that flag needed to be maintained. Another pain point were the places, where calls had to be pushed into the COM thread. Then Interrupted-, Execution- and TimeoutException were caught and rethrown as a RuntimeException. The interesting question: what happens when the COM call comes back, after the TimeoutException happened? In all fairness I have no idea, but I don't want to try. |
My usecase for this involves many different java threads accessing the COM objects, hence the reason I included the ComThread in my original implementation of this. I accept that this does make it a bottle neck, and there may be other usecases that require something like you suggest. Is there a way that we can have both options available? |
@dhakehurst did you have a look at the gist I referenced? The idea is, that you can replace the Factory class with COMFactory, that will do the same "move calling into one central thread" handling, that the old Factory did. I ran the Word MSDN sample through this and that works as I'd expect. I have to think about the callback handlers, but maybe I could retrofit the "mark thread as COM thread approach". If this works out, I see this option:
|
That sounds like it could work. On Thursday, 5 May 2016, matthiasblaesing [email protected] wrote:
|
@dhakehurst - I made a prototype implementation available as: https://github.com/matthiasblaesing/jna/tree/simple_com_htread I added unittests to cover the new baseclass ObjectFactory and the old Factory. This is pretty much the implementation sketched above. |
this looks like it could work, On 8 May 2016 at 16:56, matthiasblaesing [email protected] wrote:
|
Motivation: Quiche did a new release, update the sha to it. Modifications: Update to sha which is quiche 0.3.0 Result: Use latest "official" release of quiche
@dhakehurst raised in a comment to pullrequest #649 the following issue in regard to the removal of the COMThread from jna codebase:
The text was updated successfully, but these errors were encountered: