private static void validateFactory(TaskFactory factory) {
    if (factory == null) {
      throw new SamzaException("Either the task class name or the task factory instance is required.");
    }

    boolean isValidFactory = factory instanceof StreamTaskFactory
            || factory instanceof AsyncStreamTaskFactory;

    if (!isValidFactory) {
      throw new SamzaException(String.format("TaskFactory must be either StreamTaskFactory or AsyncStreamTaskFactory. %s is not supported",
          factory.getClass()));
    }
  }
Optionally wrap the {@link StreamTaskFactory} in a {@link AsyncStreamTaskFactory}, when running {@link StreamTask}
in multi-thread mode.

@param factory  the task factory instance loaded according to the task class
@param taskThreadPool  the thread pool to run the {@link AsyncStreamTaskAdapter} tasks
@return  the finalized task factory object
samza-core/src/main/java/org/apache/samza/task/TaskFactoryUtil.java