Hitchhiker's Guide to COM Part 2 - PowerPoint PPT Presentation

1 / 66
About This Presentation
Title:

Hitchhiker's Guide to COM Part 2

Description:

Use clerk to write user-defined log records. Log Writes are Buffered until ... CRM Recovery Infrastructure Creates CRM 'Clerk' Instances to Assist in Recovery ... – PowerPoint PPT presentation

Number of Views:84
Avg rating:3.0/5.0
Slides: 67
Provided by: lawrieg
Category:

less

Transcript and Presenter's Notes

Title: Hitchhiker's Guide to COM Part 2


1
Hitchhikers Guide to COM (Part 2)DEVQ200-03
Level 300NameTitleDepartmentMicrosoft
Corporation
2
Session Prerequisites
  • Windows DNA Application Knowledge
  • Technologies
  • COM, Microsoft Transaction Server (MTS)
  • Visual Studio and Visual Basic
  • Hitchhiker's Guide to COM (Part 1)
  • Introductory knowledge of COM

3
Agenda
  • COM Context
  • Advanced COM Services Concepts
  • Compensating Resource Manager (CRM)
  • Object Pooling
  • Events
  • Security

4
COM Context Recap
  • A Group of Objects in a Process
  • Used to Group Compatible Objects
  • All objects in a single context have compatible
    attributes
  • Used to Separate Incompatible Objects
  • Objects with at least one attribute
    incompatibility must live in different contexts
  • Each Object Belongs to Exactly One Context
  • A Process can Contain Multiple Contexts

5
COM ContextsRelation to MTS Context Wrappers
  • COM Context Replace MTS Context Wrapper
  • Context Wrappers No Longer Exist
  • Their purpose is now an integrated feature of
    COM
  • No Need to Use SafeRef
  • In MTS, SafeRef was used to obtain an object
    reference safe to pass outside of its context
    wrapper
  • In COM, simply use normal object references (Me)

6
COM Context Where Does Context Come From?
  • Objects are Associated with Context at
    Activation-Time
  • COM Compares the Target Classs Requirements to
    the Current Contexts Properties
  • If compatible, object lives in creators context
  • If not compatible, object is instantiated in a
    compatible context
  • Non-Configured Classes are Always Activated in
    Creators Context

7
COM ContextHow Does Context Flow?
  • Properties Can Flow to Downstream Objects
  • Call and Object Properties Flow Differently
  • Call context flows as one object calls to another
    object
  • Object context flows as new contexts are created
  • Object context will flow to subsequent compatible
    objects
  • CreateObject Did Not Flow Context Prior to COM

8
COM ContextCall Serialization
  • Classes Can Be Configured to Use System-Provided
    Call Serialization
  • Uses the Synchronization attribute
  • COM Can Put Contexts into a Synchronization
    Boundary Called an Activity
  • An activity is a group of contexts in which no
    concurrent execution is desired
  • Each Context Belongs To At Most One Activity

9
COM ContextThe Synchronization Attribute
  • Synchronization Has the Following Properties
  • Allows one caller to enter the component at a
    time
  • Flows from component to component within a
    process
  • Allows reentrancy from the same caller

10
COM ContextJITA and AutoComplete / AutoAbort
  • MTS Intertwined Transaction Voting and Doneness
  • Using SetComplete SetAbort Methods
  • COM Provides Independent Setter/Getters for
    Happy and Done Bits Via IContextState
    Interface
  • COM Allows the Done Bit to be Set
    Declaratively on a Method-by-Method Basis

11
COM ContextJITA and AutoComplete / AutoAbort
Interception Layer
Object Context
12
Agenda
  • COM Context
  • Advanced COM Services Concepts
  • Compensating Resource Manager (CRM)
  • Object Pooling
  • Events
  • Security

13
CRMWhat is a Resource Manager?
  • System Service that Manages Durable Data
  • Maintains durable state of an application
  • Works with the Transaction Manager
  • To provide the application with a guarantee of
    atomicity and isolation
  • SQL Server is an Example of a Resource Manager

14
CRMNot a Resource Dispenser
  • Resources Dispensers are different
  • Services that provides for the synchronization
    and management of non-durable resources within a
    process
  • Example, the ODBC resource dispenser manages
    pools of database connections

15
CRMWhat is a CRM?
  • A CRM is a Type of Resource Manager
  • Has Transactional ACID Properties
  • Atomicity
  • Consistency
  • Durability
  • Does Not Automatically Provide Isolation
  • An Easier Way to Build a Resource Manager

16
CRMWhat Does It Do?
  • Extends Transactional Capabilities to
    Non-Transactional Resources
  • Allows Custom Roll-Back Logic to be Provided

17
CRMEasy to Build a Resource Manager
  • Developed as a Pair of COM Components
  • CRM Worker
  • CRM Compensator
  • COM Provides
  • Transaction Outcome Notifications
  • Logging

18
CRMWho Is It For?
  • CRM Developers
  • Develop a specific type of CRM for a specific
    task
  • COM Application Developers
  • Use a CRM in their application
  • COM Administrators
  • Deploy CRM components as part of an application
  • COM Application End Users
  • Might not even know they are using a CRM

19
CRMScenarios for CRM
  • RegDB CRM
  • Used by COM admin System Application
  • Legacy Applications
  • Integration
  • File System, Registry, Mail
  • Beware isolation issues

20
CRMHow Does It Work?
  • Compensators Implement a Simplified Version of
    the DTC 2PC Interfaces
  • Phase One
  • Compensator is asked to prepare
  • Phase Two
  • Compensator notified of outcome
  • System Manages a Durable Log to Store State
    Between Phases

21
CRMArchitecture
YourCRM.DLL
CRM Infrastructure
CoCreateInstance
CoCreateInstance
Recovery/2PC Infrastructure
22
CRMCRM Lifetime
  • Logging is Performed in a Write-Ahead Manner
  • Log the action before performing it
  • Cleanup is Performed the Opposite Way
  • Cleanup the action then write log record to
    indicate compensation is done
  • Either Can Occur More Than Once
  • If we crash between logging and execution or lose
    messages through RPC
  • CRM Architecture Ensures That Each Operation is
    Performed at Least Once

23
CRMUsing a Compensator
  • Inside the Transaction
  • Create the clerk
  • For Operations That Require Compensation
  • Use clerk to write user-defined log records
  • Log Writes are Buffered until ForceLog is Called
  • Can Erase Last Log Entry Using ForgetLogEntry

Demo
24
CRMRepeatable Compensating Logic
  • Use Logic That Can Safely Be Performed More Than
    Once
  • Set bank account balance to 1000
  • Not
  • Add 100 to bank account
  • Logic Can Be Made Repeatable Through Careful
    Logging
  • Add 100 to bank account becomes balance
    before transaction is 900, after transaction is
    1000. If balance is 900 during recovery,
    change may be reapplied.

25
CRMIsolation Issues
  • Resource is Visible (Not Locked) During
    Transaction
  • Resource is Visible if You Crash During
    Transaction, Before Recovery is Done
  • Client Does Not Know When Transaction has
    Completed
  • Nothing Must Depend on Results of the Transaction
    Until It has Completed
  • Application Must Handle Isolation Issues

26
CRMDeployment
  • CRMs are COM Components
  • CRMs Can Be Deployed
  • In Server applications
  • In Library applications
  • CRMs Can Only Run in Server Applications
  • Must Enable Compensating Resource Managers
  • In Component Services Explorer - (server)
    application Properties Advanced

27
CRMCOM Configuration
  • CRM Worker
  • Requires transaction (or new transaction)
  • Sync yes, JIT yes (because it has a
    transaction)
  • Not main threaded (Both recommended)
  • CRM Compensator
  • No transaction
  • Not main threaded (Both recommended)
  • Some limits on Apartment threaded components

28
CRMRecovery
  • Marking an Application as CRM-Aware Means
    Recovery Process Occurs at Application Startup
  • CRM Recovery Infrastructure Creates CRM Clerk
    Instances to Assist in Recovery
  • As Records are Read from the Log, CRM Clerks
    Create CRM Compensators as Needed

29
CRMWhat a CRM Wont Do
  • The CRM Infrastructure Provides No Concurrency
    Management
  • The CRM Infrastructure Provides No Internal
    Atomicity or Consistency

30
Agenda
  • COM Context
  • Advanced COM Services Concepts
  • Compensating Resource Manager (CRM)
  • Object Pooling
  • Events
  • Security

31
Object PoolingRecap Resource Dispensers
  • MTS Introduced the Concept of Resource Dispensers
  • A service that provides the synchronization and
    management of non-durable resources within a
    process
  • Resource Dispensers Provided For
  • ODBC data access (ODBC 3.0 and above driver
    manager)
  • OLEDB data access (OLEDB 2.0 and above service
    components)
  • Mainframe connections - COMTI

32
Object PoolingRecap Resource Dispensers
  • Resource Dispensers are Convenient to Use
  • Keep the same programming model
  • Transaction enlistment is automatic
  • Connection pooling is automatic
  • Resources are garbage-collected via a timeout
    value

33
Object PoolingRecap Resource Dispensers
  • Size of Connection Pool is Not Configurable
  • Connection Pools Do Not Wait if Resource is Not
    Available
  • You Can Write Your Own Resource Dispenser
  • But its not very easy

34
Object PoolingWhat are Pooled Objects?
  • Simply Lightweight Resource Dispensers
  • Only Appropriate for Last Tier Data Object Access
  • Pooled Objects are Declaratively Configurable
  • Maximum number in the pool
  • Minimum number in the pool
  • Time to wait for resource to become available

35
Object PoolingPooled Objects
  • When Do You Use a Pooled Resource Object?
  • If objects are homogenous
  • If long initialization time
  • If precious resource
  • If Time To Construct is Long Compared to Time Used

36
Object PoolingPooled Object Requirements
  • Must Have No Thread Affinity
  • Must Manage Own State
  • Must Implement IObjectControl
  • Must Be Configured for Object Pooling
  • Cannot Be Created with Visual Basic
  • Visual Basic 6.0 components still have thread
    affinity

Demo
37
Object PoolingTransaction Management
  • COM Does Transaction Management For You
  • Disable Automatic Connection Pooling
  • Disable Automatic Transaction Enlistment in OLEDB

38
Object PoolingLifetime Management
  • Implement IObjectControl
  • Activate
  • Reset to initial state
  • Deactivate
  • Return to the pool
  • CanBePooled
  • Decide whether it can be reused

39
Object Pooling Error Handling
  • What If the DBMS is Unavailable?
  • ODBC 3.5 has configurable retry wait time
  • In your object, handle this yourself
  • Retry connection
  • Return immediate bad return code
  • Answer NO to CanBePooled to destroy object

40
Agenda
  • COM Context
  • Advanced COM Services Concepts
  • Compensating Resource Manager (CRM)
  • Object Pooling
  • Events
  • Security

41
Events
  • Event Filtering
  • Parallel Firing
  • Combining With Other COM Services
  • Queued Components
  • Programmatic Configuration

42
EventsFiltering
  • Publisher Filtering
  • Controls the order and firing of an event method
    by an EventClass
  • Allows you to determine which subscribers will
    receive a particular event
  • Parameter Filtering
  • Used on a per-method, per-subscription basis and
    provides a level of subscriber filtering at the
    event source
  • Occurs after publisher filtering

43
EventsFiltering
Publisher
Subscribers
MSFT
Event class
CPQ
INTC
interface IStockEvents HRESULT
StockPriceChange ( BSTR StockSymbol, double Price
)
  • Subscribers Called When a Specific Stock Price
    Changes
  • This Requires Filtering

44
EventsFiltering
  • Publisher Filtering
  • Declarative
  • Attribute of the EventClass
  • Gets created by the COM EventSystem
  • Filtering to be taken care by the Filter
    component
  • Runtime
  • Created by the user and set on the EventClass
    programmatically
  • Filtering to be taken care by the Filter
    component
  • Parameter Filtering
  • Filter Criteria is set on the Subscription
  • Filtering is taken care by the COM EventSystem

45
EventsParallel Firing
  • Set as an attribute on EventClass
  • Multiple subscribers can receive events in
    parallel
  • Publisher will still be blocked until the last
    subscriber completes its processing

46
EventsCombining with Queued Components
  • COM Events Include Full Support for Queued
    Components
  • Event Classes and/or Subscriberscan be queued
  • Prevents event publisher from being blocked by a
    subscriber
  • Enhances availability
  • Ensures events reach remote subscribers over
    unavailable or unreliable networks

47
EventsQueue-able Subscriber
Publisher
48
EventsProgrammatic Configuration
  • Use COM Catalog
  • Register event classes
  • Manage subscriptions

Demo
49
Agenda
  • COM Context
  • Advanced COM Services Concepts
  • Compensating Resource Manager (CRM)
  • Object Pooling
  • Events
  • Security

50
Security
  • COM Security Architecture
  • Using COM Security
  • Authentication
  • Authorization (Access Control)
  • Two-tier and Three-tier scenarios
  • COM with SQL Server 7.0

51
COM Security Architecture What is
Authentication?
  • Verifying the Authenticity of a Claim of Identity
  • For COM Applications, Authentication
  • Can be turned on
  • Is configured administratively
  • Works Transparently to the Application

52
COM Security Architecture Authorization
Roles
Client
Method Call
COM Executive
53
COM AuthorizationOverview
Roles
Client
Method Call
COM Executive
54
COM AuthorizationRoles
?
55
COM AuthorizationSecurity Call Context
  • Security Information Across Nested Calls
  • Exposed as a property collection
  • Caller identity (all upstream callers)
  • Authentication service and level etc.
  • Good Foundation for Auditing
  • Caveat As Trustworthy as Direct Caller

Demo
56
COM AuthorizationImpersonation / Delegation
  • Requires Kerberos (Auto Selected by COM, If
    Possible)
  • Main Drawback Performance
  • Two authentications per call
  • Expensive (late) access failure
  • Defeats connection pooling


57
COM AuthorizationThree-Tier Scenarios
58
COM and SQL Server 7.0Three-Tier Scenario
  • Map COM Roles to SQL Server
  • Richer access control in database
  • Suitable for most access control policy types
  • Uses Application Roles in SQL Server 7.0
  • Role is a database specific identity

SQL Server 7.0
59
COM and SQL Server 7.0Three-Tier Scenario
  • Restrict Access to Database to Trusted Components
    / Applications
  • Allows use of null password on application roles
  • Avoid SQL Server application role password
    management
  • Caveat
  • Database audit is performed under the server
    identity

60
Call to Action
  • Simplify Your Applications
  • COM Context for declarative configuration and
    execution
  • Get out of the security programming business with
    COM Security
  • Enhance Your Applications with Advanced COM
    Services
  • Compensating Resource Managers (CRM)
  • Object Pooling
  • Events

61
MSDNEssential Resources For Developers
62
Where can I get MSDN?
  • Visit MSDN Online at msdn.microsoft.com
  • Register for the MSDN Flash email newsletter at
    msdn.microsoft.com/resources/msdnflash.asp
  • Join the MSDN Online Membership at
    msdn.microsoft.com/community
  • Become an MSDN CD Subscriber at
    msdn.microsoft.com/subscriptions
  • Attend more MSDN events!

63
Questions?
64
More Resources
  • msdn.microsoft.com
  • msdn.microsoft.com/osig/win2000
  • www.microsoft.com/windows2000/ready
  • msdn.microsoft.com/vstudio/win2000
  • msdn.microsoft.com/winlogo/win2000.asp
  • www.microsoft.com/dna
  • www.microsoft.com/data/oledb/olap

65
Additional Resources from Microsoft
  • Inside COM Base Services by Guy and Henry Eddon
  • Understanding COM by David Platt

Pick up your CD today with content from these and
other Windows 2000 programming titles.
Microsoft Press Resources available through
resellers and on the web at http//mspress.microso
ft.com/developer
66
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com