IAsyncResult SendMessage(AzureServiceBusConnection connection, Func <BrokeredMessage> createMessage,
                                 int sendNumber, AsyncCallback cb, object state)
        {
            BrokeredMessage msg = createMessage();

            msg.Properties[NumberOfRetries] = sendNumber - 1;

            Address.LogBeginSend(msg.MessageId);

            Interlocked.Increment(ref _messagesInFlight);

            return(connection.MessageSender.BeginSend(msg,
                                                      cb, new StateHolder(connection.MessageSender, msg)));
        }
        ConnectionHandler <AzureServiceBusConnection> GetConnection([NotNull] IAzureServiceBusEndpointAddress address)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }
            _logger.DebugFormat("get connection( address:'{0}' )", address);

            return(_connCache.Retrieve(address.Uri, () =>
            {
                var connection = new AzureServiceBusConnection(address);
                var connectionHandler = new ConnectionHandlerImpl <AzureServiceBusConnection>(connection);

                return connectionHandler;
            }));
        }
        ConnectionHandler<AzureServiceBusConnection> GetConnection([NotNull] IAzureServiceBusEndpointAddress address)
        {
            if (address == null)
                throw new ArgumentNullException("address");
            _logger.DebugFormat("get connection( address:'{0}' )", address);

            return _connCache.Retrieve(address.Uri, () =>
                {
                    var connection = new AzureServiceBusConnection(address);
                    var connectionHandler = new ConnectionHandlerImpl<AzureServiceBusConnection>(connection);

                    return connectionHandler;
                });
        }
        IAsyncResult SendMessage(AzureServiceBusConnection connection, Func<BrokeredMessage> createMessage,
            int sendNumber, AsyncCallback cb, object state)
        {
            BrokeredMessage msg = createMessage();

            msg.Properties[NumberOfRetries] = sendNumber - 1;

            Address.LogBeginSend(msg.MessageId);

            Interlocked.Increment(ref _messagesInFlight);

            return connection.MessageSender.BeginSend(msg,
                cb, new StateHolder(connection.MessageSender, msg));
        }