use of lombok.SneakyThrows in project pravega by pravega.
the class ZKStreamMetadataStore method registerBucketChangeListener.
@Override
@SneakyThrows
public void registerBucketChangeListener(int bucket, BucketChangeListener listener) {
Preconditions.checkNotNull(listener);
PathChildrenCacheListener bucketListener = (client, event) -> {
StreamImpl stream;
switch(event.getType()) {
case CHILD_ADDED:
stream = getStreamFromPath(event.getData().getPath());
listener.notify(new StreamNotification(stream.getScope(), stream.getStreamName(), NotificationType.StreamAdded));
break;
case CHILD_REMOVED:
stream = getStreamFromPath(event.getData().getPath());
listener.notify(new StreamNotification(stream.getScope(), stream.getStreamName(), NotificationType.StreamRemoved));
break;
case CHILD_UPDATED:
stream = getStreamFromPath(event.getData().getPath());
listener.notify(new StreamNotification(stream.getScope(), stream.getStreamName(), NotificationType.StreamUpdated));
break;
case CONNECTION_LOST:
listener.notify(new StreamNotification(null, null, NotificationType.ConnectivityError));
break;
default:
log.warn("Received unknown event {} on bucket", event.getType(), bucket);
}
};
String bucketRoot = String.format(ZKStoreHelper.BUCKET_PATH, bucket);
bucketCacheMap.put(bucket, new PathChildrenCache(storeHelper.getClient(), bucketRoot, true));
PathChildrenCache pathChildrenCache = bucketCacheMap.get(bucket);
pathChildrenCache.getListenable().addListener(bucketListener);
pathChildrenCache.start(PathChildrenCache.StartMode.NORMAL);
log.info("bucket {} change notification listener registered", bucket);
}
use of lombok.SneakyThrows in project pravega by pravega.
the class TestLogItem method getFullSerialization.
@SneakyThrows(IOException.class)
byte[] getFullSerialization() {
byte[] result = new byte[Long.BYTES + Integer.BYTES + this.data.length];
serialize(new FixedByteArrayOutputStream(result, 0, result.length));
return result;
}
use of lombok.SneakyThrows in project pravega by pravega.
the class SegmentStoreAdapter method attemptReconcile.
@SneakyThrows
private Void attemptReconcile(Throwable ex, String segmentName, Duration timeout) {
ex = Exceptions.unwrap(ex);
boolean reconciled = false;
if (isPossibleEndOfSegment(ex)) {
// If we get a Sealed/Merged/NotExists exception, verify that the segment really is in that state.
try {
SegmentProperties sp = this.streamSegmentStore.getStreamSegmentInfo(segmentName, false, timeout).get(timeout.toMillis(), TimeUnit.MILLISECONDS);
reconciled = sp.isSealed() || sp.isDeleted();
} catch (Throwable ex2) {
reconciled = isPossibleEndOfSegment(Exceptions.unwrap(ex2));
}
}
if (reconciled) {
return null;
} else {
throw ex;
}
}
use of lombok.SneakyThrows in project pravega by pravega.
the class RollingStorage method checkTruncatedSegment.
@SneakyThrows(StreamingException.class)
private void checkTruncatedSegment(StreamingException ex, RollingSegmentHandle handle, SegmentChunk segmentChunk) {
if (ex != null && (Exceptions.unwrap(ex) instanceof StreamSegmentNotExistsException) || !segmentChunk.exists()) {
// We ran into a SegmentChunk that does not exist (either marked as such or due to a failed read).
segmentChunk.markInexistent();
String message = String.format("Offsets %d-%d have been deleted.", segmentChunk.getStartOffset(), segmentChunk.getLastOffset());
ex = new StreamSegmentTruncatedException(handle.getSegmentName(), message, ex);
}
if (ex != null) {
throw ex;
}
}
use of lombok.SneakyThrows in project pravega by pravega.
the class CommandEncoder method serializeMessage.
@SneakyThrows(IOException.class)
private byte[] serializeMessage(WireCommand msg) {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(bout);
out.writeInt(msg.getType().getCode());
out.write(LENGTH_PLACEHOLDER);
msg.writeFields(out);
out.flush();
out.close();
byte[] result = bout.toByteArray();
ByteBuffer asBuffer = ByteBuffer.wrap(result);
asBuffer.putInt(TYPE_SIZE, result.length - TYPE_PLUS_LENGTH_SIZE);
return result;
}
Aggregations