/** * Creates the URL path for making HTTP requests for the given topic. */ private String createTopicPath(TopicId topicId) { return topicId.getNamespace() + "/topics/" + topicId.getTopic(); }
@SuppressWarnings("unused") public static TopicId fromIdParts(Iterable<String> idString) { Iterator<String> iterator = idString.iterator(); return new TopicId(next(iterator, "namespace"), nextAndEnd(iterator, "topic")); }
public TopicId(String namespace, String topic) { super(namespace, EntityType.TOPIC); if (topic == null) { throw new NullPointerException("Topic ID cannot be null."); } ensureValidId("topic", topic); this.topic = topic; }
@Override protected void publish(TopicId topicId, Iterator<byte[]> payloads) throws IOException, TopicNotFoundException { if (NamespaceId.SYSTEM.equals(topicId.getNamespaceId())) { throw new IllegalArgumentException("Publish to '" + topicId.getNamespace() + "' namespace is not allowed"); } delegate.publish(topicId.getNamespace(), topicId.getTopic(), payloads); } }
@Override public String apply(TopicId topicId) { return topicId.getTopic(); } };
public TopicId topic(String topic) { return new TopicId(namespace, topic); }
private void checkTopic(TopicId topicId, int generation) { Preconditions.checkArgument(this.topicMetadata.getTopicId().equals(topicId), "Not allowed to use table with a " + "different topic id. Table's topic Id: {}. Specified topic id: {}", this.topicMetadata.getTopicId(), topicId); Preconditions.checkArgument(this.topicMetadata.getGeneration() == generation, "Not allowed to use table with " + "a different generation id. Table's generation: {}. Specified generation: {}", this.topicMetadata.getGeneration(), generation); }
@Override public String apply(TopicId topicId) { return topicId.getTopic(); } };
@Override protected void publish(TopicId topicId, Iterator<byte[]> payloads) throws IOException, TopicNotFoundException { if (NamespaceId.SYSTEM.equals(topicId.getNamespaceId())) { throw new IllegalArgumentException("Publish to '" + topicId.getNamespace() + "' namespace is not allowed"); } delegate.publish(topicId.getNamespace(), topicId.getTopic(), payloads); } }
public TopicId topic(String topic) { return new TopicId(namespace, topic); }
private void checkTopic(TopicId topicId, int generation) { Preconditions.checkArgument(this.topicMetadata.getTopicId().equals(topicId), "Not allowed to use table with a " + "different topic id. Table's topic Id: {}. Specified topic id: {}", this.topicMetadata.getTopicId(), topicId); Preconditions.checkArgument(this.topicMetadata.getGeneration() == generation, "Not allowed to use table with " + "a different generation id. Table's generation: {}. Specified generation: {}", this.topicMetadata.getGeneration(), generation); }
/** * Creates the URL path for making HTTP requests for the given topic. */ private String createTopicPath(TopicId topicId) { return topicId.getNamespace() + "/topics/" + topicId.getTopic(); }
@Override public String getEntityName() { return getTopic(); }
@SuppressWarnings("unused") public static TopicId fromIdParts(Iterable<String> idString) { Iterator<String> iterator = idString.iterator(); return new TopicId(next(iterator, "namespace"), nextAndEnd(iterator, "topic")); }
/** * Convert byte array encoded with the {@link #toMetadataRowKey(TopicId)} method back to the {@link TopicId} * * @param topicBytes byte array which contains the representation of the topic id * @param offset offset to start decoding * @param length number of bytes to decode * @return {@link TopicId} */ public static TopicId toTopicId(byte[] topicBytes, int offset, int length) { String topic = Bytes.toString(topicBytes, offset, length); int firstSeparator = topic.indexOf(":", offset); String ns = topic.substring(offset, firstSeparator); String topicId = topic.substring(firstSeparator + 1, topic.length() - 1); return new TopicId(ns, topicId); }
@Override protected RawPayloadTableEntry computeNext() { if (!entries.hasNext()) { return endOfData(); } Entry entry = entries.next(); if (topicId == null || (!topicId.equals(entry.getTopicId())) || (generation != entry.getGeneration())) { topicId = entry.getTopicId(); generation = entry.getGeneration(); topic = MessagingUtils.toDataKeyPrefix(topicId, entry.getGeneration()); rowKey = new byte[topic.length + (2 * Bytes.SIZEOF_LONG) + Bytes.SIZEOF_SHORT]; } Bytes.putBytes(rowKey, 0, topic, 0, topic.length); Bytes.putLong(rowKey, topic.length, entry.getTransactionWritePointer()); Bytes.putLong(rowKey, topic.length + Bytes.SIZEOF_LONG, entry.getPayloadWriteTimestamp()); Bytes.putShort(rowKey, topic.length + (2 * Bytes.SIZEOF_LONG), entry.getPayloadSequenceId()); return tableEntry.set(rowKey, entry.getPayload()); } }
public TopicId(String namespace, String topic) { super(namespace, EntityType.TOPIC); if (topic == null) { throw new NullPointerException("Topic ID cannot be null."); } ensureValidId("topic", topic); this.topic = topic; }
/** * Convert {@link TopicId} to byte array to be used a message tables row key prefix. * * @param topicId {@link TopicId} * @return byte array representation for the topic id */ public static byte[] toMetadataRowKey(TopicId topicId) { String topic = topicId.getNamespace() + ":" + topicId.getTopic() + ":"; return Bytes.toBytes(topic); }
@Override public String getEntityName() { return getTopic(); }
/** * Convert byte array encoded with the {@link #toMetadataRowKey(TopicId)} method back to the {@link TopicId} * * @param topicBytes byte array which contains the representation of the topic id * @param offset offset to start decoding * @param length number of bytes to decode * @return {@link TopicId} */ public static TopicId toTopicId(byte[] topicBytes, int offset, int length) { String topic = Bytes.toString(topicBytes, offset, length); int firstSeparator = topic.indexOf(":", offset); String ns = topic.substring(offset, firstSeparator); String topicId = topic.substring(firstSeparator + 1, topic.length() - 1); return new TopicId(ns, topicId); }