Java Code Examples for com.netflix.astyanax.connectionpool.OperationResult#getResult()
The following examples show how to use
com.netflix.astyanax.connectionpool.OperationResult#getResult() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CassandraStoreImpl.java From recipes-rss with Apache License 2.0 | 6 votes |
/** * Get the feed urls from Cassandra */ @Override public List<String> getSubscribedUrls(String userId) throws Exception{ OperationResult<ColumnList<String>> response; try { response = getKeyspace().prepareQuery(CF_SUBSCRIPTIONS).getKey(userId).execute(); } catch (NotFoundException e) { logger.error("No record found for this user: " + userId); throw e; } catch (Exception t) { logger.error("Exception occurred when fetching from Cassandra: " + t); throw t; } final List<String> items = new ArrayList<String>(); if (response != null) { final ColumnList<String> columns = response.getResult(); for (Column<String> column : columns) { items.add(column.getName()); } } return items; }
Example 2
Source File: AstyanaxStorageProvider.java From emodb with Apache License 2.0 | 5 votes |
private static <R> R execute(Execution<R> execution) { OperationResult<R> operationResult; try { operationResult = execution.execute(); } catch (ConnectionException e) { throw Throwables.propagate(e); } return operationResult.getResult(); }
Example 3
Source File: AstyanaxQueueDAO.java From emodb with Apache License 2.0 | 5 votes |
private <R> R execute(Execution<R> execution) { OperationResult<R> operationResult; try { operationResult = execution.execute(); } catch (ConnectionException e) { throw Throwables.propagate(e); } return operationResult.getResult(); }
Example 4
Source File: AstyanaxManifestPersister.java From emodb with Apache License 2.0 | 5 votes |
private <R> R execute(Execution<R> execution) { OperationResult<R> operationResult; try { operationResult = execution.execute(); } catch (ConnectionException e) { throw Throwables.propagate(e); } return operationResult.getResult(); }
Example 5
Source File: AstyanaxEventReaderDAO.java From emodb with Apache License 2.0 | 5 votes |
private <R> R execute(Execution<R> execution) { OperationResult<R> operationResult; try { operationResult = execution.execute(); } catch (ConnectionException e) { throw Throwables.propagate(e); } return operationResult.getResult(); }
Example 6
Source File: AstyanaxDataWriterDAO.java From emodb with Apache License 2.0 | 5 votes |
private <R> R execute(Execution<R> execution, String operation, Object... operationArguments) { OperationResult<R> operationResult; try { operationResult = execution.execute(); } catch (ConnectionException e) { String message = String.format(operation, operationArguments); if (isThriftFramedTransportSizeOverrun(execution, e)) { throw new ThriftFramedTransportSizeException("Thrift request to large to " + message, e); } throw new RuntimeException("Failed to " + message, e); } return operationResult.getResult(); }
Example 7
Source File: AstyanaxBlockedDataReaderDAO.java From emodb with Apache License 2.0 | 5 votes |
private <R> R execute(Execution<R> execution, String operation, Object... operationArguments) { OperationResult<R> operationResult; try { operationResult = execution.execute(); } catch (ConnectionException e) { for (int i = 0; i < operationArguments.length; i++) { if (operationArguments[i] instanceof ByteBuffer) { operationArguments[i] = ByteBufferUtil.bytesToHex((ByteBuffer) operationArguments[i]); } } String message = "Failed to " + String.format(operation, operationArguments); throw new RuntimeException(message, e); } return operationResult.getResult(); }
Example 8
Source File: AstyanaxSupport.java From brooklyn-library with Apache License 2.0 | 5 votes |
/** * Read from a {@link CassandraNode} using the Astyanax API. * @throws ConnectionException */ public void readData(String keyspaceName) throws ConnectionException { // Create context AstyanaxContext<Keyspace> context = newAstyanaxContextForKeyspace(keyspaceName); try { Keyspace keyspace = context.getEntity(); // Query data OperationResult<ColumnList<String>> query = keyspace.prepareQuery(sampleColumnFamily) .getKey("one") .execute(); assertEquals(query.getHost().getHostName(), hostname); assertTrue(query.getLatency() > 0L); ColumnList<String> columns = query.getResult(); assertEquals(columns.size(), 2); // Lookup columns in response by name String name = columns.getColumnByName("name").getStringValue(); assertEquals(name, "Alice"); // Iterate through the columns for (Column<String> c : columns) { assertTrue(ImmutableList.of("name", "company").contains(c.getName())); } } finally { context.shutdown(); } }
Example 9
Source File: AstyanaxReader.java From blueflood with Apache License 2.0 | 5 votes |
public Table<Locator, String, String> getMetadataValues(Set<Locator> locators) { ColumnFamily CF = CassandraModel.CF_METRICS_METADATA; boolean isBatch = locators.size() > 1; Table<Locator, String, String> metaTable = HashBasedTable.create(); Timer.Context ctx = isBatch ? Instrumentation.getBatchReadTimerContext(CF.getName()) : Instrumentation.getReadTimerContext(CF.getName()); try { // We don't paginate this call. So we should make sure the number of reads is tolerable. // TODO: Think about paginating this call. OperationResult<Rows<Locator, String>> query = keyspace .prepareQuery(CF) .getKeySlice(locators) .execute(); for (Row<Locator, String> row : query.getResult()) { ColumnList<String> columns = row.getColumns(); for (Column<String> column : columns) { String metaValue = column.getValue(StringMetadataSerializer.get()); String metaKey = column.getName(); metaTable.put(row.getKey(), metaKey, metaValue); } } } catch (ConnectionException e) { if (e instanceof NotFoundException) { // TODO: Not really sure what happens when one of the keys is not found. Instrumentation.markNotFound(CF.getName()); } else { if (isBatch) { Instrumentation.markBatchReadError(e); } else { Instrumentation.markReadError(e); } } log.error((isBatch ? "Batch " : "") + " read query failed for column family " + CF.getName() + " for locators: " + StringUtils.join(locators, ","), e); } finally { ctx.stop(); } return metaTable; }
Example 10
Source File: AstyanaxReader.java From blueflood with Apache License 2.0 | 5 votes |
protected Map<Locator, ColumnList<Long>> getColumnsFromDB(List<Locator> locators, ColumnFamily<Locator, Long> CF, Range range) { if (range.getStart() > range.getStop()) { throw new RuntimeException(String.format("Invalid rollup range: ", range.toString())); } boolean isBatch = locators.size() != 1; final Map<Locator, ColumnList<Long>> columns = new HashMap<Locator, ColumnList<Long>>(); final RangeBuilder rangeBuilder = new RangeBuilder().setStart(range.getStart()).setEnd(range.getStop()); Timer.Context ctx = isBatch ? Instrumentation.getBatchReadTimerContext(CF.getName()) : Instrumentation.getReadTimerContext(CF.getName()); try { // We don't paginate this call. So we should make sure the number of reads is tolerable. // TODO: Think about paginating this call. OperationResult<Rows<Locator, Long>> query = keyspace .prepareQuery(CF) .getKeySlice(locators) .withColumnRange(rangeBuilder.build()) .execute(); for (Row<Locator, Long> row : query.getResult()) { columns.put(row.getKey(), row.getColumns()); } } catch (ConnectionException e) { if (e instanceof NotFoundException) { // TODO: Not really sure what happens when one of the keys is not found. Instrumentation.markNotFound(CF.getName()); } else { if (isBatch) { Instrumentation.markBatchReadError(e); } else { Instrumentation.markReadError(e); } } log.error((isBatch ? "Batch " : "") + " read query failed for column family " + CF.getName() + " for locators: " + StringUtils.join(locators, ","), e); } finally { ctx.stop(); } return columns; }