public IMailbox ProvideMailboxFor(int?hashCode, IDispatcher?dispatcher) { RingBufferDispatcher?maybeDispatcher; if (!hashCode.HasValue) { throw new ArgumentNullException(nameof(hashCode), "Cannot provide mailbox because the hashCode is null."); } if (dispatcher != null) { maybeDispatcher = (RingBufferDispatcher)dispatcher; } else { _dispatchers.TryGetValue(hashCode.Value, out maybeDispatcher); } if (maybeDispatcher == null) { var newDispatcher = new RingBufferDispatcher( _configuration.RingSize, _configuration.FixedBackoff, _configuration.NotifyOnSend, _configuration.DispatcherThrottlingCount); var otherDispatcher = _dispatchers.GetOrAdd(hashCode.Value, newDispatcher); otherDispatcher.Start(); return(otherDispatcher.Mailbox); } return(maybeDispatcher.Mailbox); }
public IMailbox ProvideMailboxFor(int hashCode, IDispatcher dispatcher) { RingBufferDispatcher maybeDispatcher; if (dispatcher != null) { maybeDispatcher = (RingBufferDispatcher)dispatcher; } else { dispatchers.TryGetValue(hashCode, out maybeDispatcher); } if (maybeDispatcher == null) { var newDispatcher = new RingBufferDispatcher( configuration.RingSize, configuration.FixedBackoff, configuration.DispatcherThrottlingCount); var otherDispatcher = dispatchers.GetOrAdd(hashCode, newDispatcher); otherDispatcher.Start(); return(otherDispatcher.Mailbox); } return(maybeDispatcher.Mailbox); }