Ola Leifler - 2006-04-16

Hi!

I was curious about your PeerRMI library and thought it could be very useful to me. Howevver, I have still not managed to get it to work and thought I'd ask you since the forums seem rather quiet. The problem is that I have not managed to get two peers to discover and connect to each other. Is there some JXTA configuration magic that I need to perform or have I missed something else?

Best regards
Ola Leifler

PeerTest.java:

package test;

import java.rmi.AlreadyBoundException;
import java.rmi.RemoteException;

import jxl.peermi.DiscoveryListener;
import jxl.peermi.PeerManager;
import jxl.peermi.PeerRegistry;
import jxl.peermi.PeerRemote;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

/**
* @author olale
*
*/
public class PeerTest {

    /**
     *
     */
    public PeerTest() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        try {
            final PeerRegistry localRegistry = PeerRegistry.getLocalInstance();
            final String objectName = PeerTestObject.class.getName();
            PeerTestObject testObject = new PeerTestObject();
            final Logger logger = Logger.getLogger(PeerTest.class.getName());
            logger.setLevel(Level.INFO);
            Runnable initializer = new Runnable() {
                public void run() {
                    PeerManager<PeerTestInterface> peers = null;
                    try {
                        peers = localRegistry.requestPeerManager(objectName,
                                PeerTestInterface.class);
                    } catch (RemoteException exception) {
                        // TODO Auto-generated catch block
                        exception.printStackTrace();
                    }
                    if (peers.isEmpty()) {
                        logger.info("no peers found");
                    } else {
                        logger.info("Peers found!");
                    }

                }
            };
            new Thread(initializer).start();
            localRegistry.addDiscoveryListener(objectName, new DiscoveryListener() {

                public void discovery(PeerRemote remote) {
                    logger.info("Peer discovered!");
                }

            });
        } catch (RemoteException exception) {
            // TODO Auto-generated catch block
            exception.printStackTrace();
        } catch (AlreadyBoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}

PeerTestInterface.java:

package test;

import java.rmi.RemoteException;

import jxl.peermi.PeerRemote;

/**
* @author olale
*
*/
public interface PeerTestInterface extends PeerRemote {

    public int test() throws RemoteException;
   
}

PeerTestObject.java:

package test;

import java.rmi.AlreadyBoundException;
import java.rmi.RemoteException;

import jxl.peermi.PeerRemoteObject;

/**
* @author olale
*
*/
public class PeerTestObject extends PeerRemoteObject implements PeerTestInterface {

    /**
     *
     */
    private static final long serialVersionUID = 1L;

    /**
     * @throws RemoteException
     * @throws AlreadyBoundException
     */
    public PeerTestObject() throws RemoteException, AlreadyBoundException {
        super(true);
        // TODO Auto-generated constructor stub
    }

    /**
     * @param registerByClass
     * @throws RemoteException
     * @throws AlreadyBoundException
     */
    public PeerTestObject(boolean registerByClass) throws RemoteException, AlreadyBoundException {
        super(registerByClass);
        // TODO Auto-generated constructor stub
    }

    /**
     * @param port
     * @throws RemoteException
     */
    public PeerTestObject(int port) throws RemoteException {
        super(port);
        // TODO Auto-generated constructor stub
    }

    /* (non-Javadoc)
     * @see se.liu.ida.critiquer.test.PeerTestInterface#test()
     */
    public int test() throws RemoteException {
        // TODO Auto-generated method stub
        return 2;
    }

}