| Line | Hits | Source |
|---|---|---|
| 1 | package base.jdbs.network.util; | |
| 2 | ||
| 3 | import java.util.Enumeration; | |
| 4 | import java.util.Vector; | |
| 5 | ||
| 6 | import net.jxta.discovery.DiscoveryService; | |
| 7 | import net.jxta.protocol.PeerAdvertisement; | |
| 8 | import net.jxta.protocol.PeerGroupAdvertisement; | |
| 9 | ||
| 10 | import org.apache.log4j.Logger; | |
| 11 | ||
| 12 | 0 | public class JxtaUtil { |
| 13 | ||
| 14 | 0 | private static final transient Logger logger = Logger.getLogger(JxtaUtil.class.getName()); |
| 15 | ||
| 16 | ||
| 17 | /** | |
| 18 | * This method must be used to retrieve each PeerGroupAdvertisement stored in the local peer's cache. | |
| 19 | * @param discoveryService The discovery service used to check the Peer Group Advertisements stored in the local cache. | |
| 20 | * @return A set of PeerGroupAdvertisement found in the local peer's cache. | |
| 21 | */ | |
| 22 | public static PeerGroupAdvertisement[] groupsInLocalCache(DiscoveryService discoveryService) { | |
| 23 | 0 | Vector<PeerGroupAdvertisement> result = new Vector<PeerGroupAdvertisement>(); |
| 24 | 0 | logger.debug("--- local cache (Peer Groups) ---"); |
| 25 | try { | |
| 26 | 0 | PeerGroupAdvertisement peerGroupAdvertisement = null; |
| 27 | 0 | Enumeration enumeration = discoveryService.getLocalAdvertisements(DiscoveryService.GROUP, null, null); |
| 28 | 0 | if (enumeration != null) { |
| 29 | 0 | while (enumeration.hasMoreElements()) { |
| 30 | 0 | peerGroupAdvertisement = (PeerGroupAdvertisement) enumeration.nextElement(); |
| 31 | 0 | result.add(peerGroupAdvertisement); |
| 32 | 0 | logger.debug( peerGroupAdvertisement.getName() + ", group ID = " +peerGroupAdvertisement.getPeerGroupID().toString()); |
| 33 | 0 | } |
| 34 | } | |
| 35 | 0 | } catch (Exception ex) { |
| 36 | 0 | ex.printStackTrace(); |
| 37 | 0 | } |
| 38 | 0 | logger.debug("--- end local cache ---"); |
| 39 | 0 | return result.toArray(new PeerGroupAdvertisement[0]); |
| 40 | } | |
| 41 | ||
| 42 | /** | |
| 43 | * This method must be used to retrieve each PeerAdvertisement stored in the local peer's cache. | |
| 44 | * @param discoveryService The discovery service used to check the Peer Advertisements stored in the local cache. | |
| 45 | * @return A set of PeerAdvertisement found in the local peer's cache. | |
| 46 | */ | |
| 47 | public static PeerAdvertisement[] peersInLocalCache(DiscoveryService discoveryService) { | |
| 48 | 0 | Vector<PeerAdvertisement> result = new Vector<PeerAdvertisement>(); |
| 49 | 0 | logger.debug("--- local cache (Peers) ---"); |
| 50 | try { | |
| 51 | 0 | PeerAdvertisement peerAdvertisement = null; |
| 52 | 0 | Enumeration enumeration = discoveryService.getLocalAdvertisements(DiscoveryService.PEER, null, null); |
| 53 | 0 | if (enumeration != null) { |
| 54 | 0 | while (enumeration.hasMoreElements()) { |
| 55 | 0 | peerAdvertisement = (PeerAdvertisement) enumeration.nextElement(); |
| 56 | 0 | result.add(peerAdvertisement); |
| 57 | 0 | logger.debug( peerAdvertisement.getName() + ", peer ID = " +peerAdvertisement.getPeerID().toString()); |
| 58 | 0 | } |
| 59 | } | |
| 60 | 0 | } catch (Exception ex) { |
| 61 | 0 | ex.printStackTrace(); |
| 62 | 0 | } |
| 63 | 0 | logger.debug("--- end local cache ---"); |
| 64 | 0 | return result.toArray(new PeerAdvertisement[0]); |
| 65 | } | |
| 66 | ||
| 67 | ||
| 68 | ||
| 69 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |