Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See License.txt in the project root for license information.
/** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for * license information. */
package com.microsoft.azure.arm.dag; import com.microsoft.azure.arm.model.Indexable; import rx.Observable; import rx.functions.Func0;
Type representing an entry in TaskGroup that holds one TaskItem and associated information which includes: 1. references to other TaskGroupEntry dependencies 2. references to the other TaskGroupEntry dependents
Type parameters:
  • <TaskT> – the task type that can return a value
/** * Type representing an entry in {@link TaskGroup} that holds one {@link TaskItem} and associated * information which includes: * 1. references to other {@link TaskGroupEntry} dependencies * 2. references to the other {@link TaskGroupEntry} dependents * * @param <TaskT> the task type that can return a value */
final class TaskGroupEntry<TaskT extends TaskItem> extends DAGNode<TaskT, TaskGroupEntry<TaskT>> {
The proxy entry for this entry if exists.
/** * The proxy entry for this entry if exists. */
private TaskGroupEntry<TaskT> proxy;
indicates that one or more decedent dependency tasks are faulted.
/** * indicates that one or more decedent dependency tasks are faulted. */
private boolean hasFaultedDescentDependencyTasks;
Creates TaskGroupEntry.
Params:
  • taskId – id that uniquely identifies the task from other tasks in the group
  • taskItem – the task this entry holds
/** * Creates TaskGroupEntry. * * @param taskId id that uniquely identifies the task from other tasks in the group * @param taskItem the task this entry holds */
TaskGroupEntry(String taskId, TaskT taskItem) { super(taskId, taskItem); } @Override public void initialize() { super.initialize(); this.hasFaultedDescentDependencyTasks = false; }
Set the proxy entry for this entry.
Params:
  • proxy – the proxy entry
/** * Set the proxy entry for this entry. * * @param proxy the proxy entry */
public void setProxy(TaskGroupEntry<TaskT> proxy) { this.proxy = proxy; }
Returns:the proxy entry if it is set, null if not set.
/** * @return the proxy entry if it is set, null if not set. */
public TaskGroupEntry<TaskT> proxy() { return this.proxy; }
Returns:the result produced by the task.
/** * @return the result produced by the task. */
public Indexable taskResult() { return taskItem().result(); }
Returns:true if one or more decedent dependency tasks are in faulted state, false otherwise.
/** * @return true if one or more decedent dependency tasks are in faulted * state, false otherwise. */
public boolean hasFaultedDescentDependencyTasks() { return this.hasFaultedDescentDependencyTasks; }
Invokes the task this entry holds. if the task cannot be invoked due to faulted dependencies then an observable that emit ErroredDependencyTaskException will be returned.
Params:
  • ignoreCachedResult – if the task is already invoked and has result cached then a value false for this parameter indicates the cached result can be returned without invoking task again, if true then cached result will be ignored and task will be invoked
  • context – the context object shared across all the entries in the group that this entry belongs to, this will be passed to TaskItem.invokeAsync(InvocationContext) method of the task item
Returns:a cold Observable upon subscription invokes the task this entry hold, which produces a result of type Indexable.
/** * Invokes the task this entry holds. * if the task cannot be invoked due to faulted dependencies then an observable that emit * {@link ErroredDependencyTaskException} will be returned. * * @param ignoreCachedResult if the task is already invoked and has result cached then a value false for this * parameter indicates the cached result can be returned without invoking task again, * if true then cached result will be ignored and task will be invoked * @param context the context object shared across all the entries in the group that this entry belongs to, * this will be passed to {@link TaskItem#invokeAsync(TaskGroup.InvocationContext)} * method of the task item * * @return a cold Observable upon subscription invokes the task this entry hold, which produces a result of * type {@link Indexable}. */
public Observable<Indexable> invokeTaskAsync(boolean ignoreCachedResult, final TaskGroup.InvocationContext context) { if (hasFaultedDescentDependencyTasks) { return Observable.error(new ErroredDependencyTaskException()); } final TaskT taskItem = this.taskItem(); if (!ignoreCachedResult && hasCachedResult()) { return Observable.just(taskItem.result()); } if (taskItem.isHot()) { // Convert hot task to cold to delay it's execution until subscription. return Observable.defer(new Func0<Observable<Indexable>>() { @Override public Observable<Indexable> call() { return taskItem.invokeAsync(context); } }); } else { return taskItem.invokeAsync(context); } } @Override protected void onFaultedResolution(String dependencyKey, Throwable throwable) { super.onFaultedResolution(dependencyKey, throwable); this.hasFaultedDescentDependencyTasks = true; }
Returns:the TaskItem this entry holds.
/** * @return the {@link TaskItem} this entry holds. */
private TaskT taskItem() { return super.data(); }
Returns:true, if the result of the task is cached.
/** * @return true, if the result of the task is cached. */
private boolean hasCachedResult() { return taskItem().result() != null; } }