This tutorial describes how to create, develop and deploy a simple Hello World application using Rio.
Service Beans provide a simple component model defining lifecycle semantics of a dynamic service (start, init, advertise, unadvertise, stop, destroy). The fundamental premise is for the infrastructure to provide an easy to use programming model, whole maintaining access to lower level APIs such as Watches, Associations and Remote Events.
The POJO approach leverages the Service Bean model, allowing POJOs to be developed and deployed without using any Rio infrastructure code. Our example in this section uses a simple Hello World Plain Old Java Object (POJO). The bean is dynamically made available as a distributed service by Rio, allowing the bean to be accessed remotely, with built-in management, fault detection and automated deployment.
This example will also use a test client, showing how the service can be tested and invoked.
This tutorial uses the Rio Maven Archetype to create a project.
mvn archetype:generate -DarchetypeGroupId=org.rioproject -DarchetypeArtifactId=rio-archetype -DarchetypeRepository=http://www.rio-project.org/maven2 -DarchetypeVersion=4.2
Maven also comes pre-packaged with plugins for getting up and running
with your favorite IDE. Try using
mvn idea:idea or
mvn eclipse:eclipse
for each respective editor.
The Rio Maven Archetype generates a fully functional multi-module Maven project for you with the following structure:

The following items are generated
The package name is replaced with the value you provided when
prompted by the Rio Maven Archetype.
If you'd like to add a smart proxy to your service, add another module to the project as follows:

Make sure to adjust the service's module dependency to depend on the proxy, not the api.
Open up the generated Hello.java interface. You'll see the interface is quite simple:
import java.rmi.RemoteException;
public interface Hello {
}Add the following to the interface:
import java.rmi.RemoteException;
public interface Hello {
String hello(String message) throws RemoteException;
}
Note the declaration of java.rmi.RemoteException for the
hello method. This is required to distinguish that the method
invocation is remote-able. Why is this important? For one, the
distinction between local invocation vs. remote invocation is a
distinction that should not be papered over.The implementation of the bean for the Hello interface is equally as simple. You'll need to implement the hello method:
public class HelloImpl implements Hello {
int visitorNumber = 1;
public String hello(String message) {
System.out.println("Client says hello : "+message);
return("Hello visitor : "+visitorNumber++);
}
}The Rio Maven Archetype generates 3 test classes:
Open up the generated ITAbstractHelloTest.java class. Modify the testService method as follows:
void testService(Hello service) {
Assert.assertNotNull(service);
/* Add your testing code here ...*/
Throwable thrown = null;
try {
for(int i=1; i<10; i++) {
String result = service.hello("Test Client");
Assert.assertEquals("Hello visitor : "+i, result);
}
} catch(Throwable t) {
thrown = t;
}
Assert.assertNull(thrown);
}
Once you've made those modifications, the example can be run during the integration-test lifecycle phase of the project (see the declaration of the failsafe-maven-plugin in the pom), or by deploying the example to a running Rio system.
To deploy the example to a running Rio system:
Note: Make sure your project is built. If you run mvn install, your project will be built, packaged tested and installed to your local repository. The integration tests include starting Rio services and deploying the application. If you want to skip the tests and just deploy the project, run mvn install -Dmaven.test.skip and follow the steps below.