Line | Hits | Source |
---|---|---|
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 | ||
12 | 0 | public class PeerDiscoveryListener implements DiscoveryListener { |
13 | ||
14 | 0 | private static final transient Logger logger = Logger.getLogger(PeerDiscoveryListener.class.getName()); |
15 | ||
16 | private final PeerDiscoveryThread peerDiscoveryThread ; | |
17 | 0 | |
18 | 0 | public PeerDiscoveryListener(PeerDiscoveryThread peerDiscoveryThread) { |
19 | 0 | this.peerDiscoveryThread = peerDiscoveryThread; |
20 | 0 | } |
21 | ||
22 | 0 | public void discoveryEvent(DiscoveryEvent event) { |
23 | 0 | DiscoveryResponseMsg discoveryResponseMsg = event.getResponse(); |
24 | 0 | String name = "unknown"; |
25 | 0 | //Get the responding peer's advertisement |
26 | 0 | PeerAdvertisement peerAdvertisement = discoveryResponseMsg.getPeerAdvertisement(); |
27 | 0 | //some peers may not respond with their peerAdvertisement |
28 | 0 | if (peerAdvertisement != null) { |
29 | 0 | name = peerAdvertisement.getName(); |
30 | } | |
31 | 0 | |
32 | 0 | logger.info(PeerDiscoveryThread.THREAD_NAME+": Got a Discovery Response [" + discoveryResponseMsg.getResponseCount()+ " elements] from peer : " + name); |
33 | ||
34 | 0 | // printout each discovered peer |
35 | 0 | PeerAdvertisement peerArvertisement = null; |
36 | 0 | Enumeration enumeration = discoveryResponseMsg.getAdvertisements(); |
37 | 0 | if (enumeration != null ) { |
38 | 0 | while (enumeration.hasMoreElements()) { |
39 | 0 | peerArvertisement = (PeerAdvertisement) enumeration.nextElement(); |
40 | 0 | logger.debug(" Peer name = " + peerArvertisement.getName()); |
41 | 0 | this.peerDiscoveryThread.addPeer(peerArvertisement, peerDiscoveryThread.getPeerGroup()); |
42 | 0 | } |
43 | 0 | } |
44 | 0 | } |
45 | ||
46 | ||
47 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |