Search in sources :

Example 1 with OutputPortFieldAnnotation

use of com.datatorrent.api.annotation.OutputPortFieldAnnotation in project apex-core by apache.

the class Operators method describe.

public static void describe(GenericOperator operator, OperatorDescriptor descriptor) {
    for (Class<?> c = operator.getClass(); c != Object.class; c = c.getSuperclass()) {
        Field[] fields = c.getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            InputPortFieldAnnotation inputAnnotation = field.getAnnotation(InputPortFieldAnnotation.class);
            OutputPortFieldAnnotation outputAnnotation = field.getAnnotation(OutputPortFieldAnnotation.class);
            AppData.QueryPort adqAnnotation = field.getAnnotation(AppData.QueryPort.class);
            AppData.ResultPort adrAnnotation = field.getAnnotation(AppData.ResultPort.class);
            try {
                Object portObject = field.get(operator);
                if (portObject instanceof InputPort) {
                    descriptor.addInputPort((Operator.InputPort<?>) portObject, field, inputAnnotation, adqAnnotation);
                } else {
                    if (inputAnnotation != null) {
                        throw new IllegalArgumentException("port is not of type " + InputPort.class.getName() + ": " + field);
                    }
                }
                if (portObject instanceof OutputPort) {
                    descriptor.addOutputPort((Operator.OutputPort<?>) portObject, field, outputAnnotation, adrAnnotation);
                } else {
                    if (outputAnnotation != null) {
                        throw new IllegalArgumentException("port is not of type " + OutputPort.class.getName() + ": " + field);
                    }
                }
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
Also used : GenericOperator(com.datatorrent.api.DAG.GenericOperator) Operator(com.datatorrent.api.Operator) OutputPort(com.datatorrent.api.Operator.OutputPort) OutputPortFieldAnnotation(com.datatorrent.api.annotation.OutputPortFieldAnnotation) InputPort(com.datatorrent.api.Operator.InputPort) Field(java.lang.reflect.Field) InputPortFieldAnnotation(com.datatorrent.api.annotation.InputPortFieldAnnotation) AppData(com.datatorrent.common.experimental.AppData)

Aggregations

GenericOperator (com.datatorrent.api.DAG.GenericOperator)1 Operator (com.datatorrent.api.Operator)1 InputPort (com.datatorrent.api.Operator.InputPort)1 OutputPort (com.datatorrent.api.Operator.OutputPort)1 InputPortFieldAnnotation (com.datatorrent.api.annotation.InputPortFieldAnnotation)1 OutputPortFieldAnnotation (com.datatorrent.api.annotation.OutputPortFieldAnnotation)1 AppData (com.datatorrent.common.experimental.AppData)1 Field (java.lang.reflect.Field)1