[SOLVED] Caching getParameterTypes?

Unknown
edited November 5 in Community Q&A
I've noticed that the getParameterTypes method of my home-brew operator gets called quite often.  It gets called during RapidMiner's startup, when it loads the plugins (fair enough), but also twice every time my operator is selected in the Operators palette of the GUI:

Nov 26, 2012 2:06:16 PM com.rapidminer.tools.WrapperLoggingHandler log
INFO: LTFDataReader: CachedLTFExampleSource.getParameterTypes begins.
Nov 26, 2012 2:06:29 PM com.rapidminer.tools.WrapperLoggingHandler log
INFO: LTFDataReader: CachedLTFExampleSource constructor done.
...
Nov 26, 2012 2:06:30 PM com.rapidminer.tools.WrapperLoggingHandler log
INFO: LTFDataReader: CachedLTFExampleSource.getParameterTypes begins.
Nov 26, 2012 2:06:39 PM com.rapidminer.tools.WrapperLoggingHandler log
INFO: LTFDataReader: CachedLTFExampleSource constructor done.
Any thoughts/warnings/caveats concerning the possibility of rewriting my getParameterTypes so that it caches the List<ParameterType> it builds the first time, in order to return the cached List when it gets called again?  The cached values would be specific to each instance of the operator, right?

Answers

  • Nils_Woehler
    Nils_Woehler New Altair Community Member
    Hi,

    yes, getParameterTypes is called quite often. Because of this it should not take too long to finish.
    If you want to cache your parameterTypes you could try to do something like this:

    public class TestOperator extends Operator {

    private static final String PARAMETER_CHUNK_SIZE = "chunk_size";
    private static final int DEFAULT_BATCH_SIZE = 10;

    /**
    * @param description
    */
    public TestOperator(OperatorDescription description) {
    super(description);
    }

    private List<ParameterType> parameterTypes = null;

    @Override
    public List<ParameterType> getParameterTypes() {
    if (parameterTypes == null) {
    parameterTypes = new LinkedList<ParameterType>();
    ParameterTypeInt type = new ParameterTypeInt(PARAMETER_CHUNK_SIZE, "???", 1, Integer.MAX_VALUE, DEFAULT_BATCH_SIZE);
    type.setOptional(false);
    parameterTypes.add(type);
    }
    return parameterTypes;
    }
    }
    And yes the cached values are specific for each instance of the operator.

    Best,
    Nils