|
1 | 1 | package io.hstream; |
2 | 2 |
|
| 3 | +import static com.google.common.base.Preconditions.checkArgument; |
| 4 | +import static com.google.common.base.Preconditions.checkNotNull; |
| 5 | + |
3 | 6 | import java.util.Objects; |
4 | 7 |
|
5 | 8 | public class Stream { |
@@ -62,4 +65,59 @@ public boolean equals(Object o) { |
62 | 65 | public int hashCode() { |
63 | 66 | return Objects.hash(streamName, replicationFactor, backlogDuration, shardCount); |
64 | 67 | } |
| 68 | + |
| 69 | + public static final class Builder { |
| 70 | + private String streamName; |
| 71 | + private int replicationFactor = 1; |
| 72 | + private int backlogDuration = 3600 * 24; |
| 73 | + private int shardCount = 1; |
| 74 | + |
| 75 | + /** |
| 76 | + * @param streamName required, the name of the stream |
| 77 | + * @return Stream.Builder instance |
| 78 | + */ |
| 79 | + public Builder streamName(String streamName) { |
| 80 | + this.streamName = streamName; |
| 81 | + return this; |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * @param replicationFactor optional(default: 1), replication factor of the stream |
| 86 | + * @return Stream.Builder instance |
| 87 | + */ |
| 88 | + public Builder replicationFactor(int replicationFactor) { |
| 89 | + this.replicationFactor = replicationFactor; |
| 90 | + return this; |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * @param backlogDuration optional(default: 3600 * 24), backlog duration(in seconds) of the |
| 95 | + * stream |
| 96 | + * @return Stream.Builder instance |
| 97 | + */ |
| 98 | + public Builder backlogDuration(int backlogDuration) { |
| 99 | + this.backlogDuration = backlogDuration; |
| 100 | + return this; |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * @param shardCount optional(default: 1), number of shards in the stream |
| 105 | + * @return Stream.Builder instance |
| 106 | + */ |
| 107 | + public Builder shardCount(int shardCount) { |
| 108 | + this.shardCount = shardCount; |
| 109 | + return this; |
| 110 | + } |
| 111 | + |
| 112 | + public Stream build() { |
| 113 | + checkNotNull(streamName); |
| 114 | + checkArgument(replicationFactor >= 1 && replicationFactor <= 15); |
| 115 | + checkArgument(shardCount >= 1); |
| 116 | + return new Stream(streamName, replicationFactor, backlogDuration, shardCount); |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + public static Builder newBuilder() { |
| 121 | + return new Builder(); |
| 122 | + } |
65 | 123 | } |
0 commit comments