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

com.aol.micro.server.couchbase.SimpleCouchbaseClient Maven / Gradle / Ivy

package com.aol.micro.server.couchbase;

import java.util.Optional;
import java.util.concurrent.ExecutionException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.aol.cyclops.invokedynamic.ExceptionSoftener;
import com.couchbase.client.CouchbaseClient;

public class SimpleCouchbaseClient {

	private final Logger logger = LoggerFactory.getLogger(getClass());

	private final Optional couchbaseClient;

	public SimpleCouchbaseClient(CouchbaseClient couchbaseClient) {

		this.couchbaseClient = Optional.ofNullable(couchbaseClient);
	}

	
	public boolean put(final String key, final V value) {
		logger.debug("put '{}', value:{}", key, value);
		return couchbaseClient.map(c->putInternal(c,key,value)).orElse(false);

	}
	private boolean putInternal(final CouchbaseClient client, final String key, final V value){
	
		try{
			return client.set(key, value).get();
		} catch (InterruptedException | ExecutionException e) {
			ExceptionSoftener.throwSoftenedException(e);
			return false;//unreachable
		}
	}

	
	
	public Optional get(String key) {
		return couchbaseClient.map(c->(V)c.get(key));
			
	}

	public void delete(String key) {
		couchbaseClient.map(c->c.delete(key));
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy