public async void OnNext(ClientProcess value)
        {
            await Task.Run(() =>
            {
                // Get the list of nodes
                List <IPAddress> nodes = ParentNode.KnownNodes;

                // if there are no nodes, there is no point serialising the message
                if (nodes != null && !value.LocalOnly)
                {
                    // setup the message before sending
                    InterNodeCommunicationMessage msg = new InterNodeCommunicationMessage {
                        Data = ParentNode.ClientProcessSerialiser.Serialise(value), IsLocalOnly = true, MessageType = InterNodeMessageType.AddToQueue
                    };

                    byte[] data = ParentNode.InterNodeCommunicationMessageSerialiser.Serialise(msg);

                    // need to send this to all the other known nodes
                    foreach (var node in nodes)
                    {
                        ParentNode.SendToNode(node, data);
                    }

                    // be a good boy and clean up after ourselves
                    nodes.Clear();
                }
            });

            if (!value.LocalOnly)
            {
                // start the task
                ParentNode.ProcessQueue.ChangeState(value.Tag, QueuedProcessState.Running, false);
                Task <byte[]> task   = ParentNode.NodeTask.Execute(value.Data);
                var           result = await task;
                ParentNode.AddToCache(false, value.Tag, result);

                ClientResultMessage msg = new ClientResultMessage
                {
                    Data   = result,
                    Key    = value.Tag,
                    Source = value.Source
                };

                ParentNode.SendToNode(value.Source, ParentNode.DependancyInjector.Resolve <ISerialiser <ClientResultMessage, byte[]> >().Serialise(msg));
            }
        }
Example #2
0
        internal void AddToCache(bool localOnly, string key, byte[] value)
        {
            // Sanity check everything first.
            if (String.IsNullOrEmpty(key))
            {
                throw new ArgumentException("The key cannot be null", "key");
            }

            if (value == null || value.Length == 0)
            {
                throw new ArgumentException("The entry to the cache cannot be null", "value");
            }

            ClientResultMessage msg = new ClientResultMessage {
                Data = value, Key = key
            };

            // Update
            ResultCache.Write(key, msg, localOnly);
        }