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