コード例 #1
0
        public void HostCreateWithState()
        {
            var testWorkQueue = new WorkQueue();

            // the first host under test
            using DistributedHost host = CreateHost(testWorkQueue, true);

            // construct second host
            using DistributedHost host2 = CreateHost(testWorkQueue, false);

            // host could start announcing also, but host2 isn't listening so it wouldn't be detectable
            host2.Announce();

            // should generate announce response and then connection
            WaitUtils.WaitUntil(new[] { host, host2 }, () => host.PeerCount == 1 && host2.PeerCount == 1);

            // create object
            var distributedThing = new DistributedThing(host, new LocalThing(new[] { 1, 2 }));

            // wait until the proxy for the new object makes it to the other host
            WaitUtils.WaitUntil(new[] { host, host2 }, () => ProxiesForFirstPeer(host2).Count == 1);

            LocalThing host2LocalThing = FirstProxyLocalThing(host2);

            Assert.IsTrue(Enumerable.SequenceEqual(new[] { 1, 2 }, host2LocalThing.LocalValues.ToList()));

            // now create an owner object on the other host
            var distributedThing2 = new DistributedThing(host2, new LocalThing(new[] { 3, 4 }));

            // wait until the proxy for the new object makes it to the first host
            WaitUtils.WaitUntil(new[] { host, host2 }, () => ProxiesForFirstPeer(host).Count == 1);

            IDistributedObject hostProxy      = ProxiesForFirstPeer(host).Values.First();
            LocalThing         hostLocalThing = (LocalThing)hostProxy.LocalObject;

            Assert.IsTrue(Enumerable.SequenceEqual(new[] { 3, 4 }, hostLocalThing.LocalValues.ToList()));
        }
コード例 #2
0
        public static void Register(DistributedHost.ProxyCapability proxyCapability)
        {
            proxyCapability.SubscribeReusable((Create createMessage, NetPeer netPeer) =>
            {
                // wire the local and distributed things together
                var localThing       = new LocalThing(createMessage.Values);
                var distributedThing = new DistributedThing(
                    proxyCapability.Host,
                    netPeer,
                    createMessage.Id,
                    localThing);
                localThing.Initialize(distributedThing);
                proxyCapability.AddProxy(netPeer, distributedThing);
            });

            proxyCapability.SubscribeReusable((Delete deleteMessage, NetPeer netPeer) =>
                                              proxyCapability.OnDelete(netPeer, deleteMessage.Id, deleteMessage.IsRequest));

            proxyCapability.SubscribeReusable((Enqueue enqueueMessage, NetPeer netPeer) =>
                                              HandleReliableMessage <Enqueue, DistributedThing, LocalThing, IThing>(proxyCapability.Host, netPeer, enqueueMessage));

            proxyCapability.SubscribeReusable((Ping pingMessage, IPEndPoint endpoint) =>
                                              HandleBroadcastMessage <Ping, DistributedThing, LocalThing, IThing>(proxyCapability.Host, pingMessage));
        }