/* # Licensed Materials - Property of IBM # Copyright IBM Corp. 2015 */ package com.ibm.streamsx.topology.internal.functional.ops; import static com.ibm.streamsx.topology.internal.functional.FunctionalHelper.getInputMapping; import com.ibm.streams.operator.OperatorContext; import com.ibm.streams.operator.StreamingInput; import com.ibm.streams.operator.Tuple; import com.ibm.streams.operator.model.InputPortSet; import com.ibm.streams.operator.model.OutputPortSet; import com.ibm.streams.operator.model.PrimitiveOperator; import com.ibm.streamsx.topology.function.Consumer; import com.ibm.streamsx.topology.internal.functional.FunctionalHandler; import com.ibm.streamsx.topology.internal.spljava.SPLMapping; @PrimitiveOperator @InputPortSet(cardinality = 1) @OutputPortSet(cardinality = -1) public class FunctionSink extends FunctionFunctor { private FunctionalHandler<Consumer<Object>> sinkerHandler; private SPLMapping<?> mapping; @Override public synchronized void initialize(OperatorContext context) throws Exception { super.initialize(context); sinkerHandler = createLogicHandler(); mapping = getInputMapping(this, 0); } @Override public void process(StreamingInput<Tuple> stream, Tuple tuple) throws Exception { Object value = mapping.convertFrom(tuple); final Consumer<Object> sinker = sinkerHandler.getLogic(); synchronized (sinker) { sinker.accept(value); } } }