jRTPS implementation of DDS-RPC specification is implemented so, that there is no need to do any preparations like creation of "stubs" and "skeletons". Also, using rpc involves only working with ServiceManager and the actual implementation of the service.
Do define a Service that can be registered to jRTPS runtime, one needs to create first an interface that extends net.sf.jrtps.rpc.Service. This interface can then be registered to ServiceManager.
public interface SampleService extends Service { int power2(int i); }
ServiceManager mgr = new ServiceManager(); SampleService service = new MyServer(); mgr.registerService(service);
Creating a client for the service is as simple as creating a service on the server side. Again, one needs a ServiceManager, which can be asked to create a client for any Service. After getting a client side implementation from ServiceManager, one can start calling its methods.
SampleService client = mgr.createClient(SampleService.class); int i = client.power2(5);
By default, only primitive Java types and one-dimensional arrays of primitive types are handled by ServiceManager. To support other types as well, a Serializer needs to be be registered to ServiceManager.
mgr.registerSerializer(Person.class, new PersonSerializer());
Following code snippet is an example of Serializer
public class PersonSerializer implements Serializer<Person> { public void serialize(Person person, RTPSByteBuffer bb) throws SerializationException { bb.write_string(person.name); bb.write_string(person.address); } public Person deSerialize(Class<Person> type, RTPSByteBuffer bb) throws SerializationException { Person p = new Person(); p.name = bb.read_string(); p.address = bb.read_string(); return p; } }