@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getShardId() == null) ? 0 : getShardId().hashCode()); hashCode = prime * hashCode + ((getSequenceNumber() == null) ? 0 : getSequenceNumber().hashCode()); hashCode = prime * hashCode + ((getEncryptionType() == null) ? 0 : getEncryptionType().hashCode()); return hashCode; }
/** * 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 (getShardId() != null) sb.append("ShardId: ").append(getShardId()).append(","); if (getSequenceNumber() != null) sb.append("SequenceNumber: ").append(getSequenceNumber()).append(","); if (getEncryptionType() != null) sb.append("EncryptionType: ").append(getEncryptionType()); sb.append("}"); return sb.toString(); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof PutRecordResult == false) return false; PutRecordResult other = (PutRecordResult) obj; if (other.getShardId() == null ^ this.getShardId() == null) return false; if (other.getShardId() != null && other.getShardId().equals(this.getShardId()) == false) return false; if (other.getSequenceNumber() == null ^ this.getSequenceNumber() == null) return false; if (other.getSequenceNumber() != null && other.getSequenceNumber().equals(this.getSequenceNumber()) == false) return false; if (other.getEncryptionType() == null ^ this.getEncryptionType() == null) return false; if (other.getEncryptionType() != null && other.getEncryptionType().equals(this.getEncryptionType()) == false) return false; return true; }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getShardId() == null) ? 0 : getShardId().hashCode()); hashCode = prime * hashCode + ((getSequenceNumber() == null) ? 0 : getSequenceNumber().hashCode()); hashCode = prime * hashCode + ((getEncryptionType() == null) ? 0 : getEncryptionType().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 (getShardId() != null) sb.append("ShardId: " + getShardId() + ","); if (getSequenceNumber() != null) sb.append("SequenceNumber: " + getSequenceNumber() + ","); if (getEncryptionType() != null) sb.append("EncryptionType: " + getEncryptionType()); sb.append("}"); return sb.toString(); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof PutRecordResult == false) return false; PutRecordResult other = (PutRecordResult) obj; if (other.getShardId() == null ^ this.getShardId() == null) return false; if (other.getShardId() != null && other.getShardId().equals(this.getShardId()) == false) return false; if (other.getSequenceNumber() == null ^ this.getSequenceNumber() == null) return false; if (other.getSequenceNumber() != null && other.getSequenceNumber().equals(this.getSequenceNumber()) == false) return false; if (other.getEncryptionType() == null ^ this.getEncryptionType() == null) return false; if (other.getEncryptionType() != null && other.getEncryptionType().equals(this.getEncryptionType()) == false) return false; return true; } }
@Override protected void runOnce() throws Exception { ClickEvent event = inputQueue.take(); String partitionKey = event.getSessionId(); ByteBuffer data = ByteBuffer.wrap( event.getPayload().getBytes("UTF-8")); recordsPut.getAndIncrement(); PutRecordResult res = kinesis.putRecord( STREAM_NAME, data, partitionKey); MetricDatum d = new MetricDatum() .withDimensions( new Dimension().withName("StreamName").withValue(STREAM_NAME), new Dimension().withName("ShardId").withValue(res.getShardId()), new Dimension().withName("Host").withValue( InetAddress.getLocalHost().toString())) .withValue(1.0) .withMetricName("RecordsPut"); cw.putMetricData(new PutMetricDataRequest() .withMetricData(d) .withNamespace("MySampleProducer")); } }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getShardId() == null) ? 0 : getShardId().hashCode()); hashCode = prime * hashCode + ((getSequenceNumber() == null) ? 0 : getSequenceNumber().hashCode()); hashCode = prime * hashCode + ((getEncryptionType() == null) ? 0 : getEncryptionType().hashCode()); return hashCode; }
/** * 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 (getShardId() != null) sb.append("ShardId: ").append(getShardId()).append(","); if (getSequenceNumber() != null) sb.append("SequenceNumber: ").append(getSequenceNumber()).append(","); if (getEncryptionType() != null) sb.append("EncryptionType: ").append(getEncryptionType()); sb.append("}"); return sb.toString(); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof PutRecordResult == false) return false; PutRecordResult other = (PutRecordResult) obj; if (other.getShardId() == null ^ this.getShardId() == null) return false; if (other.getShardId() != null && other.getShardId().equals(this.getShardId()) == false) return false; if (other.getSequenceNumber() == null ^ this.getSequenceNumber() == null) return false; if (other.getSequenceNumber() != null && other.getSequenceNumber().equals(this.getSequenceNumber()) == false) return false; if (other.getEncryptionType() == null ^ this.getEncryptionType() == null) return false; if (other.getEncryptionType() != null && other.getEncryptionType().equals(this.getEncryptionType()) == false) return false; return true; }
@Override protected void additionalOnSuccessHeaders(AbstractIntegrationMessageBuilder<?> messageBuilder, AmazonWebServiceRequest request, Object result) { if (result instanceof PutRecordResult) { messageBuilder .setHeader(AwsHeaders.SHARD, ((PutRecordResult) result).getShardId()) .setHeader(AwsHeaders.SEQUENCE_NUMBER, ((PutRecordResult) result).getSequenceNumber()); } }
@Override protected void additionalOnSuccessHeaders(AbstractIntegrationMessageBuilder<?> messageBuilder, AmazonWebServiceRequest request, Object result) { if (result instanceof PutRecordResult) { messageBuilder .setHeader(AwsHeaders.SHARD, ((PutRecordResult) result).getShardId()) .setHeader(AwsHeaders.SEQUENCE_NUMBER, ((PutRecordResult) result).getSequenceNumber()); } }
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"); } }
@Override public Event save(Event event, String tenantId) { if (event == null || tenantId == null) { log.error(event.toString()); throw new IllegalArgumentException("Event or Tenant cannot be null"); } PutRecordRequest putRecordRequest = new PutRecordRequest(); putRecordRequest.setStreamName(stream); putRecordRequest.setPartitionKey(tenantId); putRecordRequest.setData(ByteBuffer.wrap(event.toJSON().getBytes())); PutRecordResult result = kinesisClient.putRecord(putRecordRequest); log.debug(String.format("Successfully putrecord, partition key : %s, ShardID: %s, Sequence Number: %s", putRecordRequest.getPartitionKey(),result.getShardId(),result.getSequenceNumber())); return event; }