use of org.zalando.nakadi.exceptions.NakadiRuntimeException in project nakadi by zalando.
the class AbstractZkSubscriptionClient method listSessions.
@Override
public final Collection<Session> listSessions() throws SubscriptionNotInitializedException, NakadiRuntimeException, ServiceTemporarilyUnavailableException {
getLog().info("fetching sessions information");
final List<String> zkSessions;
try {
zkSessions = getCurator().getChildren().forPath(getSubscriptionPath("/sessions"));
} catch (final KeeperException.NoNodeException e) {
throw new SubscriptionNotInitializedException(getSubscriptionId());
} catch (Exception ex) {
throw new NakadiRuntimeException(ex);
}
return loadDataAsync(zkSessions, key -> getSubscriptionPath("/sessions/" + key), this::deserializeSession).values();
}
use of org.zalando.nakadi.exceptions.NakadiRuntimeException in project nakadi by zalando.
the class ClosingState method reactOnOffset.
private void reactOnOffset(final EventTypePartition key) {
if (!listeners.containsKey(key)) {
return;
}
final NakadiCursor newCursor;
try {
newCursor = getContext().getCursorConverter().convert(key.getEventType(), listeners.get(key).getData());
} catch (Exception ex) {
throw new NakadiRuntimeException(ex);
}
if (uncommittedOffsets.containsKey(key) && getComparator().compare(uncommittedOffsets.get(key), newCursor) <= 0) {
freePartitions(Collections.singletonList(key));
}
tryCompleteState();
}
use of org.zalando.nakadi.exceptions.NakadiRuntimeException in project nakadi by zalando.
the class MultiTimelineEventConsumer method readEvents.
@Override
public List<ConsumedEvent> readEvents() {
if (timelinesChanged.compareAndSet(true, false)) {
try {
onTimelinesChanged();
} catch (final NakadiException | InvalidCursorException ex) {
throw new NakadiRuntimeException(ex);
}
}
final List<ConsumedEvent> result = poll();
for (final ConsumedEvent event : result) {
final EventTypePartition etp = event.getPosition().getEventTypePartition();
latestOffsets.put(etp, event.getPosition());
final String border = borderOffsets.get(etp);
final boolean timelineBorderReached = null != border && border.compareTo(event.getPosition().getOffset()) <= 0;
if (timelineBorderReached) {
timelinesChanged.set(true);
}
}
return result;
}
use of org.zalando.nakadi.exceptions.NakadiRuntimeException in project nakadi by zalando.
the class TopicRepositoryHolder method createStoragePosition.
public Timeline.StoragePosition createStoragePosition(final Timeline timeline) {
try {
final Storage storage = timeline.getStorage();
final List<NakadiCursor> offsets = getTopicRepository(storage).loadTopicStatistics(Collections.singleton(timeline)).stream().map(PartitionStatistics::getLast).collect(Collectors.toList());
return getTopicRepositoryCreator(storage.getType()).createStoragePosition(offsets);
} catch (final ServiceUnavailableException e) {
throw new NakadiRuntimeException(e);
}
}
use of org.zalando.nakadi.exceptions.NakadiRuntimeException in project nakadi by zalando.
the class ConsumerLimitingService method acquireConnectionSlot.
private ConnectionSlot acquireConnectionSlot(final String client, final String eventType, final String partition) {
final String parent = zkPathForConsumer(client, eventType, partition);
final String slotId = UUID.randomUUID().toString();
final String zkPath = ZKPaths.makePath(parent, slotId);
try {
zkHolder.get().create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath(zkPath);
} catch (Exception e) {
LOG.error("Zookeeper error when creating consumer node", e);
throw new NakadiRuntimeException(e);
}
final ConnectionSlot acquiredSlot = new ConnectionSlot(client, eventType, partition, slotId);
ACQUIRED_SLOTS.add(acquiredSlot);
return acquiredSlot;
}
Aggregations