当前位置: 首页>>代码示例>>Java>>正文


Java Deferred.reject方法代码示例

本文整理汇总了Java中org.jdeferred.Deferred.reject方法的典型用法代码示例。如果您正苦于以下问题:Java Deferred.reject方法的具体用法?Java Deferred.reject怎么用?Java Deferred.reject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jdeferred.Deferred的用法示例。


在下文中一共展示了Deferred.reject方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: changePassword

import org.jdeferred.Deferred; //导入方法依赖的package包/类
@Override
public Promise<Void, BError, Void> changePassword(String email, String oldPassword, String newPassword){
    
    final Deferred<Void, BError, Void> deferred = new DeferredObject<>();

    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

    OnCompleteListener<Void> resultHandler = new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (task.isSuccessful()) {
                deferred.resolve(null);
            } else {
                deferred.reject(getFirebaseError(DatabaseError.fromException(task.getException())));

            }
        }
    };

    user.updatePassword(newPassword).addOnCompleteListener(resultHandler);

    return deferred.promise();
}
 
开发者ID:MobileDev418,项目名称:chat-sdk-android-push-firebase,代码行数:24,代码来源:BChatcatNetworkAdapter.java

示例2: sendPasswordResetMail

import org.jdeferred.Deferred; //导入方法依赖的package包/类
@Override
public Promise<Void, BError, Void> sendPasswordResetMail(String email){

    final Deferred<Void, BError, Void> deferred = new DeferredObject<>();

    OnCompleteListener<Void> resultHandler = new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (task.isSuccessful()) {
                if(DEBUG) Timber.v("Email sent");
                deferred.resolve(null);
            } else {
                deferred.reject(getFirebaseError(DatabaseError.fromException(task.getException())));

            }
        }
    };

    FirebaseAuth.getInstance().sendPasswordResetEmail(email).addOnCompleteListener(resultHandler);
    
    return deferred.promise();
}
 
开发者ID:MobileDev418,项目名称:chat-sdk-android-push-firebase,代码行数:23,代码来源:BChatcatNetworkAdapter.java

示例3: handleMessage

import org.jdeferred.Deferred; //导入方法依赖的package包/类
@Override
public void handleMessage(Message msg) {
    super.handleMessage(msg);

    switch (msg.what){
        case 1:
            MessageObj obj = (MessageObj) msg.obj;
            if (obj.listener instanceof Deferred)
            {
                Deferred<Object, BError, Void> deferred= ((DeferredObject) obj.listener);


                if (msg.arg1 == ERROR)
                    deferred.reject((BError) obj.data);
                else deferred.resolve(obj.data);
            }
    }
}
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:19,代码来源:TwitterManager.java

示例4: send

import org.jdeferred.Deferred; //导入方法依赖的package包/类
public Promise<BMessage, BError, BMessage> send(){
    if (DEBUG) Timber.v("send");
    
    if (model.getThread() != null)
    {
        return push();
    }else
    {
        final Deferred<BMessage, BError, BMessage> deferred = new DeferredObject<>();
        deferred.reject(null);
        return deferred.promise();
    }           
}
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:14,代码来源:BMessageWrapper.java

示例5: onSessionStateChange

import org.jdeferred.Deferred; //导入方法依赖的package包/类
/** Re authenticate after session state changed.*/
public static Promise<Object, BError, Void> onSessionStateChange(Session session, SessionState state, Exception exception) {
    if (DEBUG) Timber.i("Session changed state");

    // If we can start the login process with no errors this promise wont be used. 
    // The returned promise will be from the loginWithFacebook.
    Deferred<Object, BError, Void> deferred = new DeferredObject<>();
    
    if (exception != null)
    {
        exception.printStackTrace();
        if (exception instanceof FacebookOperationCanceledException)
        {
            deferred.reject(new BError(BError.Code.EXCEPTION, exception));
            return deferred.promise();
        }
    }

    if (state.isOpened()) {
        if (DEBUG) Timber.i("Session is open.");

        // We will need this session later to make request.
        userFacebookAccessToken = Session.getActiveSession().getAccessToken();

        return loginWithFacebook();

    } else if (state.isClosed()) {
        // Logged out of Facebook
        if (DEBUG) Timber.i("Session is closed.");
        deferred.reject(new BError(BError.Code.SESSION_CLOSED, "Facebook session is closed."));
    }
    
    
    return deferred.promise();
}
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:36,代码来源:BFacebookManager.java

示例6: offer

import org.jdeferred.Deferred; //导入方法依赖的package包/类
/**
 * Notify deferred if the element could be added or reject if it could not due to its
 * {@link OverflowStrategy.Strategy}.
 */
void offer(Message next, Deferred<?, MessageDroppedException, Integer> deferred) {
  SendingTask task = new SendingTask(next, deferred);
  lock.lock();
  try {
    ensureCapacity(count + 1);
    if (isFull()) {
      switch (overflowStrategy) {
        case DropNew:
          deferred.reject(dropped(DropNew, next));
          return;
        case DropTail:
          SendingTask tail = dropTail();
          enqueue(task);
          tail.deferred.reject(dropped(DropTail, tail.message));
          return;
        case DropHead:
          SendingTask head = dropHead();
          enqueue(task);
          head.deferred.reject(dropped(DropHead, head.message));
          return;
        case DropBuffer:
          List<SendingTask> allElements = removeAll();
          doClear();
          enqueue(task);
          rejectAll(allElements, DropBuffer);
          return;
        case Block:
          break;
        case Fail:
          throw new BufferOverflowException("Max size of " + count + " is reached.");
      }
    }
    enqueue(task);
  } finally {
    lock.unlock();
  }
}
 
开发者ID:tramchamploo,项目名称:buffer-slayer,代码行数:42,代码来源:SizeBoundedQueue.java

示例7: rejectAll

import org.jdeferred.Deferred; //导入方法依赖的package包/类
private void rejectAll(List<SendingTask> tasks, Strategy overflowStrategy) {
  Object[] messageAndDeferred = SendingTask.unzip(tasks);
  List<Message> messages = (List<Message>) messageAndDeferred[0];
  List<Deferred> deferreds = (List<Deferred>) messageAndDeferred[1];
  for (Deferred deferred : deferreds) {
    deferred.reject(dropped(overflowStrategy, messages));
  }
}
 
开发者ID:tramchamploo,项目名称:buffer-slayer,代码行数:9,代码来源:SizeBoundedQueue.java

示例8: checkUserAuthenticated

import org.jdeferred.Deferred; //导入方法依赖的package包/类
@Override
public Promise<BUser, BError, Void> checkUserAuthenticated() {
    if (DEBUG) Timber.v("checkUserAuthenticatedWithCallback, %s", getLoginInfo().get(Prefs.AccountTypeKey));

    final Deferred<BUser, BError, Void> deferred = new DeferredObject<>();

    if (isAuthing())
    {
        if (DEBUG) Timber.d("Already Authing!, Status: %s", authingStatus.name());

        deferred.reject(BError.getError(BError.Code.AUTH_IN_PROCESS, "Cant run two auth in parallel"));
    }
    else
    {
        authingStatus = AuthStatus.CHECKING_IF_AUTH;

        if (!getLoginInfo().containsKey(Prefs.AccountTypeKey))
        {
            if (DEBUG) Timber.d(TAG, "No account type key");

            resetAuth();
            deferred.reject(new BError(BError.Code.NO_LOGIN_INFO));
        }

        FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

        if (user!=null)
        {
            handleFAUser(user).done(new DoneCallback<BUser>() {
                @Override
                public void onDone(BUser bUser) {
                    resetAuth();
                    deferred.resolve(bUser);
                }
            }).fail(new FailCallback<BError>() {
                @Override
                public void onFail(BError bError) {
                    resetAuth();
                    deferred.reject(bError);
                }
            });
        }
        else{
            resetAuth();
            deferred.reject(BError.getError(BError.Code.NO_AUTH_DATA, "No auth data found"));
        }
    }

    return deferred.promise();
}
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:51,代码来源:BChatcatNetworkAdapter.java

示例9: getFollowers

import org.jdeferred.Deferred; //导入方法依赖的package包/类
@Override
public Promise<List<BUser>, BError, Void> getFollowers(String entityId){
    if (DEBUG) Timber.v("getFollowers, Id: %s", entityId);

    final Deferred<List<BUser>, BError, Void> deferred = new DeferredObject<>();
    
    if (StringUtils.isEmpty(entityId))
    {
        return deferred.reject(BError.getError(BError.Code.NULL, "Entity id is empty"));
    }

    final BUser user = DaoCore.fetchOrCreateEntityWithEntityID(BUser.class, entityId);

    DatabaseReference followersRef = FirebasePaths.userFollowersRef(entityId);

    followersRef.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snapshot) {

            final List<BUser> followers = new ArrayList<BUser>();

            for (DataSnapshot snap : snapshot.getChildren())
            {
                String followingUserID = snap.getKey();

                if (StringUtils.isNotEmpty(followingUserID))
                {
                    BUser follwer = DaoCore.fetchOrCreateEntityWithEntityID(BUser.class, followingUserID);

                    FollowerLink f = user.fetchOrCreateFollower(follwer, FollowerLink.Type.FOLLOWER);

                    followers.add(follwer);
                } else if (DEBUG) Timber.e("Follower id is empty");
            }

            Promise[] promises= new Promise[followers.size()];
            
            int count = 0;
            for (BUser u : followers)
            {
                promises[count] = BUserWrapper.initWithModel(u).once();

                count++;
            }
            
            MasterDeferredObject masterDeferredObject = new MasterDeferredObject(promises);

            masterDeferredObject.progress(new ProgressCallback<MasterProgress>() {
                @Override
                public void onProgress(MasterProgress masterProgress) {

                    if (DEBUG) Timber.d("MasterDeferredProgress, done: %s, failed: %s, total: %s", masterProgress.getDone(), masterProgress.getFail(), masterProgress.getTotal());

                    // Reject the promise if all promisses failed.
                    if (masterProgress.getFail() == masterProgress.getTotal())
                    {
                        deferred.reject(BError.getError(BError.Code.OPERATION_FAILED, "All promises failed"));
                    }
                    else
                        deferred.resolve(followers);
                }
            });
        }

        @Override
        public void onCancelled(DatabaseError firebaseError) {
            deferred.reject(getFirebaseError(firebaseError));
        }
    });

    
    return deferred.promise();
}
 
开发者ID:MobileDev418,项目名称:chat-sdk-android-push-firebase,代码行数:74,代码来源:BChatcatNetworkAdapter.java

示例10: addUsersToThread

import org.jdeferred.Deferred; //导入方法依赖的package包/类
/** Add given users list to the given thread.
 * The RepetitiveCompletionListenerWithError will notify by his "onItem" method for each user that was successfully added.
 * In the "onItemFailed" you can get all users that the system could not add to the server.
 * When all users are added the system will call the "onDone" method.*/
@Override
public Promise<BThread, BError, Void> addUsersToThread(final BThread thread, final List<BUser> users) {
    
    final Deferred<BThread, BError, Void>  deferred = new DeferredObject<>();
            
    if (thread == null)
    {
        if (DEBUG) Timber.e("addUsersToThread, Thread is null" );
        return deferred.reject(new BError(BError.Code.NULL, "Thread is null"));
    }

    if (DEBUG) Timber.d("Users Amount: %s", users.size());

    Promise[] promises = new Promise[users.size()];
    
    BThreadWrapper threadWrapper = new BThreadWrapper(thread);
    
    int count = 0;
    for (BUser user : users){
        
        // Add the user to the thread
        if (!user.hasThread(thread))
        {
            DaoCore.connectUserAndThread(user, thread);
        }
        
        promises[count] = threadWrapper.addUser(BUserWrapper.initWithModel(user));
        count++;
    }
    
    MasterDeferredObject masterDeferredObject = new MasterDeferredObject(promises);
    
    masterDeferredObject.progress(new ProgressCallback<MasterProgress>() {
        @Override
        public void onProgress(MasterProgress masterProgress) {
            if (masterProgress.getFail() + masterProgress.getDone() == masterProgress.getTotal())
            {
                // Reject the promise if all promisses failed.
                if (masterProgress.getFail() == masterProgress.getTotal())
                {
                    deferred.reject(BError.getError(BError.Code.OPERATION_FAILED, "All promises failed"));
                }
                else
                    deferred.resolve(thread);
            }
        }
    });
    
    
    return deferred.promise();
}
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:56,代码来源:BChatcatNetworkAdapter.java

示例11: rejectAll

import org.jdeferred.Deferred; //导入方法依赖的package包/类
public static <M extends Message> void rejectAll(Throwable t, List<Deferred> deferreds, List<M> messages) {
  for (Deferred deferred : deferreds) {
    deferred.reject(MessageDroppedException.dropped(t, messages));
  }
}
 
开发者ID:tramchamploo,项目名称:buffer-slayer,代码行数:6,代码来源:Deferreds.java

示例12: getFollows

import org.jdeferred.Deferred; //导入方法依赖的package包/类
@Override
public Promise<List<BUser>, BError, Void>  getFollows(String entityId){
    if (DEBUG) Timber.v("getFollowers, Id: %s", entityId);

    final Deferred<List<BUser>, BError, Void> deferred = new DeferredObject<>();

    if (StringUtils.isEmpty(entityId))
    {
        return deferred.reject(BError.getError(BError.Code.NULL, "Entity id is empty"));
    }

    final BUser user = DaoCore.fetchOrCreateEntityWithEntityID(BUser.class, entityId);

    DatabaseReference followersRef = FirebasePaths.userFollowsRef(entityId);

    followersRef.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snapshot) {
            final List<BUser> followers = new ArrayList<BUser>();

            for (DataSnapshot snap : snapshot.getChildren())
            {
                String followingUserID = snap.getKey();

                if (StringUtils.isNotEmpty(followingUserID))
                {
                    BUser follwer = DaoCore.fetchOrCreateEntityWithEntityID(BUser.class, followingUserID);

                    FollowerLink f = user.fetchOrCreateFollower(follwer, FollowerLink.Type.FOLLOWS);

                    followers.add(follwer);
                }
            }

            Promise[] promises= new Promise[followers.size()];

            int count = 0;
            for (BUser u : followers)
            {
                promises[count] = BUserWrapper.initWithModel(u).once();

                count++;
            }

            MasterDeferredObject masterDeferredObject = new MasterDeferredObject(promises);

            masterDeferredObject.progress(new ProgressCallback<MasterProgress>() {
                @Override
                public void onProgress(MasterProgress masterProgress) {

                    if (DEBUG) Timber.d("MasterDeferredProgress, done: %s, failed: %s, total: %s", masterProgress.getDone(), masterProgress.getFail(), masterProgress.getTotal());

                    // Reject the promise if all promisses failed.
                    if (masterProgress.getFail() == masterProgress.getTotal())
                    {
                        deferred.reject(BError.getError(BError.Code.OPERATION_FAILED, "All promises failed"));
                    }
                    else
                        deferred.resolve(followers);
                }
            });
        }

        @Override
        public void onCancelled(DatabaseError firebaseError) {
            deferred.reject(getFirebaseError(firebaseError));
        }
    });

    return deferred.promise();
}
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:72,代码来源:BChatcatNetworkAdapter.java

示例13: getInvitableFriendsList

import org.jdeferred.Deferred; //导入方法依赖的package包/类
/** Does not work if your app dosent have facebook game app privileges.*/
public static Promise<List<JSONObject>, BError, Void> getInvitableFriendsList(){

    final Deferred<List<JSONObject>, BError, Void> deferred = new DeferredObject<>();
    
    final Session session = Session.getActiveSession();
    if (session != null && session.isOpened()) {

        // Get a list of friends who have _not installed_ the game.
        Request invitableFriendsRequest = Request.newGraphPathRequest(session,
                "/me/invitable_friends", new Request.Callback() {

                    @Override
                    public void onCompleted(Response response) {

                        FacebookRequestError error = response.getError();
                        if (error != null) {
                            if (DEBUG) Timber.e(error.toString());
                            deferred.reject(new BError(BError.Code.TAGGED, "Error while fetching invitable friends.", error));
                        } else if (session == Session.getActiveSession()) {
                            if (response != null) {
                                // Get the result
                                GraphObject graphObject = response.getGraphObject();
                                JSONArray dataArray = (JSONArray)graphObject.getProperty("data");

                                List<JSONObject> invitableFriends = new ArrayList<JSONObject>();
                                if (dataArray.length() > 0) {
                                    // Ensure the user has at least one friend ...

                                    for (int i=0; i<dataArray.length(); i++) {
                                        invitableFriends.add(dataArray.optJSONObject(i));
                                    }
                                }
                                deferred.resolve(invitableFriends);
                            }
                        }
                    }

                });

        Bundle invitableParams = new Bundle();
        invitableParams.putString("fields", "id,first_name,picture");
        invitableFriendsRequest.setParameters(invitableParams);
        invitableFriendsRequest.executeAsync();
    }
    else
    {
        if (DEBUG) Timber.d("Session is closed");
        deferred.reject(new BError(BError.Code.SESSION_CLOSED));
    }
    
    return deferred.promise();

}
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:55,代码来源:BFacebookManager.java


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