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


Java DeferredObject类代码示例

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


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

示例1: changePassword

import org.jdeferred.impl.DeferredObject; //导入依赖的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.impl.DeferredObject; //导入依赖的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: removeUserWithEntityID

import org.jdeferred.impl.DeferredObject; //导入依赖的package包/类
/**
 *Remove the thread from the given user threads ref.
 **/
public Promise<BThread, BError, Void> removeUserWithEntityID(String entityId){

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

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

    DatabaseReference ref = FirebasePaths.threadRef(this.entityId).child(BFirebaseDefines.Path.BUsersPath).child(entityId);

    ref.removeValue(new DatabaseReference.CompletionListener() {
        @Override
        public void onComplete(DatabaseError firebaseError, DatabaseReference firebase) {
            if (firebaseError == null)
                deferred.resolve(BThreadWrapper.this.model);
            else
                deferred.reject(getFirebaseError(firebaseError));
        }
    });
    
    return deferred.promise();
}
 
开发者ID:MobileDev418,项目名称:chat-sdk-android-push-firebase,代码行数:24,代码来源:BThreadWrapper.java

示例4: push

import org.jdeferred.impl.DeferredObject; //导入依赖的package包/类
public Promise<BUser, BError, Void> push(){
    if (DEBUG) Timber.v("push");
    
    final Deferred<BUser, BError, Void> deferred = new DeferredObject<>();
    
    ref().updateChildren(serialize(), new DatabaseReference.CompletionListener() {
        @Override
        public void onComplete(DatabaseError firebaseError, DatabaseReference firebase) {
            if (firebaseError == null)
            {
                deferred.resolve(model);
            }
            else deferred.reject(getFirebaseError(firebaseError));
        }
    });

    // index should be updated whenever the user is pushed
    updateIndex();
    
    return deferred.promise();
}
 
开发者ID:MobileDev418,项目名称:chat-sdk-android-push-firebase,代码行数:22,代码来源:BUserWrapper.java

示例5: addThreadWithEntityId

import org.jdeferred.impl.DeferredObject; //导入依赖的package包/类
public Promise<BUserWrapper, DatabaseError, Void> addThreadWithEntityId(String entityId){

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

        // Getting the user ref.
        DatabaseReference userThreadRef = ref();

        userThreadRef = userThreadRef.child(BFirebaseDefines.Path.BThreadPath).child(entityId);

        userThreadRef.child(BDefines.Keys.BNull).setValue("", new DatabaseReference.CompletionListener() {
            @Override
            public void onComplete(DatabaseError firebaseError, DatabaseReference firebase) {
                if (firebaseError == null)
                {
                    deferred.resolve(BUserWrapper.this);
                }
                else
                {
                    deferred.reject(firebaseError);
                }
            }
        });
        
        return deferred.promise();
    }
 
开发者ID:MobileDev418,项目名称:chat-sdk-android-push-firebase,代码行数:26,代码来源:BUserWrapper.java

示例6: getUserFriendList

import org.jdeferred.impl.DeferredObject; //导入依赖的package包/类
public static  Promise<List<GraphUser>, BError, Void>  getUserFriendList(){

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

        
        if (!Session.getActiveSession().getState().isOpened())
        {
            return deferred.reject(new BError(BError.Code.SESSION_CLOSED));
        }
        Request req = Request.newMyFriendsRequest(Session.getActiveSession(), new Request.GraphUserListCallback() {
            @Override
            public void onCompleted(List<GraphUser> users, Response response) {
                deferred.resolve(users);
            }
        });

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

示例7: isOnline

import org.jdeferred.impl.DeferredObject; //导入依赖的package包/类
public Promise<Boolean, BError, Void> isOnline(){

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

        if (currentUserModel() == null)
        {
            return  deferred.reject(BError.getError(BError.Code.NULL, "Current user is null"));
        }

        FirebasePaths.userOnlineRef(currentUserModel().getEntityID()).addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
                
                updateLastOnline();
                
                deferred.resolve((Boolean) snapshot.getValue());
            }

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

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

示例8: removeThreadWithEntityId

import org.jdeferred.impl.DeferredObject; //导入依赖的package包/类
public Promise<BUserWrapper, DatabaseError, Void> removeThreadWithEntityId(String entityId){

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

        DatabaseReference userThreadRef = FirebasePaths.userRef(entityId).child(BFirebaseDefines.Path.BThreadPath).child(entityId);

        userThreadRef.removeValue(new DatabaseReference.CompletionListener() {
            @Override
            public void onComplete(DatabaseError firebaseError, DatabaseReference firebase) {
                if (firebaseError == null)
                {
                    deferred.resolve(BUserWrapper.this);
                }
                else
                {
                    deferred.reject(firebaseError);
                }
            }
        });
        
        return deferred.promise();

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

示例9: uploadImageWithoutThumbnail

import org.jdeferred.impl.DeferredObject; //导入依赖的package包/类
public Promise<String, BError, SaveImageProgress> uploadImageWithoutThumbnail(final Bitmap image) {

        if(image == null) return reject();

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

        uploadHandler.uploadFile(ImageUtils.getImageByteArray(image), "image.jpg", "image/jpeg")
                .done(new DoneCallback<String>() {
                    @Override
                    public void onDone(String url) {
                        deferred.resolve(url);
                    }
                })
                .fail(new FailCallback<BError>() {
                    @Override
                    public void onFail(BError error) {
                        deferred.reject(error);
                    }
                });

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

示例10: handleMessage

import org.jdeferred.impl.DeferredObject; //导入依赖的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

示例11: addUserWithEntityID

import org.jdeferred.impl.DeferredObject; //导入依赖的package包/类
/**
 * Add the thread from the given user threads ref.
 **/
public Promise<BThread, BError, Void> addUserWithEntityID(String entityId){

    final Deferred<BThread, BError, Void>  deferred = new DeferredObject<>();
    
    DatabaseReference ref = FirebasePaths.threadRef(this.entityId)
            .child(BFirebaseDefines.Path.BUsersPath)
            .child(entityId);

    BUser user = DaoCore.fetchOrCreateEntityWithEntityID(BUser.class, entityId);
    
    Map<String, Object> values = new HashMap<String, Object>();

    // If metaname is null the data wont be saved so we have to do so.
    values.put(BDefines.Keys.BName, (user.getMetaName() == null ? "no_name" : user.getMetaName()));
    
    ref.setValue(values, new DatabaseReference.CompletionListener() {
        @Override
        public void onComplete(DatabaseError firebaseError, DatabaseReference firebase) {
            if (firebaseError == null)
                deferred.resolve(BThreadWrapper.this.model);
            else
                deferred.reject(getFirebaseError(firebaseError));
        }
    });
    
    return deferred.promise();
}
 
开发者ID:MobileDev418,项目名称:chat-sdk-android-push-firebase,代码行数:31,代码来源:BThreadWrapper.java

示例12: updateIndex

import org.jdeferred.impl.DeferredObject; //导入依赖的package包/类
public Promise<Void, BError, Void> updateIndex(){

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

        Map<String, String> values = new HashMap<String, String>();
        
        String name = model.getMetaName();
        String email = model.getMetaEmail();
        String phoneNumber = model.metaStringForKey(BDefines.Keys.BPhone);

        values.put(BDefines.Keys.BName, StringUtils.isNotEmpty(name) ? AbstractNetworkAdapter.processForQuery(name) : "");
        values.put(BDefines.Keys.BEmail, StringUtils.isNotEmpty(email) ? AbstractNetworkAdapter.processForQuery(email) : "");

        if (BDefines.IndexUserPhoneNumber && StringUtils.isNotBlank(phoneNumber))
            values.put(BDefines.Keys.BPhone, AbstractNetworkAdapter.processForQuery(phoneNumber));


        DatabaseReference ref = FirebasePaths.indexRef().child(entityId);

        ref.setValue(values, new DatabaseReference.CompletionListener() {
            @Override
            public void onComplete(DatabaseError firebaseError, DatabaseReference firebase) {
                if (firebaseError==null)
                {
                    deferred.resolve(null);
                }
                else{
                    deferred.reject(getFirebaseError(firebaseError));
                }
            }
        });
        
        
        return deferred.promise();
    }
 
开发者ID:MobileDev418,项目名称:chat-sdk-android-push-firebase,代码行数:36,代码来源:BUserWrapper.java

示例13: dropHeadWhenFull_dropHeadStrategy

import org.jdeferred.impl.DeferredObject; //导入依赖的package包/类
@Test
public void dropHeadWhenFull_dropHeadStrategy() throws InterruptedException {
  SizeBoundedQueue queue = new SizeBoundedQueue(16, OverflowStrategy.dropHead);
  CountDownLatch countDown = new CountDownLatch(1);

  for (int i = 0; i < queue.maxSize; i++) {
    Message next = newMessage(i);
    Deferred<Object, MessageDroppedException, Integer> deferred = new DeferredObject<>();
    queue.offer(next, deferred);
    if (i == 0) {
      deferred.fail(ex -> {
        assertEquals(0, ((TestMessage)ex.dropped.get(0)).key);
        countDown.countDown();
      });
    }
  }
  Message overflow = newMessage(queue.maxSize);
  queue.offer(overflow, new DeferredObject<>());
  countDown.await();

  Object[] ids = collectKeys(queue);
  assertArrayEquals(new Object[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, ids);
}
 
开发者ID:tramchamploo,项目名称:buffer-slayer,代码行数:24,代码来源:SizeBoundedQueueTest.java

示例14: dropBufferWhenFull_dropBufferStrategy

import org.jdeferred.impl.DeferredObject; //导入依赖的package包/类
@Test
public void dropBufferWhenFull_dropBufferStrategy() throws InterruptedException {
  SizeBoundedQueue queue = new SizeBoundedQueue(16, OverflowStrategy.dropBuffer);
  CountDownLatch countDown = new CountDownLatch(1);

  for (int i = 0; i < queue.maxSize; i++) {
    TestMessage next = newMessage(i);
    Deferred<Object, MessageDroppedException, Integer> deferred = new DeferredObject<>();
    queue.offer(next, deferred);
    if (i == 0) {
      deferred.fail(ex -> {
        assertEquals(16, ex.dropped.size());
        assertArrayEquals(new Integer[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
            ex.dropped.stream().map(d -> ((TestMessage) d).key).toArray());
        countDown.countDown();
      });
    }
  }

  Message overflow = newMessage(queue.maxSize);
  queue.offer(overflow, new DeferredObject<>());
  countDown.await();

  Object[] ids = collectKeys(queue);
  assertArrayEquals(new Object[]{16}, ids);
}
 
开发者ID:tramchamploo,项目名称:buffer-slayer,代码行数:27,代码来源:SizeBoundedQueueTest.java

示例15: blockCallerWhenFull_blockStrategy

import org.jdeferred.impl.DeferredObject; //导入依赖的package包/类
@Test
public void blockCallerWhenFull_blockStrategy() throws InterruptedException {
  SizeBoundedQueue queue = new SizeBoundedQueue(16, OverflowStrategy.block);
  for (int i = 0; i < queue.maxSize; i++) {
    TestMessage next = newMessage(i);
    queue.offer(next, new DeferredObject<>());
  }

  CountDownLatch countDown = new CountDownLatch(1);
  new Thread(() -> {
    TestMessage shouldBlock = newMessage(10);
    queue.offer(shouldBlock, new DeferredObject<>());
    countDown.countDown();
  }).start();
  assertFalse(countDown.await(10, TimeUnit.MILLISECONDS));
  queue.drainTo(next -> true);
  assertTrue(countDown.await(10, TimeUnit.MILLISECONDS));
}
 
开发者ID:tramchamploo,项目名称:buffer-slayer,代码行数:19,代码来源:SizeBoundedQueueTest.java


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