Table of Contents
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.
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.
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 { ServiceTest 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")); ch.getProxy(ServiceTest.class, new String[] { "sampleService" }, 10000L, 13, this); synchronized (this) { try { this.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } if (serviceProxy == null) { System.out.println("the service does not exist"); } else { String message = serviceProxy.getMessage()); System.out.println(message); } } public void gotProxy(Object proxy) { synchronized (this) { serviceProxy = (ServiceTest) proxy; this.notifyAll(); } } }
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.