@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getStartingHashKey() == null) ? 0 : getStartingHashKey().hashCode()); hashCode = prime * hashCode + ((getEndingHashKey() == null) ? 0 : getEndingHashKey().hashCode()); return hashCode; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof HashKeyRange == false) return false; HashKeyRange other = (HashKeyRange) obj; if (other.getStartingHashKey() == null ^ this.getStartingHashKey() == null) return false; if (other.getStartingHashKey() != null && other.getStartingHashKey().equals(this.getStartingHashKey()) == false) return false; if (other.getEndingHashKey() == null ^ this.getEndingHashKey() == null) return false; if (other.getEndingHashKey() != null && other.getEndingHashKey().equals(this.getEndingHashKey()) == false) return false; return true; }
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getStartingHashKey() != null) sb.append("StartingHashKey: ").append(getStartingHashKey()).append(","); if (getEndingHashKey() != null) sb.append("EndingHashKey: ").append(getEndingHashKey()); sb.append("}"); return sb.toString(); }
/** * Marshall the given parameter object. */ public void marshall(HashKeyRange hashKeyRange, ProtocolMarshaller protocolMarshaller) { if (hashKeyRange == null) { throw new SdkClientException("Invalid argument passed to marshall(...)"); } try { protocolMarshaller.marshall(hashKeyRange.getStartingHashKey(), STARTINGHASHKEY_BINDING); protocolMarshaller.marshall(hashKeyRange.getEndingHashKey(), ENDINGHASHKEY_BINDING); } catch (Exception e) { throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e); } }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getStartingHashKey() == null) ? 0 : getStartingHashKey().hashCode()); hashCode = prime * hashCode + ((getEndingHashKey() == null) ? 0 : getEndingHashKey().hashCode()); return hashCode; }
/** * Returns a string representation of this object; useful for testing and * debugging. * * @return A string representation of this object. * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getStartingHashKey() != null) sb.append("StartingHashKey: " + getStartingHashKey() + ","); if (getEndingHashKey() != null) sb.append("EndingHashKey: " + getEndingHashKey()); sb.append("}"); return sb.toString(); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof HashKeyRange == false) return false; HashKeyRange other = (HashKeyRange) obj; if (other.getStartingHashKey() == null ^ this.getStartingHashKey() == null) return false; if (other.getStartingHashKey() != null && other.getStartingHashKey().equals(this.getStartingHashKey()) == false) return false; if (other.getEndingHashKey() == null ^ this.getEndingHashKey() == null) return false; if (other.getEndingHashKey() != null && other.getEndingHashKey().equals(this.getEndingHashKey()) == false) return false; return true; } }
public void marshall(HashKeyRange hashKeyRange, AwsJsonWriter jsonWriter) throws Exception { jsonWriter.beginObject(); if (hashKeyRange.getStartingHashKey() != null) { String startingHashKey = hashKeyRange.getStartingHashKey(); jsonWriter.name("StartingHashKey"); jsonWriter.value(startingHashKey); } if (hashKeyRange.getEndingHashKey() != null) { String endingHashKey = hashKeyRange.getEndingHashKey(); jsonWriter.name("EndingHashKey"); jsonWriter.value(endingHashKey); } jsonWriter.endObject(); }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getStartingHashKey() == null) ? 0 : getStartingHashKey().hashCode()); hashCode = prime * hashCode + ((getEndingHashKey() == null) ? 0 : getEndingHashKey().hashCode()); return hashCode; }
public int compare(Shard o1, Shard o2) { return new BigInteger(o1.getHashKeyRange().getStartingHashKey()) .compareTo(new BigInteger(o2.getHashKeyRange() .getStartingHashKey())); } });
private static final int compareShardsByStartHash(Shard o1, Shard o2) { return new BigInteger(o1.getHashKeyRange().getStartingHashKey()) .compareTo(new BigInteger(o2.getHashKeyRange().getStartingHashKey())); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof HashKeyRange == false) return false; HashKeyRange other = (HashKeyRange) obj; if (other.getStartingHashKey() == null ^ this.getStartingHashKey() == null) return false; if (other.getStartingHashKey() != null && other.getStartingHashKey().equals(this.getStartingHashKey()) == false) return false; if (other.getEndingHashKey() == null ^ this.getEndingHashKey() == null) return false; if (other.getEndingHashKey() != null && other.getEndingHashKey().equals(this.getEndingHashKey()) == false) return false; return true; }
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getStartingHashKey() != null) sb.append("StartingHashKey: ").append(getStartingHashKey()).append(","); if (getEndingHashKey() != null) sb.append("EndingHashKey: ").append(getEndingHashKey()); sb.append("}"); return sb.toString(); }
public AdjacentShards(String streamName, ShardHashInfo lower, ShardHashInfo higher) throws Exception { // ensure that the shards are adjacent if (!new BigInteger(higher.getShard().getHashKeyRange().getStartingHashKey()) .subtract(new BigInteger(lower.getShard().getHashKeyRange().getEndingHashKey())) .equals(new BigInteger("1"))) { throw new Exception("Shards are not Adjacent"); } this.streamName = streamName; this.lowerShard = lower; this.higherShard = higher; }
/** * Marshall the given parameter object. */ public void marshall(HashKeyRange hashKeyRange, ProtocolMarshaller protocolMarshaller) { if (hashKeyRange == null) { throw new SdkClientException("Invalid argument passed to marshall(...)"); } try { protocolMarshaller.marshall(hashKeyRange.getStartingHashKey(), STARTINGHASHKEY_BINDING); protocolMarshaller.marshall(hashKeyRange.getEndingHashKey(), ENDINGHASHKEY_BINDING); } catch (Exception e) { throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e); } }
public ShardHashInfo(String streamName, Shard shard) { // prevent constructing a null object if (streamName == null || shard == null) { throw new ExceptionInInitializerError("Stream Name & Shard Required"); } this.shard = shard; this.streamName = streamName; this.endHash = new BigInteger(shard.getHashKeyRange().getEndingHashKey()); this.startHash = new BigInteger(shard.getHashKeyRange().getStartingHashKey()); this.hashWidth = getWidth(this.startHash, this.endHash); this.pctOfKeyspace = getPctOfKeyspace(this.hashWidth); }
/** * Determines whether to deaggregate the given records, and if they are KPL records dispatches them to deaggregation * * @param records * the records to deaggregate is deaggregation is required. * @return returns either the deaggregated records, or the original records */ @SuppressWarnings("unchecked") private List<Record> deaggregateRecords(List<Record> records) { // We deaggregate if and only if we got actual Kinesis records, i.e. // not instances of some subclass thereof. if (!records.isEmpty() && records.get(0).getClass().equals(Record.class)) { if (this.shard != null) { return (List<Record>) (List<?>) UserRecord.deaggregate(records, new BigInteger(this.shard.getHashKeyRange().getStartingHashKey()), new BigInteger(this.shard.getHashKeyRange().getEndingHashKey())); } else { return (List<Record>) (List<?>) UserRecord.deaggregate(records); } } return records; }
Set<String> childShardIds) throws KinesisClientLibIOException { BigInteger startingHashKeyOfClosedShard = new BigInteger(closedShard.getHashKeyRange().getStartingHashKey()); BigInteger endingHashKeyOfClosedShard = new BigInteger(closedShard.getHashKeyRange().getEndingHashKey()); BigInteger minStartingHashKeyOfChildren = null; BigInteger startingHashKey = new BigInteger(childShard.getHashKeyRange().getStartingHashKey()); if ((minStartingHashKeyOfChildren == null) || (startingHashKey.compareTo(minStartingHashKeyOfChildren) < 0)) {
private void sentWatermarkToShards() { try { //refresh the list of available shards, if current state is too old if (System.currentTimeMillis() - lastShardRefreshTime >= SHARD_REFRESH_MILLIES) { refreshShards(); lastShardRefreshTime = System.currentTimeMillis(); } //send a watermark to every shard of the Kinesis stream shards.parallelStream() .map(shard -> new PutRecordRequest() .withStreamName(streamName) .withData(new WatermarkEvent(currentWatermark).toByteBuffer()) .withPartitionKey("23") .withExplicitHashKey(shard.getHashKeyRange().getStartingHashKey())) .map(kinesisClient::putRecord) .forEach(putRecordResult -> LOG.trace("send watermark {} to shard {}", new DateTime(currentWatermark), putRecordResult.getShardId())); LOG.debug("send watermark {}", new DateTime(currentWatermark)); } catch (LimitExceededException | ProvisionedThroughputExceededException e) { //if any request is throttled, just wait for the next iteration to submit another watermark LOG.warn("skipping watermark due to limit/throughput exceeded exception"); } }
if (info.getShard().getHashKeyRange().getStartingHashKey().equals(targetHash.toString())) { higherShard = new ShardHashInfo(this.streamName, info.getShard()); break;