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


Java Cassandra类代码示例

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


Cassandra类属于org.apache.cassandra.thrift包,在下文中一共展示了Cassandra类的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: 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);
    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:pgaref,项目名称:ACaZoo,代码行数:21,代码来源:AbstractColumnFamilyInputFormat.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: getClientFromAddressList

import org.apache.cassandra.thrift.Cassandra; //导入依赖的package包/类
private Cassandra.Client getClientFromAddressList() throws IOException
{
    List<IOException> exceptions = new ArrayList<IOException>();
    // randomly select host to connect to
    List<String> addresses = new ArrayList<>(this.addresses);
    Collections.shuffle(addresses);
    for (String address : addresses) {
        try {
            return createConnection(address, port, factoryClassName);
        }
        catch (IOException ioe) {
            exceptions.add(ioe);
        }
    }
    log.error("failed to connect to any initial addresses");
    for (IOException exception : exceptions) {
        log.error(exception);
    }
    throw exceptions.get(exceptions.size() - 1);
}
 
开发者ID:y-lan,项目名称:presto,代码行数:21,代码来源:CassandraThriftConnectionFactory.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("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

示例7: 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

示例8: getColumnFamily

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

示例9: 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

示例10: getKeyspace

import org.apache.cassandra.thrift.Cassandra; //导入依赖的package包/类
@Test
public void getKeyspace() throws Exception {
	TTransport ttransport = ctDataSource.getTTransport();
	TProtocol tprotocol = new TBinaryProtocol(ttransport);
	Cassandra.Client client = new Cassandra.Client(tprotocol);
	//
	long beg = System.currentTimeMillis();
	String KEYSPACE = "system";
	//
	KsDef kd = client.describe_keyspace(KEYSPACE);// NotFoundException
	ttransport.close();
	//
	long end = System.currentTimeMillis();
	System.out.println((end - beg) + " at mills.");
	//
	System.out.println(kd);
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:18,代码来源:CtDataSourceImplTest.java

示例11: CassandraConnection

import org.apache.cassandra.thrift.Cassandra; //导入依赖的package包/类
/**
 * Construct an CassandaraConnection with optional authentication.
 * 
 * @param host the host to connect to
 * @param port the port to use
 * @param username the username to authenticate with (may be null
 * for no authentication)
 * @param password the password to authenticate with (may be null
 * for no authentication)
 * @throws Exception if the connection fails
 */
public CassandraConnection(String host, int port,
    String username, String password, int timeout) throws Exception {
  TSocket socket = new TSocket(host, port);
  if (timeout > 0) {
    socket.setTimeout(timeout);
  }
  
  m_transport = new TFramedTransport(socket);
  TProtocol protocol = new TBinaryProtocol(m_transport);
  m_client = new Cassandra.Client(protocol);      
  m_transport.open();
  
  if (!Const.isEmpty(username) && !Const.isEmpty(password)) {
    Map<String, String> creds = new HashMap<String, String>();
    creds.put("username", username);
    creds.put("password", password);
    m_client.login(new AuthenticationRequest(creds));
  }
}
 
开发者ID:javachen,项目名称:learning-hadoop,代码行数:31,代码来源:CassandraConnection.java

示例12: 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

示例13: 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;
    try {
        transport = ConfigHelper.getClientTransportFactory(conf).openTransport(location, port, conf);
    } catch (Exception e) {
        throw new TTransportException("Failed to open a transport to " + location + ":" + port + ".", e);
    }
    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:wso2,项目名称:wso2-cassandra,代码行数:26,代码来源:AbstractColumnFamilyInputFormat.java

示例14: 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

示例15: open

import org.apache.cassandra.thrift.Cassandra; //导入依赖的package包/类
public void open() {
    try {
        // FIXME: Is this the optimal code for thrift 0.5? This code seems to change
        // with every new Cassandra release and they never update the sample code.
        // Probably need to get the source package and look at the unit tests to verify.
        TSocket socket = new TSocket(this.host, this.port);
        transport = new TFramedTransport(socket);
        TProtocol protocol = new TBinaryProtocol(transport);
        client = new Cassandra.Client(protocol);
        transport.open();
    }
    catch (TTransportException exc) {
        close();
        throw new StorageException("Error opening Cassandra connection", exc);
    }
}
 
开发者ID:opendaylight,项目名称:archived-net-virt-platform,代码行数:17,代码来源:Connection.java


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