本文整理汇总了Java中com.netflix.astyanax.connectionpool.exceptions.ConnectionException类的典型用法代码示例。如果您正苦于以下问题:Java ConnectionException类的具体用法?Java ConnectionException怎么用?Java ConnectionException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConnectionException类属于com.netflix.astyanax.connectionpool.exceptions包,在下文中一共展示了ConnectionException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: put
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException; //导入依赖的package包/类
@Override
public void put(Buffer stream, Callback<Boolean> callback) {
MutationBatch m = keyspace.prepareMutationBatch();
BufferIterator it = stream.iterator();
while (it.hasNext()) {
Buffer keyView = it.next();
Buffer valueView = it.next();
if (valueView != null) {
m.withRow(MWG, keyView.data()).putColumn(0, valueView.data());
}
}
try {
@SuppressWarnings("unused")
OperationResult<Void> result = m.execute();
callback.on(true);
} catch (ConnectionException e) {
callback.on(false);
}
}
示例2: get
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException; //导入依赖的package包/类
@Override
public String get(String key, String versionColumnName) {
NormalizedKey normalizedKey = keyNormalizer.normalizeKey(key);
ColumnList<String> result;
try {
result = keyspace.prepareQuery(columnFamily).getKey(normalizedKey.get())
.withColumnRange(new RangeBuilder().setStart(versionColumnName).setLimit(1).setReversed(true).build())
.execute().getResult();
} catch (ConnectionException ce) {
throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, messageCatalog.getMessage("DbCommsError"), ce);
}
if (!result.isEmpty()) {
return result.getColumnByIndex(0).getStringValue();
}
return null;
}
示例3: getFolderCount
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException; //导入依赖的package包/类
private int getFolderCount(String cf, String rawPrefix, String childName) {
NormalizedKey prefix = keyNormalizer.normalizePrefix(rawPrefix);
ColumnList<String> result;
try {
ColumnFamily<String, String> cFam = ColumnFamily.newColumnFamily(cf, StringSerializer.get(), StringSerializer.get());
result = keyspace.prepareQuery(cFam).getKey(prefix.get())
.withColumnRange(new RangeBuilder().setStart(childName).setEnd(childName).setLimit(1).build())
.execute().getResult();
} catch (ConnectionException ce) {
throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, messageCatalog.getMessage("DbCommsError"), ce);
}
if (!result.isEmpty()) {
return result.getColumnByName(childName).getIntegerValue();
}
return 0;
}
示例4: getFolderChildren
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException; //导入依赖的package包/类
private List<RaptureFolderInfo> getFolderChildren(String cf, NormalizedKey prefix) {
List<RaptureFolderInfo> ret = new ArrayList<RaptureFolderInfo>();
ColumnList<String> result;
try {
ColumnFamily<String, String> cFam = ColumnFamily.newColumnFamily(cf, StringSerializer.get(), StringSerializer.get());
result = keyspace.prepareQuery(cFam).getKey(prefix.get()).withColumnRange(new RangeBuilder().setLimit(1000).build()).execute().getResult();
} catch (ConnectionException ce) {
throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, messageCatalog.getMessage("DbCommsError"), ce);
}
for (Column<String> column : result) {
RaptureFolderInfo info = new RaptureFolderInfo();
info.setName(column.getName());
info.setFolder(column.getIntegerValue() != -1);
ret.add(info);
}
return ret;
}
示例5: getPointsAfter
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException; //导入依赖的package包/类
public List<SeriesValue> getPointsAfter(String key, String startColumn, String endColumn, int maxNumber, boolean reverse) throws IOException {
List<SeriesValue> ret = new ArrayList<SeriesValue>();
int limit = (maxNumber > overflowLimit) ? overflowLimit : maxNumber;
ColumnList<String> result;
try {
result = keyspace.prepareQuery(columnFamily).getKey(key)
.withColumnRange(new RangeBuilder().setStart(startColumn).setEnd(endColumn).setLimit(limit).setReversed(reverse).build()).execute()
.getResult();
} catch (ConnectionException ce) {
throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, messageCatalog.getMessage("DbCommsError"), ce);
}
if (result.size() > overflowLimit) {
throw RaptureExceptionFactory.create(messageCatalog.getMessage("SmallerPages", "" + overflowLimit));
}
for (Column<String> column : result) {
ret.add(makeSeriesValue(column));
}
return ret;
}
示例6: addPoint
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException; //导入依赖的package包/类
public void addPoint(String key, List<SeriesValue> values) {
boolean nullKey = false;
try {
registerKey(key);
MutationBatch m = keyspace.prepareMutationBatch();
ColumnListMutation<String> mut = m.withRow(columnFamily, key);
for (SeriesValue value : values) {
if (value.getColumn() == null) nullKey = true;
else mut.putColumn(value.getColumn(), SeriesValueCodec.encodeValue(value), null);
}
m.execute();
} catch (ConnectionException ce) {
throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, messageCatalog.getMessage("DbCommsError"), ce);
} catch (UnsupportedEncodingException e) {
throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, messageCatalog.getMessage("BadSeriesValue"), e);
}
if (nullKey) throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, messageCatalog.getMessage("BadKey"));
}
示例7: createSchema
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException; //导入依赖的package包/类
private void createSchema() throws ConnectionException {
boolean keyspaceExists = false;
try {
if (keyspace.describeKeyspace() != null) {
keyspaceExists = true;
}
} catch(BadRequestException e) {
// do nothing, keyspace does not exist
}
if(!keyspaceExists) {
keyspace.createKeyspace(ImmutableMap.<String, Object> builder()
.put("strategy_options", ImmutableMap.<String, Object> builder().put("replication_factor", "1").build())
.put("strategy_class", "SimpleStrategy").build());
}
if (keyspace.describeKeyspace().getColumnFamily(blobCFName) == null) {
keyspace.createColumnFamily(blobCF,
ImmutableMap.<String, Object> builder().put("key_validation_class", "UTF8Type").put("comparator_type", "UTF8Type").build());
}
}
示例8: newPlacement
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException; //导入依赖的package包/类
@Override
public Placement newPlacement(String placement) throws ConnectionException {
String[] parsed = PlacementUtil.parsePlacement(placement);
String keyspaceName = parsed[0];
String cfPrefix = parsed[1];
CassandraKeyspace keyspace = _keyspaceMap.get(keyspaceName);
if (keyspace == null) {
throw new UnknownPlacementException(format(
"Placement string refers to unknown or non-local Cassandra keyspace: %s", keyspaceName), placement);
}
KeyspaceDefinition keyspaceDef = keyspace.getAstyanaxKeyspace().describeKeyspace();
ColumnFamily<ByteBuffer,Composite> columnFamily = getColumnFamily(keyspaceDef, cfPrefix, "blob", placement,
new SpecificCompositeSerializer(CompositeType.getInstance(Arrays.<AbstractType<?>>asList(
AsciiType.instance, IntegerType.instance))));
return new BlobPlacement(placement, keyspace, columnFamily);
}
示例9: describeCassandraTopology
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException; //导入依赖的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);
}
}
示例10: newPlacement
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException; //导入依赖的package包/类
@Override
public Placement newPlacement(String placement) throws ConnectionException {
String[] parsed = PlacementUtil.parsePlacement(placement);
String keyspaceName = parsed[0];
String cfPrefix = parsed[1];
CassandraKeyspace keyspace = _keyspaceMap.get(keyspaceName);
if (keyspace == null) {
throw new UnknownPlacementException(format(
"Placement string refers to unknown or non-local Cassandra keyspace: %s", keyspaceName), placement);
}
KeyspaceDefinition keyspaceDef = keyspace.getAstyanaxKeyspace().describeKeyspace();
AnnotatedCompositeSerializer<DeltaKey> deltaKeySerializer = new AnnotatedCompositeSerializer<DeltaKey>(DeltaKey.class);
// DDL's are not actually configurable due to the way we abstract the names from the placements here.
// In the future, we should either phase out the DDL config or change the implementation here to conform to it.
ColumnFamily<ByteBuffer, UUID> deltaCf = getColumnFamily(keyspaceDef, cfPrefix, "delta", placement, TimeUUIDSerializer.get());
ColumnFamily<ByteBuffer, DeltaKey> blockedDeltaCf = getColumnFamily(keyspaceDef, cfPrefix, "delta_v2", placement, deltaKeySerializer);
ColumnFamily<ByteBuffer, UUID> auditCf = getColumnFamily(keyspaceDef, cfPrefix, "audit", placement, TimeUUIDSerializer.get());
ColumnFamily<ByteBuffer, UUID> deltaHistoryCf = getColumnFamily(keyspaceDef, cfPrefix, "history", placement, TimeUUIDSerializer.get());
// Calculate the data centers on demand since they may change in a live system.
return new DeltaPlacement(placement, keyspace, deltaCf, blockedDeltaCf, auditCf, deltaHistoryCf);
}
示例11: newTracer
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException; //导入依赖的package包/类
@Override
public CassandraOperationTracer newTracer(final CassandraOperationType type) {
return new CassandraOperationTracer() {
private long _start;
@Override
public CassandraOperationTracer start() {
checkState(_start == 0); // Verify the tracer is used in a single threaded manner.
_start = _clock.getTick();
return this;
}
@Override
public void success() {
_successTimers.getUnchecked(type).update(_clock.getTick() - _start, TimeUnit.NANOSECONDS);
_start = 0;
}
@Override
public void failure(ConnectionException e) {
_failureTimers.getUnchecked(type).update(_clock.getTick() - _start, TimeUnit.NANOSECONDS);
_start = 0;
}
};
}
示例12: clearStorage
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException; //导入依赖的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);
}
}
示例13: getCompressionOptions
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException; //导入依赖的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);
}
}
示例14: initialize
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void initialize() {
try {
ByteBufferRange range = new RangeBuilder().setReversed(reversed).build();
ColumnFamily<byte[], byte[]> cf = cfInfo.getColumnFamilyObj();
ColumnFamilyQuery<byte[], byte[]> cfQuery = keyspace.prepareQuery(cf);
AllRowsQuery<byte[], byte[]> query = cfQuery.getAllRows();
query.withColumnRange(range)
.setExceptionCallback(new ExcCallback());
if(batchSize != null) {
if(batchSize < 10)
throw new RuntimeException("batchSize must be 10 or greater and preferably around 500 is good.");
query.setRowLimit(batchSize);
}
OperationResult<Rows<byte[], byte[]>> opResult = query.execute();
iterator = opResult.getResult().iterator();
} catch (ConnectionException e) {
throw new RuntimeException(e);
}
}
示例15: nextImpl
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException; //导入依赖的package包/类
@Override
public Holder<T> nextImpl() {
if(!forward)
throw new IllegalStateException("You must call beforeFirst to traverse the cursor forward, you cannot call next after calling previous due to limitations of talking to noSql apis");
try {
fetchMoreResultsImpl();
pointer++;
if(pointer >= subList.size())
return null; //no more results
Column<byte[]> column = subList.get(pointer);
return buildHolder(column);
} catch (ConnectionException e) {
throw new RuntimeException(e);
}
}