me.prettyprint.cassandra.service.CassandraHostConfigurator Java Examples
The following examples show how to use
me.prettyprint.cassandra.service.CassandraHostConfigurator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CassandraDB.java From cassandra-river with Apache License 2.0 | 6 votes |
protected void init(String clustername, String hosts, String username, String password, String keyspace) { CassandraHostConfigurator hostconfig = new CassandraHostConfigurator(hosts); hostconfig.setRetryDownedHosts(true); hostconfig.setRetryDownedHostsDelayInSeconds(5); hostconfig.setRetryDownedHostsQueueSize(-1); // no bounds this.cluster = HFactory.getOrCreateCluster(clustername, hostconfig); Map<String,String> credentials = new HashMap<String, String>(); if (username != null && username.length() > 0) { credentials.put("username", username); credentials.put("password", password); } this.keyspace = HFactory.createKeyspace( keyspace, cluster, new AllOneConsistencyLevelPolicy(), FailoverPolicy.ON_FAIL_TRY_ALL_AVAILABLE); }
Example #2
Source File: ClusterBootstrap.java From oneops with Apache License 2.0 | 5 votes |
/** * Create a hector cluster instance for an existing Cassandra cluster with the given configuration. * Default values for {@code CassandraHostConfigurator} are configured in properties. * * @param clusterName cluster name. This is an identifying string for the cluster. * Clusters will be created on demand per each unique clusterName * @param activeClients The maximum number of active clients to allowkey. * @param thriftSocketTimeout Cassandra Thrift Socket Timeout (in milliseconds) * @return cluster object * @see <a href="https://github.com/hector-client/hector/wiki/User-Guide#finer-grained-configuration">Hector config</a> */ public Cluster getCluster(String clusterName, int activeClients, int thriftSocketTimeout) { logger.info("Bootstrapping hector cluster client for " + clusterName); CassandraHostConfigurator config = new CassandraHostConfigurator(); String hostStr = collectionToCommaDelimitedString(resolveHosts(clusterHosts, getProp("host_resolve", Boolean.class, true), getProp("host_ipv4", Boolean.class, true))); config.setHosts(hostStr); config.setPort(clusterPort); config.setUseThriftFramedTransport(getProp("thrift", Boolean.class, true)); config.setUseSocketKeepalive(getProp("keep_alive", Boolean.class, true)); config.setCassandraThriftSocketTimeout(thriftSocketTimeout); config.setMaxActive(activeClients); config.setExhaustedPolicy(ExhaustedPolicy.valueOf(getProp("exhausted_policy", String.class, WHEN_EXHAUSTED_GROW.toString()))); config.setMaxWaitTimeWhenExhausted(getProp("exhausted_waittime", Integer.class, -1)); config.setUseHostTimeoutTracker(getProp("ht_tracker", Boolean.class, true)); config.setHostTimeoutCounter(getProp("ht_count", Integer.class, 3)); config.setRetryDownedHosts(getProp("retry_hosts", Boolean.class, true)); config.setRetryDownedHostsDelayInSeconds(getProp("retry_hosts_delay", Integer.class, 60)); boolean autoDiscovery = getProp("auto_discovery", Boolean.class, false); config.setAutoDiscoverHosts(autoDiscovery); if (autoDiscovery) { config.setRunAutoDiscoveryAtStartup(true); config.setAutoDiscoveryDelayInSeconds(60); } logger.info(config.toString()); Cluster cluster = HFactory.createCluster(clusterName, config); logger.info("Known pool hosts for " + clusterName + " cluster is " + cluster.getKnownPoolHosts(true)); if (cluster.getKnownPoolHosts(true).size() == 0) { logger.error("shutdown due to empty cluster.getKnownPoolHosts - hector doesnt throw java.net.ConnectException: Connection refused"); } return cluster; }
Example #3
Source File: CumulusDataAccessLayerFactory.java From cumulusrdf with Apache License 2.0 | 5 votes |
@Override public void accept(final Configuration<Map<String, Object>> configuration) { _hosts = configuration.getAttribute(HOSTS, "127.0.0.1:9160"); _keyspaceName = configuration.getAttribute(KEYSPACE, "KeyspaceCumulus") + _keyspaceNameSuffix; _replicationFactor = configuration.getAttribute(REPLICATION_FACTOR, Integer.valueOf(1)); _readConsistency = configuration.getAttribute(READ_CONSISTENCY, "ONE"); _writeConsistency = configuration.getAttribute(WRITE_CONSISTENCY, "ONE"); final CassandraHostConfigurator config = new CassandraHostConfigurator(_hosts); config.setRetryDownedHosts(configuration.getAttribute(RETRY_DOWNED_HOSTS, Boolean.TRUE)); final Integer socketTimeout = configuration.getAttribute(THRIFT_SOCKET_TIMEOUT, null); if (socketTimeout != null) { config.setCassandraThriftSocketTimeout(socketTimeout); } config.setRetryDownedHostsDelayInSeconds(configuration.getAttribute(RETRY_DOWNED_HOSTS_DELAY_IN_SECONDS, Integer.valueOf(10))); config.setRetryDownedHostsQueueSize(configuration.getAttribute(RETRY_DOWNED_HOSTS_QUEUE_SIZE, Integer.valueOf(256))); config.setMaxWaitTimeWhenExhausted(configuration.getAttribute(MAX_WAIT_TIME_WHEN_EXHAUSTED, Integer.valueOf(0))); final String lbPolicy = configuration.getAttribute(LOAD_BALANCING_POLICY, null); if (lbPolicy != null) { try { config.setLoadBalancingPolicy((LoadBalancingPolicy) Class.forName(lbPolicy).newInstance()); } catch (Exception ignore) { // Just use the default value } } _cluster = HFactory.getOrCreateCluster("CumulusRDFCluster", config); }
Example #4
Source File: BackplaneConfiguration.java From elasticactors with Apache License 2.0 | 5 votes |
@PostConstruct public void initialize() { String cassandraHosts = env.getProperty("ea.cassandra.hosts","localhost:9160"); CassandraHostConfigurator hostConfigurator = new CassandraHostConfigurator(cassandraHosts); hostConfigurator.setAutoDiscoverHosts(false); hostConfigurator.setMaxActive(env.getProperty("ea.cassandra.maxActive",Integer.class,Runtime.getRuntime().availableProcessors() * 3)); hostConfigurator.setRetryDownedHosts(true); hostConfigurator.setRetryDownedHostsDelayInSeconds(env.getProperty("ea.cassandra.retryDownedHostsDelayInSeconds",Integer.class,1)); hostConfigurator.setMaxWaitTimeWhenExhausted(2000L); String cassandraClusterName = env.getProperty("ea.cassandra.cluster","ElasticActorsCluster"); // it seems that there are issues with the CassandraHostRetryService and retrying downed hosts // if we don't let the HFactory manage the cluster then CassandraHostRetryService doesn't try to // be smart about finding out if a host was removed from the ring and so it will keep on retrying // all configured hosts (and ultimately fail-back when the host comes back online) // the default is TRUE, which will let HFactory manage the cluster Boolean manageClusterThroughHFactory = env.getProperty("ea.cassandra.hfactory.manageCluster", Boolean.class, Boolean.TRUE); Cluster cluster; if(manageClusterThroughHFactory) { cluster = HFactory.getOrCreateCluster(cassandraClusterName, hostConfigurator); } else { cluster = new ThriftCluster(cassandraClusterName, hostConfigurator, null); } String cassandraKeyspaceName = env.getProperty("ea.cassandra.keyspace","ElasticActors"); Keyspace keyspace = HFactory.createKeyspace(cassandraKeyspaceName,cluster); persistentActorsColumnFamilyTemplate = new ThriftColumnFamilyTemplate<>(keyspace,"PersistentActors", CompositeSerializer.get(),StringSerializer.get()); scheduledMessagesColumnFamilyTemplate = new ThriftColumnFamilyTemplate<>(keyspace,"ScheduledMessages",CompositeSerializer.get(), CompositeSerializer.get()); actorSystemEventListenersColumnFamilyTemplate = new ThriftColumnFamilyTemplate<>(keyspace,"ActorSystemEventListeners", CompositeSerializer.get(),StringSerializer.get()); // return // @TODO: make this configurable and use the ColumnSliceIterator scheduledMessagesColumnFamilyTemplate.setCount(Integer.MAX_VALUE); actorSystemEventListenersColumnFamilyTemplate.setCount(Integer.MAX_VALUE); }
Example #5
Source File: CassandraService.java From usergrid with Apache License 2.0 | 5 votes |
public CassandraService( Properties properties, Cluster cluster, CassandraHostConfigurator cassandraHostConfigurator, final Injector injector) { this.properties = properties; this.cluster = cluster; chc = cassandraHostConfigurator; lockManager = injector.getInstance( LockManager.class ); db_logger.info( "{}", cluster.getKnownPoolHosts( false ) ); //getInjector applicationKeyspace = injector.getInstance( CassandraFig.class ).getApplicationKeyspace(); }
Example #6
Source File: CassandraUserStoreManager.java From carbon-identity with Apache License 2.0 | 4 votes |
public CassandraUserStoreManager(RealmConfiguration realmConfig, int tenantId) throws UserStoreException { this.realmConfig = realmConfig; Util.setRealmConfig(realmConfig); this.tenantIdString = Integer.toString(tenantId); this.tenantId = tenantId; // Set groups read/write configuration if (realmConfig.getUserStoreProperty(UserCoreConstants.RealmConfig.READ_GROUPS_ENABLED) != null) { readGroupsEnabled = Boolean.parseBoolean(realmConfig .getUserStoreProperty(UserCoreConstants.RealmConfig.READ_GROUPS_ENABLED)); } if (realmConfig.getUserStoreProperty(UserCoreConstants.RealmConfig.WRITE_GROUPS_ENABLED) != null) { writeGroupsEnabled = Boolean.parseBoolean(realmConfig .getUserStoreProperty(UserCoreConstants.RealmConfig.WRITE_GROUPS_ENABLED)); } else { if (!isReadOnly()) { writeGroupsEnabled = true; } } if (writeGroupsEnabled) { readGroupsEnabled = true; } /* * Initialize user roles cache as implemented in AbstractUserStoreManager */ initUserRolesCache(); Map<String, String> credentials = new HashMap<String, String>(); credentials.put(CFConstants.USERNAME_PROPERTY, realmConfig.getUserStoreProperty(CFConstants.USERNAME_XML_ATTRIB)); credentials.put(CFConstants.PASSWORD_PROPERTY, realmConfig.getUserStoreProperty(CFConstants.PASSWORD_XML_ATTRIB)); CassandraHostConfigurator hostConf = new CassandraHostConfigurator(); hostConf.setHosts(realmConfig.getUserStoreProperty(CFConstants.HOST_XML_ATTRIB)); hostConf.setPort(Integer.parseInt(realmConfig.getUserStoreProperty(CFConstants.PORT_XML_ATTRIB))); // set Cassandra specific properties cluster = HFactory.getOrCreateCluster(realmConfig.getUserStoreProperty(CFConstants.KEYSPACE_NAME_XML_ATTRIB), hostConf, credentials); keyspace = HFactory.createKeyspace(realmConfig.getUserStoreProperty(CFConstants.KEYSPACE_NAME_XML_ATTRIB), cluster); insertInitialData(keyspace); }
Example #7
Source File: CassandraService.java From usergrid with Apache License 2.0 | 4 votes |
public CassandraHostConfigurator getCassandraHostConfigurator() { return chc; }
Example #8
Source File: CassandraService.java From usergrid with Apache License 2.0 | 4 votes |
public void setCassandraHostConfigurator( CassandraHostConfigurator chc ) { this.chc = chc; }