66import java .util .List ;
77import java .util .Map ;
88import java .util .Optional ;
9- import java .util .UUID ;
109
1110import com .microsoft .azure .functions .ExecutionContext ;
1211import com .microsoft .azure .functions .rpc .messages .ParameterBinding ;
1312import com .microsoft .azure .functions .rpc .messages .TypedData ;
14- import com .microsoft .azure .functions .worker .broker . CoreTypeResolver ;
13+ import com .microsoft .azure .functions .worker .converter . CoreTypeConverter ;
1514
1615import org .apache .commons .lang3 .exception .ExceptionUtils ;
1716
2120 * Thread-safety: Single thread.
2221 */
2322public final class BindingDataStore {
23+
24+ private final Map <String , DataTarget > targets ;
25+ private final Map <String , DataSource <?>> inputSources ;
26+ private final Map <Type , DataSource <?>> otherSources ;
27+ private final Map <String , DataSource <?>> metadataSources ;
28+ private Map <String , BindingDefinition > definitions ;
29+ public static final String RETURN_NAME = "$return" ;
30+
2431 public BindingDataStore () {
2532 this .targets = new HashMap <>();
2633 this .inputSources = new HashMap <>();
2734 this .otherSources = new HashMap <>();
2835 this .metadataSources = new HashMap <>();
29- this .promotedTargets = null ;
3036 }
3137
32- ///////////////////////// region Input Binding Data
33-
38+ //Logics for input Binding Data
3439 public void addParameterSources (List <ParameterBinding > parameters ) {
3540 assert parameters != null ;
3641 for (ParameterBinding parameter : parameters ) {
@@ -92,24 +97,21 @@ private static DataSource<?> rpcSourceFromParameter(ParameterBinding parameter)
9297 return rpcSourceFromTypedData (parameter .getName (), parameter .getData ());
9398 }
9499
95- ///////////////////////// end region Input Binding Data
96-
97- ///////////////////////// region Output Binding Data
98100
99- public List <ParameterBinding > getOutputParameterBindings (boolean excludeReturn ) throws Exception {
101+ //Logics for output Binding Data
102+ public List <ParameterBinding > getOutputParameterBindings () throws Exception {
100103 List <ParameterBinding > bindings = new ArrayList <>();
101- for (Map .Entry <String , DataTarget > entry : this .getTarget (this .promotedTargets ).entrySet ()) {
102- if (!excludeReturn || !entry .getKey ().equals (RETURN_NAME )) {
103- entry .getValue ().computeFromValue ().ifPresent (data ->
104- bindings .add (ParameterBinding .newBuilder ().setName (entry .getKey ()).setData (data ).build ())
105- );
106- }
104+ for (String key : this .targets .keySet ()) {
105+ if (key .equals (RETURN_NAME )) continue ;
106+ DataTarget dataTarget = this .targets .get (key );
107+ dataTarget .computeFromValue ().ifPresent (data ->
108+ bindings .add (ParameterBinding .newBuilder ().setName (key ).setData (data ).build ()));
107109 }
108110 return bindings ;
109111 }
110112
111113 public Optional <TypedData > getDataTargetTypedValue (String name ) throws Exception {
112- return Optional .ofNullable (this .getTarget ( this . promotedTargets ) .get (name )).map (o -> {
114+ return Optional .ofNullable (this .targets .get (name )).map (o -> {
113115 try {
114116 return o .computeFromValue ().orElse (null );
115117 } catch (Exception ex ) {
@@ -119,48 +121,37 @@ public Optional<TypedData> getDataTargetTypedValue(String name) throws Exception
119121 });
120122 }
121123
122- public Optional <BindingData > getOrAddDataTarget (UUID outputId , String name , Type target , boolean hasImplicitOutput ) {
124+ public Optional <BindingData > getOrAddDataTarget (String name , Type target , boolean hasImplicitOutput ) {
123125 DataTarget output = null ;
124126 if (this .isDataTargetValid (name , target )) {
125- output = this .getTarget ( outputId ) .get (name );
127+ output = this .targets .get (name );
126128 if (output == null && (this .isDefinitionOutput (name ) || hasImplicitOutput )) {
127- this .getTarget ( outputId ) .put (name , output = rpcDataTargetFromType (target ));
129+ this .targets .put (name , output = rpcDataTargetFromType (target ));
128130 }
129131 }
130- return Optional .ofNullable (output ).map (out -> new BindingData ( out ) );
132+ return Optional .ofNullable (output ).map (BindingData :: new );
131133 }
132134
133135 public void setDataTargetValue (String name , Object value ) {
134- Optional .ofNullable (this .getTarget (this .promotedTargets ).get (name )).ifPresent (out -> out .setValue (value ));
135- }
136-
137- public void promoteDataTargets (UUID outputId ) {
138- this .promotedTargets = outputId ;
139- }
140-
141- private Map <String , DataTarget > getTarget (UUID outputId ) {
142- return this .targets .computeIfAbsent (outputId , m -> new HashMap <>());
136+ Optional .ofNullable (this .targets .get (name )).ifPresent (out -> out .setValue (value ));
143137 }
144138
145139 private boolean isDataTargetValid (String name , Type target ) {
146140 if (!name .equals (RETURN_NAME )) {
147- if (!CoreTypeResolver .isValidOutputType (target )) { return false ; }
148- target = CoreTypeResolver .getParameterizedActualTypeArgumentsType (target );
141+ if (!CoreTypeConverter .isValidOutputType (target )) { return false ; }
142+ target = CoreTypeConverter .getParameterizedActualTypeArgumentsType (target );
149143 }
150144 return true ;
151145 }
152146
153147 private static DataTarget rpcDataTargetFromType (Type target ) {
154- if (CoreTypeResolver .isHttpResponse (target )) {
148+ if (CoreTypeConverter .isHttpResponse (target )) {
155149 return new RpcHttpDataTarget ();
156150 }
157151 return new RpcUnspecifiedDataTarget ();
158152 }
159153
160- ///////////////////////// end region Output Binding Data
161-
162- ///////////////////////// region Binding Definitions
163-
154+ //Logics for binding Definitions
164155 public void setBindingDefinitions (Map <String , BindingDefinition > definitions ) {
165156 this .definitions = definitions ;
166157 }
@@ -172,14 +163,4 @@ private boolean isDefinitionOutput(String name) {
172163 private Optional <BindingDefinition > getDefinition (String name ) {
173164 return Optional .ofNullable (this .definitions .get (name ));
174165 }
175-
176- ///////////////////////// endregion Binding Definitions
177-
178- private UUID promotedTargets ;
179- private final Map <UUID , Map <String , DataTarget >> targets ;
180- private final Map <String , DataSource <?>> inputSources ;
181- private final Map <Type , DataSource <?>> otherSources ;
182- private final Map <String , DataSource <?>> metadataSources ;
183- private Map <String , BindingDefinition > definitions ;
184- public static final String RETURN_NAME = "$return" ;
185166}
0 commit comments