Coverage details for base.jdbs.network.util.PipeUtil

LineHitsSource
1 package base.jdbs.network.util;
2  
3 /*
4 * Copyright (c) 2001 Sun Microsystems, Inc. All rights
5 * reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following discalimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * 3. The end-user documentation included with the redistribution,
20 * if any, must include the following acknowledgment:
21 * "This product includes software developed by the
22 * Sun Microsystems, Inc. for Project JXTA."
23 * Alternately, this acknowledgment may appear in the software itself,
24 * if and wherever such third-party acknowledgments normally appear.
25 *
26 * 4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA"
27 * must not be used to endorse or promote products derived from this
28 * software without prior written permission. For written
29 * permission, please contact Project JXTA at http://www.jxta.org.
30 *
31 * 5. Products derived from this software may not be called "JXTA",
32 * nor may "JXTA" appear in their name, without prior written
33 * permission of Sun.
34 *
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 * SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of Project JXTA. For more
51 * information on Project JXTA, please see
52 * <http://www.jxta.org/>.
53 *
54 * This license is based on the BSD license adopted by the Apache Foundation.
55 *
56 * $Id: PipeUtil.java,v 1.1 2006/05/22 18:29:41 junior-skunk Exp $
57 */
58  
59 import java.io.IOException;
60 import java.util.ArrayList;
61 import java.util.Enumeration;
62 import java.util.List;
63  
64 import net.jxta.discovery.DiscoveryListener;
65 import net.jxta.discovery.DiscoveryService;
66 import net.jxta.document.AdvertisementFactory;
67 import net.jxta.id.IDFactory;
68 import net.jxta.peergroup.PeerGroup;
69 import net.jxta.pipe.PipeID;
70 import net.jxta.protocol.PipeAdvertisement;
71  
72 /**
73  *
74  * @version $Id: PipeUtil.java,v 1.1 2006/05/22 18:29:41 junior-skunk Exp $
75  *
76  * @author james todd [gonzo at jxta dot org]
77  */
78  
790public class PipeUtil {
80  
81 // private static final Object LOCK = new Object();
82  
830    public static final byte[] GROUP_CHAT_PIPE_ID = {
84         (byte)0xD1, (byte)0xD1, (byte)0xD1, (byte)0xD1,
85         (byte)0xD1, (byte)0xD1, (byte)0xD1, (byte)0xD1,
86         (byte)0xD1, (byte)0xD1, (byte)0xD1, (byte)0xD1,
87         (byte)0xD1, (byte)0xD1, (byte)0xD1, (byte)0xD1
88     };
89  
90     public static PipeAdvertisement getAdv(PeerGroup pg, String name,
91         String type, byte[] pipeId) {
920        return getAdv(pg, name, type, pipeId, false);
93     }
94  
95     public static PipeAdvertisement getAdv(PeerGroup pg, String name,
96         String type, byte[] pipeId, boolean remote) {
970        PipeAdvertisement pa = searchLocal(pg, name);
98  
990        if (pa == null) {
1000            pa = createAdv(pg, name, type, pipeId);
101  
1020            publish(pg, pa, remote);
103         }
104  
1050        return pa;
106     }
107  
108     public static List getAdvs(PeerGroup pg, String name) {
1090        List p = new ArrayList();
110  
111         try {
1120            for (Enumeration pas = pg.getDiscoveryService().
113                 getLocalAdvertisements(DiscoveryService.ADV,
114                     PipeAdvertisement.NameTag, name);
1150                pas.hasMoreElements(); ) {
1160                Object o = pas.nextElement();
117  
1180                if (o instanceof PipeAdvertisement) {
1190                    p.add((PipeAdvertisement)o);
120                 }
1210            }
1220        } catch (IOException ioe) {}
123  
1240        return p;
125     }
126  
127     public static PipeAdvertisement searchLocal(PeerGroup pg, String name) {
1280        PipeAdvertisement pa = null;
129  
130         try {
1310            for (Enumeration pas = pg.getDiscoveryService().
132                 getLocalAdvertisements(DiscoveryService.ADV,
133                     PipeAdvertisement.NameTag, name);
1340                pas.hasMoreElements(); ) {
1350                pa = (PipeAdvertisement)pas.nextElement();
136  
1370                if (pa.getName().equals(name)) {
1380                    break;
139                 } else {
1400                    pa = null;
141                 }
1420            }
1430        } catch (IOException ioe) {}
144  
1450        return pa;
146     }
147  
148     public static void discoverAdvs(PeerGroup pg, String name,
149         DiscoveryListener listener) {
1500        DiscoveryService s = pg.getDiscoveryService();
151  
1520        s.getRemoteAdvertisements(null, DiscoveryService.ADV,
153             name != null ? PipeAdvertisement.NameTag : null,
154             name, 10, listener);
1550    }
156  
157     public static PipeAdvertisement createAdv(PeerGroup pg, String name,
158         String type) {
1590        return createAdv(pg, name, type, null);
160     }
161  
162     public static PipeAdvertisement createAdv(PeerGroup pg, String name,
163         String type, byte[] id) {
1640        PipeAdvertisement pa = (PipeAdvertisement)AdvertisementFactory.
165             newAdvertisement(PipeAdvertisement.getAdvertisementType());
166  
1670        pa.setPipeID(id != null ?
168             (PipeID)IDFactory.newPipeID(pg.getPeerGroupID(), id) :
169             (PipeID)IDFactory.newPipeID(pg.getPeerGroupID()));
1700        pa.setName(name);
1710        pa.setType(type);
172  
1730        return pa;
174     }
175  
176     public static void publish(PeerGroup pg, PipeAdvertisement pa) {
1770        publish(pg, pa, false);
1780    }
179  
180     public static void publish(PeerGroup pg, PipeAdvertisement pa,
181         boolean remote) {
1820        DiscoveryService ds = pg.getDiscoveryService();
183  
184         try {
1850            ds.publish(pa);
1860        } catch (IOException ioe) {}
187  
1880        if (remote) {
189             // xxx: no remote publishing
190             // ds.remotePublish(pa, DiscoveryService.ADV);
191         }
1920    }
193 }

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.