Java Code Examples for com.google.api.core.SettableApiFuture#set()

The following examples show how to use com.google.api.core.SettableApiFuture#set() . 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: Utilities.java    From firebase-admin-java with Apache License 2.0 6 votes vote down vote up
public static Pair<ApiFuture<Void>, DatabaseReference.CompletionListener> wrapOnComplete(
    DatabaseReference.CompletionListener optListener) {
  if (optListener == null) {
    final SettableApiFuture<Void> future = SettableApiFuture.create();
    DatabaseReference.CompletionListener listener =
        new DatabaseReference.CompletionListener() {
          @Override
          public void onComplete(DatabaseError error, DatabaseReference ref) {
            if (error != null) {
              future.setException(error.toException());
            } else {
              future.set(null);
            }
          }
        };
    return new Pair<ApiFuture<Void>, DatabaseReference.CompletionListener>(future, listener);
  } else {
    // If a listener is supplied we do not want to create a Task
    return new Pair<>(null, optListener);
  }
}
 
Example 2
Source File: CloudPubSubSourceTaskTest.java    From pubsub with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that when ackMessages() succeeds and the subsequent call to poll() has no messages, that
 * the subscriber does not invoke ackMessages because there should be no acks.
 */
@Test
public void testPollInRegularCase() throws Exception {
  task.start(props);
  ReceivedMessage rm1 = createReceivedMessage(ACK_ID1, CPS_MESSAGE, new HashMap<String, String>());
  PullResponse stubbedPullResponse = PullResponse.newBuilder().addReceivedMessages(rm1).build();
  when(subscriber.pull(any(PullRequest.class)).get()).thenReturn(stubbedPullResponse);
  List<SourceRecord> result = task.poll();
  assertEquals(1, result.size());
  task.commitRecord(result.get(0));
  stubbedPullResponse = PullResponse.newBuilder().build();
  SettableApiFuture<Empty> goodFuture = SettableApiFuture.create();
  goodFuture.set(Empty.getDefaultInstance());
  when(subscriber.ackMessages(any(AcknowledgeRequest.class))).thenReturn(goodFuture);
  when(subscriber.pull(any(PullRequest.class)).get()).thenReturn(stubbedPullResponse);
  result = task.poll();
  assertEquals(0, result.size());
  result = task.poll();
  assertEquals(0, result.size());
  verify(subscriber, times(1)).ackMessages(any(AcknowledgeRequest.class));
}
 
Example 3
Source File: RiskAnalysisLDiversity.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
private static void handleMessage(
    DlpJob job,
    SettableApiFuture<Boolean> done,
    PubsubMessage pubsubMessage,
    AckReplyConsumer ackReplyConsumer) {
  String messageAttribute = pubsubMessage.getAttributesMap().get("DlpJobName");
  if (job.getName().equals(messageAttribute)) {
    done.set(true);
    ackReplyConsumer.ack();
  } else {
    ackReplyConsumer.nack();
  }
}
 
Example 4
Source File: InspectDatastoreEntity.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
private static void handleMessage(
    DlpJob job,
    SettableApiFuture<Boolean> done,
    PubsubMessage pubsubMessage,
    AckReplyConsumer ackReplyConsumer) {
  String messageAttribute = pubsubMessage.getAttributesMap().get("DlpJobName");
  if (job.getName().equals(messageAttribute)) {
    done.set(true);
    ackReplyConsumer.ack();
  } else {
    ackReplyConsumer.nack();
  }
}
 
Example 5
Source File: InspectGcsFile.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
private static void handleMessage(
    DlpJob job,
    SettableApiFuture<Boolean> done,
    PubsubMessage pubsubMessage,
    AckReplyConsumer ackReplyConsumer) {
  String messageAttribute = pubsubMessage.getAttributesMap().get("DlpJobName");
  if (job.getName().equals(messageAttribute)) {
    done.set(true);
    ackReplyConsumer.ack();
  } else {
    ackReplyConsumer.nack();
  }
}
 
Example 6
Source File: RiskAnalysisCategoricalStats.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
private static void handleMessage(
    DlpJob job,
    SettableApiFuture<Boolean> done,
    PubsubMessage pubsubMessage,
    AckReplyConsumer ackReplyConsumer) {
  String messageAttribute = pubsubMessage.getAttributesMap().get("DlpJobName");
  if (job.getName().equals(messageAttribute)) {
    done.set(true);
    ackReplyConsumer.ack();
  } else {
    ackReplyConsumer.nack();
  }
}
 
Example 7
Source File: InspectBigQueryTableWithSampling.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
private static void handleMessage(
    DlpJob job,
    SettableApiFuture<Boolean> done,
    PubsubMessage pubsubMessage,
    AckReplyConsumer ackReplyConsumer) {
  String messageAttribute = pubsubMessage.getAttributesMap().get("DlpJobName");
  if (job.getName().equals(messageAttribute)) {
    done.set(true);
    ackReplyConsumer.ack();
  } else {
    ackReplyConsumer.nack();
  }
}
 
Example 8
Source File: InspectGcsFileWithSampling.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
private static void handleMessage(
    DlpJob job,
    SettableApiFuture<Boolean> done,
    PubsubMessage pubsubMessage,
    AckReplyConsumer ackReplyConsumer) {
  String messageAttribute = pubsubMessage.getAttributesMap().get("DlpJobName");
  if (job.getName().equals(messageAttribute)) {
    done.set(true);
    ackReplyConsumer.ack();
  } else {
    ackReplyConsumer.nack();
  }
}
 
Example 9
Source File: RiskAnalysisKMap.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
private static void handleMessage(
    DlpJob job,
    SettableApiFuture<Boolean> done,
    PubsubMessage pubsubMessage,
    AckReplyConsumer ackReplyConsumer) {
  String messageAttribute = pubsubMessage.getAttributesMap().get("DlpJobName");
  if (job.getName().equals(messageAttribute)) {
    done.set(true);
    ackReplyConsumer.ack();
  } else {
    ackReplyConsumer.nack();
  }
}
 
Example 10
Source File: RiskAnalysisKAnonymity.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
private static void handleMessage(
    DlpJob job,
    SettableApiFuture<Boolean> done,
    PubsubMessage pubsubMessage,
    AckReplyConsumer ackReplyConsumer) {
  String messageAttribute = pubsubMessage.getAttributesMap().get("DlpJobName");
  if (job.getName().equals(messageAttribute)) {
    done.set(true);
    ackReplyConsumer.ack();
  } else {
    ackReplyConsumer.nack();
  }
}
 
Example 11
Source File: RiskAnalysisNumericalStats.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
private static void handleMessage(
    DlpJob job,
    SettableApiFuture<Boolean> done,
    PubsubMessage pubsubMessage,
    AckReplyConsumer ackReplyConsumer) {
  String messageAttribute = pubsubMessage.getAttributesMap().get("DlpJobName");
  if (job.getName().equals(messageAttribute)) {
    done.set(true);
    ackReplyConsumer.ack();
  } else {
    ackReplyConsumer.nack();
  }
}
 
Example 12
Source File: InspectBigQueryTable.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
private static void handleMessage(
    DlpJob job,
    SettableApiFuture<Boolean> done,
    PubsubMessage pubsubMessage,
    AckReplyConsumer ackReplyConsumer) {
  String messageAttribute = pubsubMessage.getAttributesMap().get("DlpJobName");
  if (job.getName().equals(messageAttribute)) {
    done.set(true);
    ackReplyConsumer.ack();
  } else {
    ackReplyConsumer.nack();
  }
}
 
Example 13
Source File: AndroidAppTest.java    From firebase-admin-java with Apache License 2.0 4 votes vote down vote up
private <T> SettableApiFuture<T> createApiFuture(T value) {
  final SettableApiFuture<T> future = SettableApiFuture.create();
  future.set(value);
  return future;
}
 
Example 14
Source File: GoogleCloudPubSubFlusherTest.java    From divolte-collector with Apache License 2.0 4 votes vote down vote up
private static <V> ApiFuture<V> completedFuture(final V value) {
    final SettableApiFuture<V> future = SettableApiFuture.create();
    future.set(value);
    return future;
}