Coverage details for base.jdbs.network.PeerDiscoveryListener

LineHitsSource
1 package base.jdbs.network;
2  
3 import java.util.Enumeration;
4  
5 import net.jxta.discovery.DiscoveryEvent;
6 import net.jxta.discovery.DiscoveryListener;
7 import net.jxta.protocol.DiscoveryResponseMsg;
8 import net.jxta.protocol.PeerAdvertisement;
9  
10 import org.apache.log4j.Logger;
11  
120public class PeerDiscoveryListener implements DiscoveryListener {
13  
140    private static final transient Logger logger = Logger.getLogger(PeerDiscoveryListener.class.getName());
15  
16     private final PeerDiscoveryThread peerDiscoveryThread ;
170    
180    public PeerDiscoveryListener(PeerDiscoveryThread peerDiscoveryThread) {
190        this.peerDiscoveryThread = peerDiscoveryThread;
200    }
21  
220    public void discoveryEvent(DiscoveryEvent event) {
230        DiscoveryResponseMsg discoveryResponseMsg = event.getResponse();
240        String name = "unknown";
250        //Get the responding peer's advertisement
260        PeerAdvertisement peerAdvertisement = discoveryResponseMsg.getPeerAdvertisement();
270        //some peers may not respond with their peerAdvertisement
280        if (peerAdvertisement != null) {
290            name = peerAdvertisement.getName();
30         }
310        
320        logger.info(PeerDiscoveryThread.THREAD_NAME+": Got a Discovery Response [" + discoveryResponseMsg.getResponseCount()+ " elements] from peer : " + name);
33         
340// printout each discovered peer
350        PeerAdvertisement peerArvertisement = null;
360        Enumeration enumeration = discoveryResponseMsg.getAdvertisements();
370        if (enumeration != null ) {
380            while (enumeration.hasMoreElements()) {
390                peerArvertisement = (PeerAdvertisement) enumeration.nextElement();
400                logger.debug(" Peer name = " + peerArvertisement.getName());
410                this.peerDiscoveryThread.addPeer(peerArvertisement, peerDiscoveryThread.getPeerGroup());
420            }
430        }
440    }
45  
46     
47 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.