Example #1
0
        /// <summary>
        /// Compares whether two PartitionSelectors are the same.
        /// </summary>
        /// <param name="obj">PartitionSelector to compare t.o</param>
        /// <returns>true if same false if not.</returns>
        public override bool Equals(object obj)
        {
            PartitionSelector partitionObj = obj as PartitionSelector;

            if (partitionObj == null)
            {
                return(false);
            }

            if (this.serviceName != partitionObj.serviceName)
            {
                return(false);
            }

            if (this.selectorType != partitionObj.selectorType)
            {
                return(false);
            }

            if (this.partitionKey != partitionObj.partitionKey)
            {
                return(false);
            }

            return(true);
        }
Example #2
0
        private ReplicaSelector(PartitionSelector partitionSelector, ReplicaSelectorType selectorType, long replicaOrInstanceId)
        {
            Requires.ThrowIfNull(partitionSelector, "partitionSelector");
            this.partitionSelector    = partitionSelector;
            this.selectorType         = selectorType;
            this.replicaOrInstanceId  = replicaOrInstanceId;
            this.PowershellParameters = new Dictionary <string, string>();
            switch (this.selectorType)
            {
            case ReplicaSelectorType.Primary:
                this.PowershellParameters.Add(ReplicaKind, ReplicaKindPrimary);
                break;

            case ReplicaSelectorType.RandomSecondary:
                this.PowershellParameters.Add(ReplicaKind, ReplicaKindRandomSecondary);
                break;

            case ReplicaSelectorType.ReplicaId:
                this.PowershellParameters.Add(ReplicaOrInstanceIdParameter, this.replicaOrInstanceId.ToString());
                break;

            case ReplicaSelectorType.Random:
                break;

            default:
                throw new FabricInvalidReplicaSelectorException(string.Format(CultureInfo.CurrentCulture, StringResources.Error_InvalidReplicaSelector, this.selectorType), FabricErrorCode.InvalidReplicaSelector);
            }
        }
Example #3
0
 /// <summary>
 /// Selects a random replica for the given partition specified by the PartitionSelector.
 /// </summary>
 /// <param name="partitionSelector">PartitionSelector which indicates the partition whose replica needs to be selected.</param>
 /// <returns>Constructed ReplicaSelector.</returns>
 public static ReplicaSelector RandomOf(PartitionSelector partitionSelector)
 {
     return(new ReplicaSelector(partitionSelector, ReplicaSelectorType.Random, -1));
 }
Example #4
0
 /// <summary>
 /// Selects a replica based on the ReplicaId for the given partition specified by the PartitionSelector.
 /// </summary>
 /// <param name="partitionSelector">PartitionSelector which indicates the partition whose replica needs to be selected.</param>
 /// <param name="replicaOrInstanceId">ReplicaOrInstanceId for the replica or instance to be selected.</param>
 /// <returns>A <see cref="System.Fabric.ReplicaSelector"/> based on the input passed in. </returns>
 public static ReplicaSelector ReplicaIdOf(PartitionSelector partitionSelector, long replicaOrInstanceId)
 {
     return(new ReplicaSelector(partitionSelector, ReplicaSelectorType.ReplicaId, replicaOrInstanceId));
 }
Example #5
0
 /// <summary>
 /// Selects the primary replica for the given partition specified by the PartitionSelector.
 /// </summary>
 /// <param name="partitionSelector">PartitionSelector which indicates the partition whose replica needs to be selected.</param>
 /// <returns>Constructed ReplicaSelector.</returns>
 public static ReplicaSelector PrimaryOf(PartitionSelector partitionSelector)
 {
     return(new ReplicaSelector(partitionSelector, ReplicaSelectorType.Primary, -1));
 }