COM Shared Property Manager

The COM+ Shared Property Manager (SPM) can be used to manage shared transient state for objects. Global variables cannot be used in a distributed environment because of concurrency and name collision issues. The SPM eliminates name collisions by providing shared property groups, which establish unique namespaces for the shared properties they contain. It also implements locks and semaphores as synchronization mechanisms.

On single processor servers with small numbers of clients, the Shared Property Manager works quite well as a mechanism for storing state. However, it should be noted that it does not scale well and applications that expect frequent concurrent users should instead use a database to store state information.

In Visual Basic 6.0, the classes for implementing SPM-related functionality are the SharedPropertyManager, SharedPropertyGroup, and SharedProperty classes from the COM+ Services Type Library. Visual Basic .NET counterparts for these classes can be clearly identified with the same names, and are included in the System.EnterpriseServices namespace.

The following Visual Basic 6.0 component uses SPM objects.

Public Function SPMTest(ByVal strGrpName As String, _

ByVal strPrpName As String, ByVal vntPrpValue As String, _ ByRef blnExists As Boolean)

Dim spmMgr As COMSVCSLib.SharedPropertyGroupManager Dim spmGrp As COMSVCSLib.SharedPropertyGroup Dim spmPrp As COMSVCSLib.SharedProperty

Set spmMgr = New COMSVCSLib.SharedPropertyGroupManager

Set spmGrp = spmMgr.CreatePropertyGroup(strGrpName, LockSetGet, _

Process, blnExists) Set spmMgr = Nothing

Set spmPrp = spmGrp.CreateProperty(strPrpName, blnExists)

spmPrp.Value = vntPrpValue SPMTest = spmPrp.Value

Set spmPrp = Nothing Set spmGrp = Nothing End Function

After you upgrade the component, the class contains several statements that need to be resolved using the Security classes provided by the .NET Framework inside the System.EnterpriseServices namespace.

Option Strict Off Option Explicit On

<System.Runtime.InteropServices.ProgId("COMTest_NET.COMTest")> _ Public Class COMTest

Public Function SPMTest(ByVal strGrpName As String, _

ByVal strPrpName As String, ByVal vntPrpValue As String, _ ByRef blnExists As Boolean) As Object

Dim spmMgr As COMSVCSLib.SharedPropertyGroupManager Dim spmGrp As COMSVCSLib.SharedPropertyGroup Dim spmPrp As COMSVCSLib.SharedProperty spmMgr = New COMSVCSLib.SharedPropertyGroupManager spmGrp = spmMgr.CreatePropertyGroup(strGrpName, _

COMSVCSLib._MIDL_MIDL_itf_autosvcs_0408_0002.LockSetGet, _

COMSVCSLib._MIDL_MIDL_itf_autosvcs_0408_0003.Process, _

blnExists)

' UPGRADE_NOTE: Object spmMgr may not be destroyed until it is ' garbage collected. spmMgr = Nothing spmPrp = spmGrp.CreateProperty(strPrpName, blnExists) spmPrp.Value = vntPrpValue

' UPGRADE_WARNING: Could not resolve default property of ' object SPMTest SPMTest = spmPrp.Value

' UPGRADE_NOTE: Object spmPrp may not be destroyed until it is ' garbage collected. spmPrp = Nothing

' UPGRADE_NOTE: Object spmGrp may not be destroyed until it is ' garbage collected. spmGrp = Nothing End Function End Class

As mentioned earlier, the name of the classes used in the SPM infrastructure are the same in .NET.

0 0

Post a comment

  • Receive news updates via email from this site