private void ChangeMembershipShardwide(MembershipChangeArgs args)
        {
            Message message = new Message();

            message.NeedsResponse = false;
            message.MessageType   = MessageType.MembershipOperation;

            //Since, in order to handle deadlock scenarios, the message cannot be sent to the local node,
            // this method is being called in its stead.
            ((LocalShard)_shard).OnMembershipChanged(args);

            message.Payload = args;
            IList <Server> activeList = new List <Server>();

            foreach (var node in _shard.ActiveChannelsList)
            {
                if (!node.Address.Equals(_context.LocalAddress))
                {
                    activeList.Add(node);
                }
            }
            ShardMulticastRequest <ResponseCollection <object>, object> request = _shard.CreateMulticastRequest <ResponseCollection <object>, object>(activeList, message);
            IAsyncResult asyncResult = request.BeginExecute();

            request.EndExecute(asyncResult);
        }
Exemplo n.º 2
0
        public IDictionary <String, IResponseCollection <T> > SendMessageToAllShards <T>(Message message, bool primaryOnly)
        {
            IDictionary <String, IResponseCollection <T> > responses    = new HashVector <String, IResponseCollection <T> >();
            IDictionary <String, RequestAsync>             asyncResults = new HashVector <String, RequestAsync>();

            foreach (String shard in _remoteShards.Keys)
            {
                IShard dest = GetShardInstance(shard);
                if (dest != null)
                {
                    try
                    {
                        if (primaryOnly)
                        {
                            ShardRequestBase <T> request = dest.CreateUnicastRequest <T>(dest.Primary, message);
                            asyncResults.Add(shard, new RequestAsync(request.BeginExecute(), request, dest.Primary));
                        }
                        else
                        {
                            ShardMulticastRequest <ResponseCollection <T>, T> multicastRequest = dest.CreateMulticastRequest <ResponseCollection <T>, T>(dest.ActiveChannelsList, message);
                            asyncResults.Add(shard, new RequestAsync(multicastRequest.BeginExecute(), multicastRequest));
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }

            foreach (KeyValuePair <String, RequestAsync> pair in asyncResults)
            {
                String shardName = pair.Key;
                IResponseCollection <T> shardResponse = new ResponseCollection <T>();

                if (primaryOnly)
                {
                    ShardRequestBase <T>          req             = pair.Value.Request;
                    IClusterResponse <T>          clusterResponse = new ClusterResponse <T>(req.EndExecute(pair.Value.AsyncResult), pair.Value.Destination);
                    IList <IClusterResponse <T> > list            = new List <IClusterResponse <T> >();
                    list.Add(clusterResponse);

                    shardResponse.Responses = list;
                }
                else
                {
                    ShardMulticastRequest <ResponseCollection <T>, T> req = pair.Value.Request;
                    shardResponse = req.EndExecute(pair.Value.AsyncResult);
                }

                responses.Add(shardName, shardResponse);
            }

            return(responses);
        }
Exemplo n.º 3
0
        internal ResponseCollection <object> MulticastRequest(Object data)
        {
            Message message = new Message();

            message.Payload       = data;
            message.NeedsResponse = true;

            message.MessageType = MessageType.MembershipOperation;
            ShardMulticastRequest <ResponseCollection <object>, object> request = _shard.CreateMulticastRequest <ResponseCollection <object>, object>(_shard.ActiveChannelsList, message);
            IAsyncResult result = request.BeginExecute();

            return(request.EndExecute(result));
        }
Exemplo n.º 4
0
        public IResponseCollection <T> SendMessageToAllServers <T>(string shard, Message message)
        {
            IShard dest = GetShardInstance(shard);

            if (dest != null)
            {
                ShardMulticastRequest <ResponseCollection <T>, T> multicastRequest = dest.CreateMulticastRequest <ResponseCollection <T>, T>(dest.ActiveChannelsList, message);

                IAsyncResult asyncResult = multicastRequest.BeginExecute();

                return(multicastRequest.EndExecute(asyncResult));
            }

            throw new ArgumentException("Specified Shard Does not exist");
        }
Exemplo n.º 5
0
        internal void SendHeartbeat(HeartbeatInfo info)
        {
            List <Server> list = new List <Server>();

            if (_shard != null && _shard.ActiveChannelsList != null)
            {
                Message msg = new Message();
                msg.MessageType   = MessageType.Heartbeat;
                msg.Payload       = info;
                msg.NeedsResponse = false;

                ShardMulticastRequest <ResponseCollection <object>, object> request = _shard.CreateMulticastRequest <ResponseCollection <object>, object>(_shard.ActiveChannelsList, msg);
                IAsyncResult result = request.BeginExecute();

                ResponseCollection <Object> response = request.EndExecute(result);
            }
        }