Package co.cask.tigon.api.annotation

Examples of co.cask.tigon.api.annotation.ProcessInput


          // is visting the parent method, since the method visiting order is always from the leaf class walking
          // up the class hierarchy.
          continue;
        }

        ProcessInput processInputAnnotation = method.getAnnotation(ProcessInput.class);
        Tick tickAnnotation = method.getAnnotation(Tick.class);

        if (processInputAnnotation == null && tickAnnotation == null) {
          // Neither a process nor a tick method.
          continue;
        }

        int maxRetries = (tickAnnotation == null) ? processInputAnnotation.maxRetries() : tickAnnotation.maxRetries();

        ProcessMethod processMethod = processMethodFactory.create(method, maxRetries);
        Set<String> inputNames;
        Schema schema;
        TypeToken<?> dataType;
        ConsumerConfig consumerConfig;
        int batchSize = 1;

        if (tickAnnotation != null) {
          inputNames = ImmutableSet.of();
          consumerConfig = new ConsumerConfig(0, 0, 1, DequeueStrategy.FIFO, null);
          schema = Schema.of(Schema.Type.NULL);
          dataType = TypeToken.of(void.class);
        } else {
          inputNames = Sets.newHashSet(processInputAnnotation.value());
          if (inputNames.isEmpty()) {
            // If there is no input name, it would be ANY_INPUT
            inputNames.add(FlowletDefinition.ANY_INPUT);
          }
          // If batch mode then generate schema for Iterator's parameter type
View Full Code Here


      // is visting the parent method, since the method visiting order is always from the leaf class walking
      // up the class hierarchy.
      return;
    }

    ProcessInput processInputAnnotation = method.getAnnotation(ProcessInput.class);
    Tick tickAnnotation = method.getAnnotation(Tick.class);

    if (processInputAnnotation == null && tickAnnotation == null) {
      return;
    }

    // Check for tick method
    if (tickAnnotation != null) {
      Preconditions.checkArgument(processInputAnnotation == null,
                                  "Tick method %s.%s should not have ProcessInput.",
                                  inspectType.getRawType().getName(), method);
      Preconditions.checkArgument(method.getParameterTypes().length == 0,
                                  "Tick method %s.%s cannot have parameters.",
                                  inspectType.getRawType().getName(), method);
      return;
    }

    Type[] methodParams = method.getGenericParameterTypes();
    Preconditions.checkArgument(methodParams.length > 0 && methodParams.length <= 2,
                                "Parameter missing from process method %s.%s.",
                                inspectType.getRawType().getName(), method);

    // If there is more than one parameter there can only be exactly two; the second one must be InputContext type
    if (methodParams.length == 2) {
      Preconditions.checkArgument(InputContext.class.equals(TypeToken.of(methodParams[1]).getRawType()),
                                  "Second parameter must be InputContext type for process method %s.%s.",
                                  inspectType.getRawType().getName(), method);
    }

    // Extract the Input type from the first parameter of the process method
    Type inputType = getInputType(inspectType, method, inspectType.resolveType(methodParams[0]).getType());
    Preconditions.checkArgument(Reflections.isResolved(inputType),
                                "Invalid type in %s.%s. Only Class or ParameterizedType are supported.",
                                inspectType.getRawType().getName(), method);

    List<String> inputNames = Lists.newLinkedList();
    if (processInputAnnotation.value().length == 0) {
      inputNames.add(FlowletDefinition.ANY_INPUT);
    } else {
      Collections.addAll(inputNames, processInputAnnotation.value());
    }

    for (String inputName : inputNames) {
      Set<Type> types = inputTypes.get(inputName);
      if (types == null) {
View Full Code Here

TOP

Related Classes of co.cask.tigon.api.annotation.ProcessInput

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.