当前位置: 首页>>代码示例>>Java>>正文


Java Keyspace类代码示例

本文整理汇总了Java中com.netflix.astyanax.Keyspace的典型用法代码示例。如果您正苦于以下问题:Java Keyspace类的具体用法?Java Keyspace怎么用?Java Keyspace使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Keyspace类属于com.netflix.astyanax包,在下文中一共展示了Keyspace类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCfSplits

import com.netflix.astyanax.Keyspace; //导入依赖的package包/类
private List<CfSplit> getCfSplits(Table tbl, int desiredRecordsPerSplit, @Nullable String fromKey) {
    checkNotNull(tbl, "table");

    AstyanaxTable table = (AstyanaxTable) tbl;
    AstyanaxStorage storage = table.getReadStorage();
    DeltaPlacement placement = (DeltaPlacement) storage.getPlacement();
    Keyspace keyspace = placement.getKeyspace().getAstyanaxKeyspace();
    ColumnFamily<ByteBuffer, DeltaKey> cf = placement.getBlockedDeltaColumnFamily();

    // Create at least one split per shard, perhaps more if a shard is large.
    List<CfSplit> splits = Lists.newArrayList();
    Iterator<ByteBufferRange> it = storage.scanIterator(fromKey);
    Collection<TokenRange> allTokenRanges = describeCassandraTopology(keyspace).values();
    while (it.hasNext()) {
        ByteBufferRange keyRange = it.next();

        String start = toTokenString(keyRange.getStart());
        String end = toTokenString(keyRange.getEnd());

        splits.addAll(getCfSplits(keyspace, cf, start, end, desiredRecordsPerSplit, allTokenRanges));
    }
    return splits;
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:24,代码来源:AstyanaxBlockedDataReaderDAO.java

示例2: describeCassandraTopology

import com.netflix.astyanax.Keyspace; //导入依赖的package包/类
/**
 * Gets the topology for a Cassandra keyspace as a Multimap, where the keys identify a rack (or availability zone
 * in Amazon) and the values are the token ranges for each host in that rack.  For example, for a well distributed
 * ring of 12 hosts and a replication factor of 3 this method would return a Multimap with 3 keys and each key would
 * contain 4 token ranges.
 */
private Multimap<String, TokenRange> describeCassandraTopology(final Keyspace keyspace) {
    try {
        @SuppressWarnings ("unchecked")
        ConnectionPool<Cassandra.Client> connectionPool = (ConnectionPool<Cassandra.Client>) keyspace.getConnectionPool();

        return connectionPool.executeWithFailover(
                new AbstractKeyspaceOperationImpl<Multimap<String, TokenRange>>(EmptyKeyspaceTracerFactory.getInstance().newTracer(CassandraOperationType.DESCRIBE_RING), keyspace.getKeyspaceName()) {
                    @Override
                    protected Multimap<String, TokenRange> internalExecute(Cassandra.Client client, ConnectionContext state)
                            throws Exception {
                        Multimap<String, TokenRange> racks = ArrayListMultimap.create();
                        for (org.apache.cassandra.thrift.TokenRange tokenRange : client.describe_local_ring(getKeyspace())) {
                            // The final local endpoint "owns" the token range, the rest are for replication
                            EndpointDetails endpointDetails = Iterables.getLast(tokenRange.getEndpoint_details());
                            racks.put(endpointDetails.getRack(),
                                    new TokenRangeImpl(tokenRange.getStart_token(), tokenRange.getEnd_token(), tokenRange.getEndpoints()));
                        }
                        return Multimaps.unmodifiableMultimap(racks);
                    }
                },
                keyspace.getConfig().getRetryPolicy().duplicate()).getResult();
    } catch (ConnectionException e) {
        throw Throwables.propagate(e);
    }
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:32,代码来源:AstyanaxBlockedDataReaderDAO.java

示例3: getCfSplits

import com.netflix.astyanax.Keyspace; //导入依赖的package包/类
private List<CfSplit> getCfSplits(Table tbl, int desiredRecordsPerSplit, @Nullable String fromKey) {
    checkNotNull(tbl, "table");

    AstyanaxTable table = (AstyanaxTable) tbl;
    AstyanaxStorage storage = table.getReadStorage();
    DeltaPlacement placement = (DeltaPlacement) storage.getPlacement();
    Keyspace keyspace = placement.getKeyspace().getAstyanaxKeyspace();
    ColumnFamily<ByteBuffer, UUID> cf = placement.getDeltaColumnFamily();

    // Create at least one split per shard, perhaps more if a shard is large.
    List<CfSplit> splits = Lists.newArrayList();
    Iterator<ByteBufferRange> it = storage.scanIterator(fromKey);
    Collection<TokenRange> allTokenRanges = describeCassandraTopology(keyspace).values();
    while (it.hasNext()) {
        ByteBufferRange keyRange = it.next();

        String start = toTokenString(keyRange.getStart());
        String end = toTokenString(keyRange.getEnd());

        splits.addAll(getCfSplits(keyspace, cf, start, end, desiredRecordsPerSplit, allTokenRanges));
    }
    return splits;
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:24,代码来源:AstyanaxDataReaderDAO.java

示例4: setUp

import com.netflix.astyanax.Keyspace; //导入依赖的package包/类
@BeforeMethod
public void setUp() throws Exception {
    CassandraKeyspace keyspace = mock(CassandraKeyspace.class);

    _astyanaxStatement = mock(CqlStatement.class);
    when(_astyanaxStatement.withCql(_queryString)).thenReturn(_astyanaxStatement);
    when(_astyanaxStatement.withConsistencyLevel(any())).thenReturn(_astyanaxStatement);

    Keyspace astyanaxKeyspace = mock(Keyspace.class);
    when(astyanaxKeyspace.prepareCqlStatement()).thenReturn(_astyanaxStatement);

    when(keyspace.getAstyanaxKeyspace()).thenReturn(astyanaxKeyspace);

    _cqlSession = mock(Session.class);
    when(keyspace.getCqlSession()).thenReturn(_cqlSession);

    _clock = mock(Clock.class);

    _healthCheck = new CassandraHealthCheck(keyspace, _queryString, _clock);
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:21,代码来源:TestCassandraHealthCheck.java

示例5: AstyanaxKeyColumnValueStore

import com.netflix.astyanax.Keyspace; //导入依赖的package包/类
AstyanaxKeyColumnValueStore(String columnFamilyName,
                            Keyspace keyspace,
                            AstyanaxStoreManager storeManager,
                            RetryPolicy retryPolicy) {
    this.keyspace = keyspace;
    this.columnFamilyName = columnFamilyName;
    this.retryPolicy = retryPolicy;
    this.storeManager = storeManager;

    entryGetter = new AstyanaxGetter(storeManager.getMetaDataSchema(columnFamilyName));

    columnFamily = new ColumnFamily<ByteBuffer, ByteBuffer>(
            this.columnFamilyName,
            ByteBufferSerializer.get(),
            ByteBufferSerializer.get());

}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:18,代码来源:AstyanaxKeyColumnValueStore.java

示例6: clearStorage

import com.netflix.astyanax.Keyspace; //导入依赖的package包/类
@Override
public void clearStorage() throws BackendException {
    try {
        Cluster cluster = clusterContext.getClient();

        Keyspace ks = cluster.getKeyspace(keySpaceName);

        // Not a big deal if Keyspace doesn't not exist (dropped manually by user or tests).
        // This is called on per test setup basis to make sure that previous test cleaned
        // everything up, so first invocation would always fail as Keyspace doesn't yet exist.
        if (ks == null)
            return;

        for (ColumnFamilyDefinition cf : cluster.describeKeyspace(keySpaceName).getColumnFamilyList()) {
            ks.truncateColumnFamily(new ColumnFamily<Object, Object>(cf.getName(), null, null));
        }
    } catch (ConnectionException e) {
        throw new PermanentBackendException(e);
    }
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:21,代码来源:AstyanaxStoreManager.java

示例7: getCompressionOptions

import com.netflix.astyanax.Keyspace; //导入依赖的package包/类
@Override
public Map<String, String> getCompressionOptions(String cf) throws BackendException {
    try {
        Keyspace k = keyspaceContext.getClient();

        KeyspaceDefinition kdef = k.describeKeyspace();

        if (null == kdef) {
            throw new PermanentBackendException("Keyspace " + k.getKeyspaceName() + " is undefined");
        }

        ColumnFamilyDefinition cfdef = kdef.getColumnFamily(cf);

        if (null == cfdef) {
            throw new PermanentBackendException("Column family " + cf + " is undefined");
        }

        return cfdef.getCompressionOptions();
    } catch (ConnectionException e) {
        throw new PermanentBackendException(e);
    }
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:23,代码来源:AstyanaxStoreManager.java

示例8: getContext

import com.netflix.astyanax.Keyspace; //导入依赖的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;
}
 
开发者ID:OpenTSDB,项目名称:asynccassandra,代码行数:27,代码来源:HBaseClient.java

示例9: start

import com.netflix.astyanax.Keyspace; //导入依赖的package包/类
@Override
public List<Future<OperationResult<ColumnList<byte[]>>>> start() {
	ColumnFamily cf = info1.getColumnFamilyObj();
	Keyspace keyspace = columnFamilies.getKeyspace();
	
	List<Future<OperationResult<ColumnList<byte[]>>>> futures = new ArrayList<Future<OperationResult<ColumnList<byte[]>>>>();

	for(byte[] val : values) {
		Key from = new Key(val, true);
		Key to = new Key(val, true);
		byte[] rowKey = scanInfo.getRowKey();
		
		CompositeRangeBuilder range = CassandraSession.setupRangeBuilder(from, to, info1, reverse);
		ColumnFamilyQuery query = keyspace.prepareQuery(cf);
		RowQuery<byte[], byte[]> rowQuery = query.getKey(rowKey).withColumnRange(range);
		Future future = executeAsync(rowQuery);
		futures.add(future);
	}
	
	return futures;
}
 
开发者ID:guci314,项目名称:playorm,代码行数:22,代码来源:StartQueryManyKeys.java

示例10: find

import com.netflix.astyanax.Keyspace; //导入依赖的package包/类
@Override
public AbstractCursor<KeyValue<Row>> find(DboTableMeta colFamily,
		DirectCursor<byte[]> rowKeys, Cache cache, int batchSize, BatchListener list, MetaLookup mgr) {
	Info info = columnFamilies.fetchColumnFamilyInfo(colFamily.getColumnFamily(), mgr);
	if(info == null) {
		//If there is no column family in cassandra, then we need to return no rows to the user...
		return new CursorReturnsEmptyRows(rowKeys);
	}
	
	ColumnType type = info.getColumnType();
	if(type != ColumnType.ANY_EXCEPT_COMPOSITE) {
		throw new UnsupportedOperationException("Finding on composite type="+colFamily+" not allowed here, you should be using column slice as these rows are HUGE!!!!");
	}
	
	Keyspace keyspace = columnFamilies.getKeyspace();
	CursorKeysToRows2 cursor = new CursorKeysToRows2(rowKeys, batchSize, list, rowProvider);
	cursor.setupMore(keyspace, colFamily, info, cache);
	return cursor;
}
 
开发者ID:guci314,项目名称:playorm,代码行数:20,代码来源:CassandraSession.java

示例11: ThriftCassandraDao

import com.netflix.astyanax.Keyspace; //导入依赖的package包/类
public ThriftCassandraDao(Class<T> parameterClass,
                          Keyspace keyspace,
                          ObjectMapper objectMapper,
                          Codec codec,
                          String columnFamilyName) {
    this.parameterClass = parameterClass;
    this.keyspace = keyspace;
    this.objectMapper = objectMapper;
    this.codec = codec;
    this.columnFamily = ColumnFamily.newColumnFamily(
        columnFamilyName,
        StringSerializer.get(),
        StringSerializer.get(),
        ByteBufferSerializer.get()
    );
}
 
开发者ID:spinnaker,项目名称:scheduled-actions,代码行数:17,代码来源:ThriftCassandraDao.java

示例12: setupAstyanaxContext

import com.netflix.astyanax.Keyspace; //导入依赖的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();
}
 
开发者ID:Esquive,项目名称:iticrawler,代码行数:22,代码来源:StorageCluster.java

示例13: deleteCassandraKeySpace

import com.netflix.astyanax.Keyspace; //导入依赖的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);
        }
    }
 
开发者ID:Parth-Brahmbhatt,项目名称:storm-smoke-test,代码行数:25,代码来源:CleanupUtils.java

示例14: createKeyspace

import com.netflix.astyanax.Keyspace; //导入依赖的package包/类
private void createKeyspace(String keyspaceName, String simpleStrategy, int replicationFactor) {

        Keyspace ks = astyanaxContext.getClient();

        Properties props = new Properties();
        props.setProperty("name", keyspaceName);
        props.setProperty("strategy_class", simpleStrategy);
        props.setProperty("strategy_options.replication_factor", String.valueOf(replicationFactor));

        try {
            ks.createKeyspaceIfNotExists(props);
        } catch (ConnectionException e) {
            log.error(e);
        }

        log.info("Created keyspace " + keyspaceName);
    }
 
开发者ID:cosh,项目名称:CassandraBenchmark,代码行数:18,代码来源:AstyanaxBenchmark.java

示例15: executeBatch

import com.netflix.astyanax.Keyspace; //导入依赖的package包/类
private ListenableFuture<OperationResult<Void>> executeBatch(final List<Mutation> mutations, final Keyspace keyspace) {
    final long startTime = System.nanoTime();

    final MutationBatch batch = keyspace
            .prepareMutationBatch()
            .withAtomicBatch(false)
            .withConsistencyLevel(ConsistencyLevel.CL_ONE);

    for (Mutation aMutation : mutations) {
        batch.withRow(DefaultModel.model, aMutation.getIdentity())
                .putColumn(aMutation.getTimeStamp(), aMutation.getCommunication(), DefaultModel.valueSerializer, 0);
    }

    try {
        final ListenableFuture<OperationResult<Void>> operationResultListenableFuture = batch.executeAsync();

        operationResultListenableFuture.addListener(new OneShotTask(startTime), executorService);

    } catch (ConnectionException e) {
        logger.error("error inserting batch", e);
    }

    return null;
}
 
开发者ID:cosh,项目名称:CassandraBenchmark,代码行数:25,代码来源:BatchInsertAsyncBenchmark.java


注:本文中的com.netflix.astyanax.Keyspace类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。