/*
# 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 static com.ibm.streamsx.topology.internal.functional.FunctionalHelper.getLogicObject;

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.PrimitiveOperator;
import com.ibm.streamsx.topology.function.Consumer;
import com.ibm.streamsx.topology.internal.spljava.SPLMapping;

@PrimitiveOperator
@InputPortSet(cardinality = 1)
public class FunctionSink extends FunctionFunctor {
    private Consumer<Object> sinker;
    private SPLMapping<?> mapping;

    @Override
    public synchronized void initialize(OperatorContext context)
            throws Exception {
        super.initialize(context);

        setLogic(sinker = getLogicObject(getFunctionalLogic()));
        
        mapping = getInputMapping(this, 0);
    }

    @Override
    public void process(StreamingInput<Tuple> stream, Tuple tuple)
            throws Exception {
        Object value = mapping.convertFrom(tuple);
        synchronized (sinker) {
            sinker.accept(value);
        }
    }
}

@@ -504,16 +504,69 @@
 ortSet;%0A
+import com.ibm.streams.operator.model.OutputPortSet;%0A
 import c
@@ -779,16 +779,49 @@
 ty = 1)%0A
+@OutputPortSet(cardinality = -1)%0A
 public c

fix tests - woops, test to remove cardinality spec slipped through