36
36
import io .temporal .common .converter .DataConverter ;
37
37
import io .temporal .common .converter .EncodedValues ;
38
38
import io .temporal .common .interceptors .ActivityInboundCallsInterceptor ;
39
+ import io .temporal .common .interceptors .Header ;
39
40
import io .temporal .common .interceptors .WorkerInterceptor ;
40
41
import io .temporal .common .metadata .POJOActivityImplMetadata ;
41
42
import io .temporal .common .metadata .POJOActivityInterfaceMetadata ;
@@ -189,7 +190,7 @@ void registerLocalActivityImplementations(Object[] activitiesImplementation) {
189
190
public Result handle (ActivityTask activityTask , Scope metricsScope , boolean localActivity ) {
190
191
PollActivityTaskQueueResponse pollResponse = activityTask .getResponse ();
191
192
String activityType = pollResponse .getActivityType ().getName ();
192
- ActivityInfoImpl activityInfo =
193
+ ActivityInfoInternal activityInfo =
193
194
new ActivityInfoImpl (
194
195
pollResponse , this .namespace , localActivity , activityTask .getCompletionHandle ());
195
196
ActivityTaskExecutor activity = activities .get (activityType );
@@ -212,7 +213,7 @@ public Result handle(ActivityTask activityTask, Scope metricsScope, boolean loca
212
213
}
213
214
214
215
private interface ActivityTaskExecutor {
215
- ActivityTaskHandler .Result execute (ActivityInfoImpl task , Scope metricsScope );
216
+ ActivityTaskHandler .Result execute (ActivityInfoInternal task , Scope metricsScope );
216
217
}
217
218
218
219
private class POJOActivityImplementation implements ActivityTaskExecutor {
@@ -225,7 +226,7 @@ private class POJOActivityImplementation implements ActivityTaskExecutor {
225
226
}
226
227
227
228
@ Override
228
- public ActivityTaskHandler .Result execute (ActivityInfoImpl info , Scope metricsScope ) {
229
+ public ActivityTaskHandler .Result execute (ActivityInfoInternal info , Scope metricsScope ) {
229
230
ActivityExecutionContext context =
230
231
new ActivityExecutionContextImpl (
231
232
service ,
@@ -249,15 +250,18 @@ public ActivityTaskHandler.Result execute(ActivityInfoImpl info, Scope metricsSc
249
250
input ,
250
251
method .getParameterTypes (),
251
252
method .getGenericParameterTypes ());
252
- Object result = inboundCallsInterceptor .execute (args );
253
+ ActivityInboundCallsInterceptor .ActivityOutput result =
254
+ inboundCallsInterceptor .execute (
255
+ new ActivityInboundCallsInterceptor .ActivityInput (
256
+ new Header (info .getHeader ()), args ));
253
257
if (context .isDoNotCompleteOnReturn ()) {
254
258
return new ActivityTaskHandler .Result (
255
259
info .getActivityId (), null , null , null , null , context .isUseLocalManualCompletion ());
256
260
}
257
261
RespondActivityTaskCompletedRequest .Builder request =
258
262
RespondActivityTaskCompletedRequest .newBuilder ();
259
263
if (method .getReturnType () != Void .TYPE ) {
260
- Optional <Payloads > serialized = dataConverter .toPayloads (result );
264
+ Optional <Payloads > serialized = dataConverter .toPayloads (result . getResult () );
261
265
if (serialized .isPresent ()) {
262
266
request .setResult (serialized .get ());
263
267
}
@@ -287,10 +291,11 @@ public void init(ActivityExecutionContext context) {
287
291
}
288
292
289
293
@ Override
290
- public Object execute (Object [] arguments ) {
294
+ public ActivityOutput execute (ActivityInput input ) {
291
295
CurrentActivityExecutionContext .set (context );
292
296
try {
293
- return method .invoke (activity , arguments );
297
+ Object result = method .invoke (activity , input .getArguments ());
298
+ return new ActivityOutput (result );
294
299
} catch (InvocationTargetException e ) {
295
300
throw Activity .wrap (e .getTargetException ());
296
301
} catch (Exception e ) {
@@ -310,7 +315,7 @@ public DynamicActivityImplementation(DynamicActivity activity) {
310
315
}
311
316
312
317
@ Override
313
- public ActivityTaskHandler .Result execute (ActivityInfoImpl info , Scope metricsScope ) {
318
+ public ActivityTaskHandler .Result execute (ActivityInfoInternal info , Scope metricsScope ) {
314
319
ActivityExecutionContext context =
315
320
new ActivityExecutionContextImpl (
316
321
service ,
@@ -328,15 +333,20 @@ public ActivityTaskHandler.Result execute(ActivityInfoImpl info, Scope metricsSc
328
333
}
329
334
inboundCallsInterceptor .init (context );
330
335
try {
331
- EncodedValues args = new EncodedValues (input , dataConverter );
332
- Object result = inboundCallsInterceptor .execute (new Object [] {args });
336
+ EncodedValues encodedValues = new EncodedValues (input , dataConverter );
337
+ Object [] args = new Object [] {encodedValues };
338
+
339
+ ActivityInboundCallsInterceptor .ActivityOutput result =
340
+ inboundCallsInterceptor .execute (
341
+ new ActivityInboundCallsInterceptor .ActivityInput (
342
+ new Header (info .getHeader ()), args ));
333
343
if (context .isDoNotCompleteOnReturn ()) {
334
344
return new ActivityTaskHandler .Result (
335
345
info .getActivityId (), null , null , null , null , context .isUseLocalManualCompletion ());
336
346
}
337
347
RespondActivityTaskCompletedRequest .Builder request =
338
348
RespondActivityTaskCompletedRequest .newBuilder ();
339
- Optional <Payloads > serialized = dataConverter .toPayloads (result );
349
+ Optional <Payloads > serialized = dataConverter .toPayloads (result . getResult () );
340
350
if (serialized .isPresent ()) {
341
351
request .setResult (serialized .get ());
342
352
}
@@ -348,7 +358,8 @@ public ActivityTaskHandler.Result execute(ActivityInfoImpl info, Scope metricsSc
348
358
}
349
359
}
350
360
351
- private Result activityFailureToResult (ActivityInfoImpl info , Scope metricsScope , Throwable e ) {
361
+ private Result activityFailureToResult (
362
+ ActivityInfoInternal info , Scope metricsScope , Throwable e ) {
352
363
e = CheckedExceptionWrapper .unwrap (e );
353
364
if (e instanceof ActivityCanceledException ) {
354
365
if (log .isInfoEnabled ()) {
@@ -388,10 +399,11 @@ public void init(ActivityExecutionContext context) {
388
399
}
389
400
390
401
@ Override
391
- public Object execute (Object [] arguments ) {
402
+ public ActivityOutput execute (ActivityInput input ) {
392
403
CurrentActivityExecutionContext .set (context );
393
404
try {
394
- return activity .execute ((EncodedValues ) arguments [0 ]);
405
+ Object result = activity .execute ((EncodedValues ) input .getArguments ()[0 ]);
406
+ return new ActivityOutput (result );
395
407
} catch (Exception e ) {
396
408
throw Activity .wrap (e );
397
409
} finally {
@@ -410,7 +422,7 @@ private class POJOLocalActivityImplementation implements ActivityTaskExecutor {
410
422
}
411
423
412
424
@ Override
413
- public ActivityTaskHandler .Result execute (ActivityInfoImpl info , Scope metricsScope ) {
425
+ public ActivityTaskHandler .Result execute (ActivityInfoInternal info , Scope metricsScope ) {
414
426
ActivityExecutionContext context = new LocalActivityExecutionContextImpl (info , metricsScope );
415
427
Optional <Payloads > input = info .getInput ();
416
428
ActivityInboundCallsInterceptor inboundCallsInterceptor =
@@ -426,11 +438,14 @@ public ActivityTaskHandler.Result execute(ActivityInfoImpl info, Scope metricsSc
426
438
input ,
427
439
method .getParameterTypes (),
428
440
method .getGenericParameterTypes ());
429
- Object result = inboundCallsInterceptor .execute (args );
441
+ ActivityInboundCallsInterceptor .ActivityOutput result =
442
+ inboundCallsInterceptor .execute (
443
+ new ActivityInboundCallsInterceptor .ActivityInput (
444
+ new Header (info .getHeader ()), args ));
430
445
RespondActivityTaskCompletedRequest .Builder request =
431
446
RespondActivityTaskCompletedRequest .newBuilder ();
432
447
if (method .getReturnType () != Void .TYPE ) {
433
- Optional <Payloads > serialized = dataConverter .toPayloads (result );
448
+ Optional <Payloads > serialized = dataConverter .toPayloads (result . getResult () );
434
449
if (serialized .isPresent ()) {
435
450
request .setResult (serialized .get ());
436
451
}
0 commit comments