Exemplo n.º 1
0
 public void Leave(ZrePeer peer)
 {
     ZrePeer tmp;
     if (_peers.TryRemove(peer.Identity, out tmp))
     {
         peer.Status += 1;
     }
 }
Exemplo n.º 2
0
        private ZreGroup JoinPeerGroup(ZrePeer peer, string groupName)
        {
            var group = RequirePeerGroup(groupName);
            group.Join(peer);

            //  Now tell the caller about the peer joined group
            _pipe
                .SendMoreFrame("JOIN")
                .SendMoreFrame(peer.Identity.ToString())
                .SendMoreFrame(peer.Name)
                .SendFrame(groupName);

            if (_verbose)
            {
                Trace.WriteLine(
                    string.Format(
                        "({0}) JOIN name={1} group={2}",
                        _name,
                        peer.Name,
                        groupName));
            }

            return group;
        }
Exemplo n.º 3
0
        private ZrePeer RequirePeer(Guid identity, string endpoint)
        {
            ZrePeer peer;
            if (_peers.TryGetValue(identity, out peer))
            {
                return peer;
            }

            //  Purge any previous peer on same endpoint
            PurgePeer(endpoint);

            peer = new ZrePeer(_context, identity);
            _peers.TryAdd(identity, peer);
            peer.Origin = _name;
            peer.Verbose = _verbose;
            peer.Connect(_identity, endpoint);

            // Handshake discovery by sending HELLO as first message
            var groups = _ownGroups.Keys.ToArray();
            var headers = new ConcurrentDictionary<string, string>(_headers);
            var msg = new ZreMessage(ZreMessageType.Hello);
            msg.Endpoint = _endpoint;
            msg.Groups.UnionWith(groups);
            msg.Status = _status;
            msg.Name = _name;
            msg.Headers = headers;
            peer.Send(msg);

            return peer;
        }
Exemplo n.º 4
0
        private void RemovePeer(ZrePeer peer)
        {
            //  Tell the calling application the peer has gone
            _pipe
                .SendMoreFrame("EXIT")
                .SendMoreFrame(peer.Identity.ToString())
                .SendFrame(peer.Name);

            if (_verbose)
            {
                Trace.WriteLine(
                    string.Format(
                        "({0}) EXIT name={1} endpoint={2}",
                        _name,
                        peer.Name,
                        peer.Endpoint));
            }

            //  Remove peer from any groups we've got it in
            foreach (var peerGroup in _peerGroups)
            {
                peerGroup.Value.Leave(peer);
            }

            //  To destroy peer, we remove from peers hash table
            _peers.TryRemove(peer.Identity, out peer);
        }
Exemplo n.º 5
0
        private ZreGroup LeavePeerGroup(ZrePeer peer, string groupName)
        {
            var group = RequirePeerGroup(groupName);
            @group.Leave(peer);

            //  Now tell the caller about the peer left group
            _pipe
                .SendMoreFrame("LEAVE")
                .SendMoreFrame(peer.Identity.ToString())
                .SendMoreFrame(peer.Name)
                .SendFrame(groupName);

            if (_verbose)
            {
                Trace.WriteLine(
                    string.Format(
                        "({0}) LEAVE name={1} group={2}",
                        _name,
                        peer.Name,
                        groupName));
            }

            return group;
        }
Exemplo n.º 6
0
 public void Join(ZrePeer peer)
 {
     peer = _peers.GetOrAdd(peer.Identity, guid => peer);
     peer.Status += 1;
 }