Created
September 24, 2013 14:18
-
-
Save tgrall/6685467 to your computer and use it in GitHub Desktop.
Simple class to show how to deal with async set operation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.couchbase.devday; | |
import com.couchbase.client.CouchbaseClient; | |
import net.spy.memcached.internal.OperationFuture; | |
import java.net.URI; | |
import java.util.ArrayList; | |
import java.util.LinkedList; | |
import java.util.List; | |
import java.util.UUID; | |
public class DummyInjector { | |
public static void main(String[] args) { | |
System.out.println("--------------------------------------------------------------------------"); | |
System.out.println("\tCouchbase Storage Operations"); | |
System.out.println("--------------------------------------------------------------------------"); | |
List<URI> uris = new LinkedList<URI>(); | |
uris.add(URI.create("http://127.0.0.1:8091/pools")); | |
// reference to all the operations used to inject document | |
List<OperationFuture> allOps = new ArrayList(); | |
CouchbaseClient cb = null; | |
try { | |
cb = new CouchbaseClient(uris, "default", ""); | |
for (int i = 0 ; i <= 500000 ; i++) { | |
allOps.add(cb.set("key::" + i, UUID.randomUUID().toString())); | |
} | |
System.out.println("\n\n\n\n"); | |
} catch (Exception e) { | |
System.err.println("Error connecting to Couchbase: " + e.getMessage()); | |
} | |
for(OperationFuture op : allOps) { | |
if (! op.getStatus().isSuccess()) { | |
System.out.println("Key: key:"+ op.getKey() +" not saved due to '"+ op.getStatus().getMessage() +"'. Please retry" ); | |
} | |
} | |
if (cb != null){ | |
cb.shutdown(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment