cancel
Showing results for 
Search instead for 
Did you mean: 

Passing custom variables types to a process

jean-sébastien
Champ in-the-making
Champ in-the-making
Hello,

I try to set a custom variable type to Activiti. My code is defined as such :


In a JavaService task I do the following:


public void execute(DelegateExecution execution) throws Exception {
execution.setVariable("firstResultIterator", this.firstResultIterator);
}

I got the following exception:

org.activiti.engine.ActivitiException: couldn't find type for net.atos.wlp.tool.archive.batch.FirstResultIterator@1f9cdda
   at org.activiti.engine.impl.variable.DefaultVariableTypes.findVariableType(DefaultVariableTypes.java:62)
   at org.activiti.engine.impl.persistence.entity.VariableScopeImpl.createVariableLocal(VariableScopeImpl.java:212)
   at org.activiti.engine.impl.persistence.entity.VariableScopeImpl.setVariable(VariableScopeImpl.java:164)
   at net.atos.wlp.tool.archiving.ArchiveMI.execute(ArchiveMI.java:36)

The firstResultIterator is defined as such:

package net.atos.wlp.tool.archive.batch;

import java.util.Iterator;

public class FirstResultIterator implements Iterable<Integer>, Iterator<Integer> {
    private static final Logger logger = Logger.getLogger(FirstResultIterator.class);

    private int batchSize = 0;
    private int defaultBatchSize = 50; //SPOPV-4381
    int startNumber = 0;
    private AtomicBoolean hasNext = new AtomicBoolean(true);

    public Iterator<Integer> iterator() {
        return this;
    }

    public boolean hasNext() {
        return hasNext.get();
    }

    public Integer next() {
        int result = startNumber;
        startNumber += batchSize;
        return result;
    }

    public void remove() {
        throw new UnsupportedOperationException("remove");
    }

    /**
     * @param hasNext
     *            the hasNext to set
     */
    public void setHasNext(boolean hasNext) {
        this.hasNext.set(hasNext);
    }

    /**
     * @return the bATCH_SIZE
     */
    public int getBatchSize() {
        return batchSize;
    }

    /**
     * @param size
     *            the bATCH_SIZE to set
     */
    public void setBatchSize(int size) {
        if (size > 0)
            batchSize = size;
        else
            batchSize=defaultBatchSize;
       
        if (logger.isInfoEnabled())
           logger.info("BatchSize set to:" + batchSize);
    }
   
   public void setDefaultBatchSize(int size) {
        if (size > 0)
            defaultBatchSize = 50; //SPOPV-4381

        if (logger.isInfoEnabled())
           logger.info("defaultBatchSize set to:" + defaultBatchSize);
    }
}

How to set a custom variable type ?

Many thanks !
2 REPLIES 2

lichtin
Champ in-the-making
Champ in-the-making
From "the book":
When you use a Java bean as a process variable make sure the bean implements the Serializable interface, because the process variable will be persisted to the Activiti engine database.

jean-sébastien
Champ in-the-making
Champ in-the-making
Thanks !!