.net remoting: Update already serialized objects
Asked Answered
R

2

6

I got a MarshalByRefObject named "DefaultMeasurement", which contains a List of IPoint-objects.

public class DefaultMeasurement : MarshalByRefObject, IMeasurement
{
  private List<IPoint> iPoints;
  public this[int aIndex]
  {
    get { return iPoints[aIndex];}
  }
}

[Serializable]
public class DefaultPoint : IPoint, ISerializable
{
  public int Value {get;set;}
}

When first retrieving the DefaultMeasurement object from the server all the points get serialized and during all subsequent calls to DefaultMeasurement.Points I get the list that was correct upon startup of my client. But in the meantime the state of at least one object in that list might have changed and I don't get that current state, although in the server that state gets updated. How do I force an update of that list?

further clarification:
- it will work once I do DefaultPoint : MarshalByRefObject, but that is not an option as it negatively affects performance
- by 'update' I mean changes to existing objects on the server, no adding / removing on the list itself
- I might have up to 80k DefaultPoint objects

Radom answered 6/5, 2011 at 3:37 Comment(4)
I guess its somthing to do with the mode or Activation you are using. Lots of info here codeproject.com/KB/WCF/net_remoting.aspxMomently
thanks for the link. I don't get a lot of information about my specific scenario out of it. There's no example on returning the same object with altered values in the tutorial. The object (in section 7) is created upon invocation of the .func1() method. BTW I'm using Singleton activation mode, because I need to constantly update the values for the IPoint objects.Radom
A possible solution is to make IPoint inherit from MarshalByRefObject too (and not serializable). The single-call/singleton settings could also make a difference.Hatpin
I deliberately changed DefaultPoint away from MarshalByRefObject to increase the performance of my application. It really has tremendously done so, but at the cost of the next problemRadom
B
3

Since you don't want the Point itself to be MarshalByRef (as that introduces a LOT of traffic if you have a substantial number of points), what I would recommend is that you have explicit methods that synchronize point values. After you've made a significant number of changes on the server, you call the SynchronizePoints() method, which includes new values for all of the points. Now the client-side proxy has an updated state. Better yet, remove the state from the object in the first place (since it's not really a direct reflection of server state) and instead use client-side objects that are instantiated as needed when gathering points from the server.

Biskra answered 12/5, 2011 at 14:4 Comment(5)
that sounds interesting. Would the SynchronizePoints() method be called by the server or the client? What do you mean by 'removing the state from the object'?Radom
@yas4891, Right now you have a mutable DefaultPoint that is part of a mutable, marshalled DefaultMeasurement. This causes the problems you've observed, as you either Marshal them both to reflect the mutability (which is slow) or you get out of sync and need some workaround to update manually. If you instead use immutable values and have a mechanism to explicitly request the state as needed, you consolidate the data updates, which is more efficient and you also get better insulation in your design, since the observed values can't be mutated by the consumers of those values.Biskra
@yas4891, In other words, you can isolate the mutability of your measurement to the server and have a separate data transfer object that sends over a snapshot of the measurements when the client needs it, rather than exposing the raw mutable data.Biskra
OK. I think I know where you are getting. However, I still don't know how to get there. Would you recommend to switch DefaultPoint back to inherit MarshalByRefObject and then instead of using DefaultPoint as a return value for the Indexer create a new (serializable) TransportPoint object ?Radom
@yas4891, I suspect you'll have to do a bit of re-architecting to create read-only views of data for the client, while keeping the data in whatever form you need on the server. It's hard to know how best to accomplish this without more context on your overall design and current implementation. This is one of those cases where a slight shift in overall design can remove the technical problem entirely.Biskra
I
0

You would have to implement a callback that notifies the client of changes on the server.

The notify could pass id of the objects that have changed or the client could ask for a list of changed objects.

Intermediate answered 12/5, 2011 at 14:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.