本文整理汇总了Java中com.netflix.astyanax.AstyanaxContext.getClient方法的典型用法代码示例。如果您正苦于以下问题:Java AstyanaxContext.getClient方法的具体用法?Java AstyanaxContext.getClient怎么用?Java AstyanaxContext.getClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.netflix.astyanax.AstyanaxContext
的用法示例。
在下文中一共展示了AstyanaxContext.getClient方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getContext
import com.netflix.astyanax.AstyanaxContext; //导入方法依赖的package包/类
private Keyspace getContext(final byte[] table) {
Keyspace keyspace = keyspaces.get(table);
if (keyspace == null) {
synchronized (keyspaces) {
// avoid race conditions where another thread put the client
keyspace = keyspaces.get(table);
AstyanaxContext<Keyspace> context = contexts.get(table);
if (context != null) {
LOG.warn("Context wasn't null for new keyspace " + Bytes.pretty(table));
}
context = new AstyanaxContext.Builder()
.forCluster("localhost")
.forKeyspace(new String(table))
.withAstyanaxConfiguration(ast_config)
.withConnectionPoolConfiguration(pool)
.withConnectionPoolMonitor(monitor)
.buildKeyspace(ThriftFamilyFactory.getInstance());
contexts.put(table, context);
context.start();
keyspace = context.getClient();
keyspaces.put(table, keyspace);
}
}
return keyspace;
}
示例2: setupAstyanaxContext
import com.netflix.astyanax.AstyanaxContext; //导入方法依赖的package包/类
private Keyspace setupAstyanaxContext(String clusterName)
{
AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
.forCluster(clusterName)
.forKeyspace("CrawlerKS")
.withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
.setDiscoveryType(NodeDiscoveryType.NONE)
.setConnectionPoolType(ConnectionPoolType.TOKEN_AWARE)
)
.withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("CassandraPool")
.setPort(9160)
.setMaxConnsPerHost(3)
.setSeeds("127.0.0.1:9160")
)
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance());
context.start();
return context.getClient();
}
示例3: deleteCassandraKeySpace
import com.netflix.astyanax.AstyanaxContext; //导入方法依赖的package包/类
public static void deleteCassandraKeySpace(String cassandraConnString, String keySpace) throws Exception {
try {
AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
.forCluster("ClusterName")
.forKeyspace(keySpace)
.withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
.setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
)
.withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
.setMaxConnsPerHost(1)
.setSeeds(cassandraConnString)
)
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance());
context.start();
Keyspace keyspace = context.getClient();
keyspace.dropKeyspace();
context.shutdown();
} catch (BadRequestException e) {
LOG.warn("Could not delete cassandra keyspace, assuming it does not exist.", e);
}
}
示例4: getConnection
import com.netflix.astyanax.AstyanaxContext; //导入方法依赖的package包/类
/**
* Creates connection to Cassandra
*/
public static Keyspace getConnection() {
final AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
.forCluster("ClusterName")
.forKeyspace(KEYSPACE_NAME)
.withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
.setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
)
.withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
.setPort(9160)
.setMaxConnsPerHost(1)
.setSeeds("127.0.0.1:9160")
.setSocketTimeout(60000)
)
.withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
.setCqlVersion("3.0.0")
.setTargetCassandraVersion("1.2")
)
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance());
context.start();
return context.getClient();
}
示例5: setup
import com.netflix.astyanax.AstyanaxContext; //导入方法依赖的package包/类
@Before
public void setup() {
AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
.forCluster("Test Cluster")
.forKeyspace(KS)
.withAstyanaxConfiguration(
new AstyanaxConfigurationImpl()
.setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE))
.withConnectionPoolConfiguration(
new ConnectionPoolConfigurationImpl("MyConnectionPool")
.setPort(9160).setMaxConnsPerHost(1)
.setSeeds("127.0.0.1:9160"))
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance());
context.start();
keyspace = context.getClient();
}
示例6: AstyanaxCassandraScheduleStore
import com.netflix.astyanax.AstyanaxContext; //导入方法依赖的package包/类
private AstyanaxCassandraScheduleStore(
AstyanaxContext<Keyspace> context,
String name,
ContentStore contentStore,
MessageSender<ScheduleUpdateMessage> messageSender,
Clock clock,
ConsistencyLevel readCl,
ConsistencyLevel writeCl,
MetricRegistry metricRegistry,
String metricPrefix
) {
super(contentStore, messageSender, metricRegistry, metricPrefix);
this.serializer = new ItemAndBroadcastSerializer(new ContentSerializer(new ContentSerializationVisitor()));
this.keyspace = context.getClient();
this.cf = ColumnFamily.newColumnFamily(
name,
StringSerializer.get(),
StringSerializer.get()
);
this.clock = clock;
this.readCl = readCl;
this.writeCl = writeCl;
}
示例7: reconfigure
import com.netflix.astyanax.AstyanaxContext; //导入方法依赖的package包/类
private void reconfigure() throws ConnectionException {
String seeds = MultiValueConfigLoader.getConfig("CASSANDRA-" + getInstanceName() + ".seeds", "localhost");
String clusterName = MultiValueConfigLoader.getConfig("CASSANDRA-" + getInstanceName() + ".clusterName", "Test Cluster");
ConsistencyLevel readCL = ConsistencyLevel.CL_ONE;
ConsistencyLevel writeCL = ConsistencyLevel.CL_ONE;
if(config.containsKey(CassandraConstants.READ_CONSISTENCY)) {
readCL = ConsistencyLevel.valueOf(config.get(CassandraConstants.READ_CONSISTENCY));
}
if(config.containsKey(CassandraConstants.WRITE_CONSISTENCY)) {
writeCL = ConsistencyLevel.valueOf(config.get(CassandraConstants.WRITE_CONSISTENCY));
}
AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
.forCluster(clusterName)
.forKeyspace(blobKSName)
.withAstyanaxConfiguration(
new AstyanaxConfigurationImpl().setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE).setDefaultReadConsistencyLevel(readCL).setDefaultWriteConsistencyLevel(writeCL))
.withConnectionPoolConfiguration(
new ConnectionPoolConfigurationImpl("astyanaxConnectionPool").setPort(9160).setMaxConnsPerHost(1).setSeeds(seeds))
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor()).buildKeyspace(ThriftFamilyFactory.getInstance());
context.start();
keyspace = context.getClient();
createSchema();
chunkedProvider = new CassandraChunkedStorageProvider(keyspace, blobCF);
}
示例8: initConnection
import com.netflix.astyanax.AstyanaxContext; //导入方法依赖的package包/类
private void initConnection(String clusterName, String seeds) {
log.info(String.format("Connecting to Cassandra at %s:%s", clusterName, seeds));
AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
.forCluster(clusterName)
.forKeyspace(keyspaceName)
.withAstyanaxConfiguration(
new AstyanaxConfigurationImpl().setRetryPolicy(new ExponentialBackoff(retryDelay, numberOfRetries))
.setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE).setDefaultReadConsistencyLevel(readCL)
.setDefaultWriteConsistencyLevel(writeCL))
.withConnectionPoolConfiguration(
new ConnectionPoolConfigurationImpl("astyanaxConnectionPool").setPort(9160).setMaxConnsPerHost(connectionPoolSize).setSeeds(seeds))
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor()).buildKeyspace(ThriftFamilyFactory.getInstance());
context.start();
keyspace = context.getClient();
}
示例9: setupCassandraKeySpace
import com.netflix.astyanax.AstyanaxContext; //导入方法依赖的package包/类
public static void setupCassandraKeySpace(String cassandraConnectionString, String keySpaceName,
String columnFamily) throws ConnectionException {
try {
AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
.forCluster("ClusterName")
.forKeyspace(keySpaceName)
.withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
.setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
)
.withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
.setMaxConnsPerHost(1)
.setSeeds(cassandraConnectionString)
)
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance());
context.start();
Keyspace keyspace = context.getClient();
// Using simple strategy
keyspace.createKeyspace(ImmutableMap.<String, Object>builder()
.put("strategy_options", ImmutableMap.<String, Object>builder()
.put("replication_factor", "1")
.build())
.put("strategy_class", "SimpleStrategy")
.build()
);
ColumnFamily<String, String> CF_STANDARD1 = ColumnFamily.newColumnFamily(columnFamily,
StringSerializer.get(), StringSerializer.get());
keyspace.createColumnFamily(CF_STANDARD1, null);
context.shutdown();
} catch(BadRequestException e) {
LOG.warn("could not setup cassandra keyspace , assuming keyspace already exists.", e);
}
}
示例10: provideKeyspace
import com.netflix.astyanax.AstyanaxContext; //导入方法依赖的package包/类
@Provides
@Named("astmetaks")
@Singleton
Keyspace provideKeyspace() {
AstyanaxContext<Keyspace> keyspaceContext = new AstyanaxContext.Builder()
.forCluster("test cluster")
.forKeyspace(MetaConstants.META_KEY_SPACE)
.withAstyanaxConfiguration(
new AstyanaxConfigurationImpl()
.setDiscoveryType(
NodeDiscoveryType.NONE)
.setConnectionPoolType(
ConnectionPoolType.ROUND_ROBIN)
.setTargetCassandraVersion("1.2")
.setCqlVersion("3.0.0"))
// .withHostSupplier(hs.getSupplier(clustername))
.withConnectionPoolConfiguration(
new ConnectionPoolConfigurationImpl("localpool"
+ "_" + MetaConstants.META_KEY_SPACE)
.setSocketTimeout(30000)
.setMaxTimeoutWhenExhausted(20000)
.setMaxConnsPerHost(3).setInitConnsPerHost(1)
.setSeeds("localhost"+":"+"9160")) //uncomment for localhost
// .withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance());
keyspaceContext.start();
Keyspace keyspace;
keyspace = keyspaceContext.getClient();
return keyspace;
}
示例11: provideKeyspace
import com.netflix.astyanax.AstyanaxContext; //导入方法依赖的package包/类
@Provides
@Named("astmetaks")
Keyspace provideKeyspace(@Named("staash.metacluster") String clustername,EurekaAstyanaxHostSupplier hs) {
String clusterNameOnly = "";
String[] clusterinfo = clustername.split(":");
if (clusterinfo != null && clusterinfo.length == 2) {
clusterNameOnly = clusterinfo[0];
} else {
clusterNameOnly = clustername;
}
AstyanaxContext<Keyspace> keyspaceContext = new AstyanaxContext.Builder()
.forCluster(clusterNameOnly)
.forKeyspace(MetaConstants.META_KEY_SPACE)
.withAstyanaxConfiguration(
new AstyanaxConfigurationImpl()
.setDiscoveryType(
NodeDiscoveryType.RING_DESCRIBE)
.setConnectionPoolType(
ConnectionPoolType.TOKEN_AWARE)
.setDiscoveryDelayInSeconds(60)
.setTargetCassandraVersion("1.2")
.setCqlVersion("3.0.0"))
.withHostSupplier(hs.getSupplier(clustername))
.withConnectionPoolConfiguration(
new ConnectionPoolConfigurationImpl(clusterNameOnly
+ "_" + MetaConstants.META_KEY_SPACE)
.setSocketTimeout(11000)
.setConnectTimeout(2000)
.setMaxConnsPerHost(10).setInitConnsPerHost(3))
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance());
keyspaceContext.start();
Keyspace keyspace;
keyspace = keyspaceContext.getClient();
return keyspace;
}
示例12: createKeyspace
import com.netflix.astyanax.AstyanaxContext; //导入方法依赖的package包/类
public static void createKeyspace(String keyspacename) throws ConnectionException {
AstyanaxContext<Keyspace> ctx = builder.forKeyspace(keyspacename).buildKeyspace(ThriftFamilyFactory.getInstance());
ctx.start();
Keyspace keyspace = ctx.getClient();
keyspace.createKeyspace(ImmutableMap.<String, Object> builder()
.put("strategy_options",
ImmutableMap.<String, Object> builder().put("replication_factor", String.valueOf(Configuration.global.getValue("cassandra", "default_replication_factor", 1))).build())
.put("strategy_class", "SimpleStrategy").build());
cluster.getKeyspace(keyspacename).describeKeyspace();
Loggers.Cassandra.info("Create Keyspace " + keyspacename);
}
示例13: setKeyspaceContext
import com.netflix.astyanax.AstyanaxContext; //导入方法依赖的package包/类
/**
* @param keyspaceContext .
*/
@Autowired
protected void setKeyspaceContext(AstyanaxContext<Keyspace> keyspaceContext) {
this.keyspace = keyspaceContext.getClient();
}
示例14: createAstyanaxKeyspace
import com.netflix.astyanax.AstyanaxContext; //导入方法依赖的package包/类
private Keyspace createAstyanaxKeyspace(String clustername, String db,
EurekaAstyanaxHostSupplier supplier) {
String clusterNameOnly = "localhost";
String clusterPortOnly = "9160";
String[] clusterinfo = clustername.split(":");
if (clusterinfo != null && clusterinfo.length == 2) {
clusterNameOnly = clusterinfo[0];
} else {
clusterNameOnly = clustername;
}
AstyanaxContext<Keyspace> keyspaceContext;
if (supplier!=null) {
keyspaceContext = new AstyanaxContext.Builder()
.forCluster("Casss_Paas")
.forKeyspace(db)
.withAstyanaxConfiguration(
new AstyanaxConfigurationImpl()
.setDiscoveryType(
NodeDiscoveryType.DISCOVERY_SERVICE)
.setConnectionPoolType(
ConnectionPoolType.TOKEN_AWARE)
.setDiscoveryDelayInSeconds(60)
.setTargetCassandraVersion("1.2")
.setCqlVersion("3.0.0"))
.withHostSupplier(supplier.getSupplier(clustername))
.withConnectionPoolConfiguration(
new ConnectionPoolConfigurationImpl(clusterNameOnly
+ "_" + db)
.setSocketTimeout(10000)
.setPort(7102)
.setMaxConnsPerHost(10).setInitConnsPerHost(3)
.setSeeds(null))
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance());
} else {
keyspaceContext = new AstyanaxContext.Builder()
.forCluster(clusterNameOnly)
.forKeyspace(db)
.withAstyanaxConfiguration(
new AstyanaxConfigurationImpl()
.setDiscoveryType(
NodeDiscoveryType.RING_DESCRIBE)
.setConnectionPoolType(
ConnectionPoolType.TOKEN_AWARE)
.setDiscoveryDelayInSeconds(60)
.setTargetCassandraVersion("1.2")
.setCqlVersion("3.0.0"))
//.withHostSupplier(hs.getSupplier(clustername))
.withConnectionPoolConfiguration(
new ConnectionPoolConfigurationImpl(clusterNameOnly
+ "_" + db)
.setSocketTimeout(11000)
.setConnectTimeout(2000)
.setMaxConnsPerHost(10).setInitConnsPerHost(3)
.setSeeds(clusterNameOnly+":"+clusterPortOnly))
.buildKeyspace(ThriftFamilyFactory.getInstance());
}
keyspaceContext.start();
Keyspace keyspace;
keyspace = keyspaceContext.getClient();
return keyspace;
}
示例15: provideKeyspace
import com.netflix.astyanax.AstyanaxContext; //导入方法依赖的package包/类
@Provides
@Named("astmetaks")
@Singleton
Keyspace provideKeyspace(@Named("paas.metacluster") String clustername) {
String clusterNameOnly = "";
String clusterPortOnly = "";
String[] clusterinfo = clustername.split(":");
if (clusterinfo != null && clusterinfo.length == 2) {
clusterNameOnly = clusterinfo[0];
clusterPortOnly = clusterinfo[1];
} else {
clusterNameOnly = clustername;
clusterPortOnly = "9160";
}
// hs = new EurekaAstyanaxHostSupplier();
AstyanaxContext<Keyspace> keyspaceContext = new AstyanaxContext.Builder()
.forCluster(clusterNameOnly)
.forKeyspace(MetaConstants.META_KEY_SPACE)
.withAstyanaxConfiguration(
new AstyanaxConfigurationImpl()
.setDiscoveryType(
NodeDiscoveryType.RING_DESCRIBE)
.setConnectionPoolType(
ConnectionPoolType.TOKEN_AWARE)
.setDiscoveryDelayInSeconds(60000)
.setTargetCassandraVersion("1.1")
.setCqlVersion("3.0.0"))
// .withHostSupplier(hs.getSupplier(clustername))
.withConnectionPoolConfiguration(
new ConnectionPoolConfigurationImpl(clusterNameOnly
+ "_" + MetaConstants.META_KEY_SPACE)
.setSocketTimeout(3000)
.setMaxTimeoutWhenExhausted(2000)
.setMaxConnsPerHost(3).setInitConnsPerHost(1)
.setSeeds(clusterNameOnly+":"+clusterPortOnly)) //uncomment for localhost
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance());
keyspaceContext.start();
Keyspace keyspace;
keyspace = keyspaceContext.getClient();
return keyspace;
}