本文整理汇总了Java中com.netflix.astyanax.AstyanaxContext类的典型用法代码示例。如果您正苦于以下问题:Java AstyanaxContext类的具体用法?Java AstyanaxContext怎么用?Java AstyanaxContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AstyanaxContext类属于com.netflix.astyanax包,在下文中一共展示了AstyanaxContext类的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: initialSetup
import com.netflix.astyanax.AstyanaxContext; //导入依赖的package包/类
public void initialSetup() throws NotFoundException, InvalidRequestException, NoSuchFieldException, UnavailableException, IllegalAccessException, InstantiationException, ClassNotFoundException, TimedOutException, URISyntaxException, IOException, TException {
context = new AstyanaxContext.Builder()
.forCluster(_cluster) //"Test Cluster"
.forKeyspace(_keyspaceName)
.withAstyanaxConfiguration(new AstyanaxConfigurationImpl().setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE))
.withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl(_pool).setPort(_port).setMaxConnsPerHost(1).setSeeds(_host+":"+_port))
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance());
context.start();
GlobalVariables.KS_AST = context.getClient();
CF_AST_BACK = ColumnFamily
.newColumnFamily(_columnFamilyNameBack,
StringSerializer.get(), // Key Serializer
StringSerializer.get()) ; // Column Serializer
CF_AST_DYNA = ColumnFamily
.newColumnFamily(_columnFamilyNameDyna,
StringSerializer.get(), // Key Serializer
StringSerializer.get()) ; // Column Serializer
this.cliSchema();
}
示例4: 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);
}
}
示例5: createCacheLoader
import com.netflix.astyanax.AstyanaxContext; //导入依赖的package包/类
@Override
CacheLoader<DefaultAstyanaxKeyspaceFactory.KeyspaceKey, AstyanaxContext<Keyspace>> createCacheLoader(AstyanaxConfiguration astyanaxConfiguration,
ConnectionPoolConfiguration connectionPoolConfiguration,
KeyspaceConnectionPoolMonitorFactory connectionPoolMonitorFactory,
ClusterHostSupplierFactory hostSupplierFactory,
KeyspaceInitializer keyspaceInitializer) {
final CacheLoader<KeyspaceKey, AstyanaxContext<Keyspace>> delegate = super.createCacheLoader(astyanaxConfiguration, connectionPoolConfiguration, connectionPoolMonitorFactory, hostSupplierFactory, keyspaceInitializer);
return new CacheLoader<KeyspaceKey, AstyanaxContext<Keyspace>>() {
@Override
public AstyanaxContext<Keyspace> load(KeyspaceKey key) throws Exception {
createCount.incrementAndGet();
return delegate.load(key);
}
};
}
示例6: 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();
}
示例7: initWithThriftDriverWithEurekaHostsSupplier
import com.netflix.astyanax.AstyanaxContext; //导入依赖的package包/类
private AstyanaxContext<Keyspace> initWithThriftDriverWithEurekaHostsSupplier() {
logger.info("Boot cluster (BOOT_CLUSTER) is {}, keyspace name (KS_NAME) is {}", BOOT_CLUSTER, KS_NAME);
return new AstyanaxContext.Builder()
.forCluster(BOOT_CLUSTER)
.forKeyspace(KS_NAME)
.withAstyanaxConfiguration(
new AstyanaxConfigurationImpl()
.setDiscoveryType(
NodeDiscoveryType.DISCOVERY_SERVICE))
.withConnectionPoolConfiguration(
new ConnectionPoolConfigurationImpl(
"MyConnectionPool")
.setMaxConnsPerHost(3)
.setPort(thriftPortForAstyanax))
.withHostSupplier(eurekaHostsSupplier.getSupplier(BOOT_CLUSTER))
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance());
}
示例8: initWithThriftDriverWithExternalHostsSupplier
import com.netflix.astyanax.AstyanaxContext; //导入依赖的package包/类
private AstyanaxContext<Keyspace> initWithThriftDriverWithExternalHostsSupplier() {
logger.info("Boot cluster (BOOT_CLUSTER) is {}, keyspace name (KS_NAME) is {}", BOOT_CLUSTER, KS_NAME);
return new AstyanaxContext.Builder()
.forCluster(BOOT_CLUSTER)
.forKeyspace(KS_NAME)
.withAstyanaxConfiguration(
new AstyanaxConfigurationImpl()
.setDiscoveryType(
NodeDiscoveryType.DISCOVERY_SERVICE)
.setConnectionPoolType(
ConnectionPoolType.ROUND_ROBIN))
.withConnectionPoolConfiguration(
new ConnectionPoolConfigurationImpl(
"MyConnectionPool")
.setMaxConnsPerHost(3)
.setPort(thriftPortForAstyanax))
.withHostSupplier(getSupplier())
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance());
}
示例9: setProperties
import com.netflix.astyanax.AstyanaxContext; //导入依赖的package包/类
@Override
public void setProperties(Map<String, Object> properties) {
super.setProperties(properties);
AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
.forCluster("ClusterName")
.forKeyspace((String) properties.get(KEYSPACE))
.withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
.setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
)
.withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
.setPort((int)properties.get(PORT))
.setMaxConnsPerHost(1)
.setSeeds((String) properties.get(HOST_LIST))
)
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance() );
context.start();
keyspace = context.getEntity();
}
示例10: TimedGroupByEngine
import com.netflix.astyanax.AstyanaxContext; //导入依赖的package包/类
public TimedGroupByEngine(String ks, int port, String hostlist){
AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
.forCluster("ClusterName")
.forKeyspace(ks)
.withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
.setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
)
.withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
.setPort(port)
.setMaxConnsPerHost(1)
.setSeeds(hostlist)
)
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance() );
context.start();
keyspace = context.getEntity();
}
示例11: setProperties
import com.netflix.astyanax.AstyanaxContext; //导入依赖的package包/类
@Override
public void setProperties(Map<String, Object> properties) {
super.setProperties(properties);
AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
.forCluster("ClusterName")
.forKeyspace((String) properties.get(KEYSPACE))
.withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
.setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
)
.withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
.setPort((int)properties.get(PORT))
.setMaxConnsPerHost(1)
.setSeeds((String) properties.get(HOST_LIST))
)
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance() );
context.start();
batchSize = (Integer) properties.get(BATCH_SIZE);
keyspace = context.getEntity();
m = keyspace.prepareMutationBatch();
}
示例12: CassandraArtifactCache
import com.netflix.astyanax.AstyanaxContext; //导入依赖的package包/类
public CassandraArtifactCache(
String hosts,
int port,
int timeoutSeconds,
boolean doStore,
BuckEventBus buckEventBus)
throws ConnectionException {
this(timeoutSeconds, doStore, buckEventBus, new AstyanaxContext.Builder()
.forCluster(CLUSTER_NAME)
.forKeyspace(KEYSPACE_NAME)
.withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
.setCqlVersion("3.0.0")
.setTargetCassandraVersion("1.2")
.setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
)
.withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl(POOL_NAME)
.setSeeds(hosts)
.setPort(port)
.setMaxConnsPerHost(1)
)
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance()));
}
示例13: beforeClass
import com.netflix.astyanax.AstyanaxContext; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() {
astyanaxContext =
new AstyanaxContext.Builder()
.forKeyspace("timeSeriesKeyspace")
.withConnectionPoolConfiguration(
new ConnectionPoolConfigurationImpl("myCPConfig")
.setSeeds("localhost")
.setPort(9171))
.withAstyanaxConfiguration(
new AstyanaxConfigurationImpl()
.setConnectionPoolType(ConnectionPoolType.TOKEN_AWARE)
.setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE))
.buildKeyspace(ThriftFamilyFactory.getInstance());
keyspace = astyanaxContext.getClient();
astyanaxContext.start();
}
示例14: 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();
}
示例15: acquireCluster
import com.netflix.astyanax.AstyanaxContext; //导入依赖的package包/类
@Override
public synchronized Cluster acquireCluster(ClusterKey clusterKey) {
String clusterName = clusterKey.getClusterName().toLowerCase();
Preconditions.checkNotNull(clusterName, "Invalid cluster name 'null'");
ClusterContextHolder holder = contextMap.get(clusterName);
if (holder == null) {
HostSupplierProvider hostSupplierProvider = hostSupplierProviders.get(clusterKey.getDiscoveryType());
Preconditions.checkNotNull(hostSupplierProvider, String.format("Unknown host supplier provider '%s' for cluster '%s'", clusterKey.getDiscoveryType(), clusterName));
AstyanaxContext<Cluster> context = new AstyanaxContext.Builder()
.forCluster(clusterName)
.withAstyanaxConfiguration(configurationProvider.get(clusterName))
.withConnectionPoolConfiguration(cpProvider.get(clusterName))
.withConnectionPoolMonitor(monitorProvider.get(clusterName))
.withHostSupplier(hostSupplierProvider.getSupplier(clusterName))
.buildCluster(ThriftFamilyFactory.getInstance());
holder = new ClusterContextHolder(context);
holder.start();
}
holder.addRef();
return holder.getKeyspace();
}