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
        listener);

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 java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

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();
		me.doItAll();
	}

	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 {
				this.wait();5
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		if (serviceProxy == null) {6
			System.out.println("the service does not exist");
		} else {
			String message = serviceProxy.getMessage());7
			System.out.println(message);
		}
	}

	public void gotProxy(Object proxy) {8
		synchronized (this) {
			serviceProxy = (ServiceTest) proxy;
			this.notifyAll();9
		}

	}
}
     
1

The class implements the BackgroundSearchListener interface

2

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

3

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

4

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

5

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

8

This method is called by the background search when it finishes

9

The background search unblocks the main thread which was waiting

6

The main thread continues its execution

7

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.