private Callback createCallback(Flowlet flowlet, FlowletSpecification flowletSpec) { if (flowlet instanceof Callback) { return (Callback) flowlet; } final FailurePolicy failurePolicy = flowletSpec.getFailurePolicy(); return new Callback() { @Override public void onSuccess(Object input, InputContext inputContext) { // No-op } @Override public FailurePolicy onFailure(Object input, InputContext inputContext, FailureReason reason) { return failurePolicy; } }; }
@Override public FailurePolicy onFailure(@Nullable Object input, @Nullable InputContext inputContext, FailureReason reason) { // Return the policy as specified in the spec return flowletContext.getSpecification().getFailurePolicy(); }
@Override public JsonElement serialize(FlowletSpecification src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); jsonObj.add("className", new JsonPrimitive(src.getClassName())); jsonObj.add("name", new JsonPrimitive(src.getName())); jsonObj.add("description", new JsonPrimitive(src.getDescription())); jsonObj.add("failurePolicy", new JsonPrimitive(src.getFailurePolicy().name())); jsonObj.add("properties", serializeMap(src.getProperties(), context, String.class)); jsonObj.add("resources", context.serialize(src.getResources(), new TypeToken<ResourceSpecification>() { }.getType())); jsonObj.add("maxInstances", new JsonPrimitive(src.getMaxInstances())); return jsonObj; }
FlowletDefinition(String flowletName, Flowlet flowlet, int instances) { FlowletSpecification flowletSpec = flowlet.configure(); this.instances = instances; Map<String, Set<Type>> inputTypes = Maps.newHashMap(); Map<String, Set<Type>> outputTypes = Maps.newHashMap(); Map<String, String> properties = Maps.newHashMap(flowletSpec.getProperties()); Reflections.visit(flowlet, TypeToken.of(flowlet.getClass()), new PropertyFieldExtractor(properties), new OutputEmitterFieldExtractor(outputTypes), new ProcessMethodExtractor(inputTypes)); this.inputTypes = immutableCopyOf(inputTypes); this.outputTypes = immutableCopyOf(outputTypes); this.flowletSpec = new DefaultFlowletSpecification(flowlet.getClass().getName(), flowletName == null ? flowletSpec.getName() : flowletName, flowletSpec.getDescription(), flowletSpec.getFailurePolicy(), properties, flowletSpec.getResources(), flowletSpec.getMaxInstances()); }