本文整理汇总了Java中com.google.api.core.ApiFuture类的典型用法代码示例。如果您正苦于以下问题:Java ApiFuture类的具体用法?Java ApiFuture怎么用?Java ApiFuture使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ApiFuture类属于com.google.api.core包,在下文中一共展示了ApiFuture类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testAddListener
import com.google.api.core.ApiFuture; //导入依赖的package包/类
@Test
public void testAddListener() throws Exception {
Task<String> task = Tasks.forResult("test");
ApiFuture<String> future = new TaskToApiFuture<>(task);
final AtomicBoolean result = new AtomicBoolean(false);
future.addListener(new Runnable() {
@Override
public void run() {
result.set(true);
}
}, MoreExecutors.directExecutor());
assertEquals("test", future.get());
assertTrue(result.get());
assertFalse(future.isCancelled());
assertTrue(future.isDone());
}
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:17,代码来源:TaskToApiFutureTest.java
示例2: testInitAfterAppDelete
import com.google.api.core.ApiFuture; //导入依赖的package包/类
@Test
public void testInitAfterAppDelete() throws ExecutionException, InterruptedException,
TimeoutException {
FirebaseApp app = FirebaseApp.initializeApp(firebaseOptions, "testInitAfterAppDelete");
FirebaseAuth auth1 = FirebaseAuth.getInstance(app);
assertNotNull(auth1);
app.delete();
app = FirebaseApp.initializeApp(firebaseOptions, "testInitAfterAppDelete");
FirebaseAuth auth2 = FirebaseAuth.getInstance(app);
assertNotNull(auth2);
assertNotSame(auth1, auth2);
if (isCertCredential) {
ApiFuture<String> future = auth2.createCustomTokenAsync("foo");
assertNotNull(future);
assertNotNull(future.get(TestUtils.TEST_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS));
}
}
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:20,代码来源:FirebaseAuthTest.java
示例3: retrieveAllDocuments
import com.google.api.core.ApiFuture; //导入依赖的package包/类
void retrieveAllDocuments() throws Exception {
// [START fs_get_all]
// asynchronously retrieve all users
ApiFuture<QuerySnapshot> query = db.collection("users").get();
// ...
// query.get() blocks on response
QuerySnapshot querySnapshot = query.get();
List<DocumentSnapshot> documents = querySnapshot.getDocuments();
for (DocumentSnapshot document : documents) {
System.out.println("User: " + document.getId());
System.out.println("First: " + document.getString("first"));
if (document.contains("middle")) {
System.out.println("Middle: " + document.getString("middle"));
}
System.out.println("Last: " + document.getString("last"));
System.out.println("Born: " + document.getLong("born"));
}
// [END fs_get_all]
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:20,代码来源:Quickstart.java
示例4: createAQuery
import com.google.api.core.ApiFuture; //导入依赖的package包/类
/**
* Creates a sample query.
*
* @return query
*/
Query createAQuery() throws Exception {
// [START fs_create_query]
// Create a reference to the cities collection
CollectionReference cities = db.collection("cities");
// Create a query against the collection.
Query query = cities.whereEqualTo("capital", true);
// retrieve query results asynchronously using query.get()
ApiFuture<QuerySnapshot> querySnapshot = query.get();
for (DocumentSnapshot document : querySnapshot.get().getDocuments()) {
System.out.println(document.getId());
}
// [END fs_create_query]
return query;
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:21,代码来源:QueryDataSnippets.java
示例5: createAQueryAlternate
import com.google.api.core.ApiFuture; //导入依赖的package包/类
/**
* Creates a sample query.
*
* @return query
*/
Query createAQueryAlternate() throws Exception {
// [START fs_create_query_country]
// Create a reference to the cities collection
CollectionReference cities = db.collection("cities");
// Create a query against the collection.
Query query = cities.whereEqualTo("state", "CA");
// retrieve query results asynchronously using query.get()
ApiFuture<QuerySnapshot> querySnapshot = query.get();
for (DocumentSnapshot document : querySnapshot.get().getDocuments()) {
System.out.println(document.getId());
}
// [END fs_create_query_country]
return query;
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:21,代码来源:QueryDataSnippets.java
示例6: addSimpleDocumentAsMap
import com.google.api.core.ApiFuture; //导入依赖的package包/类
/**
* Add a document to a collection using a map.
*
* @return document data
*/
Map<String, Object> addSimpleDocumentAsMap() throws Exception {
// [START fs_add_doc_as_map]
// Create a Map to store the data we want to set
Map<String, Object> docData = new HashMap<>();
docData.put("name", "Los Angeles");
docData.put("state", "CA");
docData.put("country", "USA");
// Add a new document (asynchronously) in collection "cities" with id "LA"
ApiFuture<WriteResult> future = db.collection("cities").document("LA").set(docData);
// ...
// future.get() blocks on response
System.out.println("Update time : " + future.get().getUpdateTime());
// [END fs_add_doc_as_map]
return docData;
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:21,代码来源:ManageDataSnippets.java
示例7: addDocumentWithDifferentDataTypes
import com.google.api.core.ApiFuture; //导入依赖的package包/类
/**
* Add a document to a collection using a map with different supported data types.
*
* @return document data
*/
Map<String, Object> addDocumentWithDifferentDataTypes() throws Exception {
// [START fs_add_doc_data_types]
Map<String, Object> docData = new HashMap<>();
docData.put("stringExample", "Hello, World");
docData.put("booleanExample", false);
docData.put("numberExample", 3.14159265);
docData.put("nullExample", null);
ArrayList<Object> arrayExample = new ArrayList<>();
Collections.addAll(arrayExample, 5L, true, "hello");
docData.put("arrayExample", arrayExample);
Map<String, Object> objectExample = new HashMap<>();
objectExample.put("a", 5L);
objectExample.put("b", true);
docData.put("objectExample", objectExample);
ApiFuture<WriteResult> future = db.collection("data").document("one").set(docData);
System.out.println("Update time : " + future.get().getUpdateTime());
// [END fs_add_doc_data_types]
return docData;
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:30,代码来源:ManageDataSnippets.java
示例8: addDocumentDataAfterAutoGeneratingId
import com.google.api.core.ApiFuture; //导入依赖的package包/类
/**
* Add data to a document after generating the document id.
*
* @return auto generated id
*/
String addDocumentDataAfterAutoGeneratingId() throws Exception {
City data = new City();
// [START fs_add_doc_data_after_auto_id]
// Add document data after generating an id.
DocumentReference addedDocRef = db.collection("cities").document();
System.out.println("Added document with ID: " + addedDocRef.getId());
// later...
ApiFuture<WriteResult> writeResult = addedDocRef.set(data);
// [END fs_add_doc_data_after_auto_id]
// writeResult.get() blocks on operation
System.out.println("Update time : " + writeResult.get().getUpdateTime());
return addedDocRef.getId();
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:22,代码来源:ManageDataSnippets.java
示例9: updateUsingMap
import com.google.api.core.ApiFuture; //导入依赖的package包/类
/** Partially update fields of a document using a map (field => value). */
void updateUsingMap() throws Exception {
db.collection("cities").document("DC").set(new City("Washington D.C.")).get();
// [START fs_update_doc_map]
// update multiple fields using a map
DocumentReference docRef = db.collection("cities").document("DC");
Map<String, Object> updates = new HashMap<>();
updates.put("name", "Washington D.C.");
updates.put("country", "USA");
updates.put("capital", true);
//asynchronously update doc
ApiFuture<WriteResult> writeResult = docRef.update(updates);
// ...
System.out.println("Update time : " + writeResult.get().getUpdateTime());
// [END fs_update_doc_map]
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:19,代码来源:ManageDataSnippets.java
示例10: updateAndCreateIfMissing
import com.google.api.core.ApiFuture; //导入依赖的package包/类
/** Partially update fields of a document using a map (field => value). */
void updateAndCreateIfMissing() throws Exception {
// [START fs_update_create_if_missing]
//asynchronously update doc, create the document if missing
Map<String, Object> update = new HashMap<>();
update.put("capital", true);
ApiFuture<WriteResult> writeResult =
db
.collection("cities")
.document("BJ")
.set(update, SetOptions.merge());
// ...
System.out.println("Update time : " + writeResult.get().getUpdateTime());
// [END fs_update_create_if_missing]
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:17,代码来源:ManageDataSnippets.java
示例11: deleteCollection
import com.google.api.core.ApiFuture; //导入依赖的package包/类
/** Delete a collection in batches to avoid out-of-memory errors.
* Batch size may be tuned based on document size (atmost 1MB) and application requirements.
*/
void deleteCollection(CollectionReference collection, int batchSize) {
try {
// retrieve a small batch of documents to avoid out-of-memory errors
ApiFuture<QuerySnapshot> future = collection.limit(batchSize).get();
int deleted = 0;
// future.get() blocks on document retrieval
List<DocumentSnapshot> documents = future.get().getDocuments();
for (DocumentSnapshot document : documents) {
document.getReference().delete();
++deleted;
}
if (deleted >= batchSize) {
// retrieve and delete another batch
deleteCollection(collection, batchSize);
}
} catch (Exception e) {
System.err.println("Error deleting collection : " + e.getMessage());
}
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:23,代码来源:ManageDataSnippets.java
示例12: publish
import com.google.api.core.ApiFuture; //导入依赖的package包/类
private void publish(Record record) throws StageException {
ByteArrayOutputStream os = new ByteArrayOutputStream();
try (DataGenerator generator = generatorFactory.getGenerator(os)) {
generator.write(record);
} catch (IOException | DataGeneratorException e) {
errorRecordHandler.onError(new OnRecordErrorException(record, Errors.PUBSUB_06, e.toString(), e));
return;
}
ByteString data = ByteString.copyFrom(os.toByteArray());
Map<String, String> attributes = new HashMap<>();
Record.Header header = record.getHeader();
header.getAttributeNames().forEach(k -> attributes.put(k, header.getAttribute(k)));
PubsubMessage message = PubsubMessage.newBuilder().setData(data).putAllAttributes(attributes).build();
ApiFuture<String> messageIdFuture = publisher.publish(message);
pendingMessages.add(new PendingMessage(record, messageIdFuture));
}
开发者ID:streamsets,项目名称:datacollector,代码行数:21,代码来源:PubSubTarget.java
示例13: testGetResult
import com.google.api.core.ApiFuture; //导入依赖的package包/类
@Test
public void testGetResult() throws Exception {
Task<String> task = Tasks.forResult("test");
ApiFuture<String> future = new TaskToApiFuture<>(task);
assertEquals("test", future.get());
assertFalse(future.isCancelled());
assertTrue(future.isDone());
}
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:9,代码来源:TaskToApiFutureTest.java
示例14: testGetError
import com.google.api.core.ApiFuture; //导入依赖的package包/类
@Test
public void testGetError() throws Exception {
Task<String> task = Tasks.forException(new RuntimeException("test"));
ApiFuture<String> future = new TaskToApiFuture<>(task);
try {
future.get();
} catch (ExecutionException e) {
assertEquals("test", e.getCause().getMessage());
}
assertFalse(future.isCancelled());
assertTrue(future.isDone());
}
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:13,代码来源:TaskToApiFutureTest.java
示例15: testCancel
import com.google.api.core.ApiFuture; //导入依赖的package包/类
@Test
public void testCancel() throws Exception {
Task<String> task = Tasks.forResult("test");
ApiFuture<String> future = new TaskToApiFuture<>(task);
assertFalse(future.cancel(true));
assertEquals("test", future.get());
assertFalse(future.isCancelled());
assertTrue(future.isDone());
}
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:10,代码来源:TaskToApiFutureTest.java
示例16: publish
import com.google.api.core.ApiFuture; //导入依赖的package包/类
@Override
public ListenableFuture<String> publish(final String topic, PubsubMessage pubsubMessage) {
ApiFuture<String> publishFuture =
this.publisherFactory.createPublisher(topic).publish(pubsubMessage);
final SettableListenableFuture<String> settableFuture = new SettableListenableFuture<>();
ApiFutures.addCallback(publishFuture, new ApiFutureCallback<String>() {
@Override
public void onFailure(Throwable throwable) {
LOGGER.warn("Publishing to " + topic + " topic failed.", throwable);
settableFuture.setException(throwable);
}
@Override
public void onSuccess(String result) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
"Publishing to " + topic + " was successful. Message ID: " + result);
}
settableFuture.set(result);
}
});
return settableFuture;
}
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:28,代码来源:PubSubTemplate.java
示例17: publishTask
import com.google.api.core.ApiFuture; //导入依赖的package包/类
@Override
public void publishTask(final String queue, final String task) {
Topic topic = getTopic(queue);
ByteString data = ByteString.copyFromUtf8(task);
TopicName topicName = topic.getNameAsTopicName();
try {
PubsubMessage psmessage = PubsubMessage.newBuilder().setData(data).build();
Publisher publisher = randomHouse.get(topicName);
if (publisher == null) {
logger.trace("No publisher found for " + topicName + " - creating");
Builder builder = Publisher.defaultBuilder(topicName);
// The default executor provider creates an insane number of threads.
if (executor != null) builder.setExecutorProvider(executor);
publisher = builder.build();
randomHouse.put(topicName, publisher);
} else {
logger.trace("Existing publisher found for " + topicName);
}
ApiFuture<String> messageIdFuture = publisher.publish(psmessage);
if (executor != null) messageIdFuture.addListener(listener, executor.getExecutor());
} catch (IOException e) {
String error = String.format("Cannot send message to topic %s:\n%s", topic.getName(), ExceptionToString.format(e));
logger.error(error);
throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, error, e);
}
}
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:31,代码来源:PubsubPipeline2Handler.java
示例18: runAQuery
import com.google.api.core.ApiFuture; //导入依赖的package包/类
void runAQuery() throws Exception {
// [START fs_add_query]
// asynchronously query for all users born before 1900
ApiFuture<QuerySnapshot> query =
db.collection("users").whereLessThan("born", 1900).get();
// ...
// query.get() blocks on response
QuerySnapshot querySnapshot = query.get();
List<DocumentSnapshot> documents = querySnapshot.getDocuments();
for (DocumentSnapshot document : documents) {
System.out.println("User: " + document.getId());
System.out.println("First: " + document.getString("first"));
if (document.contains("middle")) {
System.out.println("Middle: " + document.getString("middle"));
}
System.out.println("Last: " + document.getString("last"));
System.out.println("Born: " + document.getLong("born"));
}
// [END fs_add_query]
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:21,代码来源:Quickstart.java
示例19: prepareExamples
import com.google.api.core.ApiFuture; //导入依赖的package包/类
/** Create cities collection and add sample documents. */
void prepareExamples() throws Exception {
// [START fs_retrieve_create_examples]
CollectionReference cities = db.collection("cities");
List<ApiFuture<WriteResult>> futures = new ArrayList<>();
futures.add(cities.document("SF").set(new City("San Francisco", "CA", "USA", false, 860000L)));
futures.add(cities.document("LA").set(new City("Los Angeles", "CA", "USA", false, 3900000L)));
futures.add(cities.document("DC").set(new City("Washington D.C.", null, "USA", true, 680000L)));
futures.add(cities.document("TOK").set(new City("Tokyo", null, "Japan", true, 9000000L)));
futures.add(cities.document("BJ").set(new City("Beijing", null, "China", true, 21500000L)));
// (optional) block on operation
ApiFutures.allAsList(futures).get();
// [END fs_retrieve_create_examples]
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:15,代码来源:RetrieveDataSnippets.java
示例20: getQueryResults
import com.google.api.core.ApiFuture; //导入依赖的package包/类
/**
* Return multiple documents from a collection based on a query.
*
* @return list of documents of capital cities.
*/
public List<DocumentSnapshot> getQueryResults() throws Exception {
// [START fs_get_multiple_docs]
//asynchronously retrieve multiple documents
ApiFuture<QuerySnapshot> future =
db.collection("cities").whereEqualTo("capital", true).get();
// future.get() blocks on response
List<DocumentSnapshot> documents = future.get().getDocuments();
for (DocumentSnapshot document : documents) {
System.out.println(document.getId() + " => " + document.toObject(City.class));
}
// [END fs_get_multiple_docs]
return documents;
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:19,代码来源:RetrieveDataSnippets.java
注:本文中的com.google.api.core.ApiFuture类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论