
As EasyVIPER is an extensible engine, it is possible to add specific services, thanks to the {{com.ebmwebsourcing.easyviper.core.api.engine.thread.service.Service}} interface.
To create a new extended service, the basic thing is to develop a class implementing this interface, and then to add the service to a core instance of EasyVIPER.
A good way to perform this task follows these steps:
* Create an interface that extends Service with specific operations
{code:title=MyExtendedService.java|borderStyle=solid}
import com.ebmwebsourcing.easyviper.core.api.engine.thread.service.Service;
public interface MyExtendedService extends Service {
// Some specific stuff
}
{code}
* Create the class implementing {{MyExtendedService}} and extending the utility abstract class {{AbstractServiceImpl}}:
{code:title=MyExtendedServiceImpl.java|borderStyle=solid}
import com.ebmwebsourcing.easyviper.core.api.engine.thread.service.AbstractServiceImpl;
import mypackage.MyExtendedService;
public class MyExtendedServiceImpl extends AbstractServiceImpl implements
MyExtendedService {
public MyExtendedServiceImpl(Engine engine) {
super(engine);
// Some specific stuff
}
@Override
public void run() {
try {
Thread.sleep(this.getRefreshFrequency());
// Some specific stuff
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
{code}
The method {{run()}} can be filled as in the example for a by default behaviour.
Once done the new {{MyExtendedServiceImpl}} service can be added to EasyVIPER core with the following code:
{code}
...
import com.ebmwebsourcing.easyviper.core.api.engine.configuration.ConfigurationEngine;
import com.ebmwebsourcing.easyviper.core.impl.engine.configuration.ConfigurationEngineImpl;
import com.ebmwebsourcing.easyviper.core.api.soa.message.MessageConverter;
import java.util.logging.Logger;
...
ConfigurationEngine conf = new ConfigurationEngineImpl();
/** Add extended service **/
conf.getAdditionnalServices().add(MyExtendedServiceImpl.class);
...
MessageConverter converter = new ...
Logger logger = new ...
...
Core core = BPELFactoryImpl.getInstance().newBPELEngine(conf, converter, 10,
MyReceiverImpl.class, 10, MySenderImpl.class, logger);
{code}
In order to call methods of the extended service you can use the following code:
{code}
MyExtendedService myService = core.getEngine().getServiceManager().getService(MyExtendedServiceImpl.class);
myService.callMyOperation();
{code}
Finally a good way to conceive an extended service is to start from a formal description of its interface, with a WSDL definition for example.
Then, the corresponding Java interface can be generated thanks to CXF wsdl2java facilities. The interface of {{MyExtendedService}} is then extending the EasyVIPER service and the description interface:
{code:title=MyExtendedService.java|borderStyle=solid}
import com.ebmwebsourcing.easyviper.core.api.engine.thread.service.Service;
import generated.mypackage.MyServiceDescription;
public interface MyExtendedService extends MyServiceDescription, Service {
// Some specific stuff
}
{code}
The implementation class development is then led by the formal description.
h1. How to implement an extended behaviour in EasyVIPER?
As EasyVIPER is an extensible engine, it provides a way to implement new behaviours, in addition of the existing ones.
To create a new behaviour, you have to extend the {{com.ebmwebsourcing.easyviper.core.service.extended.behaviour.api.ExtendedBehaviour}} interface.
A good way to process is to perform the following steps:
* Create an interface that extends the {{ExtendedBehaviour}} interface:
{code:title=MyBehaviour.java|borderStyle=solid}
import com.ebmwebsourcing.easyviper.core.service.extended.behaviour.api.ExtendedBehaviour;
public interface MyBehaviour extends MyBehaviourImpl {
QName name = new QName(ExtendedBehaviour.name.getNamespaceURI(), "MyBehaviour");
}
{code}
* Create an implementation that implements this interface and extends the utility abstract class {{AbstractExtendedBehaviourImpl}}:
{code:title=MyBehaviourImpl.java|borderStyle=solid}
...
import com.ebmwebsourcing.easyviper.core.service.extended.behaviour.api.AbstractExtendedBehaviourImpl;
import mypackage.MyBehaviour;
import com.ebmwebsourcing.easycommons.sca.helper.api.SCAException;
import com.ebmwebsourcing.easyviper.core.api.CoreException;
import com.ebmwebsourcing.easyviper.core.api.engine.Node;
...
@Scope("COMPOSITE")
@Service(value=MyBehaviour.class,names="service")
@PolicySets("frascati:scaEasyPrimitive")
public class MyBehaviourImpl extends AbstractExtendedBehaviourImpl implements MyBehaviour {
@Reference(name="node",required=false)
protected Node node;
@Override
protected void executeOnInactive() throws CoreException {
// Some specific stuff
}
@Override
protected void executeOnStarted() throws CoreException {
// Some specific stuff
}
@Override
protected void executeOnEnded() throws CoreException {
// Some specific stuff
}
}
{code}
The main method to fill is {{executeOnInactive()}}. It is the one that will be executed when the execution token crosses over the behaviour.
h1. How to add Frascati Explorer into your EasyVIPER application?
You have to add these dependencies:
{code:xml}
<dependency>
<groupId>org.ow2.frascati.tinfi</groupId>
<artifactId>frascati-tinfi-membranes-oo</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>org.ow2.frascati.tinfi</groupId>
<artifactId>frascati-tinfi-runtime</artifactId>
<version>1.4.1</version>
</dependency>
{code}
Version 1.4.1 is compliant with 1.4.X versions of EasyVIPER.
Then the following code allows to add any SCA component (EasyVIPER core for instance) into the Frascati Explorer GUI:
{code:title=extract|borderStyle=solid}
...
import org.objectweb.util.explorer.api.Tree;
import org.ow2.frascati.FraSCAti;
import org.ow2.frascati.explorer.api.FraSCAtiExplorer;
...
System.setProperty(FraSCAti.FRASCATI_BOOTSTRAP_PROPERTY_NAME, "org.ow2.frascati.bootstrap.FraSCAtiFractal");
// Start FraSCAti and its Explorer.
FraSCAti frascati = FraSCAti.newFraSCAti();
Tree explorerTree = FraSCAtiExplorer.SINGLETON.get().getFraSCAtiExplorerService(Tree.class);
// Add the EasyBPEL core component.
explorerTree.addEntry("EasyBPEL", core.getComponent());
{code}
This will launch Frascati Explorer at runtime.