Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Remoting / July 2003

Tip: Looking for answers? Try searching our database.

Notifying Clients - Events or Observers?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michael Curry - 23 Jul 2003 01:52 GMT
Hi,

Am getting very confused with remoting. We are building a large data
management application which uses a Server application to load light,
serialized objects on a client. eg:

Dim myPerson as Person
iPersonID = 1
myPerson = PersonFactory.Load(iPersonID)
myPerson.Name = "Fred Jones"
PersonFactory.Save(myPerson)

PersonFactory resides on the server, it is a singleton which contains
an object map so as to avoid database loads. Essentially all clients
requesting PersonID = 1 receive the same object - Serialized. When the
object is changed and saved (as above) the Factory does the saving,
REPLACES the object in its map, and SOMEHOW notifies any clients who
have a copy of that object to get the new copy (to avoid inconsistant
reads the object is replaced rather than just updated with the new
values).

My plan was to have an EventHandler object for each Person object,
passsed byRef and subscribed to by any client requesting a Person. All
notification was to be done through this EventHandler. eg:

Public Class PersonEventHandler
   Inherits MarshallByRef

   Dim mPerson as Person

   Public Event Updated(NewPerson as Person)

   Public Sub Update(NewPerson as Person)
       mPerson = NewPerson
       RaiseEvent Updated(mPerson)
   End Sub
End Class

The event handler was to be passed back to the client as a Property of
the Person Object. The requesting client would then subscribe to its
Updated event using a delegate (AddHandler method) and receive
notification whenever the object was updated. eg:

Public Class SomeGUIClient

Dim mPerson as Person

Sub Form_Load
   mPerson = PersonFactory.Load(1)
   AddHandler (mPerson.PersonEventHandler.Updated, AddressOf
me.PersonUpdated)
   RefreshFields
End Sub

Sub PersonUpdated(NewPerson as Person)
   mPerson = NewPerson
   RefreshFields
End Sub

Sub RefreshFields
   'REfresh any GUI fields using Person
End Sub
End Class

Now I am reading articles saying not to use events in remoting. (Ingo
Rammer esp). He actually suggests using no callback methods and using
message queing instead. This all seems a bit beyond me.

Microsoft suggest using the observer patter for notifications, this
seems a reasonable approach.

What is best to use in this situation?

1. EventHandler (as above - will this even work??)
2. Observer pattern (isn't this really the same as the EventHandler
approach?)
3. Something Else????

Thanks for any pointers anyone can give me.

Michael
Ingo Rammer - 29 Jul 2003 10:21 GMT
Hi Michael,

> Microsoft suggest using the observer patter for notifications, this
> seems a reasonable approach.

Hmm ... this seems interesting. Could you please point me to any URL - I'd
really like to have a chat with the author of this recommendation.

I know that Microsoft suggest observer patterns for notification in local
(that is, single-process) applications. I however strongly doubt that anyone
inside Microsoft suggests the use of observers or events for arbitrarily
complex and scalable distributed applications.

> What is best to use in this situation?
>
> 1. EventHandler (as above - will this even work??)
> 2. Observer pattern (isn't this really the same as the EventHandler
> approach?)
> 3. Something Else????

EventHandlers essentially follow the Observer pattern so, yes, you are
right - these are the same.

Something else: Yes. MSMQ (System.Messaging) - it's not very difficult to
learn (but it takes a day or two to wrap your head around the different
programming model) but VERY effective for these kinds of scenarios. In fact,
depending on the number of users, it is the only thing which will scale.

Cheers,
-Ingo

Author of Advanced .NET Remoting
Read my "Distributed .NET Newsletter" at http://www.ingorammer.com/NL

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.