/// <summary> /// Given an incoming broadcast message, look up the referenced object and invoke the message appropriately. /// </summary> /// <typeparam name="TMessage">The type of the message.</typeparam> /// <typeparam name="TObject">The actual type of distributed object.</typeparam> /// <typeparam name="TLocalObject">The corresponding type of local object.</typeparam> /// <typeparam name="TInterface">The distributed interface implemented by both the distributed and local objects.</typeparam> /// <param name="host">The distributed host.</param> /// <param name="message">The message.</param> public static void HandleBroadcastMessage <TMessage, TObject, TLocalObject, TInterface>( DistributedHost host, TMessage message) where TMessage : BroadcastMessage where TLocalObject : ILocalObject, TInterface where TObject : IDistributedObject, TInterface where TInterface : IDistributedInterface { if (message.OwnerAddress == host.SocketAddress) { // ignore messages to objects that no longer exist IDistributedObject target; if (host.Owners.TryGetValue(message.Id, out target)) { // Invoke on the local object. message.Invoke(target.LocalObject); } } else { // this object really ought to exist, but in case it doesn't (maybe disconnection race?), // ignore object targets that don't resolve. IDistributedObject target; if (host.ProxiesForPeer(message.OwnerAddress).TryGetValue(message.Id, out target)) { // Call straight through to the local object; don't invoke Enqueue on the proxy. // (If we do, it will call back to the owner, and whammo, infinite loop!) message.Invoke(target.LocalObject); } } }
/// <summary> /// Create an owner DistributedObject. /// </summary> protected DistributedObject(DistributedHost host, ILocalObject localObject) { Contract.Requires(host != null); Contract.Requires(localObject != null); Host = host; Id = host.NextOwnerId(); LocalObject = localObject; }
/// <summary> /// Create a proxy DistributedObject. /// </summary> protected DistributedObject(DistributedHost host, NetPeer netPeer, DistributedId id, ILocalObject localObject) { Contract.Requires(host != null); Contract.Requires(netPeer != null); Contract.Requires(localObject != null); Host = host; OwningPeer = netPeer; Id = id; LocalObject = localObject; }
internal Listener(DistributedHost host) { Host = host; }
internal ProxyCapability(DistributedHost host) { Host = host; }