/// <summary>
 /// Returns the weight of the instance based on XML config. Defaults to 1 if value is not provided.
 /// </summary>
 /// <param name="target">Endpoint instance.</param>
 static int GetWeight(UnicastRoutingTarget target)
 {
     string weight;
     return target.Instance != null && target.Instance.Properties.TryGetValue("weight", out weight)
         ? int.Parse(weight)
         : 1;
 }
Example #2
0
    /// <summary>
    /// There is 1/weight chance of returning 1 (which means move to next instance). Otherwise we continue sending to the current instance.
    /// </summary>
    /// <param name="currentInstance">Current instance.</param>
    /// <returns>1 if should move to next instance. 0 if should continue sending to the current one.</returns>
    #region Should-Rotate
    long ShouldMoveToNextInstance(UnicastRoutingTarget currentInstance)
    {
        var weight = GetWeight(currentInstance);
        var r      = random.Next(weight);

        return(r == 0 ? 1 : 0);
    }
Example #3
0
    /// <summary>
    /// Returns the weight of the instance based on XML config. Defaults to 1 if value is not provided.
    /// </summary>
    /// <param name="target">Endpoint instance.</param>
    static int GetWeight(UnicastRoutingTarget target)
    {
        string weight;

        return(target.Instance != null && target.Instance.Properties.TryGetValue("weight", out weight)
            ? int.Parse(weight)
            : 1);
    }
Example #4
0
 IEnumerable <UnicastRoutingTarget> IUnicastRoute.Resolve(Func <Endpoint, IEnumerable <EndpointInstance> > instanceResolver)
 {
     if (physicalAddress != null)
     {
         yield return(UnicastRoutingTarget.ToTransportAddress(physicalAddress));
     }
     else if (instance != null)
     {
         yield return(UnicastRoutingTarget.ToEndpointInstance(instance));
     }
     else
     {
         var instances = instanceResolver(endpoint);
         foreach (var i in instances)
         {
             yield return(UnicastRoutingTarget.ToEndpointInstance(i));
         }
     }
 }
 /// <summary>
 /// There is 1/weight chance of returning 1 (which means move to next instance). Otherwise we continue sending to the current instance.
 /// </summary>
 /// <param name="currentInstance">Current instance.</param>
 /// <returns>1 if should move to next instance. 0 if should continue sending to the current one.</returns>
 #region Should-Rotate
 long ShouldMoveToNextInstance(UnicastRoutingTarget currentInstance)
 {
     var weight = GetWeight(currentInstance);
     var r = random.Next(weight);
     return r == 0 ? 1 : 0;
 }