[Mono-list] .NET Remoting and Hashtable

2008-03-27 Thread nemesis35

Hi,

we work on a project of distributed system where we use the technology
dotNET Remoting. But we have there a small issue.

We have two types of nodes there, managers and storages. They both use the
same method (the method is in dll file - manager and storage have the same
copy of this file).
The method is:


  public void UpdateLastSeen(Node n)
  {
 if (lastSeen.ContainsKey(n))
lastSeen[n] = DateTime.Now;
 else
lastSeen.Add(n, DateTime.Now);
  }

// Node n - is our own object
// lastSeen is hashtable (key is our own object Node, value is DateTime)

Problem:
The both nodes - managers and also storage peridiocally call this method,
while one of them works well, another one does somethig different with the
same code. 
For example the topology is point-to-point, one manager, one storage.
Storage updates active status of the manager well, but manager can't
recognize that it has is connected stil the same node - the same storage.
The result is that the manager does not overwrite the time of last seen of
the node storage, but by timer click it adds allways a new entry into the
hashtable. With the same code storage works great. 

No idea where the problem could be, maybe the copy of the object Node is not
the same like in the object stored in the hashtable??
Hope that someone will understand what we tried to explain;) and help.

Thanks a lot

Regards,

michal kohut
-- 
View this message in context: 
http://www.nabble.com/.NET-Remoting-and-Hashtable-tp16324136p16324136.html
Sent from the Mono - General mailing list archive at Nabble.com.

___
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list


Re: [Mono-list] .NET Remoting and Hashtable

2008-03-27 Thread Robert Jordan
Hi,

nemesis35 wrote:
 No idea where the problem could be, maybe the copy of the object Node is not
 the same like in the object stored in the hashtable??

It is definitely not the same object, so you have to implement
Node.GetHashCode() to establish a consistent identity that does
not rely upon Object.GetHashCode.

Note that if Node is a MarshalByRefObject, GetHashCode won't
be called remotely. This means that overriding GetHashCode has
no effect in other app domains than the creator domain.

Robert

___
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list


Re: [Mono-list] .NET Remoting and Hashtable

2008-03-27 Thread Michał Ziemski
Hi!

Does your Hashtable sit in a MarshalByRef class or a [Serializable] one?
If the latter is the case then each connecting node works on its 
separate copy.

Are you positive yor class is marshaled as a singleton rather than 
single-call?

Other than that, only putting: lastSeen[n] = DateTime.Now; in the 
method body will be a faster solution.
You should also consider using lock(lastSeen) if more than one client 
can be connected at a time.

Cheers!
Michał Ziemski

nemesis35 pisze:
 Hi,

 we work on a project of distributed system where we use the technology
 dotNET Remoting. But we have there a small issue.

 We have two types of nodes there, managers and storages. They both use the
 same method (the method is in dll file - manager and storage have the same
 copy of this file).
 The method is:


   public void UpdateLastSeen(Node n)
   {
  if (lastSeen.ContainsKey(n))
 lastSeen[n] = DateTime.Now;
  else
 lastSeen.Add(n, DateTime.Now);
   }

 // Node n - is our own object
 // lastSeen is hashtable (key is our own object Node, value is DateTime)

 Problem:
 The both nodes - managers and also storage peridiocally call this method,
 while one of them works well, another one does somethig different with the
 same code. 
 For example the topology is point-to-point, one manager, one storage.
 Storage updates active status of the manager well, but manager can't
 recognize that it has is connected stil the same node - the same storage.
 The result is that the manager does not overwrite the time of last seen of
 the node storage, but by timer click it adds allways a new entry into the
 hashtable. With the same code storage works great. 

 No idea where the problem could be, maybe the copy of the object Node is not
 the same like in the object stored in the hashtable??
 Hope that someone will understand what we tried to explain;) and help.

 Thanks a lot

 Regards,

 michal kohut
   

___
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list