use of voldemort.client.StoreClientFactory in project voldemort by voldemort.
the class ClientExample method stringStoreExample.
public static void stringStoreExample() {
System.out.println("==============String store example=================");
// In production environment, the StoreClient instantiation should be done using factory pattern
// through a Framework such as Spring
String bootstrapUrl = "tcp://localhost:6666";
StoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
StoreClient<String, String> client = factory.getStoreClient("test");
// put initial value
System.out.println("Putting an initial value");
client.put("some_key", "initial value");
// get the value
System.out.println("Getting Initial value");
Versioned<String> versioned = client.get("some_key");
System.out.println("Initial Versioned Object: " + String.valueOf(versioned));
System.out.println(" Initial Value: " + String.valueOf(versioned.getValue()));
// modify the value
System.out.println("Modifying the value");
versioned.setObject("new_value");
// update the value
System.out.println("Putting the new value");
client.put("some_key", versioned);
// get again and print
System.out.println("Getting the new value");
versioned = client.get("some_key");
System.out.println("Putting the value");
System.out.println(" New Versioned Object: " + String.valueOf(versioned));
System.out.println(" New Value: " + String.valueOf(versioned.getValue()));
}
use of voldemort.client.StoreClientFactory in project voldemort by voldemort.
the class EndToEndTest method setUp.
@Before
public void setUp() throws IOException {
int numServers = 2;
VoldemortServer[] servers = new VoldemortServer[numServers];
int[][] partitionMap = { { 0, 2, 4, 6 }, { 1, 3, 5, 7 } };
Cluster cluster = ServerTestUtils.startVoldemortCluster(numServers, servers, partitionMap, socketStoreFactory, useNio, null, STORES_XML, new Properties());
Node node = cluster.getNodeById(0);
String bootstrapUrl = "tcp://" + node.getHost() + ":" + node.getSocketPort();
StoreClientFactory storeClientFactory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
storeClient = storeClientFactory.getStoreClient(STORE_NAME);
}
use of voldemort.client.StoreClientFactory in project voldemort by voldemort.
the class TestClientShutdown method main.
public static void main(String[] args) throws Exception {
if (args.length < 2 || args.length > 3)
Utils.croak("USAGE: java VoldemortClientShell store_name bootstrap_url [command_file]");
String storeName = args[0];
String bootstrapUrl = args[1];
StoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setEnableLazy(false).setBootstrapUrls(bootstrapUrl));
DefaultStoreClient<Object, Object> client = null;
try {
client = (DefaultStoreClient<Object, Object>) factory.getStoreClient(storeName);
} catch (Exception e) {
Utils.croak("Could not connect to server: " + e.getMessage());
}
System.out.println("Established connection to " + storeName + " via " + bootstrapUrl);
client.get("hello");
System.out.println("Got value");
}
use of voldemort.client.StoreClientFactory in project voldemort by voldemort.
the class RemoteDataGenerator method generateData.
/**
* Populate the store with
*
* @param requests key-value pairs with key of size, appending
* @param postfix for uniqueness.
*
* @param keySize bytes and value of size
* @param valueSize bytes
* @param requests How many key-value pairs to generate
* @param keySize Size (in bytes) of the key
* @param valueSize Size (in bytes) of the value
* @param postfix Postfix to append (for uniqueness)
*/
public void generateData(int requests, int keySize, int valueSize, String postfix) {
StoreClientFactory storeClientFactory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(url).setMaxThreads(workers));
StoreClient<String, String> client = storeClientFactory.getStoreClient(storeName);
for (int i = 0; i < requests; i++) {
StringBuilder keyBuilder = new StringBuilder(makeString(keySize)).append(i);
StringBuilder valueBuilder = new StringBuilder(makeString(valueSize)).append(i);
if (postfix != null) {
keyBuilder.append(postfix);
}
try {
client.put(keyBuilder.toString(), valueBuilder.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Aggregations