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