Feature/Possible Bug: Activity Name generation


Currently, if there is no namePrefix specified in the @ActivityInterface method, then the activity name becomes same as the meothod name, which will cause an issue if multiple interfaces have the same meothodName.

To overcome this, instead of doing:

      Method method, Class<?> interfaceType, ActivityInterface activityAnnotation) {
    this.method = Objects.requireNonNull(method);
    this.interfaceType = Objects.requireNonNull(interfaceType);
    ActivityMethod activityMethod = method.getAnnotation(ActivityMethod.class);
    this.name =
        **activityMethod != null && !activityMethod.name().isEmpty()**
**            ? activityMethod.name()**
**            : activityAnnotation.namePrefix() + getActivityNameFromMethod(method);**

it would be better to do:

    this.name =
        activityMethod != null && !activityMethod.name().isEmpty()
            ? activityMethod.name()
            :activityAnnotation.namePrefix()? activityAnnotation.namePrefix() + getActivityNameFromMethod(method)
:method.clazz.name.split("\\.")[method.clazz.name.split("\\.").length -1] +  getActivityNameFromMethod(method);

so that the className itself becomes the NamePrefix

We had exactly that naming convention in Cadence. We found that most developers didn’t like long activity names it generated and manually changed them to shorter name using @ActivityMethod annotations.

So we give you ability to specify prefix if you prefer longer names, but default to shorter names.

Note that activity name must be unique only within a single task queue name. There is no problem using the same activity name when scheduling activities in different task queues.

But anyhow, if the developer wants to have a short name he can make use of the namePrefix right? By default wouldn’t the longer name be more safe?

Otherwise when developing activities in collaborative environment, many things need to be ensured, like activity names should be unique across all packages, name prefix should be unique. Instead of that if the canonical name of the class is pre appended, it would solve the problem of not having to enforce developers from making sure that namePrefix is set or activity names are unique

In a collaborative environment in the majority of cases, different teams run different processes that use different task queues. So similar activity names are not a problem.

I filed an issue to make this logic pluggable to support different user requirements.

1 Like

Cool, Thanks!