com.couchbase.client.CouchbaseClient Java Examples

The following examples show how to use com.couchbase.client.CouchbaseClient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CouchBaseSetTest.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
@Test
public void test()
{
  URI uri = null;
  ArrayList<URI> nodes = new ArrayList<URI>();

  // Add one or more nodes of your cluster (exchange the IP with yours)
  nodes.add(URI.create("http://localhost:8091/pools"));

  // Try to connect to the client
  try {
    client = new CouchbaseClient(nodes, "default", "");
  } catch (Exception e) {
    throw new RuntimeException(e);
  }

  TestPojo obj = new TestPojo();
  obj.setName("test");
  obj.setPhone(123344555);
  HashMap<String, Integer> map = new HashMap<String, Integer>();
  map.put("test", 12345);
  obj.setMap(map);
  future = processKeyValue("key", obj);
  future.addListener(listener);

}
 
Example #2
Source File: ConfigureCouchbase.java    From micro-server with Apache License 2.0 5 votes vote down vote up
@Bean(name = "couchbaseClient")
public CouchbaseClient couchbaseClient() throws IOException, URISyntaxException {
    if (couchbaseClientEnabled) {
        logger.info("Creating CouchbaseClient for servers: {}", couchbaseServers);
        CouchbaseConnectionFactoryBuilder builder = new CouchbaseConnectionFactoryBuilder();
        builder.setOpTimeout(opTimeout);
        CouchbaseConnectionFactory cf = builder.buildCouchbaseConnection(getServersList(), couchbaseBucket,
                                                                         StringUtils.trimAllWhitespace(Optional.ofNullable(couchbasePassword)
                                                                                                               .orElse("")));
        return new CouchbaseClient(
                                   cf);
    }
    return null;

}
 
Example #3
Source File: CouchbaseDistributedMapClient.java    From micro-server with Apache License 2.0 5 votes vote down vote up
private boolean putInternal(final CouchbaseClient client, final String key, final V value) {

        try {
            return client.set(key, value)
                         .get();
        } catch (InterruptedException | ExecutionException e) {
            throw ExceptionSoftener.throwSoftenedException(e);

        }
    }
 
Example #4
Source File: CouchBaseWindowStore.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Override
public void connect() throws IOException
{
  super.connect();
  logger.debug("connection established");
  try {
    CouchbaseConnectionFactoryBuilder cfb = new CouchbaseConnectionFactoryBuilder();
    cfb.setOpTimeout(timeout);  // wait up to 10 seconds for an operation to succeed
    cfb.setOpQueueMaxBlockTime(blockTime); // wait up to 10 second when trying to enqueue an operation
    clientMeta = new CouchbaseClient(cfb.buildCouchbaseConnection(baseURIs, bucketMeta, passwordMeta));
  } catch (IOException e) {
    logger.error("Error connecting to Couchbase: ", e);
    DTThrowable.rethrow(e);
  }
}
 
Example #5
Source File: HiwayDBNoSQL.java    From Hi-WAY with Apache License 2.0 5 votes vote down vote up
private void getConnection() {
	try {
		System.out.println("connecting to Couchbase NEUE Tocks gesetzt, bucket: " + this.bucket + " pwd:" + this.password);
		client = new CouchbaseClient(this.dbURLs, this.bucket, this.password);

	} catch (Exception e) {
		System.out.println("hiwayDBNoSQL |Error connecting to Couchbase: " + e.getMessage());
	}
}
 
Example #6
Source File: CouchBaseClientFactory.java    From GraceKelly with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and returns {@link CouchbaseClient} based on the parameters provided.
 * @param urls
 * @param bucketName
 * @param password
 * @return {@link CouchbaseClient} instance.
 * @throws IOException
 */
public static CouchbaseClient getCouchBaseClient(String[] urls, String bucketName, String password) throws IOException {

    List<URI> uris = new ArrayList<URI>();
    for (String url: urls){
        uris.add(URI.create(url));
    }

    CouchbaseConnectionFactoryBuilder builder = new CouchbaseConnectionFactoryBuilder();
    CouchbaseClient couchbaseClient = new CouchbaseClient(builder.buildCouchbaseConnection(uris,bucketName,password));
    return couchbaseClient;
}
 
Example #7
Source File: CouchBaseStore.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
public CouchbaseClient getInstance()
{
  return client;
}
 
Example #8
Source File: CouchBaseWindowStore.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
public CouchbaseClient getMetaInstance()
{
  return clientMeta;
}
 
Example #9
Source File: Reader.java    From Hi-WAY with Apache License 2.0 4 votes vote down vote up
private static int copyWorkflowNoSQL(ViewResponse result, int limit, CouchbaseClient client, int currentSize, CouchbaseClient hiwayClient) {
	Gson gson = new Gson();
	WfRunDoc newRun = null;
	WfRunDoc run = null;

	System.out.println("copy NoSQL anzwahl wf:" + currentSize + " resultSize:" + result.size());

	int i = 0;
	// Iterate over the found wf documents
	for (ViewRow row : result) {
		i++;
		if (currentSize + i >= limit + 1) {
			System.out.println("Break and raus: all: " + currentSize + " | i: " + i + " limit: " + limit);
			return i;
		}
		run = gson.fromJson((String) row.getDocument(), WfRunDoc.class);

		if (run.getRunId() != null) {
			String newName = run.getRunId().substring(0, 36) + "_" + Calendar.getInstance().getTimeInMillis();
			System.out.println("Run: " + run.getName() + " , I: " + i + " | " + newName);

			newRun = new WfRunDoc();
			newRun.setRunId(newName);
			newRun.setName(run.getName());
			newRun.setWfTime(run.getWfTime());
			newRun.setHiwayEvent(run.getHiwayEvent());
			newRun.setTaskIDs(run.getTaskIDs());

			client.set(newName, gson.toJson(newRun));

			View view = hiwayClient.getView("Workflow", "WfRunInvocs");
			Query query = new Query();
			query.setIncludeDocs(true).setKey(run.getRunId());

			// Query the Cluster
			ViewResponse newResult = hiwayClient.query(view, query);

			InvocDoc newInvoc = null;
			InvocDoc oldInvoc = null;

			for (ViewRow invocDoc : newResult) {
				oldInvoc = gson.fromJson((String) invocDoc.getDocument(), InvocDoc.class);

				newInvoc = new InvocDoc();
				newInvoc.setHostname(oldInvoc.getHostname());
				newInvoc.setLang(oldInvoc.getLang());
				newInvoc.setRealTime(oldInvoc.getRealTime());
				newInvoc.setRealTimeIn(oldInvoc.getRealTimeIn());
				newInvoc.setRealTimeOut(oldInvoc.getRealTimeOut());
				newInvoc.setRunId(newName);
				newInvoc.setScheduleTime(oldInvoc.getScheduleTime());
				newInvoc.setStandardError(oldInvoc.getStandardError());
				newInvoc.setStandardOut(oldInvoc.getStandardOut());
				newInvoc.setTaskId(oldInvoc.getTaskId());
				newInvoc.setTaskname(oldInvoc.getTaskname());
				newInvoc.setTimestamp(Calendar.getInstance().getTimeInMillis());
				newInvoc.setInvocId(oldInvoc.getInvocId());
				newInvoc.setFiles(oldInvoc.getFiles());
				newInvoc.setInput(oldInvoc.getInput());
				newInvoc.setOutput(oldInvoc.getOutput());
				newInvoc.setUserevents(oldInvoc.getUserevents());

				String invocID = newName + "_" + newInvoc.getInvocId();

				System.out.println("save invoc..." + invocID);
				client.set(invocID, gson.toJson(newInvoc));
			}
		}

	}
	return i;

}
 
Example #10
Source File: CouchBaseCacheProvider.java    From GraceKelly with Apache License 2.0 4 votes vote down vote up
/**
 * Constructor with no timeouts for cache gets
 * @param couchbaseClient
 */
public CouchBaseCacheProvider(CouchbaseClient couchbaseClient){
    this.couchbaseClient = couchbaseClient;
    this.timeout = 0;
}
 
Example #11
Source File: CouchbaseDistributedMapClient.java    From micro-server with Apache License 2.0 2 votes vote down vote up
public CouchbaseDistributedMapClient(CouchbaseClient couchbaseClient) {

        this.couchbaseClient = Optional.ofNullable(couchbaseClient);
    }
 
Example #12
Source File: CouchBaseCacheProvider.java    From GraceKelly with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor with timeout for cache gets
 * @param couchbaseClient
 * @param timeout
 */
public CouchBaseCacheProvider(CouchbaseClient couchbaseClient , long timeout){
    this.couchbaseClient = couchbaseClient;
    this.timeout = timeout;
}