RNSO – A Remote Notifiers,Subjects and Observers Server over DCOM

RNSO is a server where the well known Observer Design
Pattern is implemented with Distributed COM.

The Observer Design Pattern helps you to build
applications when a change on a data need to be notified to another of your app.

The Datas are called Subjects, and parts of applications interrested by the
changes is (are) Observers.
Changes are notified from Subjects to Observers
by notifications, throught a Server (called the Manager). Only the manager knows
about the Observers who want to be notified. It maintains the connections called
Subscriptions.

Generally, Observers indicates they want to be notified by a method :

Observer1.Subscribe( pSubject ) ;
Observer2.Subscribe( pSubject ) ;

Subject prevents changes by another method :
Subject.Notify( ..something
) ;

Here, the 2 observers Observer1 and Observer2 will be notified ..

This design pattern is very usefull for GUI applications (MDI..), but this
can be used in several other cases. As an example, if you build a DLL to access
to a hardware equipment and  you’d like to use it on remote Machine,
you ‘ll be able with RNSO.

RNSO allows to build client-server applications over DCOM, without knowing
about DCOM or the Observer Design Pattern, and is independant of applications.
The Server can serve several applications at the same time, even they have no
relations.

How does RNSO Work?


 



Subject1 notifies about changes. The server (RNSO.EXE, is
automatically launched by the OS) notify the Observers who subscribed to the
subject.

Observers have a sink interface used by server to notify
them. This is also a component, with a mailbox. The mailbox is read by a thread
of the component. So the server is not blocked by clients.

Datas that a subject can notify are binary. So you can
transmit all you want.

Binaries of RNSO


I made several binaries for RNSO :

RNSO.exe                          
The server
RNSOSupport.DLL            
Dll used both by the server and the clients.
RNSOClient.DLL               
Dll used to build the observer clients (need also RNSOSupport.DLL). You don’t
need of it if you just build a Subject.

The binaries are build with Visual C++ 6.0.

The Sample Application


The sample application shows you:
– how to make a
CDialog as an Observer and a Subject.
– how to use
classes and ready-to-use components .

The following figure shows 2 instances of the application.

1) On the left, we declared the name of the object for
the dialog: Subject1.
2) On the rite, we declare the
dialog as an observer to Subject1.
3) On the left, the
subject notify a change  ‘My Message’
4) On the
rite, the subscriber received the notification.
 

You can start several apps and subscribe to ‘Subject1’.
All of them will be notified. When a subject is going down, subscribers receive
a notification.


In my sample, I derived my CDialog from CDialog an from
RnsoNotificationRout. This class has 2 virtuals methods. Overload them to handle
notifications:



class AFX_EXT_CLASS RnsoNotificationRout
{
public:
RnsoNotificationRout();
virtual ~RnsoNotificationRout();
virtual void OnNotifyNOTIFY(ObserverNotification* pNotification);
virtual void OnNotifyNOTIFY_SUBJECTBROKEN(DWORD dwSubjectID);
};

You aren’t obliged to have a dialog or a window to build an Observer
or a Subject. You can also make you class just as an Observer, or just
a Subject.

This is very simple.

Why to use this framework?


You dont have to maintain subscriptions yourself with lists,  arrays..
etc.


You can build interprocess / intermachines apps.


Download demo project – 197 KB

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read