use of com.datastax.oss.driver.api.core.session.Request in project java-driver by datastax.
the class ExecutionInfo method getSafePagingState.
/**
* The paging state of the query, in a safe wrapper that checks if it's reused on the right
* statement.
*
* <p>This represents the next page to be fetched if this query has multiple page of results. It
* can be saved and reused later on the same statement.
*
* @return the paging state, or {@code null} if there is no next page.
*/
@Nullable
default PagingState getSafePagingState() {
// Default implementation for backward compatibility, but we override it in the concrete class,
// because it knows the attachment point.
ByteBuffer rawPagingState = getPagingState();
if (rawPagingState == null) {
return null;
} else {
Request request = getRequest();
if (!(request instanceof Statement)) {
throw new IllegalStateException("Only statements should have a paging state");
}
Statement<?> statement = (Statement<?>) request;
return new DefaultPagingState(rawPagingState, statement, AttachmentPoint.NONE);
}
}
use of com.datastax.oss.driver.api.core.session.Request in project java-driver by datastax.
the class BasicLoadBalancingPolicy method maybeAddDcFailover.
@NonNull
protected Queue<Node> maybeAddDcFailover(@Nullable Request request, @NonNull Queue<Node> local) {
if (maxNodesPerRemoteDc <= 0 || localDc == null) {
return local;
}
if (!allowDcFailoverForLocalCl && request instanceof Statement) {
Statement<?> statement = (Statement<?>) request;
ConsistencyLevel consistency = statement.getConsistencyLevel();
if (consistency == null) {
consistency = defaultConsistencyLevel;
}
if (consistency.isDcLocal()) {
return local;
}
}
QueryPlan remote = new LazyQueryPlan() {
@Override
protected Object[] computeNodes() {
Object[] remoteNodes = liveNodes.dcs().stream().filter(Predicates.not(Predicates.equalTo(localDc))).flatMap(dc -> liveNodes.dc(dc).stream().limit(maxNodesPerRemoteDc)).toArray();
int remoteNodesLength = remoteNodes.length;
if (remoteNodesLength == 0) {
return EMPTY_NODES;
}
shuffleHead(remoteNodes, remoteNodesLength);
return remoteNodes;
}
};
return new CompositeQueryPlan(local, remote);
}
Aggregations