cancel
Showing results for 
Search instead for 
Did you mean: 

how to call TaskListener in osgi

minikiller
Champ in-the-making
Champ in-the-making
I run activiti in OSGI environment using blueprint file,I also want to use TaskListener. But I can not find a way to call TaskListener,because my TaskListener class can not be found by Activiti engine. How can help me to solve this problem.thanks.
3 REPLIES 3

pelorousjack
Champ in-the-making
Champ in-the-making
I am trying to do the same thing - use TaskListeners in an OSGI environment.  I cannot get them to work.  I believe I have found the problem in the Activiti code.

The BlueprintELResolver class has a bind and unbind method that accepts a JavaDelegate.  Therefore when I define a service in my blueprint file that implements the JavaDelegate interface, I can see that the bind method is called, and my JavaDelegate class works.

When I define a service in my blueprint file that implements TaskListener or ExecutionListener interfaces, they are not found because there is no bind method to call that accepts them.

I think the BlueprintELResolver class could be updated to include bind methods for all the different interfaces, and then TaskListeners and ExecutionListeners would work in OSGI.  Can someone open a JIRA ticket for this?  I could not log in to the Activiti JIRA.

Thanks.

jbarrez
Star Contributor
Star Contributor
My osgi is really limited … but would this recent pull req solve your problem: https://github.com/alien11689/Activiti/commit/a5a80265c169aa5eb40f2edd99914cb9fabebbc4 ?

mikuc
Champ in-the-making
Champ in-the-making
Does this solve the problem?


package org.activiti.osgi.blueprint;

import java.beans.FeatureDescriptor;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.activiti.engine.delegate.JavaDelegate;
import org.activiti.engine.delegate.TaskListener;
import org.activiti.engine.impl.javax.el.ELContext;
import org.activiti.engine.impl.javax.el.ELResolver;
import org.activiti.engine.impl.pvm.delegate.ActivityBehavior;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* @see org.activiti.spring.ApplicationContextElResolver
*/
public class BlueprintELResolver extends ELResolver {

  private static final Logger LOGGER = LoggerFactory.getLogger(BlueprintELResolver.class);
private Map<String, JavaDelegate> delegateMap = new HashMap<String, JavaDelegate>();
private Map<String, TaskListener> taskListenerMap = new HashMap<String, TaskListener>();
        private Map<String, ActivityBehavior> activityBehaviourMap = new HashMap<String, ActivityBehavior>();

    public Object getValue(ELContext context, Object base, Object property) {
        if (base == null) {
            // according to javadoc, can only be a String
            String key = (String) property;
            for (String name : delegateMap.keySet()) {
                if (name.equalsIgnoreCase(key)) {
                    context.setPropertyResolved(true);
                    return delegateMap.get(name);
                }
            }
            for (String name : taskListenerMap.keySet()) {
                if (name.equalsIgnoreCase(key)) {
                    context.setPropertyResolved(true);
                    return taskListenerMap.get(name);
                }
            }
            for (String name : activityBehaviourMap.keySet()) {
                if (name.equalsIgnoreCase(key)) {
                    context.setPropertyResolved(true);
                    return activityBehaviourMap.get(name);
                }
            }
        }

  return null;
}

@SuppressWarnings("rawtypes")
public void bindService(JavaDelegate delegate, Map props) {
    String name = (String) props.get("osgi.service.blueprint.compname");
    delegateMap.put(name, delegate);
    LOGGER.info("added Activiti service to delegate cache {}", name);
}

@SuppressWarnings("rawtypes")
public void unbindService(JavaDelegate delegate, Map props) {
  String name = (String) props.get("osgi.service.blueprint.compname");
    if(delegateMap.containsKey(name)) {
     delegateMap.remove(name);
    }
    LOGGER.info("removed Activiti service from delegate cache {}", name);
}


@SuppressWarnings("rawtypes")
public void bindTaskListenerService(TaskListener delegate, Map props) {
    String name = (String) props.get("osgi.service.blueprint.compname");
    taskListenerMap.put(name, delegate);
    LOGGER.info("added Activiti service to delegate cache {}", name);
}

@SuppressWarnings("rawtypes")
public void unbindTaskListenerService(TaskListener delegate, Map props) {
  String name = (String) props.get("osgi.service.blueprint.compname");
    if(taskListenerMap.containsKey(name)) {
     taskListenerMap.remove(name);
    }
    LOGGER.info("removed Activiti service from delegate cache {}", name);
}

    @SuppressWarnings("rawtypes")
    public void bindActivityBehaviourService(ActivityBehavior delegate, Map props) {
        String name = (String) props.get("osgi.service.blueprint.compname");
        activityBehaviourMap.put(name, delegate);
        LOGGER.info("added Activiti service to activity behaviour cache {}", name);
    }

    @SuppressWarnings("rawtypes")
    public void unbindActivityBehaviourService(ActivityBehavior delegate, Map props) {
        String name = (String) props.get("osgi.service.blueprint.compname");
        if(activityBehaviourMap.containsKey(name)) {
            activityBehaviourMap.remove(name);
        }
        LOGGER.info("removed Activiti service from activity behaviour cache {}", name);
    }

public boolean isReadOnly(ELContext context, Object base, Object property) {
  return true;
}

public void setValue(ELContext context, Object base, Object property,
     Object value) {
}

public Class<?> getCommonPropertyType(ELContext context, Object arg) {
  return Object.class;
}

public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context,
     Object arg) {
  return null;
}

public Class<?> getType(ELContext context, Object arg1, Object arg2) {
  return Object.class;
}
}