本文整理汇总了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);
}
}
示例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()));
}
示例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;
}
示例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);
}
}
示例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();
}
}
示例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();
}
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
}
}
}
示例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();
}
示例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();
}
示例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);
}
}