-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced interface on KinesisProducer for testability/mockability
Introduced UserRecord object and KinesisProducer.addUserRecord(UserRecord) method.
- Loading branch information
1 parent
46340d9
commit 79d4b43
Showing
4 changed files
with
200 additions
and
3 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
...esis-producer/src/main/java/com/amazonaws/services/kinesis/producer/IKinesisProducer.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,33 @@ | ||
package com.amazonaws.services.kinesis.producer; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.List; | ||
import java.util.concurrent.ExecutionException; | ||
import com.google.common.util.concurrent.ListenableFuture; | ||
|
||
|
||
public interface IKinesisProducer { | ||
ListenableFuture<UserRecordResult> addUserRecord(String stream, String partitionKey, ByteBuffer data); | ||
|
||
ListenableFuture<UserRecordResult> addUserRecord(UserRecord userRecord); | ||
|
||
ListenableFuture<UserRecordResult> addUserRecord(String stream, String partitionKey, String explicitHashKey, ByteBuffer data); | ||
|
||
int getOutstandingRecordsCount(); | ||
|
||
List<Metric> getMetrics(String metricName, int windowSeconds) throws InterruptedException, ExecutionException; | ||
|
||
List<Metric> getMetrics(String metricName) throws InterruptedException, ExecutionException; | ||
|
||
List<Metric> getMetrics() throws InterruptedException, ExecutionException; | ||
|
||
List<Metric> getMetrics(int windowSeconds) throws InterruptedException, ExecutionException; | ||
|
||
void destroy(); | ||
|
||
void flush(String stream); | ||
|
||
void flush(); | ||
|
||
void flushSync(); | ||
} |
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
96 changes: 96 additions & 0 deletions
96
...on-kinesis-producer/src/main/java/com/amazonaws/services/kinesis/producer/UserRecord.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,96 @@ | ||
package com.amazonaws.services.kinesis.producer; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
public class UserRecord { | ||
/** | ||
* Stream to put to. | ||
*/ | ||
private String streamName; | ||
|
||
/** | ||
* Partition key. Length must be at least one, and at most 256 (inclusive). | ||
*/ | ||
private String partitionKey; | ||
|
||
/** | ||
* The hash value used to explicitly determine the shard the data | ||
* record is assigned to by overriding the partition key hash. | ||
* Must be a valid string representation of a positive integer | ||
* with value between 0 and <tt>2^128 - 1</tt> (inclusive). | ||
*/ | ||
private String explicitHashKey; | ||
|
||
/** | ||
* Binary data of the record. Maximum size 1MiB. | ||
*/ | ||
private ByteBuffer data; | ||
|
||
public UserRecord() { | ||
} | ||
|
||
public UserRecord(String streamName, String partitionKey, ByteBuffer data) { | ||
this.streamName = streamName; | ||
this.partitionKey = partitionKey; | ||
this.data = data; | ||
} | ||
|
||
public UserRecord(String streamName, String partitionKey, String explicitHashKey, ByteBuffer data) { | ||
this.streamName = streamName; | ||
this.partitionKey = partitionKey; | ||
this.explicitHashKey = explicitHashKey; | ||
this.data = data; | ||
} | ||
|
||
public String getStreamName() { | ||
return streamName; | ||
} | ||
|
||
public void setStreamName(String streamName) { | ||
this.streamName = streamName; | ||
} | ||
|
||
public UserRecord withStreamName(String streamName) { | ||
this.streamName = streamName; | ||
return this; | ||
} | ||
|
||
public String getPartitionKey() { | ||
return partitionKey; | ||
} | ||
|
||
public void setPartitionKey(String partitionKey) { | ||
this.partitionKey = partitionKey; | ||
} | ||
|
||
public UserRecord withPartitionKey(String partitionKey) { | ||
this.partitionKey = partitionKey; | ||
return this; | ||
} | ||
|
||
public ByteBuffer getData() { | ||
return data; | ||
} | ||
|
||
public void setData(ByteBuffer data) { | ||
this.data = data; | ||
} | ||
|
||
public UserRecord withData(ByteBuffer byteBuffer) { | ||
this.data = byteBuffer; | ||
return this; | ||
} | ||
|
||
public String getExplicitHashKey() { | ||
return explicitHashKey; | ||
} | ||
|
||
public void setExplicitHashKey(String explicitHashKey) { | ||
this.explicitHashKey = explicitHashKey; | ||
} | ||
|
||
public UserRecord withExplicitHashKey(String explicitHashKey) { | ||
this.explicitHashKey = explicitHashKey; | ||
return this; | ||
} | ||
} |
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