Ejemplo n.º 1
0
        public void BootStrapTopology()
        {
            var handledTypes = new HashSet<Type>(_assemblyScanner.GetHandledCommands().Union(_assemblyScanner.GetHandledEvents()));

            var messageSubscriptions = _assemblyScanner.GetMessageOptions().Where(x => handledTypes.Contains(x.MessageType))
                .Select(x => new MessageSubscription(x.MessageType, _peerConfiguration.PeerId,
                                            new ZmqEndpoint(_zmqTransportConfiguration.GetConnectEndpoint()),
                                            GetSubscription(x), x.ReliabilityLevel));

            var peer = new ServicePeer(_peerConfiguration.PeerName,_peerConfiguration.PeerId, messageSubscriptions.ToList(), _peerConfiguration.ShadowedPeers);
            var commandRequest = new InitializeTopologyRequest(peer);

            var directoryServiceRegisterPeerSubscription = new MessageSubscription(typeof(InitializeTopologyRequest),
                                                                                   _bootstrapperConfiguration.
                                                                                       DirectoryServiceId,
                                                                                   new ZmqEndpoint(
                                                                                       _bootstrapperConfiguration.
                                                                                           DirectoryServiceEndpoint),
                                                                                   null, Shared.ReliabilityLevel.FireAndForget);

            var directoryServiceRegisterPeerSubscription2 = new MessageSubscription(typeof(InitializeTopologyAndMessageSettings),
                                                                       _bootstrapperConfiguration.
                                                                           DirectoryServiceId,
                                                                       new ZmqEndpoint(
                                                                           _bootstrapperConfiguration.
                                                                               DirectoryServiceEndpoint),
                                                                       null, Shared.ReliabilityLevel.FireAndForget);

            var directoryServiceCompletionMessageSubscription = new MessageSubscription(typeof(CompletionAcknowledgementMessage),
                                                                       _bootstrapperConfiguration.
                                                                           DirectoryServiceId,
                                                                       new ZmqEndpoint(
                                                                           _bootstrapperConfiguration.
                                                                               DirectoryServiceEndpoint),
                                                                       null, Shared.ReliabilityLevel.FireAndForget);

            var directoryServiceBarebonesPeer = new ServicePeer(_bootstrapperConfiguration.DirectoryServiceName, _bootstrapperConfiguration.DirectoryServiceId,
                                                                new List<MessageSubscription> { directoryServiceRegisterPeerSubscription, directoryServiceCompletionMessageSubscription, directoryServiceRegisterPeerSubscription2 }, null);

            _peerManager.RegisterPeerConnection(directoryServiceBarebonesPeer);
            _peerManager.RegisterPeerConnection(peer); //register yourself after dir service in case dirService=Service;

            _logger.InfoFormat("Requesting topology from {0}", _bootstrapperConfiguration.DirectoryServiceName);
            var completionCallback = _messageSender.Route(commandRequest, _bootstrapperConfiguration.DirectoryServiceId);
            completionCallback.WaitForCompletion(); //now should get a init topo (or not) reply and the magic is done?

            //now register with everybody we know of
            _messageSender.Publish(new PeerConnected(peer));

            var persistenceShadowPeer = (_peerManager.PeersThatShadowMe() ?? Enumerable.Empty<ServicePeerShadowInformation>()).SingleOrDefault(x => x.IsPersistenceProvider);
            if (persistenceShadowPeer != null)
            {
                _logger.InfoFormat("Requesting missed messages for {0}", _peerConfiguration.PeerName);
                _messageSender.Route(new SynchronizeWithBrokerCommand(_peerConfiguration.PeerId), persistenceShadowPeer.ServicePeer.PeerId).WaitForCompletion();
            }

            //ask for topo again in case someone connected simulataneously to other node
            //    completionCallback = _messageSender.Route(commandRequest, _bootstrapperConfiguration.DirectoryServiceName);
            //    completionCallback.WaitForCompletion(); //now should get a init topo (or not) reply and the magic is done?
        }
Ejemplo n.º 2
0
 public PeerConnected(ServicePeer peer)
 {
     Peer = peer;
 }
 public RegisterPeerCommand(ServicePeer peer)
 {
     Peer = peer;
 }
 public InitializeTopologyRequest(ServicePeer peer)
 {
     Peer = peer;
 }
 private void OnPeerChange(ServicePeer obj)
 {
     _peersToShadows = _peerManager.GetAllShadows().ToDictionary(x => x.Key, x => new HashSet<ServicePeer>(x.Value.Select(y => y.ServicePeer)));
     _selfShadows = _peerManager.PeersThatShadowMe().Select(x => x.ServicePeer).ToList();
     //if (obj.PeerName == _peerConfiguration.PeerName)
     //{
     //    Dictionary<string, MessageSubscription> newSelfMessageSubscriptions = new Dictionary<string, MessageSubscription>();
     //    foreach (var messageSubscription in obj.HandledMessages)
     //    {
     //        newSelfMessageSubscriptions[messageSubscription.MessageType.FullName] = messageSubscription;
     //    }
     //    _messageOptions = newSelfMessageSubscriptions;
     //}
 }
Ejemplo n.º 6
0
 protected bool Equals(ServicePeer other)
 {
     return string.Equals(PeerName, other.PeerName);
 }