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

com.jeesuite.filesystem.sdk.fdfs.TrackerClient Maven / Gradle / Ivy

There is a newer version: 1.3.6
Show newest version
/**
 *
 */
package com.jeesuite.filesystem.sdk.fdfs;

import com.jeesuite.filesystem.sdk.fdfs.codec.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.InetSocketAddress;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;


final class TrackerClient {

    private static final Logger LOG = LoggerFactory.getLogger(TrackerClient.class);

    private final FastdfsExecutor executor;
    private final TrackerSelector selector;
    private final List servers;

    TrackerClient(FastdfsExecutor executor, TrackerSelector selector, List servers) {
        this.executor = executor;
        this.servers = Collections.unmodifiableList(servers);
        this.selector = servers.size() == 1 ? TrackerSelector.FIRST : selector;
        LOG.info("TrackerClient inited with {} servers and selector {}.", servers.size(), this.selector);
    }

    private InetSocketAddress trackerSelect() {
        return selector.select(servers).toInetAddress();
    }

    /**
     * @return
     */
    CompletableFuture uploadStorageGet() {
        return uploadStorageGet(null);
    }

    /**
     * @param group
     * @return
     */
    CompletableFuture uploadStorageGet(String group) {
        return executor.execute(trackerSelect(), new UploadStorageGetEncoder(group), StorageServerDecoder.INSTANCE);
    }

    /**
     * @param fileId
     * @return
     */
    CompletableFuture downloadStorageGet(FileId fileId) {
        CompletableFuture> result = executor.execute(trackerSelect(), new DownloadStorageGetEncoder(fileId), StorageServerListDecoder.INSTANCE);
        return result.thenApply(FastdfsUtils::first);
    }

    /**
     * 获取更新存储服务器地址
     *
     * @param fileId
     */
    CompletableFuture updateStorageGet(FileId fileId) {
        CompletableFuture> result = executor.execute(trackerSelect(), new UpdateStorageGetEncoder(fileId), StorageServerListDecoder.INSTANCE);
        return result.thenApply(FastdfsUtils::first);
    }

    /**
     * @param fileId
     * @return
     */
    CompletableFuture> downloadStorageList(FileId fileId) {
        return executor.execute(trackerSelect(), new DownloadStorageListEncoder(fileId), StorageServerListDecoder.INSTANCE);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy