{toc}
h1. *Adding Core Services*
If you want to add your own services, the best way to follow is to create your own 'kernel' which is extending the DSB kernel. Since we are using the Fractal component model in Petals ESB/DSB, you must also use it for your service.
To illustrate this chapter, let's add a simple and powerful service : The HelloWorld Service\!
{info}The source code for this illustration is available under the DSB samples folder in SVN at [https://svn.petalslink.com/svnroot/trunk/research/commons/dsb/samples]{info}
We assume that you are Maven-aware so we do not explain all the commands here...
h2. Create a new kernel
Create a new project :
{code}
mvn archetype:generate
{code}
and choose groupId:org.petalslink.dsb.sample.custom, artifactId:custom-kernel, version:1.0-SNAPSHOT
Use the dsb-kernel as dependency in your new project POM:
{code:language=xml|linenumbers=true|theme=Confluence} <dependency>
<groupId>org.petalslink.dsb</groupId>
<artifactId>dsb-kernel</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>{code}
h2. Create the interface
Let's create a new project for the API definition of your service:
{code}
mvn archetype:generate
{code}
and choose groupId:org.petalslink.dsb.sample.custom, artifactId:custom-api, version:1.0-SNAPSHOT
Let's create a simple interface for our Hello service, HelloService.java:
{code:language=java|linenumbers=true|theme=Confluence}
package org.petalslink.dsb.sample.custom.api;
/**
* @author chamerling
*
*/
public interface HelloService {
String sayHello(String input);
}
{code}
h2. Implement your service
Let's go back to our kernel and add the API as dependency:
{code}
<groupId>org.petalslink.dsb.sample.custom</groupId>
<artifactId>custom-api</artifactId>
<version>1.0-SNAPSHOT</version>
{code}
Now, let's implement the Hello service, create the HelloServiceImpl in the org.petalslink.dsb.sample.custom.kernel package :
{code}
package org.petalslink.dsb.sample.custom.kernel;
import org.petalslink.dsb.sample.custom.api.HelloService;
/**
* @author chamerling
*
*/
public class HelloServiceImpl implements HelloService {
@Override
public String sayHello(String input) {
return "Hello : " + input;
}
}
{code}
Is it enough? No... Since we use a component framework, we need to add component related configuration and dependencies in our kernel project. First let's add all the dependencies we need in the POM file :
{code}
<!-- FRACTAL -->
<dependency>
<groupId>org.objectweb.fractal.julia</groupId>
<artifactId>julia-runtime</artifactId>
<version>2.5.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.objectweb.fractal.julia</groupId>
<artifactId>julia-asm</artifactId>
<version>2.5.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.objectweb.fractal.julia</groupId>
<artifactId>julia-mixins</artifactId>
<version>2.5.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.objectweb.fractal.fractaladl</groupId>
<artifactId>fractal-adl</artifactId>
<version>2.3</version>
<exclusions>
<exclusion>
<groupId>org.objectweb.monolog</groupId>
<artifactId>monolog-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.objectweb.fractal.fraclet.annotation</groupId>
<artifactId>fractal-spoonlet</artifactId>
<version>2.0.2</version>
<exclusions>
<exclusion>
<groupId>org.objectweb.monolog</groupId>
<artifactId>monolog</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.objectweb.fractal.fractaljmx</groupId>
<artifactId>fractal-jmx</artifactId>
<version>0.3.0</version>
<exclusions>
<exclusion>
<groupId>org.objectweb.fractal.julia</groupId>
<artifactId>julia-asm</artifactId>
</exclusion>
<exclusion>
<groupId>org.objectweb.fractal.julia</groupId>
<artifactId>julia-runtime</artifactId>
</exclusion>
<exclusion>
<groupId>org.objectweb.fractal.julia</groupId>
<artifactId>julia-mixins</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- !FRACTAL -->
{code}
Let's rebuild the project with 'mvn eclipse:eclipse' in order to have a good classpath...
Now, let's add the required Fractal annotations and methods in the service implementation, the updated implementation looks like :
{code}
package org.petalslink.dsb.sample.custom.kernel;
import org.objectweb.fractal.fraclet.annotation.annotations.FractalComponent;
import org.objectweb.fractal.fraclet.annotation.annotations.Interface;
import org.objectweb.fractal.fraclet.annotation.annotations.LifeCycle;
import org.objectweb.fractal.fraclet.annotation.annotations.Monolog;
import org.objectweb.fractal.fraclet.annotation.annotations.Provides;
import org.objectweb.fractal.fraclet.annotation.annotations.type.LifeCycleType;
import org.objectweb.util.monolog.api.Logger;
import org.petalslink.dsb.sample.custom.api.HelloService;
/**
* @author chamerling
*
*/
@FractalComponent
@Provides(interfaces = { @Interface(name = "service", signature = HelloService.class) })
public class HelloServiceImpl implements HelloService {
@Monolog(name = "logger")
private Logger logger;
private LoggingUtil log;
@LifeCycle(on = LifeCycleType.START)
protected void start() {
this.log = new LoggingUtil(this.logger);
}
@LifeCycle(on = LifeCycleType.STOP)
protected void stop() {
}
@Override
public String sayHello(String input) {
return "Hello : " + input;
}
}
{code}
Is it enough? Almost... Let's say to Maven he has to do some extra steps at compilation time:
{code}
<plugin>
<groupId>net.sf.alchim</groupId>
<artifactId>spoon-maven-plugin</artifactId>
<version>0.7.1</version>
<executions>
<execution>
<goals>
<goal>recompile</goal>
<goal>test-recompile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.9</version>
</dependency>
<dependency>
<groupId>org.objectweb.monolog</groupId>
<artifactId>monolog</artifactId>
<version>1.8</version>
</dependency>
</dependencies>
</plugin>
{code}
And add the spoon.cfg.xml at the root level of the custom-kernel project with this content :
{code}
<?xml version="1.0" encoding="UTF-8"?>
<spoon>
<spoonlet artifactId="fractal-spoonlet" groupId="org.objectweb.fractal.fraclet.annotation"
version="2.0.2"/>
</spoon>
{code}
h2. Create your custom distribution
h2. Add your service to the distribution
h1. Packaging your distribution
h1. *Adding Core Services*
If you want to add your own services, the best way to follow is to create your own 'kernel' which is extending the DSB kernel. Since we are using the Fractal component model in Petals ESB/DSB, you must also use it for your service.
To illustrate this chapter, let's add a simple and powerful service : The HelloWorld Service\!
{info}The source code for this illustration is available under the DSB samples folder in SVN at [https://svn.petalslink.com/svnroot/trunk/research/commons/dsb/samples]{info}
We assume that you are Maven-aware so we do not explain all the commands here...
h2. Create a new kernel
Create a new project :
{code}
mvn archetype:generate
{code}
and choose groupId:org.petalslink.dsb.sample.custom, artifactId:custom-kernel, version:1.0-SNAPSHOT
Use the dsb-kernel as dependency in your new project POM:
{code:language=xml|linenumbers=true|theme=Confluence} <dependency>
<groupId>org.petalslink.dsb</groupId>
<artifactId>dsb-kernel</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>{code}
h2. Create the interface
Let's create a new project for the API definition of your service:
{code}
mvn archetype:generate
{code}
and choose groupId:org.petalslink.dsb.sample.custom, artifactId:custom-api, version:1.0-SNAPSHOT
Let's create a simple interface for our Hello service, HelloService.java:
{code:language=java|linenumbers=true|theme=Confluence}
package org.petalslink.dsb.sample.custom.api;
/**
* @author chamerling
*
*/
public interface HelloService {
String sayHello(String input);
}
{code}
h2. Implement your service
Let's go back to our kernel and add the API as dependency:
{code}
<groupId>org.petalslink.dsb.sample.custom</groupId>
<artifactId>custom-api</artifactId>
<version>1.0-SNAPSHOT</version>
{code}
Now, let's implement the Hello service, create the HelloServiceImpl in the org.petalslink.dsb.sample.custom.kernel package :
{code}
package org.petalslink.dsb.sample.custom.kernel;
import org.petalslink.dsb.sample.custom.api.HelloService;
/**
* @author chamerling
*
*/
public class HelloServiceImpl implements HelloService {
@Override
public String sayHello(String input) {
return "Hello : " + input;
}
}
{code}
Is it enough? No... Since we use a component framework, we need to add component related configuration and dependencies in our kernel project. First let's add all the dependencies we need in the POM file :
{code}
<!-- FRACTAL -->
<dependency>
<groupId>org.objectweb.fractal.julia</groupId>
<artifactId>julia-runtime</artifactId>
<version>2.5.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.objectweb.fractal.julia</groupId>
<artifactId>julia-asm</artifactId>
<version>2.5.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.objectweb.fractal.julia</groupId>
<artifactId>julia-mixins</artifactId>
<version>2.5.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.objectweb.fractal.fractaladl</groupId>
<artifactId>fractal-adl</artifactId>
<version>2.3</version>
<exclusions>
<exclusion>
<groupId>org.objectweb.monolog</groupId>
<artifactId>monolog-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.objectweb.fractal.fraclet.annotation</groupId>
<artifactId>fractal-spoonlet</artifactId>
<version>2.0.2</version>
<exclusions>
<exclusion>
<groupId>org.objectweb.monolog</groupId>
<artifactId>monolog</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.objectweb.fractal.fractaljmx</groupId>
<artifactId>fractal-jmx</artifactId>
<version>0.3.0</version>
<exclusions>
<exclusion>
<groupId>org.objectweb.fractal.julia</groupId>
<artifactId>julia-asm</artifactId>
</exclusion>
<exclusion>
<groupId>org.objectweb.fractal.julia</groupId>
<artifactId>julia-runtime</artifactId>
</exclusion>
<exclusion>
<groupId>org.objectweb.fractal.julia</groupId>
<artifactId>julia-mixins</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- !FRACTAL -->
{code}
Let's rebuild the project with 'mvn eclipse:eclipse' in order to have a good classpath...
Now, let's add the required Fractal annotations and methods in the service implementation, the updated implementation looks like :
{code}
package org.petalslink.dsb.sample.custom.kernel;
import org.objectweb.fractal.fraclet.annotation.annotations.FractalComponent;
import org.objectweb.fractal.fraclet.annotation.annotations.Interface;
import org.objectweb.fractal.fraclet.annotation.annotations.LifeCycle;
import org.objectweb.fractal.fraclet.annotation.annotations.Monolog;
import org.objectweb.fractal.fraclet.annotation.annotations.Provides;
import org.objectweb.fractal.fraclet.annotation.annotations.type.LifeCycleType;
import org.objectweb.util.monolog.api.Logger;
import org.petalslink.dsb.sample.custom.api.HelloService;
/**
* @author chamerling
*
*/
@FractalComponent
@Provides(interfaces = { @Interface(name = "service", signature = HelloService.class) })
public class HelloServiceImpl implements HelloService {
@Monolog(name = "logger")
private Logger logger;
private LoggingUtil log;
@LifeCycle(on = LifeCycleType.START)
protected void start() {
this.log = new LoggingUtil(this.logger);
}
@LifeCycle(on = LifeCycleType.STOP)
protected void stop() {
}
@Override
public String sayHello(String input) {
return "Hello : " + input;
}
}
{code}
Is it enough? Almost... Let's say to Maven he has to do some extra steps at compilation time:
{code}
<plugin>
<groupId>net.sf.alchim</groupId>
<artifactId>spoon-maven-plugin</artifactId>
<version>0.7.1</version>
<executions>
<execution>
<goals>
<goal>recompile</goal>
<goal>test-recompile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.9</version>
</dependency>
<dependency>
<groupId>org.objectweb.monolog</groupId>
<artifactId>monolog</artifactId>
<version>1.8</version>
</dependency>
</dependencies>
</plugin>
{code}
And add the spoon.cfg.xml at the root level of the custom-kernel project with this content :
{code}
<?xml version="1.0" encoding="UTF-8"?>
<spoon>
<spoonlet artifactId="fractal-spoonlet" groupId="org.objectweb.fractal.fraclet.annotation"
version="2.0.2"/>
</spoon>
{code}
h2. Create your custom distribution
h2. Add your service to the distribution
h1. Packaging your distribution