All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.turbospaces.grpc.GrpcContextWorkUnit Maven / Gradle / Ivy

There is a newer version: 2.0.33
Show newest version
package com.turbospaces.grpc;

import org.apache.commons.lang3.StringUtils;

import com.google.common.io.ByteSource;
import com.turbospaces.executor.WorkUnit;

import lombok.ToString;

@ToString
public class GrpcContextWorkUnit implements WorkUnit {
    //
    // ~ preserve context at the moment of creation
    //
    private final String topic = GrpcHeaders.CONTEXT_TOPIC.get();
    private final long timestamp = GrpcHeaders.CONTEXT_TIMESTAMP.get();
    private final String routingKey = GrpcHeaders.CONTEXT_ROUTING_KEY.get();

    @Override
    public String topic() {
        return topic;
    }
    @Override
    public long timestamp() {
        return timestamp;
    }
    @Override
    public byte[] key() {
        if (StringUtils.isNotEmpty(routingKey)) {
            return routingKey.getBytes();
        }
        return null;
    }
    @Override
    public ByteSource value() {
        return ByteSource.empty();
    }
    public static GrpcContextWorkUnit fromCurrentContext() {
        return new GrpcContextWorkUnit();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy