COM Events for Late-bound Delivery of Information

arunsnarayanan 5 views 37 slides Mar 12, 2025
Slide 1
Slide 1 of 37
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37

About This Presentation

COM+ is an evolution of Microsoft Component Object Model (COM) and Microsoft Transaction Server (MTS). COM+ builds on and extends applications written using COM, MTS, and other COM-based technologies.


Slide Content

COM+ EVENTS
LATE-BOUNDDELIVERYOF
INFORMATION
Computer Call
April 08, 1999

PUBLISHING INFORMATION
•One of the classic programming problems of distributed
computing is how to advertise and deliver information to
one or more interested parties without a priori knowledge
of their identity
•In this context there are only two types of programs:
those who possess info, and those who need it

Application client
IStockEvents
Component
THE COMPONENT PROGRAMMING MODEL
(REQUEST/REPLY)
•Early bound
•Class Identity (CLSID) usually compiled in
•1 : 1
•Client calls a single component
•Blocking
•Client thread generally blocks until
the call completes

Subscriber
Publisher
PUBLISH/SUBSCRIBE SYSTEMS
(PUSH)
•Late bound
•Subscriber identity not known at development time
•1 : many
•“Events” are sent to all registered subscribers
•Non-blocking
•Publishers generally do not wait
for a response from subscribers
Subscriber
Subscriber

EVENT PROGRAMMING MODELS
•Standard event interface
•FireEvent(VARIANT StockEvent)
•Standard event object
•StockPriceChange(Event StockEvent)
•Arbitrary interface
•StockPriceChange(char* Company,
double StockPrice)

COM EVENTS TODAY
(CONNECTION POINTS)
•No activation
•Shared life-cycles between publisher
and subscriber
•Interface-only (no implementation)
•Binding, dispatching, error semantic,
etc., left to developer
•Subscriptions aren’t persistent
•No opportunity for interception between publisher and subscriber

option explicit
' --------------------------------------------------
' Call a simple component
' --------------------------------------------------
Dim obj
set obj = CreateObject(”StockComponent.1")
obj.StockPriceChange ”MSFT", 185.00
set obj = Nothing
COM+ PROGRAMMING MODEL
•Simple programming model
•Create Object, Invoke method, Release
Client
IStockEvents
StockComponent.1

option explicit
' ------------------------------------------
' Fire an event
' ------------------------------------------
Dim obj
set obj = CreateObject(”StockEvents.1")
obj.StockPriceChange ”MSFT", 185.00
set obj = Nothing
COM EVENTS
PROGRAMMING MODEL
•Same basic programming model
•Create Object, Invoke method, Release
Subscriber
Publisher
IStockEvents
Event class
(StockEvents.1)
IStockEvents
IStockEvents
IStockEvents
Subscriber
Subscriber

EVENT CLASS AS INTERMEDIARY
•Indirection between the publisher
and subscriber
•Meta-data defined (CLSID, ProgID, IID)
•Requires no coding on part of developer
•Exposes arbitrary interface
•May be Secured to control event delivery
•Subscriptions are wired to methods within the EventClass’ firing
interface

TRANSFORMATIONS VIA
THE “EVENTCLASS”
•Introduction of the EventClass caused two transformations:
•Ordinary, vanilla COM client
became a publisher
•Ordinary, vanilla COM component became a subscriber
•Publisher = COM client
•Subscriber = COM component

EVENT CLASS INTERFACE
EXAMPLE
interface IStockEvents
{
HRESULT StockPriceChange ( BSTR StockSymbol, double Price );
HRESULT NewStock ( BSTR StockSymbol, BSTR CompanyName );
HRESULT StockSymbolChanged (BSTR OldSymbol,
BSTR NewSymbol );
HRESULT DowJonesUpdate ( double Current );
};
•Each method may have 0 - n subscriptions
•Subscribers expose this interface as well
You subscribe
to individual
methods on the
firing interface
IStockEvents
StockEvents.1
{ 877E7998-E8EC-11D1-B994-00C04F990088 }

option explicit
Dim EventSystem
Dim EventClass
set EventSystem = CreateObject("EventSystem.EventSystem")
' ----------------------------------------------
' Subscription for IStockEvents.StockPriceChange
' ----------------------------------------------
set EventClass = CreateObject("EventSystem.EventClass")
EventClass.EventClassID = "{58A7E1A1-5A4A-11d2-BD11-0080C72B9899}"
EventClass.EventClassName = "StockEvents"
EventClass.FiringInterfaceID = "{58A7E1A2-5A4A-11d2-BD11-0080C72B9899}"
EventSystem.Store "EventSystem.EventClass", EventClass
Set EventClass = Nothing
CREATING AN EVENTCLASS

Subscribers
COM EVENTS
FIRING
Publisher
EventClass
IStockEvents IStockEvents

HOW DO I SUBSCRIBE?
•Traditionally:
•Subscriber gives pointer to
self to a publisher
•This is problematic!
•Lifecycles must be shared
•Assumes one publisher of the event
•Adds complexity to subscriber
•Subscriber now “knows about”
the publisher
•Subscriber includes subscription
building logic

Subscriber
(Start-up)
Publisher
(Start-up)
Time
Publisher
(Shutdown)
Subscriber
(Shutdown)
Subscribe
Un-Subscribe
TRADITIONAL LIFE-CYCLES
(A LA CONNECTION-POINTS)

TIGHTLY-COUPLED SUBSCRIPTIONS
•This model cannot be used if:
•Subscribers do not want to be active until the event is fired
•Subscribers want to subscribe prior to publisher start-up or installation
•Administrative management of subscriptions is required
•Publisher of event changes over time

◆A subscription is a relation composed of:
◆EventClass (IID inferred)
◆A specific method within the EventClass interface
◆A subscriber
◆May be a CLSID, moniker or an interface pointer
◆The use of CLSID solves the activation problems, but not the
life-cycle issue
Publisher
Event
class
Subscriber
StockEvents StockPriceChange StockSubscriber StockSymbol = “MSFT”
EventClass EventMethod Subscriber PublisherProperties
SUBSCRIPTION AS
A FORMAL OBJECT

SUBSCRIPTION DETAILS
•MachineName
•Used to indicate that the subscribing component must be called remotely
•Subscriber
•May be a CLSID, moniker or interface pointer
•Security
•May be Secured
•Publisher Properties
•May be used by the publisher for filtering, etc.
•Subscriber Properties
•May be used by the subscriber for filtering, forwarding, etc.
•Roaming
•Subscription follows the user (owner)

Publisher
Event
class
Subscriber
COM+ Events
Subscription
DECOUPLING THE LIFE-CYCLES
•Achieving independent life-cycles requires that a third-party become involved: COM+
events
•Subscribers add subscriptions to COM+ events
•Publisher’s EventClass retrieves subscriptions from
COM+ events

Subscriptions
SURVIVING SYSTEM FAILURES
•Ensuring subscriptions survive software failures requires persistence
•COM+ Events stores subscriptions
in a database
Publisher
Event
class
Subscriber
COM+ Events
Subscription

FORMALIZING THE ROLE OF
“SUBSCRIPTION BUILDER”
•Most publish/subscribe models do not delineate between:
•Subscribers
•Subscription builders
•Subscriber = Component which receives an event call
•Subscription Builder = Entity that registers the subscriber to receive
the event

Admins
WHO BUILDS SUBSCRIPTIONS?
•Answer: Everyone!
Subscriptions
Publisher Subscriber
COM+ events
Subscription

set EventSub = CreateObject("EventSubscription")
EventSub.EventClassID = “...”
EventSub.MethodName = “...”
EventSub.SubscriberCLSID = “...”
EventSystem.Store(EventSub)
MMC Snap-in
Programmatic
Subscriptions

StockEvents StockPriceChangeStockTicker
COM EVENTS - WIRING
COM+ Events
Subscription

Dim EventSystem
Dim EventSubscription
set EventSystem = CreateObject("EventSystem.EventSystem")
' ----------------------------------------------
' Subscription for IStockEvents.StockPriceChange
' ----------------------------------------------
set EventSubscription = CreateObject("EventSystem.EventSubscription")
EventSubscription.SubscriptionID = "{0019B161-69D9-11D1-88D1-0080C7D771BF}"
EventSubscription.SubscriptionName= "ESSample.StockPriceChange"
EventSubscription.EventClassID = "{F89859D1-6565-11D1-88C8-0080C7D771BF}"
EventSubscription.MethodName = "StockPriceChange"
EventSubscription.SubscriberCLSID = "{C658CAB0-89A2-11D1-891C-0080C7D771BF}"
'EventSubscription.PutPublisherProperty "StockSymbol", "MSFT"
EventSystem.Store "EventSystem.EventSubscription", EventSubscription
Set EventSubscription = Nothing
CREATING A SUBSCRIPTION

SUBSCRIPTION SUMMARY
•Subscriptions as objects are more expressive than mere
“object pointers”
•Subscriptions are added to COM+ events
•Subscriptions are managed by COM+ events
•Subscriptions are persisted by COM+ events
•Subscriptions may be queried
•Subscriptions may be secured
•Subscriptions may be shared by multiple publishers
(instances)
•Publishers and subscribers
•May be uncoupled
•Need not share life-cycles

NT Service
Firing
Subscribers
IStockEvents
IStockEvents
EventClass
Wiring
COM EVENTS
OVERALL ARCHITECTURE
Subscriptions
StockEvents StockPriceChangeStockTicker
Subscription

Event service
Subscriptions
Event store
COM EVENTS
FIRING
Subscribers
IStockEvents
IStockEvents
EventClass
Publisher

COM EVENTS
FIRING Subscribers
IStockEvents
IStockEvents
EventClass
Publishers
Subscription
cache
Event service
Subscriptions
Event store
◆Publishers cache subscriptions
⚫Cache is kept coherent with Event
Store automatically
⚫Cache may contain
private subscriptions

Publisher
Event class
Subscribers
“MSFT”
“CPQ”
“INTC”
interface IStockEvents
{
HRESULT StockPriceChange ( BSTR StockSymbol, double Price );
};
EVENT FILTERING
•Most Subscribers will want to be called only when a specific stock price
changes
•This requires filtering

Publisher Subscribers
IStockEvents IStockEvents
EventClass
Event service
Event store
EventFilter
Subscription
cache
interface IStockEvents
{
HRESULT StockPriceChange ( BSTR StockSymbol, double Price );
};
Subscription
EventClassMethodSubscriberStockSymbol = “MSFT”
COM EVENTS
FILTERING IN PUBLISHER

Publisher
Subscribers
IStockEvents
IStockEvents
EventClass
Event service
Subscriptions
Event store
EventFilter
Subscription
Cache
COM EVENTS
FIRING (CUSTOM CACHE)

Publisher process
Stock events
IStockEvents
Subscriber
Subscriber
Subscriber
Machine 1
Machine 2
IStockEvents
IStockEvents
Subscriber process
Subscriber process
REMOTEABLE EVENTS

COM+ EVENTS STORE
•Component-based
•Load balancing, security, transactions
•Secure
•Accessible via Windows NT
®
service
(COM+ event system)
•Publishes events
•EventObject added, modified, deleted
•Not required for firing events

COM+ EVENTS SECURITY
•Subscriber
•Subscriber components use standard COM/COM+ security to protect
against “fake” publishers
•EventClass
•COM+ role based security prevents unauthorized subscriptions from being
registered to receive secure events
•All objects in Event Store may be Secured
•Event Store
•Only accessible by Windows NT Service running as “Local system”

COM+ EVENTS
COMPOSITION
•COM/COM+ features:
•Interfaces
•Transactions
•Object pooling
•Just-in-time activation
•Queued components
•Deployment
•Load balancing
•Role-based security
•Windows NT features:
•MMC-based admin
•Windows NT roaming

Publisher
Subscribers
Logger
Screen saver
(Per-user, roaming))
Emailer
IStockEvents
IStockEvents
StockEvents
Event Service
Subscriptions
Event store
MAPI, SMTP
MSMQ
Audit log
Debug/trace
(Transient subscriptions)
Performance monitor
(Transient subscriptions)
STOCK TICKER SCENARIO

MS PRODUCTS IMPLEMENTING COM+
EVENTS
•SENS - System Event Notification Service
•Publishes login/logout, network connect/disconnect, Plug and Play,
shell start/end, etc.
•SyncMgr
•Subscribes to SENS and coordinates
application synchronization
•COM+
•All COM+ components fire debug/trace
events using COM+ events
•Tools
•Support currently being added across
both our languages and tools
Tags