forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
1ae4191 Merge pull request #19 from jianghaolu/updates 8b43962 Remove header after use 3e644d9 Fix parameterized host concurrency issue 7ad2207 Update dependencies to official releases 87afa33 Merge pull request #18 from jianghaolu/renamesetters 9c4442d Address checkstyle errors c09b620 Merge commit '083e8ab0c10b58e1491cd38235da5110121ef326' into javavnext b5859aa Merge pull request #17 from jianghaolu/renamesetters 24d5c1e Fix all sets to be withs 9e11dd2 Some more renamings 1b17bc9 Renamed setXXX() to withXXX() for non-top level methods b859906 Framework for Creatable composition, managing dependency between them and creating resources based on topotogical order faf7508 Merge commit '97bc529bbb06017de0bb069012c016c2949157be' into javavnext f116efa Merge branch 'master' of github.com:Azure/AutoRest into quickvm 5202139 Fix styles and tests 99cd7ee Merge commit 'fddca6a8917951772a65a3e5b47c5e72c1f42fb5' into ua f1585bd Use SNAPSHOT runtime as dependency 9295380 Merge commit '9513e6ec31afd0bc1418f07feb3ff8202041f608' into javavnext 4a965fd Merge pull request Azure#984 from jianghaolu/builder 8009399 Address checkstyle errors 9a27d68 Support base URL replace using Interceptor (Retrofit 2.0) b6c78d5 Add RestClient dfba322 Move .build() from collection calls to initialize() b7dc878 Use String for OData ea61512 Fix paged list to use hasNextPage() for hasNext() 4ff082d Extend functionality for paged lists cea6f72 Remove get prefix on model property getters fc7d9a9 Rename AutoRestException to RestException a6feaf0 Okio 1.7.0 e4ba498 Merge pull request Azure#908 from jianghaolu/master 5a6f236 Merge pull request Azure#891 from dtretyakov/master 711df83 Azure#622: Shutdown ADAL auth executors 49a0c03 Fix head response with headers 045fb77 Fix status code validation in java client 7a39169 Merge pull request Azure#872 from jianghaolu/large 7fbb811 Fix stream type in input mappings 84c75d9 Azure#742 Hide RFC1123 on parameters d9c5f88 Azure#742: Hide DateTimeRfc1123 a718459 commons-io was for debugging 589df22 Add download streaming support beefee6 Merge pull request Azure#851 from jianghaolu/lazy 26c3d3a Fix NPE 4d07844 Remove system.err 639f69e Change file upload type to java.io.File 9946a01 Fix close() in retry handler 4bbb4a5 add close() to response bodies 6ac47d9 Manually change byte[] to File d1d64d7 Add missing javadoc 689ff03 Add more laziness to PagedList f4307d2 Fix iterator and add tests for PagedList 31794ef Add lazy behavior in get() 6fc1dd9 Add Javadoc and cleanup b1e5619 A working solution for lazy initiliazed paging 5e04616 Use 1.0.0-SNAPSHOT for new dev phase 97b7174 Unify resources in runtime 5071471 Merge pull request Azure#821 from jianghaolu/moredev d75ac2c parameter.getClass() -> parameterType aa043b7 Fix recursive validation 1f13aa5 Merge pull request Azure#803 from jianghaolu/moredev d44df63 Fix credentials test c1ce2de Add more info to revision file 54f180a Add gradle task to generate git revision 23b9424 Fix flattening and bump up to 1.0.0-beta1 b6b7223 Merge pull request #5 from jianghaolu/flattening c60a85b Merge branch 'flattening' of https://github.com/stankovski/AutoRest into readonly git-subtree-dir: runtimes git-subtree-split: 1ae4191
- Loading branch information
1 parent
469f442
commit 4aa3dd4
Showing
20 changed files
with
774 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,4 +114,4 @@ task javadocJar(type: Jar, dependsOn: [javadoc]) { | |
artifacts { | ||
archives sourcesJar | ||
archives javadocJar | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
azure-client-runtime/src/main/java/com/microsoft/azure/DAGNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** | ||
* | ||
* 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; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* The type representing node in a {@link DAGraph}. | ||
* | ||
* @param <T> the type of the data stored in the node | ||
*/ | ||
public class DAGNode<T> extends Node<T> { | ||
private List<String> dependentKeys; | ||
private int toBeResolved; | ||
|
||
/** | ||
* Creates a DAG node. | ||
* | ||
* @param key unique id of the node | ||
* @param data data to be stored in the node | ||
*/ | ||
public DAGNode(String key, T data) { | ||
super(key, data); | ||
dependentKeys = new ArrayList<>(); | ||
} | ||
|
||
/** | ||
* @return a list of keys of nodes in {@link DAGraph} those are dependents on this node | ||
*/ | ||
List<String> dependentKeys() { | ||
return this.dependentKeys; | ||
} | ||
|
||
/** | ||
* mark the node identified by the given key as dependent of this node. | ||
* | ||
* @param key the id of the dependent node | ||
*/ | ||
public void addDependent(String key) { | ||
this.dependentKeys.add(key); | ||
} | ||
|
||
/** | ||
* @return a list of keys of nodes in {@link DAGraph} that this node depends on | ||
*/ | ||
public List<String> dependencyKeys() { | ||
return this.children(); | ||
} | ||
|
||
/** | ||
* mark the node identified by the given key as this node's dependency. | ||
* | ||
* @param dependencyKey the id of the dependency node | ||
*/ | ||
public void addDependency(String dependencyKey) { | ||
toBeResolved++; | ||
super.addChild(dependencyKey); | ||
} | ||
|
||
/** | ||
* @return <tt>true</tt> if this node has any dependency | ||
*/ | ||
public boolean hasDependencies() { | ||
return this.hasChildren(); | ||
} | ||
|
||
/** | ||
* @return <tt>true</tt> if all dependencies of this node are ready to be consumed | ||
*/ | ||
boolean hasAllResolved() { | ||
return toBeResolved == 0; | ||
} | ||
|
||
/** | ||
* Reports that one of this node's dependency has been resolved and ready to be consumed. | ||
* | ||
* @param dependencyKey the id of the dependency node | ||
*/ | ||
void reportResolved(String dependencyKey) { | ||
if (toBeResolved == 0) { | ||
throw new RuntimeException("invalid state - " + this.key() + ": The dependency '" + dependencyKey + "' is already reported or there is no such dependencyKey"); | ||
} | ||
toBeResolved--; | ||
} | ||
} |
163 changes: 163 additions & 0 deletions
163
azure-client-runtime/src/main/java/com/microsoft/azure/DAGraph.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
/** | ||
* | ||
* 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; | ||
|
||
import java.util.ArrayDeque; | ||
import java.util.Map; | ||
import java.util.Queue; | ||
|
||
/** | ||
* Type representing a DAG (directed acyclic graph). | ||
* <p> | ||
* each node in a DAG is represented by {@link DAGNode} | ||
* | ||
* @param <T> the type of the data stored in the graph nodes | ||
* @param <U> the type of the nodes in the graph | ||
*/ | ||
public class DAGraph<T, U extends DAGNode<T>> extends Graph<T, U> { | ||
private Queue<String> queue; | ||
private boolean hasParent; | ||
private U rootNode; | ||
|
||
/** | ||
* Creates a new DAG. | ||
* | ||
* @param rootNode the root node of this DAG | ||
*/ | ||
public DAGraph(U rootNode) { | ||
this.rootNode = rootNode; | ||
this.queue = new ArrayDeque<>(); | ||
this.addNode(rootNode); | ||
} | ||
|
||
/** | ||
* @return <tt>true</tt> if this DAG is merged with another DAG and hence has a parent | ||
*/ | ||
public boolean hasParent() { | ||
return hasParent; | ||
} | ||
|
||
/** | ||
* Checks whether the given node is root node of this DAG. | ||
* | ||
* @param node the node {@link DAGNode} to be checked | ||
* @return <tt>true</tt> if the given node is root node | ||
*/ | ||
public boolean isRootNode(U node) { | ||
return this.rootNode == node; | ||
} | ||
|
||
/** | ||
* Merge this DAG with another DAG. | ||
* <p> | ||
* this will mark this DAG as a child DAG, the dependencies of nodes in this DAG will be merged | ||
* with (copied to) the parent DAG | ||
* | ||
* @param parent the parent DAG | ||
*/ | ||
public void merge(DAGraph<T, U> parent) { | ||
this.hasParent = true; | ||
parent.rootNode.addDependency(this.rootNode.key()); | ||
this.rootNode.addDependent(parent.rootNode.key()); | ||
for (Map.Entry<String, U> entry: graph.entrySet()) { | ||
String key = entry.getKey(); | ||
if (!parent.graph.containsKey(key)) { | ||
parent.graph.put(key, entry.getValue()); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Prepares this DAG for traversal using getNext method, each call to getNext returns next node | ||
* in the DAG with no dependencies. | ||
*/ | ||
public void prepare() { | ||
initializeQueue(); | ||
if (queue.isEmpty()) { | ||
throw new RuntimeException("Found circular dependency"); | ||
} | ||
} | ||
|
||
/** | ||
* Gets next node in the DAG which has no dependency or all of it's dependencies are resolved and | ||
* ready to be consumed. | ||
* <p> | ||
* null will be returned when all the nodes are explored | ||
* | ||
* @return next node | ||
*/ | ||
public U getNext() { | ||
return graph.get(queue.poll()); | ||
} | ||
|
||
/** | ||
* Gets the data stored in a graph node with a given key. | ||
* | ||
* @param key the key of the node | ||
* @return the value stored in the node | ||
*/ | ||
public T getNodeData(String key) { | ||
return graph.get(key).data(); | ||
} | ||
|
||
/** | ||
* Reports that a node is resolved hence other nodes depends on it can consume it. | ||
* | ||
* @param completed the node ready to be consumed | ||
*/ | ||
public void reportedCompleted(U completed) { | ||
String dependency = completed.key(); | ||
for (String dependentKey : graph.get(dependency).dependentKeys()) { | ||
DAGNode<T> dependent = graph.get(dependentKey); | ||
dependent.reportResolved(dependency); | ||
if (dependent.hasAllResolved()) { | ||
queue.add(dependent.key()); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* populate dependents of all nodes. | ||
* <p> | ||
* the DAG will be explored in DFS order and all node's dependents will be identified, | ||
* this prepares the DAG for traversal using getNext method, each call to getNext returns next node | ||
* in the DAG with no dependencies. | ||
*/ | ||
public void populateDependentKeys() { | ||
this.queue.clear(); | ||
visit(new Visitor<U>() { | ||
@Override | ||
public void visit(U node) { | ||
if (node.dependencyKeys().isEmpty()) { | ||
queue.add(node.key()); | ||
return; | ||
} | ||
|
||
String dependentKey = node.key(); | ||
for (String dependencyKey : node.dependencyKeys()) { | ||
graph.get(dependencyKey) | ||
.dependentKeys() | ||
.add(dependentKey); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Initializes the queue that tracks the next set of nodes with no dependencies or | ||
* whose dependencies are resolved. | ||
*/ | ||
private void initializeQueue() { | ||
this.queue.clear(); | ||
for (Map.Entry<String, U> entry: graph.entrySet()) { | ||
if (!entry.getValue().hasDependencies()) { | ||
this.queue.add(entry.getKey()); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.