Search in sources :

Example 6 with StoreClientFactory

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()));
}
Also used : SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ClientConfig(voldemort.client.ClientConfig) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) StoreClientFactory(voldemort.client.StoreClientFactory)

Example 7 with StoreClientFactory

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);
}
Also used : SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) Node(voldemort.cluster.Node) Cluster(voldemort.cluster.Cluster) Properties(java.util.Properties) ClientConfig(voldemort.client.ClientConfig) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) StoreClientFactory(voldemort.client.StoreClientFactory) Before(org.junit.Before)

Example 8 with StoreClientFactory

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");
}
Also used : SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ClientConfig(voldemort.client.ClientConfig) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) StoreClientFactory(voldemort.client.StoreClientFactory)

Example 9 with StoreClientFactory

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();
        }
    }
}
Also used : SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ClientConfig(voldemort.client.ClientConfig) IOException(java.io.IOException) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) StoreClientFactory(voldemort.client.StoreClientFactory)

Aggregations

ClientConfig (voldemort.client.ClientConfig)9 SocketStoreClientFactory (voldemort.client.SocketStoreClientFactory)9 StoreClientFactory (voldemort.client.StoreClientFactory)9 IOException (java.io.IOException)2 Properties (java.util.Properties)2 Schema (org.apache.avro.Schema)2 Before (org.junit.Before)2 Cluster (voldemort.cluster.Cluster)2 Node (voldemort.cluster.Node)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 InputStreamReader (java.io.InputStreamReader)1 PostConstruct (javax.annotation.PostConstruct)1 GenericRecord (org.apache.avro.generic.GenericRecord)1 Test (org.junit.Test)1 AdminClient (voldemort.client.protocol.admin.AdminClient)1 VoldemortServer (voldemort.server.VoldemortServer)1