private object CreateAggregator <T>(string name) { var aggregator = new DefaultAuditAggregator <T>(); var dataSetCircularBuffer = new DataPointCircularBuffer <AggregateStatistics <T> >(kLogLength); dataSetCircularBuffersByName.AddOrThrow(name, dataSetCircularBuffer); updaterActions.TryAdd(() => { var statistics = aggregator.GetAndReset(); if (statistics != null) { dataSetCircularBuffer.Put(statistics); } }); return(aggregator); }
public async Task <RmiResponseDto> Invoke(RemoveServiceInfo serviceInfo, MethodInfo methodInfo, object[] methodArguments) { var invocationId = Guid.NewGuid(); var request = new RmiRequestDto { InvocationId = invocationId, MethodArguments = methodArguments, MethodGenericArguments = methodInfo.GetGenericArguments(), MethodName = methodInfo.Name, ServiceId = serviceInfo.ServiceId }; if (logger.IsDebugEnabled) { logger.Debug($"Sending RMI {invocationId.ToString("n").Substring(0, 6)} Request on method {methodInfo.Name} for service {serviceInfo.ServiceType.Name}. Local: {localIdentity.Id.ToString("n").Substring(0, 6)}, Remote: {serviceInfo.Peer.Identity.Id.ToString("n").Substring(0, 6)}"); } if (localIdentity.Id == serviceInfo.Peer.Identity.Id) { if (logger.IsErrorEnabled) { logger.Error($"Swallowing as routed to self - RMI {invocationId.ToString("n").Substring(0, 6)} Request on method {methodInfo.Name} for service {serviceInfo.ServiceType.Name}. Local: {localIdentity.Id.ToString("n").Substring(0, 6)}, Remote: {serviceInfo.Peer.Identity.Id.ToString("n").Substring(0, 6)}"); } throw new ArgumentException("Attempted to perform remote service invocation on self."); } var responseBox = new AsyncBox <RmiResponseDto>(); responseBoxes.AddOrThrow(invocationId, responseBox); await messenger.SendReliableAsync(request, serviceInfo.Peer.Identity.Id).ConfigureAwait(false); if (logger.IsDebugEnabled) { logger.Debug($"Sent RMI {invocationId.ToString("n").Substring(0, 6)} Request on method {methodInfo.Name} for service {serviceInfo.ServiceType.Name}"); } // response box removed by HandleInvocationResponse - don't cleanup var result = await responseBox.GetResultAsync().ConfigureAwait(false); if (logger.IsDebugEnabled) { logger.Debug($"Received RMI {invocationId.ToString("n").Substring(0, 6)} Response on method {methodInfo.Name} for service {serviceInfo.ServiceType.Name}"); } return(result); }
private async Task SendHelperAsync(Guid destination, MessageDto message) { Debug( $"Sending to {destination.ToString("n").Substring(0, 6)} message {message}. " + Environment.NewLine + $"clientIdentity matches destination: {remoteIdentity.Matches(destination, IdentityMatchingScope.Broadcast)}"); if (!isHandshakeComplete || !remoteIdentity.Matches(destination, IdentityMatchingScope.Broadcast)) { return; } var completionLatch = new AsyncLatch(); sendCompletionLatchByMessage.AddOrThrow(message, completionLatch); outboundMessageQueue.Enqueue(message); outboundMessageSignal.Release(); Debug($"Awaiting completion for send to {destination.ToString("n").Substring(0, 6)} message {message}."); await completionLatch.WaitAsync().ConfigureAwait(false); sendCompletionLatchByMessage.RemoveOrThrow(message, completionLatch); Debug($"Completed send to {destination.ToString("n").Substring(0, 6)} message {message}."); }
public void AssociateRemoteIdentityOrThrow(Guid remoteId, TcpRoutingContext routingContext) { clientRoutingContextsByClientId.AddOrThrow(remoteId, routingContext); }
public void AddOrThrow(T item) { storage.AddOrThrow <T, byte>(item, 0); }
public void Add(MobContext context) { mobIdByFullName.AddOrThrow(context.IdentifierDto.FullName, context.IdentifierDto.Id); mobContextById.AddOrThrow(context.IdentifierDto.Id, context); }
public async Task DiscoverAsync() { var rateLimit = ChannelFactory.Timer(1000); // 5000, 5000); var connectedNeighborContextsByAdapterId = new ConcurrentDictionary <Guid, NeighborConnectionContext>(); while (true) { Debug("Starting discovery round!"); var discoveryStartTime = DateTime.Now; var neighbors = await bluetoothAdapter.DiscoverAsync().ConfigureAwait(false); var discoveryDurationSeconds = Math.Max(10, 3 * (DateTime.Now - discoveryStartTime).TotalSeconds); try { var neighborsToConnectTo = new List <IBluetoothNeighbor>(); foreach (var neighbor in neighbors) { if (neighbor.IsConnected) { Debug("Connection Candidate: {0} already connected.", neighbor.AdapterId); continue; } if (connectedNeighborContextsByAdapterId.ContainsKey(neighbor.AdapterId)) { Debug("Connection Candidate: {0} already has connected context.", neighbor.AdapterId); continue; } Debug("Connection Candidate: {0} looks like a go.", neighbor.AdapterId); neighborsToConnectTo.Add(neighbor); } await Task.WhenAll( neighborsToConnectTo.Select(neighbor => ChannelsExtensions.Go(async() => { Debug("Attempt to connect to: {0}", neighbor.AdapterId); var connected = await neighbor.TryHandshakeAsync(discoveryDurationSeconds).ConfigureAwait(false); if (!connected) { Debug("Failed to connect to: {0}", neighbor.AdapterId); return; } Debug("Successfully connected to: {0}", neighbor.AdapterId); // Console.WriteLine("Discovered neighbor: " + neighbor.AdapterId); var remoteMerkleTree = merkleTreeFactory.CreateForNeighbor(neighbor.AdapterId.ToString("N")); var connectionContext = new NeighborConnectionContext(identity, bluetoothAdapter, neighbor, broadcastMessageSerializer, localMerkleTree, remoteMerkleTree); connectedNeighborContextsByAdapterId.AddOrThrow(neighbor.AdapterId, connectionContext); connectionContext.BroadcastReceived += HandleBroadcastReceived; connectionContext.Start(() => { Debug("Connection Context Torn Down: {0}", neighbor.AdapterId); connectionContext.BroadcastReceived -= HandleBroadcastReceived; connectedNeighborContextsByAdapterId.RemoveOrThrow(neighbor.AdapterId); neighbor.Disconnect(); }); })) ) .ConfigureAwait(false); } catch (Exception e) { Debug("Discovery threw!"); Debug(e.ToString()); } Debug("Ending discovery round!"); await ChannelsExtensions.ReadAsync(rateLimit).ConfigureAwait(false); } }
public void AddOrThrow(Guid id, BinaryLog binaryLog) { binaryLogsById.AddOrThrow(id, binaryLog); }