View Source

{children:excerpt=true}

h1. How to implement and add en extended service to EasyVIPER?

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;
...

ConfigurationEngine conf = new ConfigurationEngineImpl();
conf.getAdditionnalServices().add(EasyVIPERAdministrationImpl.class);
{code}