public void update(Observable obs, Object arg) { Config config = (Config) arg; storageTracing = config.getBoolean("tracing.storage"); commandTracing = config.getBoolean("tracing.command"); heartbeatPeriod = config.getInt("raft.heartbeat_period"); requestVotePeriod = config.getInt("raft.request_vote_period"); summaryTracingPeriod = config.getInt("tracing.summary_period"); electionTimeout = config.getInt("raft.election_timeout"); leaderTimeout = config.getInt("raft.leader_timeout"); incomingQueueSize = config.getInt("gondola.incoming_queue_size"); waitQueueThrottleSize = config.getInt("gondola.wait_queue_throttle_size"); fileLockDir = new File(config.get("gondola.file_lock_dir")); // Some validations if (heartbeatPeriod >= electionTimeout) { throw new IllegalStateException(String.format("heartbeat period (%d) must be < election timeout (%d)", heartbeatPeriod, electionTimeout)); } }
private void init() throws Exception { // Create implementations String clockClassName = config.get(config.get("clock.impl") + ".class"); clock = (Clock) Class.forName(clockClassName).getConstructor(Gondola.class, String.class) .newInstance(this, hostId); String networkClassName = config.get(config.get("network.impl") + ".class"); network = (Network) Class.forName(networkClassName).getConstructor(Gondola.class, String.class) .newInstance(this, hostId); String storageClassName = config.get(config.get("storage.impl") + ".class"); storage = (Storage) Class.forName(storageClassName).getConstructor(Gondola.class, String.class) .newInstance(this, hostId); // Create the shards running on a host for (String shardId : config.getShardIds(hostId)) { Shard shard = new Shard(this, shardId); shards.add(shard); shardMap.put(shardId, shard); } inited = true; }
public NastyStorage(Gondola gondola, String hostId) throws Exception { String storageClassName = gondola.getConfig().get(gondola.getConfig().get("storage_nasty.impl") + ".class"); storage = (Storage) Class.forName(storageClassName).getConstructor(Gondola.class, String.class) .newInstance(gondola, hostId); tracing = gondola.getConfig().getBoolean("storage_nasty.tracing"); }
String user = cfg.get("storage.mysql.user"); String password = cfg.get("storage.mysql.password"); String url = cfg.get("storage.mysql.url"); String storeId = cfg.getAttributesForHost(hostId).get("storeId"); if (storeId != null) { String urlKey = "storage." + storeId + ".mysql.url"; if (cfg.has(urlKey)) { url = cfg.get(urlKey);
void createConnection() throws GondolaException { Config cfg = gondola.getConfig(); String user = cfg.get("storage.h2.user"); String password = cfg.get("storage.h2.password"); // If there's a store-specific setting, use it; otherwise use default String url = cfg.get("storage.h2.url"); String storeId = cfg.getAttributesForHost(hostId).get("storeId"); if (storeId != null) { String urlKey = "storage." + storeId + ".h2.url"; if (cfg.has(urlKey)) { url = cfg.get(urlKey); } } url = url.replace("$hostId", hostId); logger.info("Initializing H2DB storage. maxCommandSize={} url={} user={}", maxCommandSize, url, user); try { c = DriverManager.getConnection(url, user, password); c.setAutoCommit(true); } catch (SQLException e) { throw new GondolaException(e); } }
String clockClassName = config.get(config.get("clock.impl") + ".class"); clock = (Clock) Class.forName(clockClassName).getConstructor(Gondola.class, String.class) .newInstance(this, hostId); String networkClassName = config.get(config.get("network.impl") + ".class"); network = (Network) Class.forName(networkClassName).getConstructor(Gondola.class, String.class) .newInstance(this, hostId); String storageClassName = config.get(config.get("storage.impl") + ".class"); storage = (Storage) Class.forName(storageClassName).getConstructor(Gondola.class, String.class) .newInstance(this, hostId);
public static RegistryConfig getRegistryConfig(Config config) { RegistryConfig conf = new RegistryConfig(); conf.attributes = new HashMap<>(); try { String impl = config.get("registry.impl"); switch (impl) { case "registry.zookeeper": conf.type = Type.ZOOKEEPER; conf.attributes.put("connectString", config.get("registry.zookeeper.connect_string")); conf.attributes.put("serviceName", config.get("registry.zookeeper.service_name")); break; case "registry.http": conf.type = Type.HTTP; break; default: throw new IllegalArgumentException("Impl=" + impl + " does not supported"); } } catch (Exception e) { conf.type = Type.NONE; } return conf; }
public NastyStorage(Gondola gondola, String hostId) throws GondolaException { String storageClassName = gondola.getConfig().get(gondola.getConfig().get("storage.nasty.impl") + ".class"); try { storage = (Storage) Class.forName(storageClassName).getConstructor(Gondola.class, String.class) .newInstance(gondola, hostId); } catch (Exception e) { throw new GondolaException(e); } tracing = gondola.getConfig().getBoolean("storage.nasty.tracing"); }