+ ActionCodecContext createActionContext(final Class<? extends Action<?, ?, ?>> action) {
+ if (KeyedListAction.class.isAssignableFrom(action)) {
+ return prepareActionContext(2, 3, 4, action, KeyedListAction.class);
+ } else if (Action.class.isAssignableFrom(action)) {
+ return prepareActionContext(1, 2, 3, action, Action.class);
+ }
+ throw new IllegalArgumentException("The specific action type does not exist for action " + action.getName());
+ }
+
+ private ActionCodecContext prepareActionContext(final int inputOffset, final int outputOffset,
+ final int expectedArgsLength, final Class<? extends Action<?, ?, ?>> action, final Class<?> actionType) {
+ final Optional<ParameterizedType> optParamType = ClassLoaderUtils.findParameterizedType(action, actionType);
+ checkState(optParamType.isPresent(), "%s does not specialize %s", action, actionType);
+
+ final ParameterizedType paramType = optParamType.get();
+ final Type[] args = paramType.getActualTypeArguments();
+ checkArgument(args.length == expectedArgsLength, "Unexpected (%s) Action generatic arguments", args.length);
+ final ActionDefinition schema = factory().getRuntimeContext().getActionDefinition(action);
+ return new ActionCodecContext(
+ DataContainerCodecPrototype.from(asClass(args[inputOffset], RpcInput.class), schema.getInput(),
+ factory()).get(),
+ DataContainerCodecPrototype.from(asClass(args[outputOffset], RpcOutput.class), schema.getOutput(),
+ factory()).get());
+ }
+
+ private static <T extends DataObject> Class<? extends T> asClass(final Type type, final Class<T> target) {
+ verify(type instanceof Class, "Type %s is not a class", type);
+ return ((Class<?>) type).asSubclass(target);
+ }
+
+ ContainerNodeCodecContext<?> createRpcDataContext(final Class<?> key) {
+ checkArgument(DataContainer.class.isAssignableFrom(key));