We help IT Professionals succeed at work.

COM+ Object Pooling

CHORN
CHORN asked
on
This is not a specific question, but more of a design question.  I want to create two MTSObjects.

The first object (DataServer) will be installed on a COM+ server and exported to client.  This object will have one method, which retrieves data from another MTSObject and returns it to the methods caller.  This object will be stateless and will be pooled.

The other object (DataProvider) is the data provider for the object described in the previous paragraph.  The data this object accesses is in a structured file and is loaded when the object is created.  It can not be accessed with BDE or any other ODBC driver, which can pool connections.  I have to load this data when the object is created.

What I want to do is create the DataProvider once to be utilized by all of the instances DataServer.  Since the object (DataProvider) takes so long to load I would not want the initialization to happen again after it is created the first time, and I would want all of the DataServers to be able to utilize the DataProvider for their data queries.  In short it would be ideal if I could create the DataProvider as a singleton and have the DataServers access the one DataProvider for their data.  My main goal is to keep the data from being loaded over and over again each time I create a DataProvider.

Any suggestions would be appreciated.
Comment
Watch Question

Commented:
What you need to do is to register your data provider object in the systems Running Object Table (ROT) so that
multiple clients can connect to the same object instance:

type
  TDataProvider = class...
  private
    FROTID: Longint;
.....
....
procedure TDataProvider.Initialize....
begin
  inherited;
  .....
  //load your heaps of data
  .....  
  OleCheck(RegisterActiveObject(Self, Class_DataProvider, ActiveObject_Weak, FROTID));
  ....
  ....
end;

destructor TAutoServer.Destroy...
begin
  OleCheck(RevokeActiveObject(FROTID, nil));
  ....
  ....
  inherited;  
end;

-----------------------------------------------
The data server would look like:

type
  TDataServer = class....
  private
    FProvider: IDataProvider;
....
....
TDataServer.GetProvider(...
begin
  try
    FProvider := GetActiveOLEObject('CHORN.DataProvider') as IDataProdvider;
  except
    FProvider := CreateOLEObject('CHORN.DataProvider') as IDataProdvider;
  end;
  ......
end;

-----------------------------------------------
This will prevent clients creating a new provider object if
there's already one there, however if the provider gets
released by the last data server, it may be destroyed, hopefully COM+'s pooling should kick in here...

rondi

Author

Commented:
Thanks for the suggestion.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.