Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2017-2023 O2 Czech Republic, a.s.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cz.o2.proxima.server;
import com.google.common.annotations.VisibleForTesting;
import com.google.protobuf.ByteString;
import com.google.protobuf.MessageOrBuilder;
import com.google.protobuf.TextFormat;
import cz.o2.proxima.direct.core.DirectAttributeFamilyDescriptor;
import cz.o2.proxima.direct.core.DirectDataOperator;
import cz.o2.proxima.direct.randomaccess.KeyValue;
import cz.o2.proxima.direct.randomaccess.RandomAccessReader;
import cz.o2.proxima.direct.transaction.TransactionalOnlineAttributeWriter.TransactionRejectedException;
import cz.o2.proxima.proto.service.RetrieveServiceGrpc;
import cz.o2.proxima.proto.service.Rpc;
import cz.o2.proxima.proto.service.Rpc.GetRequest;
import cz.o2.proxima.proto.service.Rpc.GetResponse;
import cz.o2.proxima.proto.service.Rpc.ListRequest;
import cz.o2.proxima.proto.service.Rpc.ListResponse;
import cz.o2.proxima.proto.service.Rpc.MultifetchRequest;
import cz.o2.proxima.proto.service.Rpc.MultifetchResponse;
import cz.o2.proxima.repository.AttributeDescriptor;
import cz.o2.proxima.repository.EntityDescriptor;
import cz.o2.proxima.repository.Repository;
import cz.o2.proxima.server.metrics.Metrics;
import cz.o2.proxima.server.transaction.TransactionContext;
import cz.o2.proxima.transaction.KeyAttribute;
import cz.o2.proxima.transaction.KeyAttributes;
import cz.o2.proxima.transaction.Response.Flags;
import io.grpc.stub.StreamObserver;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import lombok.extern.slf4j.Slf4j;
/** Service for reading data. */
@Slf4j
public class RetrieveService extends RetrieveServiceGrpc.RetrieveServiceImplBase {
private final Map, RandomAccessReader> readerMap;
private final Repository repo;
private final DirectDataOperator direct;
private final TransactionContext transactionContext;
public RetrieveService(
Repository repo, DirectDataOperator direct, TransactionContext transactionContext) {
this.repo = repo;
this.direct = direct;
this.readerMap = Collections.synchronizedMap(new HashMap<>());
this.transactionContext = transactionContext;
}
private static class Status extends Exception {
final int statusCode;
final String message;
Status(int statusCode, String message) {
this.statusCode = statusCode;
this.message = message;
}
}
@Override
public void begin(
Rpc.BeginTransactionRequest request,
StreamObserver responseObserver) {
String transactionId = transactionContext.create(request.getTranscationId());
responseObserver.onNext(
Rpc.BeginTransactionResponse.newBuilder().setTransactionId(transactionId).build());
responseObserver.onCompleted();
}
@Override
public void listAttributes(
Rpc.ListRequest request, StreamObserver responseObserver) {
try {
Metrics.LIST_REQUESTS.increment();
if (request.getEntity().isEmpty()
|| request.getKey().isEmpty()
|| request.getWildcardPrefix().isEmpty()) {
throw new Status(400, "Missing some required fields");
}
if (!request.getTransactionId().isEmpty()
&& (!request.getOffset().isEmpty() || request.getLimit() > 0)) {
throw new Status(
400, "Unsupported: transactions do not support limited list requests, currently");
}
EntityDescriptor entity =
repo.findEntity(request.getEntity())
.orElseThrow(() -> new Status(404, "Entity " + request.getEntity() + " not found"));
AttributeDescriptor