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.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.bookkeeper.clients;
import com.google.common.annotations.VisibleForTesting;
import io.netty.buffer.ByteBuf;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import org.apache.bookkeeper.api.StorageClient;
import org.apache.bookkeeper.api.exceptions.ApiException;
import org.apache.bookkeeper.api.kv.PTable;
import org.apache.bookkeeper.api.kv.Table;
import org.apache.bookkeeper.clients.config.StorageClientSettings;
import org.apache.bookkeeper.clients.impl.internal.StorageServerClientManagerImpl;
import org.apache.bookkeeper.clients.impl.internal.api.StorageServerClientManager;
import org.apache.bookkeeper.clients.impl.kv.ByteBufTableImpl;
import org.apache.bookkeeper.clients.impl.kv.PByteBufTableImpl;
import org.apache.bookkeeper.clients.utils.ClientResources;
import org.apache.bookkeeper.common.concurrent.FutureUtils;
import org.apache.bookkeeper.common.util.AbstractAutoAsyncCloseable;
import org.apache.bookkeeper.common.util.ExceptionUtils;
import org.apache.bookkeeper.common.util.OrderedScheduler;
import org.apache.bookkeeper.common.util.SharedResourceManager;
import org.apache.bookkeeper.stream.proto.StorageType;
import org.apache.bookkeeper.stream.proto.StreamProperties;
/**
* The implementation of {@link StorageClient} client.
*/
@Slf4j
public class StorageClientImpl extends AbstractAutoAsyncCloseable implements StorageClient {
private static final String COMPONENT_NAME = StorageClientImpl.class.getSimpleName();
private final String defaultNamespace;
private final StorageClientSettings settings;
private final ClientResources resources;
private final OrderedScheduler scheduler;
// clients
private final StorageServerClientManager serverManager;
private final boolean ownServerManager;
StorageClientImpl(String namespaceName,
StorageClientSettings settings,
ClientResources resources) {
this(
namespaceName,
settings,
resources,
new StorageServerClientManagerImpl(settings, resources.scheduler()),
true);
}
public StorageClientImpl(String namespaceName,
StorageClientSettings settings,
ClientResources resources,
StorageServerClientManager serverManager,
boolean ownServerManager) {
this.defaultNamespace = namespaceName;
this.settings = settings;
this.resources = resources;
this.serverManager = serverManager;
this.ownServerManager = ownServerManager;
this.scheduler = SharedResourceManager.shared().get(resources.scheduler());
}
CompletableFuture getStreamProperties(String namespaceName,
String streamName) {
return this.serverManager.getRootRangeClient().getStream(namespaceName, streamName);
}
//
// Tables
//
@Override
public CompletableFuture> openPTable(String tableName) {
return openPTable(defaultNamespace, tableName);
}
@Override
public CompletableFuture> openPTable(String namespaceName,
String tableName) {
return ExceptionUtils.callAndHandleClosedAsync(
COMPONENT_NAME,
isClosed(),
(future) -> openTableImpl(namespaceName, tableName, future));
}
@Override
public CompletableFuture