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

net.spy.memcached.vbucket.config.Pool Maven / Gradle / Ivy

package net.spy.memcached.vbucket.config;

import net.spy.memcached.vbucket.ConfigurationException;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import java.util.Collections;

/**
 * Pool represents a collection of buckets
 */
public class Pool {
    // pool name
    private final String name;
    // pool's uri
    private final URI uri;
    // pool's streaming uri
    private final URI streamingUri;
    // buckets related to this pool
    private URI bucketsUri;
    private final AtomicReference> currentBuckets =
        new AtomicReference>();

    public Pool(String name, URI uri, URI streamingUri) {
        this.name = name;
        this.uri = uri;
        this.streamingUri = streamingUri;
    }

    public String getName() {
        return name;
    }

    public URI getUri() {
        return uri;
    }

    public URI getStreamingUri() {
        return streamingUri;
    }

    /**
     * Get the current set of buckets known to this pool member.
     *
     * @return an atomic reference to the current Map of buckets
     */
    private AtomicReference> getCurrentBuckets() {
	if (currentBuckets == null) {
	    throw new ConfigurationException("Buckets were never populated.");
	}
	return currentBuckets;
    }

    public Map getROBuckets() {
	return Collections.unmodifiableMap(currentBuckets.get());
    }

    public URI getBucketsUri() {
        return bucketsUri;
    }

    void setBucketsUri(URI bucketsUri) {
        this.bucketsUri = bucketsUri;
    }

    public void replaceBuckets(Map replacingMap) {
	HashMap swapMap = new HashMap(replacingMap); //TODO: replace this with a deep copy
	currentBuckets.set(swapMap);
    }

    public boolean hasBucket(String bucketName) {
	boolean bucketFound = false;
	if (getCurrentBuckets().get().containsKey(bucketName)) {
		bucketFound = true;
	}
	return bucketFound;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy