Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*******************************************************************************
* Copyright 2011 Netflix
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package com.netflix.astyanax.thrift;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.concurrent.ConcurrentMap;
import org.apache.cassandra.thrift.Cassandra;
import org.apache.cassandra.thrift.Cassandra.Client;
import org.apache.cassandra.thrift.CfDef;
import org.apache.cassandra.thrift.KsDef;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.netflix.astyanax.AstyanaxConfiguration;
import com.netflix.astyanax.Cluster;
import com.netflix.astyanax.Keyspace;
import com.netflix.astyanax.CassandraOperationType;
import com.netflix.astyanax.KeyspaceTracerFactory;
import com.netflix.astyanax.connectionpool.ConnectionPool;
import com.netflix.astyanax.connectionpool.OperationResult;
import com.netflix.astyanax.connectionpool.ConnectionContext;
import com.netflix.astyanax.connectionpool.exceptions.BadRequestException;
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
import com.netflix.astyanax.connectionpool.exceptions.NotFoundException;
import com.netflix.astyanax.connectionpool.exceptions.OperationException;
import com.netflix.astyanax.connectionpool.exceptions.SchemaDisagreementException;
import com.netflix.astyanax.ddl.ColumnDefinition;
import com.netflix.astyanax.ddl.ColumnFamilyDefinition;
import com.netflix.astyanax.ddl.KeyspaceDefinition;
import com.netflix.astyanax.ddl.SchemaChangeResult;
import com.netflix.astyanax.ddl.impl.SchemaChangeResponseImpl;
import com.netflix.astyanax.retry.RunOnce;
import com.netflix.astyanax.thrift.ddl.*;
public class ThriftClusterImpl implements Cluster {
private static final Logger LOG = LoggerFactory.getLogger(ThriftClusterImpl.class);
private static final int MAX_SCHEMA_CHANGE_ATTEMPTS = 6;
private static final int SCHEMA_DISAGREEMENT_BACKOFF = 10000;
private final ConnectionPool connectionPool;
private final ConcurrentMap keyspaces;
private final AstyanaxConfiguration config;
private final KeyspaceTracerFactory tracerFactory;
public ThriftClusterImpl(
AstyanaxConfiguration config,
ConnectionPool connectionPool,
KeyspaceTracerFactory tracerFactory) {
this.config = config;
this.connectionPool = connectionPool;
this.tracerFactory = tracerFactory;
this.keyspaces = Maps.newConcurrentMap();
}
@Override
public String describeClusterName() throws ConnectionException {
return connectionPool.executeWithFailover(
new AbstractOperationImpl(tracerFactory.newTracer(CassandraOperationType.DESCRIBE_CLUSTER)) {
@Override
public String internalExecute(Client client, ConnectionContext context) throws Exception {
return client.describe_cluster_name();
}
}, config.getRetryPolicy().duplicate()).getResult();
}
@Override
public String describeSnitch() throws ConnectionException {
return connectionPool.executeWithFailover(
new AbstractOperationImpl(tracerFactory.newTracer(CassandraOperationType.DESCRIBE_SNITCH)) {
@Override
public String internalExecute(Client client, ConnectionContext context) throws Exception {
return client.describe_snitch();
}
}, config.getRetryPolicy().duplicate()).getResult();
}
@Override
public String describePartitioner() throws ConnectionException {
return connectionPool
.executeWithFailover(
new AbstractOperationImpl(
tracerFactory.newTracer(CassandraOperationType.DESCRIBE_PARTITIONER)) {
@Override
public String internalExecute(Client client, ConnectionContext context) throws Exception {
return client.describe_partitioner();
}
}, config.getRetryPolicy().duplicate()).getResult();
}
@Override
public Map> describeSchemaVersions() throws ConnectionException {
return connectionPool.executeWithFailover(
new AbstractOperationImpl