package net.onrc.onos.datastore;

import edu.stanford.ramcloud.JRamCloud;

public class RCClient {

    // Value taken from RAMCloud's Status.h
    // FIXME These constants should be defined by JRamCloud
    public static final int STATUS_OK = 0;

    // FIXME come up with a proper way to retrieve configuration
    public static final int MAX_MULTI_READS = Math.max(1, Integer
	    .valueOf(System.getProperty("ramcloud.max_multi_reads", "400")));

    public static final int MAX_MULTI_WRITES = Math.max(1, Integer
	    .valueOf(System.getProperty("ramcloud.max_multi_writes", "800")));

    private static final ThreadLocal<JRamCloud> tlsRCClient = new ThreadLocal<JRamCloud>() {
	@Override
	protected JRamCloud initialValue() {
	    // FIXME come up with a proper way to retrieve configuration
	    return new JRamCloud(System.getProperty("ramcloud.coordinator",
		    "fast+udp:host=127.0.0.1,port=12246"));
	}
    };

    /**
     * @return JRamCloud instance intended to be used only within the
     *         SameThread.
     * @note Do not store the returned instance in a member variable, etc. which
     *       may be accessed later by another thread.
     */
    static JRamCloud getClient() {
	return tlsRCClient.get();
    }

}

@@ -38,65 +38,411 @@
 ort 
-edu.stanford.ramcloud.JRamCloud;%0A%0Apublic class RCClient %7B
+java.io.File;%0A%0Aimport org.apache.commons.configuration.Configuration;%0Aimport org.apache.commons.configuration.ConfigurationException;%0Aimport org.apache.commons.configuration.PropertiesConfiguration;%0A%0Aimport edu.stanford.ramcloud.JRamCloud;%0A%0Apublic class RCClient %7B%0A%0A    private static final String DB_CONFIG_FILE = %22conf/ramcloud.conf%22;%0A    public static final Configuration config = getConfiguration();
 %0A%0A  
@@ -1081,180 +1081,53 @@
     
-// FIXME come up with a proper way to retrieve configuration%0A%09    return new JRamCloud(System.getProperty(%22ramcloud.coordinator%22,%0A%09%09    %22fast+udp:host=127.0.0.1,port=12246%22
+return new JRamCloud(getCoordinatorUrl(config
 ));%0A
@@ -1454,10 +1454,1137 @@
 %0A    %7D%0A%0A
+    public static final Configuration getConfiguration() %7B%0A%09    final File configFile = new File(System.getProperty(%22ramcloud.config.path%22, DB_CONFIG_FILE));%0A%09    return getConfiguration(configFile);%0A    %7D%0A%0A    public static final Configuration getConfiguration(final File configFile) %7B%0A%09if (configFile == null) %7B%0A%09    throw new IllegalArgumentException(%22Need to specify a configuration file or storage directory%22);%0A%09%7D%0A%0A%09if (!configFile.isFile()) %7B%0A%09    throw new IllegalArgumentException(%22Location of configuration must be a file%22);%0A%09%7D%0A%0A%09try %7B%0A%09    return new PropertiesConfiguration(configFile);%0A%09%7D catch (ConfigurationException e) %7B%0A%09    throw new IllegalArgumentException(%22Could not load configuration at: %22 + configFile, e);%0A%09%7D%0A    %7D%0A%0A    public static String getCoordinatorUrl(final Configuration configuration) %7B%0A%09final String coordinatorIp = configuration.getString(%22ramcloud.coordinatorIp%22, %22fast+udp:host=127.0.0.1%22);%0A%09final String coordinatorPort = configuration.getString(%22ramcloud.coordinatorPort%22, %22port=12246%22);%0A%09final String coordinatorURL = coordinatorIp + %22,%22 + coordinatorPort;%0A%09return coordinatorURL;%0A    %7D%0A
 %7D%0A

Read RAMCloud config from file instead of System.getProperty