本文整理汇总了Java中org.jdeferred.Deferred类的典型用法代码示例。如果您正苦于以下问题:Java Deferred类的具体用法?Java Deferred怎么用?Java Deferred使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Deferred类属于org.jdeferred包,在下文中一共展示了Deferred类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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();
}
示例3: removeUserWithEntityID
import org.jdeferred.Deferred; //导入依赖的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();
}
示例4: push
import org.jdeferred.Deferred; //导入依赖的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();
}
示例5: getUserFriendList
import org.jdeferred.Deferred; //导入依赖的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();
}
示例6: send
import org.jdeferred.Deferred; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Promise<MultipleResults, OneReject, MasterProgress> send(final List<SendingTask<M>> tasks) {
logger.debug("Sending {} messages.", tasks.size());
Object[] messageAndDeferred = SendingTask.unzipGeneric(tasks);
final List<M> messages = (List<M>) messageAndDeferred[0];
final List<Deferred> deferreds = (List<Deferred>) messageAndDeferred[1];
executor.execute(new Runnable() {
@Override
public void run() {
try {
List<R> result = delegate.send(messages);
Deferreds.resolveAll(result, deferreds);
} catch (Throwable t) {
Deferreds.rejectAll(t, deferreds, messages);
}
}
});
return new MasterDeferredObject(deferreds.toArray(new Deferred[0])).promise();
}
示例7: isOnline
import org.jdeferred.Deferred; //导入依赖的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();
}
示例8: getAll
import org.jdeferred.Deferred; //导入依赖的package包/类
@Override
public <T extends BaseModel> Deferred getAll() {
String verb = "GET";
String resourceUrl = T.url;
try {
final Deferred deferred = this.request(resourceUrl, verb).addAuthenticationHeaders(true).send();
return deferred;
} catch (AuthenticationRequiredError authenticationRequiredError) {
authenticationRequiredError.printStackTrace();
}
return null;
}
示例9: addThreadWithEntityId
import org.jdeferred.Deferred; //导入依赖的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();
}
示例10: removeThreadWithEntityId
import org.jdeferred.Deferred; //导入依赖的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();
}
示例11: threadOn
import org.jdeferred.Deferred; //导入依赖的package包/类
public void threadOn(String threadId, Deferred<BThread, Void, Void> deferred){
if (DEBUG) Timber.v("threadOn, EntityID: %s",threadId);
if (!isListeningToThread(threadId))
{
threadsIds.add(threadId);
final DatabaseReference threadRef = FirebasePaths.threadRef(threadId);
// Add an observer to the thread details so we get
// updated when the thread details change
DatabaseReference detailsRef = threadRef.child(BFirebaseDefines.Path.BDetailsPath);
FirebaseEventCombo combo = getCombo(threadId, detailsRef.toString(), new ThreadUpdateChangeListener(threadId, handlerThread, deferred));
detailsRef.addValueEventListener(combo.getListener());
}
else if (DEBUG) Timber.e("Thread is already handled..");
}
示例12: uploadImageWithoutThumbnail
import org.jdeferred.Deferred; //导入依赖的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();
}
示例13: 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);
}
}
}
示例14: addUserWithEntityID
import org.jdeferred.Deferred; //导入依赖的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();
}
示例15: updateIndex
import org.jdeferred.Deferred; //导入依赖的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();
}