cancel
Showing results for 
Search instead for 
Did you mean: 

Camel and Osgi

rvi
Champ in-the-making
Champ in-the-making
Hi,

I want deploy a process with some camel servicetasks in a osgi container.

I get this problem:
the osgi engine bundle looks for JavaDelegate services,
but CamelBehavior implements ActivityBehavior.

It seems to work if we expose the CamelBehavior as a JavaDelegate with this implementation:
public class CamelDelegate extends CamelBehaviour implements JavaDelegate {

   public CamelDelegate(Collection<ContextProvider> camelContext) {
      super(camelContext);
   }

   public void execute(DelegateExecution execution) throws Exception {
      if(execution instanceof ActivityExecution) {
         super.execute((ActivityExecution)execution);
      } else {
         throw new UnsupportedOperationException("cannot execute execution of type "+execution.getClass().getName()+" , "+execution.getEventName() );
      }
   }

}

is it correct ? what is the difference between a JavaDelegate and and ActivityBehavior ?

would it be possible to better support camel with a osgi container in the activiti code:
- CamelBehavior implements directly JavaDelegate
- or BlueprintELResolver looks for ActivitiBehavior
?

thanks for help
Richard
3 REPLIES 3

rvi
Champ in-the-making
Champ in-the-making
is it correct ? what is the difference between a JavaDelegate and and ActivityBehavior ?

would it be possible to better support camel with a osgi container in the activiti code:
- CamelBehavior implements directly JavaDelegate
- or BlueprintELResolver looks for ActivitiBehavior
?

actually this solution DOESN'T work. (it executes twice the outgoing relations..)

The only solution is to extend the BlueprintELResolver so it accepts ActivitiBehavior.
I've tested that with an extended ELresolver:

public class ExtendedELResolver extends BlueprintELResolver {

    private static final Logger LOGGER = Logger.getLogger(ExtendedELResolver.class.getName());
    private Map<String, ActivityBehavior> behaviorMap = 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 : behaviorMap.keySet()) {
                if(name.equalsIgnoreCase(key)) {
                    context.setPropertyResolved(true);
                    return behaviorMap.get(name);
                }
            }
        }

        return super.getValue(context,base,property);
    }

    public void bindService(ActivityBehavior delegate, Map props) {
        String name = (String) props.get("osgi.service.blueprint.compname");
        behaviorMap.put(name, delegate);
        LOGGER.info("added Activiti service to behavior cache " + name);
    }

    public void unbindService(ActivityBehavior delegate, Map props) {
        String name = (String) props.get("osgi.service.blueprint.compname");
        if(behaviorMap.containsKey(name)) {
            behaviorMap.remove(name);
        }
        LOGGER.info("removed Activiti service from behavior cache " + name);
    }
}
and adding a reference-listener in the blueprint context of the osgi:

    <reference-list id="activityBehaviorProviders" availability="optional"
                    interface=[b]"org.activiti.engine.impl.pvm.delegate.ActivityBehavior"[/b]
                    activation="eager">
        <reference-listener ref="blueprintELResolver" bind-method="bindService" unbind-method="unbindService"/>
    </reference-list>
    <bean id="blueprintELResolver" [b]class="test.ExtendedBlueprintELResolver"[/b] />

of course it would be better to directly modify the BlueprintELResolver so it accepts the ActivitiBehavior. Should I open a JIRA ?

thanks,
Richard

nils1
Champ in-the-making
Champ in-the-making
Hi Richard,

as a starting point, maybe you can have a look at the examples from Tijs Rademakers' book "Activiti in Action", available at http://activitiinaction.googlecode.com/svn/trunk/book-osgi-app

Hope that helps!

Cheers,
Nils

nils1
Champ in-the-making
Champ in-the-making
Hi Richard,

you can also have a look at a showcase I created. It demonstrates how you can combine activiti and camel on an OSGi container (Karaf 2.2.5 in this case).

More specifically, it shows how to
1) start a process instance from a camel route
2) how to trigger a waiting process instance from a camel route

You'll find the code at https://svn.camunda.com/fox/demo/activiti/osgi-activiti-camel-showcase/

Please have a look at the README.txt for installation instructions.

Also, note that the demo uses Activiti 5.10-SNAPSHOT, so you'll need to check out and build the current trunk and install it to your local maven repository!

Hope that helps.

Cheers,
Nils