いくつかのアクティビティがあり、カスタム例外をスローできます。問題は、Activity Worker クラスでスローされた例外をキャッチできず、スタック トレースが表示されていることです。Throwable をキャッチしようとしましたが、スタック トレースが再び表示されるため、役に立ちません。
活動実施クラス
public class TestActivitiesImpl implements TestActivities{
@Override
public Integer testAct1() {
System.out.println("Activity 1 ---->Start");
int count = 0;
while(count < 1000){
count ++;
}
return 1;
}
@SuppressWarnings("unused")
@Override
public Integer testAct2() throws MyException {
System.out.println("Activity 2 ---->Start");
if(true){
throw new MyException("Failed to execute the activity");
}
return 1;
}
}
アクティビティ ワーカー クラス
public class TestActivitiesWorker {
public static void main(String[] args) {
try {
ClientConfiguration config = new ClientConfiguration().withSocketTimeout(70*1000);
String swfAccessId = "ABCDXYZ";
String swfSecretKey = "ABCDXYZ";
AWSCredentials awsCredentials = new BasicAWSCredentials(swfAccessId, swfSecretKey);
AmazonSimpleWorkflow service = new AmazonSimpleWorkflowClient(awsCredentials, config);
service.setEndpoint("ABCDXYZ");
String domain = "EC2-TEST";
ActivityWorker aw = new ActivityWorker(service, domain, "TestList");
aw.addActivitiesImplementation(new TestActivitiesImpl());
aw.start();
}catch (Throwable e) {
System.out.println("Failed to execute Job");
System.out.println(e.getMessage());
}
}
}
スタックトレース
2014 年 10 月 18 日 14:02:53
com.amazonaws.services.simpleworkflow.flow.worker.SynchronousActivityTaskPoller execute
SEVERE: Failure processing activity task with taskId=12, workflowGenerationId=AsyncTest, activity={Name: TestActivities.testAct2,Version: 1.2}, activityInstanceId=2
com.amazonaws.services.simpleworkflow.flow.ActivityFailureException: Failed to execute the activity : ["com.myapp.test.MyException",{"cause":null,"stackTrace":[{"methodName":"testAct2","fileName":"TestActivitiesImpl.java","lineNumber":20,"className":"com.myapp.test.TestActivitiesImpl","nativeMethod":false},{"methodName":"invoke0","fileName":"NativeMethodAccessorImpl.java","lineNumber":-2,"className":"sun.reflect.NativeMethodAccessorImpl","nativeMethod":true},{"methodName":"invoke","fileName":"NativeMethodAccessorImpl.java","lineNumber":57,"className":"sun.reflect.NativeMethodAccessorImpl","nativeMethod":false},{"methodName":"invoke","fileName":"DelegatingMethodAccessorImpl.java","lineNumber":43,"className":"sun.reflect.DelegatingMethodAccessorImpl","nativeMethod":false},{"methodName":"invoke","fileName":"Method.java","lineNumber":606,"className":"java.lang.reflect.Method","nativeMethod":false},{"methodName":"execute","fileName":"POJOActivityImplementation.java","lineNumber":64,"className":"com.amazonaws.services.simpleworkflow.flow.pojo.POJOActivityImplementation","nativeMethod":false},{"methodName":"execute","fileName":"ActivityImplementationBase.java","lineNumber":46,"className":"com.amazonaws.services.simpleworkflow.flow.generic.ActivityImplementationBase","nativeMethod":false},{"methodName":"execute","fileName":"SynchronousActivityTaskPoller.java","lineNumber":196,"className":"com.amazonaws.services.simpleworkflow.flow.worker.SynchronousActivityTaskPoller","nativeMethod":false},{"methodName":"run","fileName":"ActivityTaskPoller.java","lineNumber":92,"className":"com.amazonaws.services.simpleworkflow.flow.worker.ActivityTaskPoller$2","nativeMethod":false},{"methodName":"runWorker","fileName":"ThreadPoolExecutor.java","lineNumber":1145,"className":"java.util.concurrent.ThreadPoolExecutor","nativeMethod":false},{"methodName":"run","fileName":"ThreadPoolExecutor.java","lineNumber":615,"className":"java.util.concurrent.ThreadPoolExecutor$Worker","nativeMethod":false},{"methodName":"run","fileName":"Thread.java","lineNumber":724,"className":"java.lang.Thread","nativeMethod":false}],"message":"Failed to execute the activity","localizedMessage":"Failed to execute the activity","suppressed":["[Ljava.lang.Throwable;",[]]}]
at com.amazonaws.services.simpleworkflow.flow.pojo.POJOActivityImplementation.throwActivityFailureException(POJOActivityImplementation.java:110)
at com.amazonaws.services.simpleworkflow.flow.pojo.POJOActivityImplementation.execute(POJOActivityImplementation.java:67)
at com.amazonaws.services.simpleworkflow.flow.generic.ActivityImplementationBase.execute(ActivityImplementationBase.java:46)
at com.amazonaws.services.simpleworkflow.flow.worker.SynchronousActivityTaskPoller.execute(SynchronousActivityTaskPoller.java:196)
at com.amazonaws.services.simpleworkflow.flow.worker.ActivityTaskPoller$2.run(ActivityTaskPoller.java:92)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)