New features in release 0.3.1

Chapter 1. What's new

These are the new Servent features included in the new release:

  • Searches in the p2pdirectory in the background, through the org.dbe.servent.p2p.BackgroundSearchListener interface.

  • Reorganization of the jar files servent-core and servent-impl have been substituted by common, client, server, dynamic and provider.

Background Searches

To perform a search in the background using the ClientHelper class, a new version of the overloaded method getProxy() has been created.

This version has the following signature:

public void getProxy(Class serviceInterface, String[] entries,
        long timeout, int hops, BackgroundSearchListener

The BackgroundSearchListener must be implemented by the user of this method. This interface looks as follows:

public interface BackgroundSearchListener {
	public void gotProxy(Object proxy);

The lonely gotProxy method is called by the background search when the search has finished, and the listener gets the proxy object that matches the search parameters specified in the call to getProxy as can be seen above.

Background search example


import org.dbe.servent.NoSuchServiceException;
import org.dbe.servent.p2p.BackgroundSearchListener;
import org.sun.dbe.ClientHelper;

public class ServiceConsumer implements BackgroundSearchListener 1{
	ServiceTest2 serviceProxy;

	public ServiceConsumer() {
		serviceProxy = null;

	public static void main(String[] args) throws Exception {
		ServiceConsumer me = new ServiceConsumer();

	private void doItAll() throws MalformedURLException,
			NoSuchServiceException, IOException {
		ClientHelper ch = new ClientHelper(new URL("http://localhost:2728"));3
		ch.getProxy(ServiceTest.class, new String[] { "sampleService" },
				10000L, 13, this4);

		synchronized (this) {
			try {
			} catch (InterruptedException e) {
		if (serviceProxy == null) {6
			System.out.println("the service does not exist");
		} else {
			String message = serviceProxy.getMessage());7

	public void gotProxy(Object proxy) {8
		synchronized (this) {
			serviceProxy = (ServiceTest) proxy;


The class implements the BackgroundSearchListener interface


The ServiceTest interface has only one method, getMessage(), which returns a String.


The client creates an instance of ClientHelper that points to a servent.


By calling getProxy and passing as a parameter an instance of BackgroundSearchListener the search starts in the background


In this example the main thread waits for the search to finish


This method is called by the background search when it finishes


The background search unblocks the main thread which was waiting


The main thread continues its execution


The proxy is not null anymore, and the service method can be called in the usual way

Jar reorganization

The jar files of the project have been splitted to allow easier building of clients and service providers while isolating changes in the implementation of a servent node.

Clients should only need to use the servent-common-<version>.jar and the servent-client-<version>.jar files.

Service providers should only need to use the servent-common-<version>.jar and the servent-provider-<version>.jar files.