Search in sources :

Example 41 with SneakyThrows

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);
}
Also used : SneakyThrows(lombok.SneakyThrows) StreamImpl(io.pravega.client.stream.impl.StreamImpl) RetentionPolicy(io.pravega.client.stream.RetentionPolicy) SerializationUtils(org.apache.commons.lang3.SerializationUtils) CompletableFuture(java.util.concurrent.CompletableFuture) StreamNotification(io.pravega.controller.server.retention.BucketChangeListener.StreamNotification) PathChildrenCacheListener(org.apache.curator.framework.recipes.cache.PathChildrenCacheListener) AtomicReference(java.util.concurrent.atomic.AtomicReference) ConcurrentMap(java.util.concurrent.ConcurrentMap) BucketOwnershipListener(io.pravega.controller.server.retention.BucketOwnershipListener) ZKPaths(org.apache.curator.utils.ZKPaths) BucketNotification(io.pravega.controller.server.retention.BucketOwnershipListener.BucketNotification) Data(io.pravega.controller.store.stream.tables.Data) NotificationType(io.pravega.controller.server.retention.BucketChangeListener.StreamNotification.NotificationType) BucketChangeListener(io.pravega.controller.server.retention.BucketChangeListener) Executor(java.util.concurrent.Executor) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) Base64(java.util.Base64) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) Config(io.pravega.controller.util.Config) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) Preconditions(com.google.common.base.Preconditions) ZKHostIndex(io.pravega.controller.store.index.ZKHostIndex) PathChildrenCacheListener(org.apache.curator.framework.recipes.cache.PathChildrenCacheListener) StreamImpl(io.pravega.client.stream.impl.StreamImpl) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) StreamNotification(io.pravega.controller.server.retention.BucketChangeListener.StreamNotification) SneakyThrows(lombok.SneakyThrows)

Example 42 with SneakyThrows

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;
}
Also used : FixedByteArrayOutputStream(io.pravega.common.io.FixedByteArrayOutputStream) SneakyThrows(lombok.SneakyThrows)

Example 43 with SneakyThrows

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;
    }
}
Also used : SegmentProperties(io.pravega.segmentstore.contracts.SegmentProperties) SneakyThrows(lombok.SneakyThrows)

Example 44 with SneakyThrows

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;
    }
}
Also used : StreamSegmentTruncatedException(io.pravega.segmentstore.contracts.StreamSegmentTruncatedException) StreamSegmentNotExistsException(io.pravega.segmentstore.contracts.StreamSegmentNotExistsException) SneakyThrows(lombok.SneakyThrows)

Example 45 with SneakyThrows

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;
}
Also used : DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteBuffer(java.nio.ByteBuffer) SneakyThrows(lombok.SneakyThrows)

Aggregations

SneakyThrows (lombok.SneakyThrows)592 lombok.val (lombok.val)292 Test (org.junit.Test)66 ArrayList (java.util.ArrayList)59 HashMap (java.util.HashMap)51 List (java.util.List)42 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)33 LinkedHashMap (java.util.LinkedHashMap)29 File (java.io.File)27 Collectors (java.util.stream.Collectors)25 Path (java.nio.file.Path)24 IOException (java.io.IOException)23 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)22 URL (java.net.URL)20 Slf4j (lombok.extern.slf4j.Slf4j)20 InputStream (java.io.InputStream)19 Map (java.util.Map)19 Cleanup (lombok.Cleanup)17 FishingActivityQuery (eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery)16 SearchFilter (eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter)16