@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; }
setEncryptionType(encryptionType); return this;
/** * <p> * The sequence number identifier that was assigned to the put data record. The sequence number for the record is * unique across all records in the stream. A sequence number is the identifier associated with every record put * into the stream. * </p> * * @param sequenceNumber * The sequence number identifier that was assigned to the put data record. The sequence number for the * record is unique across all records in the stream. A sequence number is the identifier associated with * every record put into the stream. * @return Returns a reference to this object so that method calls can be chained together. */ public PutRecordResult withSequenceNumber(String sequenceNumber) { setSequenceNumber(sequenceNumber); return this; }
@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()); } }
public PutRecordResult unmarshall(JsonUnmarshallerContext context) throws Exception { PutRecordResult putRecordResult = new PutRecordResult(); if (context.testExpression("ShardId", targetDepth)) { context.nextToken(); putRecordResult.setShardId(context.getUnmarshaller(String.class).unmarshall(context)); putRecordResult.setSequenceNumber(context.getUnmarshaller(String.class).unmarshall(context)); putRecordResult.setEncryptionType(context.getUnmarshaller(String.class).unmarshall(context));
@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 void write(StreamsDatum entry) { String document = (String) TypeConverterUtil.getInstance().convert(entry.getDocument(), String.class); PutRecordRequest putRecordRequest = new PutRecordRequest() .withStreamName(config.getStream()) .withPartitionKey(entry.getId()) .withData(ByteBuffer.wrap(document.getBytes())); PutRecordResult putRecordResult = client.putRecord(putRecordRequest); entry.setSequenceid(new BigInteger(putRecordResult.getSequenceNumber())); LOGGER.debug("Wrote {}", entry); }
PutRecordRequest request = invocation.getArgument(0); AsyncHandler<PutRecordRequest, PutRecordResult> handler = invocation.getArgument(1); PutRecordResult result = new PutRecordResult() .withSequenceNumber(request.getSequenceNumberForOrdering()) .withShardId("shardId-1"); handler.onSuccess(new PutRecordRequest(), result); return mock(Future.class);
/** * <p> * The shard ID of the shard where the data record was placed. * </p> * * @param shardId * The shard ID of the shard where the data record was placed. * @return Returns a reference to this object so that method calls can be chained together. */ public PutRecordResult withShardId(String shardId) { setShardId(shardId); return this; }
@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()); } }
public PutRecordResult unmarshall(JsonUnmarshallerContext context) throws Exception { PutRecordResult putRecordResult = new PutRecordResult(); AwsJsonReader reader = context.getReader(); reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("ShardId")) { putRecordResult.setShardId(StringJsonUnmarshaller.getInstance() .unmarshall(context)); } else if (name.equals("SequenceNumber")) { putRecordResult.setSequenceNumber(StringJsonUnmarshaller.getInstance() .unmarshall(context)); } else if (name.equals("EncryptionType")) { putRecordResult.setEncryptionType(StringJsonUnmarshaller.getInstance() .unmarshall(context)); } else { reader.skipValue(); } } reader.endObject(); return putRecordResult; }
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"); } }
/** * <p> * The shard ID of the shard where the data record was placed. * </p> * * @param shardId * The shard ID of the shard where the data record was placed. * @return Returns a reference to this object so that method calls can be chained together. */ public PutRecordResult withShardId(String shardId) { setShardId(shardId); return this; }
@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 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; }
public PutRecordResult unmarshall(JsonUnmarshallerContext context) throws Exception { PutRecordResult putRecordResult = new PutRecordResult(); if (context.testExpression("ShardId", targetDepth)) { context.nextToken(); putRecordResult.setShardId(context.getUnmarshaller(String.class).unmarshall(context)); putRecordResult.setSequenceNumber(context.getUnmarshaller(String.class).unmarshall(context)); putRecordResult.setEncryptionType(context.getUnmarshaller(String.class).unmarshall(context));
/** * <p> * The sequence number identifier that was assigned to the put data record. The sequence number for the record is * unique across all records in the stream. A sequence number is the identifier associated with every record put * into the stream. * </p> * * @param sequenceNumber * The sequence number identifier that was assigned to the put data record. The sequence number for the * record is unique across all records in the stream. A sequence number is the identifier associated with * every record put into the stream. * @return Returns a reference to this object so that method calls can be chained together. */ public PutRecordResult withSequenceNumber(String sequenceNumber) { setSequenceNumber(sequenceNumber); return this; }
setEncryptionType(encryptionType); return this;
/** * 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 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; }