8000 Improved type resolution in decider registration cargs · sdatgit/aws-sdk-java@e81820d · GitHub
[go: up one dir, main page]

Skip to content

Commit e81820d

Browse files
committed
Improved type resolution in decider registration cargs
Brought in java.beans.Expression class to perform dynamic constructor resolution. This is in response to some feedback from Luc on the SWF team. Also removed some redundant code and added a stub POJO to replace an anonymous SWF POJO implementation.
1 parent 8e89db0 commit e81820d

File tree

6 files changed

+58
-55
lines changed

6 files changed

+58
-55
lines changed

aws-java-sdk-osgi/dependency-reduced-pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<artifactId>aws-java-sdk-pom</artifactId>
55
<groupId>com.amazonaws</groupId>
6-
<version>1.10.39</version>
6+
<version>1.10.40-SNAPSHOT</version>
77
</parent>
88
<modelVersion>4.0.0</modelVersion>
99
<groupId>com.amazonaws</groupId>

aws-java-sdk-swf-libraries/src/main/java/com/amazonaws/services/simpleworkflow/flow/junit/spring/SpringTestPOJOWorkflowImplementationGenericWorkflowClient.java

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.util.Map;
1919

2020
import com.amazonaws.services.simpleworkflow.flow.DataConverter;
21-
import com.amazonaws.services.simpleworkflow.flow.DecisionContext;
2221
import com.amazonaws.services.simpleworkflow.flow.DecisionContextProvider;
2322
import com.amazonaws.services.simpleworkflow.flow.WorkflowException;
2423
import com.amazonaws.services.simpleworkflow.flow.core.Promise;
@@ -29,7 +28,7 @@
2928
import com.amazonaws.services.simpleworkflow.flow.generic.StartChildWorkflowReply;
3029
import com.amazonaws.services.simpleworkflow.flow.pojo.POJOWorkflowDefinitionFactoryFactory;
3130
import com.amazonaws.services.simpleworkflow.flow.pojo.POJOWorkflowImplementationFactory;
32-
import com.amazonaws.services.simpleworkflow.flow.spring.WorkflowScope;
31+
import com.amazonaws.services.simpleworkflow.flow.spring.POJOWorkflowStubImplementationFactory;
3332
import com.amazonaws.services.simpleworkflow.flow.test.TestGenericWorkflowClient;
3433
import com.amazonaws.services.simpleworkflow.model.WorkflowExecution;
3534
import com.amazonaws.services.simpleworkflow.model.WorkflowType;
@@ -49,25 +48,7 @@ protected POJOWorkflowImplementationFactory getImplementationFactory(Class<?> wo
4948
if (instanceProxy == null) {
5049
throw new IllegalArgumentException("unknown workflowImplementationType: " + workflowImplementationType);
5150
}
52-
return new POJOWorkflowImplementationFactory() {
53-
54-
@Override
55-
public Object newInstance(DecisionContext decisionContext) throws Exception {
56-
WorkflowScope.setDecisionContext(decisionContext);
57-
return instanceProxy;
58-
}
59-
60-
@Override
61-
public Object newInstance(DecisionContext decisionContext, Object[] constructorArgs) throws Exception {
62-
WorkflowScope.setDecisionContext(decisionContext);
63-
return instanceProxy;
64-
}
65-
66-
@Override
67-
public void deleteInstance(Object instance) {
68-
WorkflowScope.removeDecisionContext();
69-
}
70-
};
51+
return new POJOWorkflowStubImplementationFactory(instanceProxy);
7152
}
7253
});
7354
}

aws-java-sdk-swf-libraries/src/main/java/com/amazonaws/services/simpleworkflow/flow/pojo/POJOWorkflowDefinitionFactoryFactory.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
package com.amazonaws.services.simpleworkflow.flow.pojo;
1616

17+
import java.beans.Expression;
1718
import java.lang.reflect.Method;
1819
import java.util.ArrayList;
1920
import java.util.Collection;
@@ -233,15 +234,7 @@ public Object newInstance(DecisionContext decisionContext) throws Exception {
233234

234235
@Override
235236
public Object newInstance(DecisionContext decisionContext, Object[] constructorArgs) throws Exception {
236-
List<Class<?>> constructorArgsTypes = new ArrayList<Class<?>>();
237-
238-
for (Object arg : constructorArgs) {
239-
constructorArgsTypes.add(arg.getClass());
240-
}
241-
242-
Class<?>[] constructorArgsTypesArray = constructorArgsTypes.toArray(new Class<?>[constructorArgs.length]);
243-
244-
return workflowImplementationType.getDeclaredConstructor(constructorArgsTypesArray).newInstance(constructorArgs);
237+
return new Expression(workflowImplementationType, "new", constructorArgs).getValue();
245238
}
246239

247240
@Override

aws-java-sdk-swf-libraries/src/main/java/com/amazonaws/services/simpleworkflow/flow/pojo/POJOWorkflowImplementationFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
public interface POJOWorkflowImplementationFactory {
2020

21-
public Object newInstance(DecisionContext decisionContext) throws Exception;
21+
Object newInstance(DecisionContext decisionContext) throws Exception;
2222

23-
public Object newInstance(DecisionContext decisionContext, Object[] constructorArgs) throws Exception;
23+
Object newInstance(DecisionContext decisionContext, Object[] constructorArgs) throws Exception;
2424

25-
public void deleteInstance(Object instance);
25+
void deleteInstance(Object instance);
2626

2727
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2012-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
package com.amazonaws.services.simpleworkflow.flow.spring;
16+
17+
import com.amazonaws.services.simpleworkflow.flow.DecisionContext;
18+
import com.amazonaws.services.simpleworkflow.flow.pojo.POJOWorkflowImplementationFactory;
19+
20+
/**
21+
* A stub implementation of the @see{POJOWorkflowImplementationFactory}
22+
* Used for Spring injection proxying
23+
*
24+
* @author nicholasterry
25+
*/
26+
public class POJOWorkflowStubImplementationFactory implements POJOWorkflowImplementationFactory {
27+
28+
private Object instanceProxy;
29+
30+
public POJOWorkflowStubImplementationFactory(Object instanceProxy) {
31+
this.instanceProxy = instanceProxy;
32+
}
33+
34+
@Override
35+
public Object newInstance(DecisionContext decisionContext) throws Exception {
36+
return newInstance(decisionContext, null);
37+
}
38+
39+
@Override
40+
public Object newInstance(DecisionContext decisionContext, Object[] constructorArgs) throws Exception {
41+
WorkflowScope.setDecisionContext(decisionContext);
42+
return instanceProxy;
43+
}
44+
45+
@Override
46+
public void deleteInstance(Object instance) {
47+
WorkflowScope.removeDecisionContext();
48+
}
49+
}

aws-java-sdk-swf-libraries/src/main/java/com/amazonaws/services/simpleworkflow/flow/spring/SpringWorkflowDefinitionFactoryFactory.java

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.util.Map;
1919

2020
import com.amazonaws.services.simpleworkflow.flow.DataConverter;
21-
import com.amazonaws.services.simpleworkflow.flow.DecisionContext;
2221
import com.amazonaws.services.simpleworkflow.flow.generic.WorkflowDefinitionFactory;
2322
import com.amazonaws.services.simpleworkflow.flow.generic.WorkflowDefinitionFactoryFactory;
2423
import com.amazonaws.services.simpleworkflow.flow.pojo.POJOWorkflowDefinitionFactoryFactory;
@@ -36,26 +35,7 @@ protected POJOWorkflowImplementationFactory getImplementationFactory(Class<?> wo
3635
if (instanceProxy == null) {
3736
throw new IllegalArgumentException("unknown workflowImplementationType: " + workflowImplementationType);
3837
}
39-
return new POJOWorkflowImplementationFactory() {
40-
41-
@Override
42-
public Object newInstance(DecisionContext decisionContext) throws Exception {
43-
WorkflowScope.setDecisionContext(decisionContext);
44-
return instanceProxy;
45-
}
46-
47-
@Override
48-
public Object newInstance(DecisionContext decisionContext, Object[] constructorArgs) throws Exception {
49-
WorkflowScope.setDecisionContext(decisionContext);
50-
return instanceProxy;
51-
}
52-
53-
@Override
54-
public void deleteInstance(Object instance) {
55-
WorkflowScope.removeDecisionContext();
56-
}
57-
58-
};
38+
return new POJOWorkflowStubImplementationFactory(instanceProxy);
5939
}
6040

6141
};

0 commit comments

Comments
 (0)
0