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?
}