Source/NFX/Glue/Bindings.cs
/// <summary>
/// Tries to acquire an available client transport to make a call.
/// This method respects binding/transport settings that impose a limit on the number of
///  open concurrent transports and timeouts for acqusition waiting
/// </summary>
/// <param name="remoteNode">remote node to connect to</param>
/// <returns>Available acquired transport or null</returns>
Tries to acquire an available client transport to make a call.
This method respects binding/transport settings that impose a limit on the number of
open concurrent transports and timeouts for acqusition waiting
Tries to acquire an available client transport to make a call . This method respects binding / transport settings that impose a limit on the number of open concurrent transports and timeouts for acqusition waiting
protected virtual ClientTransport TryGetExistingAcquiredTransportPerRemoteNode(Node remoteNode)
            {
                int GRANULARITY_MS = 5 + ((System.Threading.Thread.CurrentThread.GetHashCode() & CoreConsts.ABS_HASH_MASK) % 15);
                var elapsed = 0;
                do
                {
                    var lst = m_Transports;
                    var count = 0;
                    for(var i=0; i<lst.Count; i++)
                    {
                        var tr = lst[i] as ClientTransport;
                        if (tr==null) continue;
                        if (!AreNodesIdentical(tr.Node, remoteNode)) continue;
                        count++;
                        if (tr.TryAcquire())
                           return tr;
                    }
                    if (m_ClientTransportMaxCount<=0 || count<m_ClientTransportMaxCount)
                    {
                      if (count<= m_ClientTransportCountWaitThreshold) return null;
                      if (elapsed>=m_ClientTransportExistingAcquisitionTimeoutMs) return null;
                    }
                    System.Threading.Thread.Sleep(GRANULARITY_MS);
                    elapsed+=GRANULARITY_MS;
                    if (m_ClientTransportMaxExistingAcquisitionTimeoutMs>0 && elapsed>m_ClientTransportMaxExistingAcquisitionTimeoutMs)
                     throw new ClientCallException(CallStatus.Timeout,
                                                   StringConsts.GLUE_CLIENT_CALL_TRANSPORT_ACQUISITION_TIMEOUT_ERROR
                                                   .Args(this.Name, elapsed)
                                                   );
                }while(App.Active && Running);
                return null;
            }
protected virtual ClientTransport TryGetExistingAcquiredTransportPerRemoteNode ( Node remoteNode ) { int GRANULARITY_MS = 5 + ( ( System . Threading . Thread . CurrentThread . GetHashCode ( ) & CoreConsts . ABS_HASH_MASK ) % 15 ) ; var elapsed = 0 ; do { var lst = m_Transports ; var count = 0 ; for ( var i = 0 ; i < lst . Count ; i ++ ) { var tr = lst [ i ] as ClientTransport ; if ( tr == null ) continue ; if ( ! AreNodesIdentical ( tr . Node , remoteNode ) ) continue ; count ++ ; if ( tr . TryAcquire ( ) ) return tr ; } if ( m_ClientTransportMaxCount <= 0 || count < m_ClientTransportMaxCount ) { if ( count <= m_ClientTransportCountWaitThreshold ) return null ; if ( elapsed >= m_ClientTransportExistingAcquisitionTimeoutMs ) return null ; } System . Threading . Thread . Sleep ( GRANULARITY_MS ) ; elapsed += GRANULARITY_MS ; if ( m_ClientTransportMaxExistingAcquisitionTimeoutMs > 0 && elapsed > m_ClientTransportMaxExistingAcquisitionTimeoutMs ) throw new ClientCallException ( CallStatus . Timeout , StringConsts . GLUE_CLIENT_CALL_TRANSPORT_ACQUISITION_TIMEOUT_ERROR . Args ( this . Name , elapsed ) ) ; } while ( App . Active && Running ) ; return null ; }
Tries to acquire an available client transport to make a call.
Tries to acquire an available client transport to make a call .
//atomic //count transports PER DESTINATION //the loop is faster than intermediary enumerables produced by LINQ //Per destination //dont wait - create new one
Available acquired transport or null
Available acquired transport or null
remoteNode
Node
remote node to connect to
remote node to connect to