本文整理汇总了Java中com.firebase.client.MutableData类的典型用法代码示例。如果您正苦于以下问题:Java MutableData类的具体用法?Java MutableData怎么用?Java MutableData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MutableData类属于com.firebase.client包,在下文中一共展示了MutableData类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: shouldRunCachedTransaction
import com.firebase.client.MutableData; //导入依赖的package包/类
public void shouldRunCachedTransaction() {
Firebase child = ref.child("states/NY");
Status status = QuasarUtil.INSTANCE.runInFiber(() -> {
return new TransactionHandlerCachedAsync() {
@Override
protected void requestAsync() {
child.addValueEventListener(this);
}
@Override
public Transaction.Result doTransaction(MutableData snap) {
snap.setValue("New York");
return Transaction.success(snap);
}
}.run();
});
verify(status, child, "New York");
}
开发者ID:azell,项目名称:quasar-firebase,代码行数:21,代码来源:FirebaseTest.java
示例2: completeTodoList
import com.firebase.client.MutableData; //导入依赖的package包/类
@Override
public void completeTodoList() {
// Update all child tasks for this key to have done = true.
Firebase tasksRef = mTasks;
tasksRef.runTransaction(new Transaction.Handler() {
@Override
public Transaction.Result doTransaction(MutableData mutableData) {
// Note: This is very easy to make conflicts with. It may be better to avoid doing
// this in a batch or to split up the Task into components.
for (MutableData taskData : mutableData.getChildren()) {
TaskSpec spec = taskData.getValue(TaskSpec.class);
if (!spec.getDone()) {
spec.setDone(true);
}
taskData.setValue(spec);
}
return Transaction.success(mutableData);
}
@Override
public void onComplete(FirebaseError firebaseError, boolean b,
DataSnapshot dataSnapshot) {
}
});
// Further, update this todo list to set its last updated time.
updateListTimestamp();
}
开发者ID:vanadium-archive,项目名称:todos,代码行数:29,代码来源:FirebaseTodoList.java
示例3: doTransaction
import com.firebase.client.MutableData; //导入依赖的package包/类
@Override
public Transaction.Result doTransaction(MutableData mutableData) {
if (mutableData.getValue() == null) {
mutableData.setValue(increment);
} else {
mutableData.setValue((Long) mutableData.getValue() + increment);
}
return Transaction.success(mutableData);
}
开发者ID:rapidpro,项目名称:ureport-android,代码行数:10,代码来源:ValueIncrementerTransaction.java
示例4: shouldRunUncachedTransaction
import com.firebase.client.MutableData; //导入依赖的package包/类
public void shouldRunUncachedTransaction() {
AtomicInteger count = new AtomicInteger(0);
Firebase child = ref.child("states/AL");
Status status = QuasarUtil.INSTANCE.runInFiber(() -> {
return new TransactionHandlerAsync() {
@Override
protected void requestAsync() {
child.runTransaction(this, false);
}
@Override
public Transaction.Result doTransaction(MutableData snap) {
Object obj = snap.getValue();
if (count.getAndIncrement() == 0) {
assertNull(obj);
} else {
assertNotNull(obj);
snap.setValue("Roll Tide");
}
return Transaction.success(snap);
}
}.run();
});
verify(status, child, "Roll Tide");
}
开发者ID:azell,项目名称:quasar-firebase,代码行数:31,代码来源:FirebaseTest.java
示例5: reset
import com.firebase.client.MutableData; //导入依赖的package包/类
private void reset(@NotNull final Firebase taskRef, @Nullable final String ownerId, @NotNull final String inProgressState, @Nullable final Listener listener, final long retries) {
taskRef.runTransaction(new Transaction.Handler() {
@Override
public Transaction.Result doTransaction(MutableData task) {
if(task.getValue() == null) {
return Transaction.success(task);
}
Log.log("Resetting task " + taskRef.getKey());
@SuppressWarnings("unchecked") Map<String, Object> value = task.getValue(Map.class);
Object taskOwner = value.get(Task.OWNER_KEY);
// if the ownerId is null it means that we're force resetting this task, so we allow it to go through
boolean ownersMatch = ownerId == null || ownerId.equals(taskOwner);
if(inProgressState.equals(value.get(Task.STATE_KEY)) && ownersMatch) {
value.put(Task.STATE_KEY, taskSpec.getStartState());
value.put(Task.STATE_CHANGED_KEY, ServerValue.TIMESTAMP);
value.put(Task.OWNER_KEY, null);
value.put(Task.ERROR_DETAILS_KEY, null);
task.setValue(value);
return Transaction.success(task);
}
else {
if(listener != null) listener.onResetFailed("Couldn't reset this task because it is owned by another worker", false);
if(!ownersMatch) {
Log.log("Can't reset task " + taskRef.getKey() + " on " + ownerId + " because it is owned by " + taskOwner);
}
else {
Log.log("Can't reset task " + taskRef.getKey() + " - _state != in_progress_state");
}
return Transaction.abort();
}
}
@Override
public void onComplete(FirebaseError error, boolean committed, DataSnapshot snapshot) {
String taskKey = snapshot.getKey();
if(error != null) {
final long incrementedRetries = retries + 1;
if(incrementedRetries < Queue.MAX_TRANSACTION_RETRIES) {
Log.log("Received error while resetting task " + taskKey + "...retrying", error);
reset(taskRef, ownerId, inProgressState, listener, incrementedRetries);
}
else {
Log.log("Can't reset task " + taskKey + " - transaction errored too many times, no longer retrying", error);
if(listener != null) listener.onResetFailed("Can't reset task - transaction errored too many times, no longer retrying", true);
}
}
else {
if(committed && snapshot.exists()) {
Log.log("reset " + taskKey);
}
if(listener != null) listener.onReset();
}
}
}, false);
}
开发者ID:isapp,项目名称:firebase-queue-java,代码行数:59,代码来源:TaskReset.java
示例6: resolve
import com.firebase.client.MutableData; //导入依赖的package包/类
private void resolve(@NotNull final Map<String, Object> newTask, @Nullable final Listener listener, final long retries) {
Log.debug("Attempting to resolve task " + taskRef.getKey() + " on " + ownerId);
if(!canActionBeTakenBeforeTransaction(ACTION_RESOLVED, listener)) {
return;
}
taskRef.runTransaction(new Transaction.Handler() {
private boolean abortedTransactionBecauseOfState;
@Override
public Transaction.Result doTransaction(MutableData task) {
if(!canActionBeTakenInTransaction(listener, ACTION_RESOLVED)) {
abortedTransactionBecauseOfState = true;
return Transaction.abort();
}
// if this task no longer exists
if(task.getValue() == null) {
Log.debug("Tried resolving task " + taskRef.getKey() + " on " + ownerId + " after someone else removed it");
return Transaction.success(task);
}
@SuppressWarnings("unchecked") Map<String, Object> value = task.getValue(Map.class);
String ourInProgressState = taskSpec.getInProgressState();
Object taskState = value.get(STATE_KEY);
Object taskOwner = value.get(OWNER_KEY);
boolean ownersMatch = ownerId.equals(taskOwner);
if((ourInProgressState == taskState || (ourInProgressState != null && ourInProgressState.equals(taskState))) && ownersMatch) {
if(taskSpec.getFinishedState() == null) {
task.setValue(null);
return Transaction.success(task);
}
newTask.put(STATE_KEY, taskSpec.getFinishedState());
newTask.put(STATE_CHANGED_KEY, ServerValue.TIMESTAMP);
newTask.put(OWNER_KEY, null);
newTask.put(ERROR_DETAILS_KEY, null);
task.setValue(newTask);
return Transaction.success(task);
}
else {
if(!ownersMatch) {
Log.debug("Tried resolving task " + taskRef.getKey() + " on " + ownerId + " but it is owned by " + taskOwner);
}
else {
Log.debug("Tried resolving task " + taskRef.getKey() + " on " + ownerId + " but its _state (" + taskState + ") did not match our _in_progress_state (" + ourInProgressState + ")");
}
return Transaction.abort();
}
}
@Override
public void onComplete(FirebaseError error, boolean committed, DataSnapshot snapshot) {
final String taskKey = snapshot.getKey();
if(abortedTransactionBecauseOfState) {
return;
}
if(error != null) {
final long incrementedRetries = retries + 1;
if(incrementedRetries < Queue.MAX_TRANSACTION_RETRIES) {
Log.debug("Received onFailure while resolving task " + taskKey + " on " + ownerId + "...retrying", error);
resolve(newTask, listener, incrementedRetries);
}
else {
Log.debug("Can't resolve task " + taskKey + " on " + ownerId + " - transaction errored too many times, no longer retrying", error);
if(listener != null) listener.onFailure("Can't resolve task - transaction errored too many times, no longer retrying", true);
}
}
else {
onTransactionSuccess(committed, taskKey, ACTION_RESOLVED, listener);
}
}
}, false);
}
开发者ID:isapp,项目名称:firebase-queue-java,代码行数:79,代码来源:Task.java
示例7: run
import com.firebase.client.MutableData; //导入依赖的package包/类
abstract Transaction.Result run(MutableData currentData);
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:2,代码来源:FirebaseDB.java
注:本文中的com.firebase.client.MutableData类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论