• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Task类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.firebase.tasks.Task的典型用法代码示例。如果您正苦于以下问题:Java Task类的具体用法?Java Task怎么用?Java Task使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Task类属于com.google.firebase.tasks包,在下文中一共展示了Task类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: deleteInstanceId

import com.google.firebase.tasks.Task; //导入依赖的package包/类
private Task<Void> deleteInstanceId(final String instanceId) {
  checkArgument(!Strings.isNullOrEmpty(instanceId), "instance ID must not be null or empty");
  return ImplFirebaseTrampolines.submitCallable(app, new Callable<Void>(){
    @Override
    public Void call() throws Exception {
      String url = String.format(
          "%s/project/%s/instanceId/%s", IID_SERVICE_URL, projectId, instanceId);
      HttpRequest request = requestFactory.buildDeleteRequest(new GenericUrl(url));
      request.setParser(new JsonObjectParser(jsonFactory));
      request.setResponseInterceptor(interceptor);
      HttpResponse response = null;
      try {
        response = request.execute();
        ByteStreams.exhaust(response.getContent());
      } catch (Exception e) {
        handleError(instanceId, e);
      } finally {
        if (response != null) {
          response.disconnect();
        }
      }
      return null;
    }
  });
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:26,代码来源:FirebaseInstanceId.java


示例2: wrapOnComplete

import com.google.firebase.tasks.Task; //导入依赖的package包/类
public static Pair<Task<Void>, DatabaseReference.CompletionListener> wrapOnComplete(
    DatabaseReference.CompletionListener optListener) {
  if (optListener == null) {
    final TaskCompletionSource<Void> source = new TaskCompletionSource<>();
    DatabaseReference.CompletionListener listener =
        new DatabaseReference.CompletionListener() {
          @Override
          public void onComplete(DatabaseError error, DatabaseReference ref) {
            if (error != null) {
              source.setException(error.toException());
            } else {
              source.setResult(null);
            }
          }
        };
    return new Pair<>(source.getTask(), listener);
  } else {
    // If a listener is supplied we do not want to create a Task
    return new Pair<>(null, optListener);
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:22,代码来源:Utilities.java


示例3: testAddListener

import com.google.firebase.tasks.Task; //导入依赖的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


示例4: setValueInternal

import com.google.firebase.tasks.Task; //导入依赖的package包/类
private Task<Void> setValueInternal(Object value, Node priority, CompletionListener optListener) {
  Validation.validateWritablePath(getPath());
  ValidationPath.validateWithObject(getPath(), value);
  Object bouncedValue = CustomClassMapper.convertToPlainJavaTypes(value);
  Validation.validateWritableObject(bouncedValue);
  final Node node = NodeUtilities.NodeFromJSON(bouncedValue, priority);
  final Pair<Task<Void>, CompletionListener> wrapped = Utilities.wrapOnComplete(optListener);
  repo.scheduleNow(
      new Runnable() {
        @Override
        public void run() {
          repo.setValue(getPath(), node, wrapped.getSecond());
        }
      });
  return wrapped.getFirst();
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:17,代码来源:DatabaseReference.java


示例5: updateChildrenInternal

import com.google.firebase.tasks.Task; //导入依赖的package包/类
private Task<Void> updateChildrenInternal(
    final Map<String, Object> update, final CompletionListener optListener) {
  if (update == null) {
    throw new NullPointerException("Can't pass null for argument 'update' in updateChildren()");
  }
  final Map<String, Object> bouncedUpdate = CustomClassMapper.convertToPlainJavaTypes(update);
  final Map<Path, Node> parsedUpdate =
      Validation.parseAndValidateUpdate(getPath(), bouncedUpdate);
  final CompoundWrite merge = CompoundWrite.fromPathMerge(parsedUpdate);

  final Pair<Task<Void>, CompletionListener> wrapped = Utilities.wrapOnComplete(optListener);
  repo.scheduleNow(
      new Runnable() {
        @Override
        public void run() {
          repo.updateChildren(getPath(), merge, wrapped.getSecond(), bouncedUpdate);
        }
      });
  return wrapped.getFirst();
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:21,代码来源:DatabaseReference.java


示例6: onDisconnectSetInternal

import com.google.firebase.tasks.Task; //导入依赖的package包/类
private Task<Void> onDisconnectSetInternal(
    Object value, Node priority, final CompletionListener optListener) {
  Validation.validateWritablePath(path);
  ValidationPath.validateWithObject(path, value);
  Object bouncedValue = CustomClassMapper.convertToPlainJavaTypes(value);
  Validation.validateWritableObject(bouncedValue);
  final Node node = NodeUtilities.NodeFromJSON(bouncedValue, priority);
  final Pair<Task<Void>, CompletionListener> wrapped = Utilities.wrapOnComplete(optListener);
  repo.scheduleNow(
      new Runnable() {
        @Override
        public void run() {
          repo.onDisconnectSetValue(path, node, wrapped.getSecond());
        }
      });
  return wrapped.getFirst();
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:18,代码来源:OnDisconnect.java


示例7: createCustomToken

import com.google.firebase.tasks.Task; //导入依赖的package包/类
/**
 * Similar to {@link #createCustomTokenAsync(String, Map)}, but returns a {@link Task}.
 *
 * @param uid The UID to store in the token. This identifies the user to other Firebase services
 *     (Realtime Database, Storage, etc.). Should be less than 128 characters.
 * @param developerClaims Additional claims to be stored in the token (and made available to
 *     security rules in Database, Storage, etc.). These must be able to be serialized to JSON
 *     (e.g. contain only Maps, Arrays, Strings, Booleans, Numbers, etc.)
 * @return A {@link Task} which will complete successfully with the created Firebase Custom Token,
 *     or unsuccessfully with the failure Exception.
 * @deprecated Use {@link #createCustomTokenAsync(String, Map)}
 */
public Task<String> createCustomToken(
    final String uid, final Map<String, Object> developerClaims) {
  checkNotDestroyed();
  checkState(credentials instanceof ServiceAccountCredentials,
      "Must initialize FirebaseApp with a service account credential to call "
          + "createCustomToken()");

  final ServiceAccountCredentials serviceAccount = (ServiceAccountCredentials) credentials;
  return call(new Callable<String>() {
    @Override
    public String call() throws Exception {
      FirebaseTokenFactory tokenFactory = FirebaseTokenFactory.getInstance();
      return tokenFactory.createSignedCustomAuthTokenForUser(
          uid,
          developerClaims,
          serviceAccount.getClientEmail(),
          serviceAccount.getPrivateKey());
    }
  });
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:33,代码来源:FirebaseAuth.java


示例8: verifyIdToken

import com.google.firebase.tasks.Task; //导入依赖的package包/类
/**
 * Similar to {@link #verifyIdTokenAsync(String)}, but returns a {@link Task}.
 *
 * @param token A Firebase ID Token to verify and parse.
 * @return A {@link Task} which will complete successfully with the parsed token, or
 *     unsuccessfully with the failure Exception.
 * @deprecated Use {@link #verifyIdTokenAsync(String)}
 */
public Task<FirebaseToken> verifyIdToken(final String token) {
  checkNotDestroyed();
  checkState(!Strings.isNullOrEmpty(projectId),
      "Must initialize FirebaseApp with a project ID to call verifyIdToken()");
  return call(new Callable<FirebaseToken>() {
    @Override
    public FirebaseToken call() throws Exception {
      FirebaseTokenVerifier firebaseTokenVerifier =
          new FirebaseTokenVerifier.Builder()
              .setProjectId(projectId)
              .setPublicKeysManager(googlePublicKeysManager)
              .setClock(clock)
              .build();
      FirebaseToken firebaseToken = FirebaseToken.parse(jsonFactory, token);

      // This will throw a FirebaseAuthException with details on how the token is invalid.
      firebaseTokenVerifier.verifyTokenAndSignature(firebaseToken.getToken());

      return firebaseToken;
    }
  });
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:31,代码来源:FirebaseAuth.java


示例9: testWrapOnComplete

import com.google.firebase.tasks.Task; //导入依赖的package包/类
@Test
public void testWrapOnComplete() {
  Pair<Task<Void>, DatabaseReference.CompletionListener> result =
      Utilities.wrapOnComplete(null);
  assertNotNull(result.getFirst());
  assertNotNull(result.getSecond());
  try {
    result.getFirst().getResult();
    fail("No error thrown for pending task");
  } catch (Exception e) {
    // expected
  }

  result.getSecond().onComplete(null, null);
  result.getFirst().getResult();
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:17,代码来源:UtilitiesTest.java


示例10: testWrapOnCompleteErrorResult

import com.google.firebase.tasks.Task; //导入依赖的package包/类
@Test
public void testWrapOnCompleteErrorResult() {
  Pair<Task<Void>, DatabaseReference.CompletionListener> result =
      Utilities.wrapOnComplete(null);
  assertNotNull(result.getFirst());
  assertNotNull(result.getSecond());
  try {
    result.getFirst().getResult();
    fail("No error thrown for pending task");
  } catch (Exception e) {
    // expected
  }

  result.getSecond().onComplete(DatabaseError.fromStatus("test error"), null);
  assertNotNull(result.getFirst().getException());
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:17,代码来源:UtilitiesTest.java


示例11: createOptionsWithCustomFirebaseCredential

import com.google.firebase.tasks.Task; //导入依赖的package包/类
@Test
public void createOptionsWithCustomFirebaseCredential() throws IOException {
  FirebaseOptions firebaseOptions =
      new FirebaseOptions.Builder()
          .setCredential(new FirebaseCredential() {
            @Override
            public Task<GoogleOAuthAccessToken> getAccessToken() {
              return null;
            }
          })
          .build();

  assertNotNull(firebaseOptions.getJsonFactory());
  assertNotNull(firebaseOptions.getHttpTransport());
  assertNull(firebaseOptions.getDatabaseUrl());
  assertNull(firebaseOptions.getStorageBucket());

  GoogleCredentials credentials = firebaseOptions.getCredentials();
  assertNotNull(credentials);
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:21,代码来源:FirebaseOptionsTest.java


示例12: setPriorityInternal

import com.google.firebase.tasks.Task; //导入依赖的package包/类
private Task<Void> setPriorityInternal(final Node priority, CompletionListener optListener) {
  Validation.validateWritablePath(getPath());

  final Pair<Task<Void>, CompletionListener> wrapped = Utilities.wrapOnComplete(optListener);
  repo.scheduleNow(
      new Runnable() {
        @Override
        public void run() {
          repo.setValue(
              getPath().child(ChildKey.getPriorityKey()), priority, wrapped.getSecond());
        }
      });
  return wrapped.getFirst();
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:15,代码来源:DatabaseReference.java


示例13: updateChildrenInternal

import com.google.firebase.tasks.Task; //导入依赖的package包/类
private Task<Void> updateChildrenInternal(
    final Map<String, Object> update, final CompletionListener optListener) {
  final Map<Path, Node> parsedUpdate = Validation.parseAndValidateUpdate(path, update);
  final Pair<Task<Void>, CompletionListener> wrapped = Utilities.wrapOnComplete(optListener);
  repo.scheduleNow(
      new Runnable() {
        @Override
        public void run() {
          repo.onDisconnectUpdate(path, parsedUpdate, wrapped.getSecond(), update);
        }
      });
  return wrapped.getFirst();
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:14,代码来源:OnDisconnect.java


示例14: cancelInternal

import com.google.firebase.tasks.Task; //导入依赖的package包/类
private Task<Void> cancelInternal(final CompletionListener optListener) {
  final Pair<Task<Void>, CompletionListener> wrapped = Utilities.wrapOnComplete(optListener);
  repo.scheduleNow(
      new Runnable() {
        @Override
        public void run() {
          repo.onDisconnectCancel(path, wrapped.getSecond());
        }
      });
  return wrapped.getFirst();
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:12,代码来源:OnDisconnect.java


示例15: getAccessToken

import com.google.firebase.tasks.Task; //导入依赖的package包/类
@Override
public Task<GoogleOAuthAccessToken> getAccessToken() {
  try {
    AccessToken accessToken = googleCredentials.refreshAccessToken();
    GoogleOAuthAccessToken googleToken = new GoogleOAuthAccessToken(accessToken.getTokenValue(),
        accessToken.getExpirationTime().getTime());
    return Tasks.forResult(googleToken);
  } catch (Exception e) {
    return Tasks.forException(e);
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:12,代码来源:BaseCredential.java


示例16: getUser

import com.google.firebase.tasks.Task; //导入依赖的package包/类
/**
 * Similar to {@link #getUserAsync(String)}, but returns a {@link Task}.
 *
 * @param uid A user ID string.
 * @return A {@link Task} which will complete successfully with a {@link UserRecord} instance.
 *     If an error occurs while retrieving user data or if the specified user ID does not exist,
 *     the task fails with a {@link FirebaseAuthException}.
 * @throws IllegalArgumentException If the user ID string is null or empty.
 * @deprecated Use {@link #getUserAsync(String)}
 */
public Task<UserRecord> getUser(final String uid) {
  checkNotDestroyed();
  checkArgument(!Strings.isNullOrEmpty(uid), "uid must not be null or empty");
  return call(new Callable<UserRecord>() {
    @Override
    public UserRecord call() throws Exception {
      return userManager.getUserById(uid);
    }
  });
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:21,代码来源:FirebaseAuth.java


示例17: getUserByEmail

import com.google.firebase.tasks.Task; //导入依赖的package包/类
/**
 * Similar to {@link #getUserByEmailAsync(String)}, but returns a {@link Task}.
 *
 * @param email A user email address string.
 * @return A {@link Task} which will complete successfully with a {@link UserRecord} instance.
 *     If an error occurs while retrieving user data or if the email address does not correspond
 *     to a user, the task fails with a {@link FirebaseAuthException}.
 * @throws IllegalArgumentException If the email is null or empty.
 * @deprecated Use {@link #getUserByEmailAsync(String)}
 */
public Task<UserRecord> getUserByEmail(final String email) {
  checkNotDestroyed();
  checkArgument(!Strings.isNullOrEmpty(email), "email must not be null or empty");
  return call(new Callable<UserRecord>() {
    @Override
    public UserRecord call() throws Exception {
      return userManager.getUserByEmail(email);
    }
  });
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:21,代码来源:FirebaseAuth.java


示例18: getUserByPhoneNumber

import com.google.firebase.tasks.Task; //导入依赖的package包/类
/**
 * Similar to {@link #getUserByPhoneNumberAsync(String)}, but returns a {@link Task}.
 *
 * @param phoneNumber A user phone number string.
 * @return A {@link Task} which will complete successfully with a {@link UserRecord} instance.
 *     If an error occurs while retrieving user data or if the phone number does not
 *     correspond to a user, the task fails with a {@link FirebaseAuthException}.
 * @throws IllegalArgumentException If the phone number is null or empty.
 * @deprecated Use {@link #getUserByPhoneNumberAsync(String)}
 */
public Task<UserRecord> getUserByPhoneNumber(final String phoneNumber) {
  checkNotDestroyed();
  checkArgument(!Strings.isNullOrEmpty(phoneNumber), "phone number must not be null or empty");
  return call(new Callable<UserRecord>() {
    @Override
    public UserRecord call() throws Exception {
      return userManager.getUserByPhoneNumber(phoneNumber);
    }
  });
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:21,代码来源:FirebaseAuth.java


示例19: listUsers

import com.google.firebase.tasks.Task; //导入依赖的package包/类
private Task<ListUsersPage> listUsers(@Nullable String pageToken, int maxResults) {
  checkNotDestroyed();
  final PageFactory factory = new PageFactory(
      new DefaultUserSource(userManager, jsonFactory), maxResults, pageToken);
  return call(new Callable<ListUsersPage>() {
    @Override
    public ListUsersPage call() throws Exception {
      return factory.create();
    }
  });
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:12,代码来源:FirebaseAuth.java


示例20: createUser

import com.google.firebase.tasks.Task; //导入依赖的package包/类
/**
 * Similar to {@link #createUserAsync(CreateRequest)}, but returns a {@link Task}.
 *
 * @param request A non-null {@link CreateRequest} instance.
 * @return A {@link Task} which will complete successfully with a {@link UserRecord} instance
 *     corresponding to the newly created account. If an error occurs while creating the user
 *     account, the task fails with a {@link FirebaseAuthException}.
 * @throws NullPointerException if the provided request is null.
 * @deprecated Use {@link #createUserAsync(CreateRequest)}
 */
public Task<UserRecord> createUser(final CreateRequest request) {
  checkNotDestroyed();
  checkNotNull(request, "create request must not be null");
  return call(new Callable<UserRecord>() {
    @Override
    public UserRecord call() throws Exception {
      String uid = userManager.createUser(request);
      return userManager.getUserById(uid);
    }
  });
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:22,代码来源:FirebaseAuth.java



注:本文中的com.google.firebase.tasks.Task类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PutLogEventsResult类代码示例发布时间:2022-05-22
下一篇:
Java GenericVersionScheme类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap