Solved

COM+ / Object Pooling / DECLARE_NOT_AGGREGATABLE

Posted on 2000-03-30
3
576 Views
Last Modified: 2013-11-25
With a VB component object pooling is not possible.  With a C++ component it is but can lead to very strange results and data corruption.  From the brief MS help: When pooling is enabled objects will be recycled and reused.  Object pooling can only be enabled for components that a written to meet the reusability requirements for poolable objects.  

Sounds good!  Questions:

1) Can someone explain from an implementation point of view in C++ what would be needed to support object pooling?

2) Why would you ever choose not to enable pooling?

3) Any comments on JIT activation?

Thanks!
0
Comment
Question by:eeuserex
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
gelbert earned 100 total points
ID: 2670934
Requirements for Poolable Objects
[This is preliminary documentation and subject to change. This technology works only on computers running Windows 2000 Beta 3 or later.]

Poolable objects must meet certain requirements to enable a single object instance to be used by multiple clients.

Stateless
Poolable objects should hold no client-specific state from client to client, to maintain security, consistency, and isolation. You can manage any per-client state using IObjectControl, performing context-specific initialization with Activate and cleaning up any client state with Deactivate. For more detail, see Controlling Object Lifetime and State.

No thread affinity
Poolable objects cannot be bound to a particular thread, otherwise performance could potentially be disastrous. For this reason, poolable objects cannot be marked Apartment model, they must run in the Multi-Threaded Apartment or the Neutral Apartment. In addition, poolable objects should not use thread local storage (TLS), nor should they aggregate the Free-Threaded Marshaller (FTM). For more detail about threading in COM+, see Concurrency.

Note that currently, the Microsoft Visual Basic development environment can only create Apartment model components. For this reason, Visual Basic components cannot be pooled.

Aggregatable
Poolable objects must support aggregation– that is, they must support being created with a pUnkOuter. When COM+ activates a pooled object it will create an aggregate to manage the lifetime of the pooled object and to call methods on IObjectControl. For details on writing aggregatable objects, see Aggregation.

Transactional components
Poolable objects that participate in transactions must manually enlist managed resources. If your object holds a managed resource such as a database connection while it is pooled, there will be no way for the resource manager to automatically enlist in a transaction when the object is activated in given context. Therefore, the object itself must handle the logic of detecting the transaction, turning off the resource manager's auto-enlistment, and manually enlisting any resources that it holds. In addition, a transactional pooled object should reflect the current state of its resources in IObjectControl::CanBePooled. For more detail, see Pooling Transactional Objects.

Implement IObjectControl to manage the object lifetime
Poolable objects should implement IObjectControl, though it is not strictly necessary to do so. Transactional components that are pooled, however, must implement IObjectControl. They should monitor the state of the resources they hold and indicate when they can't be reused; when CanBePooled returns false it will doom a transaction. For more detail, see Controlling Object Lifetime and State.

Language restrictions
Currently, components developed using Microsoft Visual Basic cannot be pooled, as these components will be apartment-model threaded.

Legacy components
Components can be pooled even if they are not specifically written with this in mind, so long as they are non-transactional and conform to the appropriate requirements above. It is not necessary to implement IObjectControl; a component that does not do so simply won't participate in managing its lifetime. If CanBePooled is not implemented, the object will always be reused, up until the pool maximum size.

0
 

Author Comment

by:eeuserex
ID: 2671107
Thanks for the information.  If you can answer the specific questions I would be happy to accept your comment as an answer.  Also, where did you find that specific documentation?
0
 

Author Comment

by:eeuserex
ID: 2671124
Found it on MSDN.  Also some other goodies...

Thanks.  For anyone else:

http://msdn.microsoft.com/isapi/msdnlib2.idc?theURL=/library/psdk/cossdk/pgservices_objectpooling_6ep3.htm
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now