use of com.datastax.driver.core.ResultSetFuture in project thingsboard by thingsboard.
the class CassandraAbstractModelDao method findListByStatementAsync.
protected ListenableFuture<List<D>> findListByStatementAsync(Statement statement) {
if (statement != null) {
statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel());
ResultSetFuture resultSetFuture = executeAsyncRead(statement);
return Futures.transform(resultSetFuture, new Function<ResultSet, List<D>>() {
@Nullable
@Override
public List<D> apply(@Nullable ResultSet resultSet) {
Result<E> result = getMapper().map(resultSet);
if (result != null) {
List<E> entities = result.all();
return DaoUtil.convertDataList(entities);
} else {
return Collections.emptyList();
}
}
});
}
return Futures.immediateFuture(Collections.emptyList());
}
use of com.datastax.driver.core.ResultSetFuture in project thingsboard by thingsboard.
the class RateLimitedResultSetFuture method addListener.
@Override
public void addListener(Runnable listener, Executor executor) {
originalFuture.addListener(() -> {
try {
ResultSetFuture resultSetFuture = Uninterruptibles.getUninterruptibly(originalFuture);
resultSetFuture.addListener(listener, executor);
} catch (CancellationException | ExecutionException e) {
Futures.immediateFailedFuture(e).addListener(listener, executor);
}
}, executor);
}
use of com.datastax.driver.core.ResultSetFuture in project thingsboard by thingsboard.
the class RateLimitedResultSetFuture method getUninterruptibly.
@Override
public ResultSet getUninterruptibly(long timeout, TimeUnit unit) throws TimeoutException {
long rateLimitStart = System.nanoTime();
ResultSetFuture resultSetFuture = null;
try {
resultSetFuture = originalFuture.get(timeout, unit);
} catch (InterruptedException | ExecutionException e) {
throw new IllegalStateException(e);
}
long rateLimitDurationNano = System.nanoTime() - rateLimitStart;
long innerTimeoutNano = unit.toNanos(timeout) - rateLimitDurationNano;
if (innerTimeoutNano > 0) {
return resultSetFuture.getUninterruptibly(innerTimeoutNano, TimeUnit.NANOSECONDS);
}
throw new TimeoutException("Timeout waiting for task.");
}
use of com.datastax.driver.core.ResultSetFuture in project thingsboard by thingsboard.
the class CassandraAssetDao method findTenantAssetTypesAsync.
@Override
public ListenableFuture<List<EntitySubtype>> findTenantAssetTypesAsync(UUID tenantId) {
Select select = select().from(ENTITY_SUBTYPE_COLUMN_FAMILY_NAME);
Select.Where query = select.where();
query.and(eq(ENTITY_SUBTYPE_TENANT_ID_PROPERTY, tenantId));
query.and(eq(ENTITY_SUBTYPE_ENTITY_TYPE_PROPERTY, EntityType.ASSET));
query.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel());
ResultSetFuture resultSetFuture = executeAsyncRead(query);
return Futures.transform(resultSetFuture, new Function<ResultSet, List<EntitySubtype>>() {
@Nullable
@Override
public List<EntitySubtype> apply(@Nullable ResultSet resultSet) {
Result<EntitySubtypeEntity> result = cluster.getMapper(EntitySubtypeEntity.class).map(resultSet);
if (result != null) {
List<EntitySubtype> entitySubtypes = new ArrayList<>();
result.all().forEach((entitySubtypeEntity) -> entitySubtypes.add(entitySubtypeEntity.toEntitySubtype()));
return entitySubtypes;
} else {
return Collections.emptyList();
}
}
});
}
use of com.datastax.driver.core.ResultSetFuture in project wildfly-swarm by wildfly-swarm.
the class StatefulTestBean method asyncQuery.
public Row asyncQuery() {
openConnection();
try {
session.execute("CREATE TABLE employee (lastname varchar primary key, firstname varchar, age int, city varchar, email varchar)");
session.execute("INSERT INTO employee (lastname, firstname, age, city, email) VALUES ('Smith','Leanne', 30, 'Boston', 'lea@yahoo.com')");
session.execute("update employee set age = 36 where lastname = 'Smith'");
// Select and show the change
try {
ResultSetFuture results = session.executeAsync("select * from employee where lastname='Smith'");
return results.get().one();
} catch (Throwable exception) {
throw new RuntimeException("could not get executeAsync result for some reason", exception);
}
} finally {
try {
session.execute("DROP TABLE employee");
} catch (Throwable ignore) {
}
closeConnection();
}
}
Aggregations