-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: pranikum <109206473+pranikum@users.noreply.github.com>
- Loading branch information
Showing
1 changed file
with
77 additions
and
0 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
server/src/main/java/org/opensearch/cluster/routing/WRRWeights.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.cluster.routing; | ||
|
||
import org.opensearch.common.io.stream.StreamInput; | ||
import org.opensearch.common.io.stream.StreamOutput; | ||
import org.opensearch.common.io.stream.Writeable; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Entity for Weighted Round Robin weights | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class WRRWeights implements Writeable { | ||
private String attributeName; | ||
private Map<String, Object> weights; | ||
|
||
public WRRWeights(String attributeName, Map<String, Object> weights) { | ||
this.attributeName = attributeName; | ||
this.weights = weights; | ||
} | ||
|
||
public WRRWeights(WRRWeights wrrWeight) { | ||
this.attributeName = wrrWeight.attributeName(); | ||
this.weights = wrrWeight.weights; | ||
} | ||
|
||
public WRRWeights(StreamInput in) throws IOException { | ||
attributeName = in.readString(); | ||
weights = in.readMap(); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeString(attributeName); | ||
out.writeMap(weights); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
WRRWeights that = (WRRWeights) o; | ||
|
||
if (!attributeName.equals(that.attributeName)) return false; | ||
return weights.equals(that.weights); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(attributeName, weights); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "WRRWeightsDefinition{" + attributeName + "}{" + weights().toString() + "}"; | ||
} | ||
|
||
public Map<String, Object> weights() { | ||
return this.weights; | ||
} | ||
|
||
public String attributeName() { | ||
return this.attributeName; | ||
} | ||
} |