本文整理汇总了Java中com.basho.riak.client.core.query.RiakObject类的典型用法代码示例。如果您正苦于以下问题:Java RiakObject类的具体用法?Java RiakObject怎么用?Java RiakObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RiakObject类属于com.basho.riak.client.core.query包,在下文中一共展示了RiakObject类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import com.basho.riak.client.core.query.RiakObject; //导入依赖的package包/类
public boolean create(String filename)
throws FileNotFoundException, IOException, InterruptedException, ExecutionException {
PRTable table = readTable(filename);
SchemaTableName schemaTableName = new SchemaTableName(schemaName, table.getName());
List<RiakObject> objects = client.getSchemaRiakObjects(schemaTableName.getSchemaName());
for (RiakObject o : objects) {
CLI.log(o.getValue().toStringUtf8());
PRSchema schema = objectMapper.readValue(o.getValue().toStringUtf8(), PRSchema.class);
CLI.log(table.toString());
schema.addTable(table, "added today");
o.setValue(BinaryValue.create(objectMapper.writeValueAsBytes(schema)));
if (client.storeSchema(schemaName, o)) {
if (client.storeTable(schemaTableName, table)) {
CLI.log("Table " + schemaTableName + " successfully created.");
}
}
}
return false;
}
示例2: setupSchema
import com.basho.riak.client.core.query.RiakObject; //导入依赖的package包/类
public void setupSchema(String schemaName) {
try {
setupClient(config);
List<RiakObject> objects = client.getSchemaRiakObjects(schemaName);
if (objects.size() > 0) {
CLI.log("Schema is already up: " + schemaName);
return;
}
// NOTE: there can be an interleaved schema creation here
// and as a consequence, there are multiple siblings. At any
// moment, presto-riak does not handle siblings in metadata.
// Just picks up the first sibling.
PRSchema schema = new PRSchema(new HashSet<String>(), new HashSet<String>());
if (!client.storeSchema(schemaName, schema)) {
CLI.log("failed creating schema");
}
CLI.log("success: " + schemaName);
} catch (Exception e) {
log.error(e);
} finally {
client.shutdown();
}
}
示例3: register
import com.basho.riak.client.core.query.RiakObject; //导入依赖的package包/类
public void register() throws InterruptedException {
String host = HostAndPort.fromString(config.getHost()).getHostText();
log.debug("presto port ===> %s:%s", host, config.getPrestoPort());
// riak.erlang.node => { presto.erlang.node, node.ip, http-server.http.port }
PairwiseNode pairNode = new PairwiseNode(config.getLocalNode(), host, config.getPrestoPort());
RiakObject obj = new RiakObject();
obj.setContentType("application/json");
obj.setValue(BinaryValue.create(pairNode.toString()));
log.debug("Registering membership: %s", pairNode.toString());
log.info("localnode: %s", config.getLocalNode());
BinaryValue localNode = BinaryValue.create(config.getLocalNode());
StoreOperation op = new StoreOperation.Builder(new Location(NAMESPACE, localNode))
.withContent(obj).build();
cluster.execute(op);
op.await();
if (op.isSuccess()) {
log.info("membership registered: %s => %s:%s",
config.getLocalNode(), pairNode.getHost(), pairNode.getPort());
} else {
log.error("failed to register membership");
}
}
示例4: getTableNames
import com.basho.riak.client.core.query.RiakObject; //导入依赖的package包/类
public Set<String> getTableNames(String schemaName)
throws InterruptedException, ExecutionException, IOException {
log.info("checking... %s\n", schemaName);
List<RiakObject> objects = getSchemaRiakObjects(schemaName);
if (objects.size() == 0) {
throw new SchemaNotFoundException(schemaName, "No siblings in " + SCHEMA_KEY_NAME);
}
for (RiakObject o : objects) {
PRSchema schema = objectMapper.readValue(o.getValue().toStringUtf8(), PRSchema.class);
checkNotNull(schema, "no schema key exists in Riak");
HashSet<String> set = new HashSet<>();
for (String t : schema.getTables()) {
set.add(t);
}
return ImmutableSet.copyOf(set);
}
Set<String> s = new HashSet<String>();
return ImmutableSet.copyOf(s);
}
示例5: addTableToSchema
import com.basho.riak.client.core.query.RiakObject; //导入依赖的package包/类
public boolean addTableToSchema(String schemaName, PRTable table)
throws InterruptedException, ExecutionException, IOException {
List<RiakObject> objects = getSchemaRiakObjects(schemaName);
if (objects.size() == 0) {
throw new SchemaNotFoundException(schemaName, "No siblings in " + SCHEMA_KEY_NAME);
}
for (RiakObject o : objects) {
PRSchema schema = objectMapper.readValue(o.getValue().toStringUtf8(), PRSchema.class);
checkNotNull(schema, "no schema key exists in Riak");
return true;
}
return false;
}
示例6: getTable
import com.basho.riak.client.core.query.RiakObject; //导入依赖的package包/类
public PRTable getTable(SchemaTableName schemaTableName)
throws InterruptedException, ExecutionException, IOException {
List<RiakObject> objects = getTableRiakObjects(schemaTableName);
//log.info("RiakClient.getTable(%s)", schemaTableName);
for (RiakObject o : objects) {
//log.debug("ro: %s", o.getValue().toStringUtf8());
PRTable table = objectMapper.readValue(o.getValue().toStringUtf8(), PRTable.class);
checkNotNull(table, "table schema (%s) wasn't found.", schemaTableName.getSchemaName());
log.debug("table schema found: %s.", table.getName());
return table;
}
throw new TableNotFoundException(schemaTableName, "no siblings for " + schemaTableName.toString());
}
示例7: storeTable
import com.basho.riak.client.core.query.RiakObject; //导入依赖的package包/类
public boolean storeTable(SchemaTableName schemaTableName, PRTable table)
throws JsonProcessingException, InterruptedException {
checkNotNull(schemaTableName, "schemaTableName is null");
checkNotNull(table, "table is null");
// don't get from Riak with vclock
// if notfound, just create a new RiakObject and store it
RiakObject obj = new RiakObject();
obj.setContentType("application/json");
obj.setValue(BinaryValue.create(objectMapper.writeValueAsBytes(table)));
Namespace namespace = new Namespace(schemaTableName.getSchemaName(), META_BUCKET_NAME);
Location location = new Location(namespace, schemaTableName.getTableName());
StoreOperation op = new StoreOperation.Builder(location).withContent(obj).build();
cluster.execute(op);
op.await();
return op.isSuccess();
}
示例8: getSchemaRiakObjects
import com.basho.riak.client.core.query.RiakObject; //导入依赖的package包/类
public List<RiakObject> getSchemaRiakObjects(String schemaName)
throws InterruptedException, ExecutionException, IOException {
// null returns if not found
FetchOperation op = buildFetchOperation(schemaName, META_BUCKET_NAME, SCHEMA_KEY_NAME);
cluster.execute(op);
op.await();
if (!op.isSuccess()) {
throw new SchemaNotFoundException(schemaName, SCHEMA_KEY_NAME + " was not found", op.cause());
}
return op.get().getObjectList();
}
示例9: getTableRiakObjects
import com.basho.riak.client.core.query.RiakObject; //导入依赖的package包/类
private List<RiakObject> getTableRiakObjects(SchemaTableName schemaTableName)
throws InterruptedException, ExecutionException, IOException {
checkNotNull(schemaTableName, "tableName is null");
FetchOperation op = buildFetchOperation(
schemaTableName.getSchemaName(),
META_BUCKET_NAME, schemaTableName.getTableName());
cluster.execute(op);
op.await();
if (!op.isSuccess()) {
throw new TableNotFoundException(schemaTableName, op.cause());
}
return op.get().getObjectList();
}
示例10: storeSchema
import com.basho.riak.client.core.query.RiakObject; //导入依赖的package包/类
public boolean storeSchema(String schemaName, PRSchema schema)
throws JsonProcessingException, InterruptedException {
RiakObject obj = new RiakObject();
obj.setContentType("application/json");
obj.setValue(BinaryValue.create(objectMapper.writeValueAsBytes(schema)));
return storeSchema(schemaName, obj);
}
示例11: get
import com.basho.riak.client.core.query.RiakObject; //导入依赖的package包/类
@Override
public void get(Buffer keys, Callback<Buffer> callback) {
List<Location> locations = new ArrayList<Location>();
BufferIterator it = keys.iterator();
while (it.hasNext()) {
Buffer keyView = it.next();
Location location = new Location(_ns, new String(keyView.data()));
locations.add(location);
}
MultiFetch multifetch = new MultiFetch.Builder().addLocations(locations).build();
try {
MultiFetch.Response response = _client.execute(multifetch);
java.util.Map<Location, byte[]> alignedResults = new HashMap<Location, byte[]>();
List<RiakFuture<FetchValue.Response, Location>> l = response.getResponses();
for (int i = 0; i < l.size(); i++) {
FetchValue.Response fetchResponse = l.get(i).get();
List<RiakObject> objs = fetchResponse.getValues();
if (!objs.isEmpty()) {
alignedResults.put(fetchResponse.getLocation(), objs.get(0).getValue().getValue());
}
}
final Buffer result = _graph.newBuffer();
for (int i = 0; i < locations.size(); i++) {
if (i != 0) {
result.write(Constants.BUFFER_SEP);
}
byte[] resolved = alignedResults.get(locations.get(i));
if (resolved != null) {
result.writeAll(resolved);
}
}
callback.on(result);
} catch (Exception e) {
e.printStackTrace();
}
/*
_client.executeAsync(multifetch).addListener(new RiakFutureListener<MultiFetch.Response, List<Location>>() {
@Override
public void handle(RiakFuture<MultiFetch.Response, List<Location>> f) {
try {
System.out.println("BEFORE GET");
MultiFetch.Response resp = f.get();
java.util.Map<Location, byte[]> alignedResults = new HashMap<Location, byte[]>();
List<RiakFuture<FetchValue.Response, Location>> l = resp.getResponses();
for (int i = 0; i < l.size(); i++) {
FetchValue.Response response = l.get(i).get();
List<RiakObject> objs = response.getValues();
if (!objs.isEmpty()) {
alignedResults.put(response.getLocation(), objs.get(0).getValue().getValue());
}
}
final Buffer result = _graph.newBuffer();
for (int i = 0; i < locations.size(); i++) {
if (i != 0) {
result.write(Constants.BUFFER_SEP);
}
byte[] resolved = alignedResults.get(locations.get(i));
if (resolved != null) {
result.writeAll(resolved);
}
}
System.out.println("AFTER GET");
callback.on(result);
} catch (Exception e) {
e.printStackTrace();
callback.on(null);
}
}
});*/
}
示例12: put
import com.basho.riak.client.core.query.RiakObject; //导入依赖的package包/类
@Override
public void put(Buffer stream, Callback<Boolean> callback) {
BufferIterator it = stream.iterator();
List<StoreValue> all = new ArrayList<StoreValue>();
while (it.hasNext()) {
Buffer keyView = it.next();
Buffer valueView = it.next();
if (valueView != null) {
try {
Location location = new Location(_ns, new String(keyView.data()));
RiakObject riakObject = new RiakObject();
riakObject.setValue(BinaryValue.create(valueView.data()));
StoreValue store = new StoreValue.Builder(riakObject)
.withLocation(location)
.withOption(StoreValue.Option.W, new Quorum(3))
.build();
all.add(store);
} catch (Exception e) {
e.printStackTrace();
}
}
}
//CountDownLatch latch = new CountDownLatch(all.size());
final DeferCounter counter = _graph.newCounter(all.size());
counter.then(() -> {
callback.on(true);
});
for (int i = 0; i < all.size(); i++) {
/*
try {
_client.execute(all.get(i));
counter.count();
} catch (Exception e) {
e.printStackTrace();
}*/
_client.executeAsync(all.get(i)).addListener(new RiakFutureListener<StoreValue.Response, Location>() {
@Override
public void handle(RiakFuture<StoreValue.Response, Location> f) {
//latch.countDown();
counter.count();
}
});
}
/*
try {
latch.await();
callback.on(true);
} catch (InterruptedException e) {
e.printStackTrace();
}*/
}
示例13: dummy_main
import com.basho.riak.client.core.query.RiakObject; //导入依赖的package包/类
public static void dummy_main(String args[]) throws UnknownHostException, InterruptedException {
System.out.println("foobar");
RiakNode node = new RiakNode.Builder().withRemoteAddress("127.0.0.1")
.withRemotePort(8087)
.withMaxConnections(10)
.withConnectionTimeout(CONNECTION_TIMEOUT_MIL)
.build();
List<RiakNode> nodes = Arrays.asList(node);
RiakCluster cluster = RiakCluster.builder(nodes).build();
long startTime = System.currentTimeMillis();
//Bucket bucket = client.createBucket("demo_bucket").execute();
for (int i = 0; i < DATA_COUNT; i++) {
try {
if (i % 1000 == 0) {
log("storing key #" + i);
}
;
BinaryValue key = BinaryValue.create("demo_key_" + i);
RiakObject obj = new RiakObject();
obj.setContentType("application/json");
obj.setValue(BinaryValue.create("{'name':'bob','age':18}"));
StoreOperation op = new StoreOperation.Builder(new Location(NAMESPACE, key))
.withContent(obj)
.withReturnBody(false)
.build();
cluster.execute(op);
op.await();
if (!op.isSuccess()) {
throw op.cause();
}
} catch (Throwable t) {
log(t.getMessage());
log(t.getStackTrace().toString());
}
}
long duration = System.currentTimeMillis() - startTime;
log("ops per sec: " + DATA_COUNT / (duration / 1000.0));
}