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


Java Cassandra.Client方法代码示例

本文整理汇总了Java中org.apache.cassandra.thrift.Cassandra.Client方法的典型用法代码示例。如果您正苦于以下问题:Java Cassandra.Client方法的具体用法?Java Cassandra.Client怎么用?Java Cassandra.Client使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.cassandra.thrift.Cassandra的用法示例。


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

示例1: describeCassandraTopology

import org.apache.cassandra.thrift.Cassandra; //导入方法依赖的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

示例2: setup

import org.apache.cassandra.thrift.Cassandra; //导入方法依赖的package包/类
private void setup(String server, int port) throws Exception
{
    /* Establish a thrift connection to the cassandra instance */
    TSocket socket = new TSocket(server, port);
    System.out.println(" connected to " + server + ":" + port + ".");
    TBinaryProtocol binaryProtocol = new TBinaryProtocol(new TFramedTransport(socket));
    Cassandra.Client cassandraClient = new Cassandra.Client(binaryProtocol);
    socket.open();
    thriftClient = cassandraClient;
    String seed = DatabaseDescriptor.getSeeds().iterator().next().getHostAddress();
    conf = new Configuration();
    ConfigHelper.setOutputPartitioner(conf, DatabaseDescriptor.getPartitioner().getClass().getName());
    ConfigHelper.setOutputInitialAddress(conf, seed);
    ConfigHelper.setOutputRpcPort(conf, Integer.toString(DatabaseDescriptor.getRpcPort()));

}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:17,代码来源:TestRingCache.java

示例3: getColumn

import org.apache.cassandra.thrift.Cassandra; //导入方法依赖的package包/类
/**
 * getting a column
 *
 * @param client
 * @param keyspace
 * @param columnFamily
 * @return
 */
protected static ColumnDef getColumn(Cassandra.Client client,
		String keyspace, String columnFamily, String column) {
	ColumnDef result = null;
	//
	try {
		CfDef cd = getColumnFamily(client, keyspace, columnFamily);
		for (ColumnDef entry : cd.getColumn_metadata()) {
			if (new String(entry.getName()).equals(column)) {
				result = entry;
				break;
			}
		}
	} catch (Exception ex) {
		ex.printStackTrace();
	}
	return result;
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:26,代码来源:CassandraThriftDDLTest.java

示例4: CassandraClient

import org.apache.cassandra.thrift.Cassandra; //导入方法依赖的package包/类
CassandraClient(String hostName, int port, boolean framed) throws TTransportException
{
    TSocket socket = new TSocket(hostName, port);
    transport = (framed) ? socket : new TFastFramedTransport(socket);
    transport.open();
    client = new Cassandra.Client(new TBinaryProtocol(transport));

    try
    {
        client.set_cql_version("3.0.0");
    }
    catch (Exception e)
    {
        throw new RuntimeException(e);
    }
}
 
开发者ID:pgaref,项目名称:ACaZoo,代码行数:17,代码来源:Shuffle.java

示例5: connectToKeyspace

import org.apache.cassandra.thrift.Cassandra; //导入方法依赖的package包/类
@Test
public void connectToKeyspace() throws Exception
{
    TTransport tr = new TFramedTransport(new TSocket("localhost", Integer.getInteger( "rpcPort", 9160 )));
    TProtocol proto = new TBinaryProtocol(tr);
    Cassandra.Client client = new Cassandra.Client(proto);
    tr.open();
    try
    {
        assertThat(client.describe_keyspace("testkeyspace").getStrategy_options().entrySet(),
                hasItem((Map.Entry<String, String>)new AbstractMap.SimpleEntry<String,String>("replication_factor","1")));
    } finally
    {
        tr.close();
    }
}
 
开发者ID:mojohaus,项目名称:cassandra-maven-plugin,代码行数:17,代码来源:SmokeIT.java

示例6: connectToKeyspace

import org.apache.cassandra.thrift.Cassandra; //导入方法依赖的package包/类
@Test
public void connectToKeyspace() throws Exception
{
    TTransport tr = new TFramedTransport(new TSocket("localhost", Integer.getInteger( "rpcPort", 9160 )));
    TProtocol proto = new TBinaryProtocol(tr);
    Cassandra.Client client = new Cassandra.Client(proto);
    tr.open();
    try
    {
        assertThat(client.describe_keyspace("testkeyspacewithspace").getStrategy_options().entrySet(),
                hasItem((Map.Entry<String, String>)new AbstractMap.SimpleEntry<String,String>("replication_factor","1")));
    } finally
    {
        tr.close();
    }
}
 
开发者ID:mojohaus,项目名称:cassandra-maven-plugin,代码行数:17,代码来源:SmokeIT.java

示例7: createAuthenticatedClient

import org.apache.cassandra.thrift.Cassandra; //导入方法依赖的package包/类
public static Cassandra.Client createAuthenticatedClient(String location, int port, Configuration conf) throws Exception
{
    logger.debug("Creating authenticated client for CF input format");
    TTransport transport = ConfigHelper.getClientTransportFactory(conf).openTransport(location, port, conf);
    TProtocol binaryProtocol = new TBinaryProtocol(transport, true, true);
    Cassandra.Client client = new Cassandra.Client(binaryProtocol);

    // log in
    client.set_keyspace(ConfigHelper.getInputKeyspace(conf));
    if (ConfigHelper.getInputKeyspaceUserName(conf) != null)
    {
        Map<String, String> creds = new HashMap<String, String>();
        creds.put(IAuthenticator.USERNAME_KEY, ConfigHelper.getInputKeyspaceUserName(conf));
        creds.put(IAuthenticator.PASSWORD_KEY, ConfigHelper.getInputKeyspacePassword(conf));
        AuthenticationRequest authRequest = new AuthenticationRequest(creds);
        client.login(authRequest);
    }
    logger.debug("Authenticated client for CF input format created successfully");
    return client;
}
 
开发者ID:dprguiuc,项目名称:Cassandra-Wasef,代码行数:21,代码来源:AbstractColumnFamilyInputFormat.java

示例8: getColumnValue

import org.apache.cassandra.thrift.Cassandra; //导入方法依赖的package包/类
private String getColumnValue(String ks, String cf, String colName, String key, String validator)
throws AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, IOException
{
    Cassandra.Client client = getClient();
    client.set_keyspace(ks);

    ByteBuffer key_user_id = ByteBufferUtil.bytes(key);

    long timestamp = System.currentTimeMillis();
    ColumnPath cp = new ColumnPath(cf);
    ColumnParent par = new ColumnParent(cf);
    cp.column = ByteBufferUtil.bytes(colName);

    // read
    ColumnOrSuperColumn got = client.get(key_user_id, cp, ConsistencyLevel.ONE);
    return parseType(validator).getString(got.getColumn().value);
}
 
开发者ID:wso2,项目名称:wso2-cassandra,代码行数:18,代码来源:ThriftColumnFamilyTest.java

示例9: createAuthenticatedClient

import org.apache.cassandra.thrift.Cassandra; //导入方法依赖的package包/类
public static Cassandra.Client createAuthenticatedClient(String location, int port, Configuration conf) throws Exception {
    logger.debug("Creating authenticated client for CF input format");
    //TTransport transport = ConfigHelper.getClientTransportFactory(conf).openTransport(location, port, conf);
    logger.info(">>>>>>>>>>>> Connecting to host " + location + " and port " + port);
    TTransport transport = ConfigHelper.getClientTransportFactory(conf).openTransport(location, port);
    TProtocol binaryProtocol = new TBinaryProtocol(transport, true, true);
    Cassandra.Client client = new Cassandra.Client(binaryProtocol);

    // log in
    client.set_keyspace(ConfigHelper.getInputKeyspace(conf));
    if (ConfigHelper.getInputKeyspaceUserName(conf) != null) {
        Map<String, String> creds = new HashMap<String, String>();
        creds.put(IAuthenticator.USERNAME_KEY, ConfigHelper.getInputKeyspaceUserName(conf));
        creds.put(IAuthenticator.PASSWORD_KEY, ConfigHelper.getInputKeyspacePassword(conf));
        AuthenticationRequest authRequest = new AuthenticationRequest(creds);
        client.login(authRequest);
    }
    logger.debug("Authenticated client for CF input format created successfully");
    return client;
}
 
开发者ID:2013Commons,项目名称:hive-cassandra,代码行数:21,代码来源:AbstractColumnFamilyInputFormat.java

示例10: connect

import org.apache.cassandra.thrift.Cassandra; //导入方法依赖的package包/类
/**
 * Connect cassandra and open Transport variable(tr)
 */
public Cassandra.Client connect(){
	try{
		TFramedTransport tf = new TFramedTransport(tr);
		TProtocol proto = new TBinaryProtocol(tf);
		Cassandra.Client client = new Cassandra.Client(proto);
		tr.open();

		client.set_keyspace(KEYSPACE);
		return client;
	}catch(Exception e) {
		e.printStackTrace();
	}
	
	return null;
}
 
开发者ID:YinYanfei,项目名称:CadalWorkspace,代码行数:19,代码来源:Connector.java

示例11: CasTimeBook

import org.apache.cassandra.thrift.Cassandra; //导入方法依赖的package包/类
public CasTimeBook() {
	try {
		TTransport tr = new TFramedTransport(new TSocket("10.15.61.111",
				9160));
		TProtocol proto = new TBinaryProtocol(tr);
		client = new Cassandra.Client(proto);
		tr.open();

		client.set_keyspace("CadalSecTest");

		predicate = new SlicePredicate();
		SliceRange range = new SliceRange();
		range.setStart(new byte[0]);
		range.setFinish(new byte[0]);
		range.setCount(10000);
		predicate.setSlice_range(range);

		columnParent = new ColumnParent();
		columnParent.setColumn_family("RecordMinute");
	} catch (Exception e) {
		System.out.println(e);
	}
}
 
开发者ID:YinYanfei,项目名称:CadalWorkspace,代码行数:24,代码来源:CasTimeBook.java

示例12: waitForNodeInitialization

import org.apache.cassandra.thrift.Cassandra; //导入方法依赖的package包/类
private void waitForNodeInitialization(InetAddress addr)
{
    while (true)
    {
        try
        {
            Cassandra.Client client = createClient(addr);
            client.describe_cluster_name();
            break;
        }
        catch (TException e)
        {
            LOG.debug(e.toString());
            try
            {
                Thread.sleep(1000);
            }
            catch (InterruptedException ie)
            {
                break;
            }
        }
    }
}
 
开发者ID:devdattakulkarni,项目名称:Cassandra-KVPM,代码行数:25,代码来源:CassandraServiceController.java

示例13: dropOldKeyspace

import org.apache.cassandra.thrift.Cassandra; //导入方法依赖的package包/类
private void dropOldKeyspace() throws InvalidRequestException, SchemaDisagreementException, TException {
  TTransport tr = new TFramedTransport(new TSocket("localhost", 9160));
  TProtocol proto = new TBinaryProtocol(tr);
  Cassandra.Client client = new Cassandra.Client(proto);
  tr.open();

  client.system_drop_keyspace(JANUSGRAPH);
  LOGGER.info("DROPPED keyspace janusgraph");
  tr.close();
}
 
开发者ID:marcelocf,项目名称:janusgraph_tutorial,代码行数:11,代码来源:Schema.java

示例14: getConnection

import org.apache.cassandra.thrift.Cassandra; //导入方法依赖的package包/类
private void getConnection() throws TTransportException {
    log.info(String.format("Connecting to Cassandra at %s:%d", cassHost, cassPort));
    tr = new TFramedTransport(new TSocket(cassHost, cassPort));
    proto = new TBinaryProtocol(tr);
    client = new Cassandra.Client(proto);
    tr.open();
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:8,代码来源:CassandraBase.java

示例15: CassandraThriftFacade

import org.apache.cassandra.thrift.Cassandra; //导入方法依赖的package包/类
public CassandraThriftFacade(TFramedTransport transport) {
    _transport = transport;
    _client = new Cassandra.Client(new TBinaryProtocol(_transport));
    try {
        _transport.open();
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:10,代码来源:CassandraThriftFacade.java


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