⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 startnetpeergroup.java

📁 jxta_src_2.41b jxta 2.41b 最新版源码 from www.jxta.org
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                            try {                                paEnum = disco.getLocalAdvertisements(DiscoveryService.PEER,                                                                      "PID",                                                                      pg.getPeerID().toString());                            } catch (Exception justGiveUp) {}                            while (paEnum.hasMoreElements()) {                                PeerAdvertisement pa =                                    (PeerAdvertisement)paEnum.nextElement();                                if (pa.getPeerGroupID().equals(a.getPeerGroupID())) {                                    self = "*";                                    if (!kw.equals("NetPeerGroup by default")) {                                        // This user has used the disco                                        // option before therefore he                                        // wants to use it.                                        doDisco = doDisco || beSmart;                                        break;                                    }                                }                            }                            advs.put(kw+a.getPeerGroupID().toString(), a);                            System.out.println(self + " " + kw);                        }                    }                }                // If doDisco is not true the first time around (after                // a local discovery), then we don't want it.                if (! doDisco) {                    advs.clear();                    break;                }            }            Vector advVect = new Vector();            Enumeration each = advs.elements();            // Make an ordered list and display it with numbering.            int s = 0;            while (each.hasMoreElements()) {                PeerGroupAdvertisement a =                    (PeerGroupAdvertisement) each.nextElement();                String self = " ";                // Do a quick lookup for a past local instantiation.                // May not find anything if we do not publish padvs                // in the parent grp.                Enumeration paEnum = (new Vector().elements());                try {                    paEnum = disco.getLocalAdvertisements(DiscoveryService.PEER,                                                          "PID",                                                          pg.getPeerID().toString());                } catch (Exception forgetIt) {}                while (paEnum.hasMoreElements()) {                    PeerAdvertisement pa =                        (PeerAdvertisement) paEnum.nextElement();                    if (pa.getPeerGroupID().equals(a.getPeerGroupID())) {                        self = "*";                        break;                    }                }                System.out.println(self + s + ": " + a.getDescription());                advVect.addElement(a);                ++s;            }            if (s > 0) {                while (true) {                    System.out.println(" " + s + ": None of the above");                    System.out.println("\n* = previously instantiated here\n");                    try {                        while (in.ready()) in.readLine();                        System.out.print("Chose which advertisement you want"                                         + " to use: ");                        answer = in.readLine();                        int i = s + 1;                        try {                            i = Integer.parseInt(answer);                        } catch(Exception ignored) {}                        if (i == s) break;                        if (i >= 0 && i <= s) {                            npgAdv = (PeerGroupAdvertisement) advVect.elementAt(i);                            break;                        }                        i = 0;                        System.out.println("\n\nFound:");                        while (i < s) {                            PeerGroupAdvertisement a =                                (PeerGroupAdvertisement) advVect.elementAt(i);                            String self = " ";                            // Do a quick lookup for a past local instantiation.                            // May not find anything if we do not publish padvs                            // in the parent grp.                            Enumeration paEnum =                                disco.getLocalAdvertisements(DiscoveryService.PEER,                                                             "PID",                                                             pg.getPeerID().toString());                            while (paEnum.hasMoreElements()) {                                PeerAdvertisement pa =                                    (PeerAdvertisement) paEnum.nextElement();                                if (pa.getPeerGroupID().equals(a.getPeerGroupID())) {                                    self = "*";                                    break;                                }                            }                            String kw = a.getDescription();                            if (kw == null) kw = "";                            System.out.println(self + i + ": " + kw);                            i++;                        }                    } catch (Exception e) {                        break;                    }                }            }            if (npgAdv != null) {                // Good, just start it then. For now, we pass-on the conf.                PeerGroup g = pg.newGroup(npgAdv);                g.startApp(null);                g.unref();                pg.unref();                return 0;            }            // Ok, then, maybe we should seed that group.            // NB: seeding the NPG right now is somewhat useless; since it creates            // nothing different form the default one. It is just there for the            // sake of example.            if (doDisco) {                System.out.println("\nNo NetPeerGroup advertisement selected.");                try {                    while (in.ready()) in.readLine();                    System.out.println("Do you want to start a shell in the "                                       + "Platform Group ? [no]:");                    answer = in.readLine();                    if("yes".equalsIgnoreCase(answer)) {                        try {                            // Build a ModuleImplAdv for the shell; cannot rely                            // on the shell having been published yet.                            // FIXME: Modules built-in jxta should have                            // a static method for that.                            ModuleImplAdvertisement newAppAdv =                                (ModuleImplAdvertisement)                                AdvertisementFactory.newAdvertisement(                                    ModuleImplAdvertisement.getAdvertisementType());                            // The shell's spec id is a canned one.                            newAppAdv.setModuleSpecID(PeerGroup.refShellSpecID);                            // Don't known how to ID the document itself yet.                            // Just use the spec                            // FIXME: we should probably hash the adv, like for                            // codat.                            newAppAdv.setModuleSpecID(PeerGroup.refShellSpecID);                            // Steal the compat, provider, and uri from the                            // group's own impl adv. We DO want them identical in                            // this case.                            ModuleImplAdvertisement pgImpl =                                (ModuleImplAdvertisement)pg.getImplAdvertisement();                            newAppAdv.setCompat(pgImpl.getCompat());                            newAppAdv.setUri(pgImpl.getUri());                            newAppAdv.setProvider(pgImpl.getProvider());                            // Make up a description                            newAppAdv.setDescription("JXTA Shell");                            // Tack in the class name                            newAppAdv.setCode(                                "net.jxta.impl.shell.bin.Shell.Shell");                            // Finaly load and init the shell.                            Application app = (Application)                                              pg.loadModule(PeerGroup.applicationClassID,                                                            newAppAdv);                            app.startApp(null);                            pg.unref();                            return 0;                        } catch (Exception e) {                            e.printStackTrace();                            System.err.println("Error loading Shell.");                        }                    }                    while (in.ready()) in.readLine();                    System.out.println("Do you want to start the default net peer"                                       + " group ? [yes]:");                    answer = in.readLine();                    if("no".equalsIgnoreCase(answer)) {                        System.exit(0);                    }                } catch(Exception e2) {                    e2.printStackTrace();                    System.err.println("Unable to query desired behaviour. "                                       + "Starting the default net peer group.");                }            }            // We can start the net peer group now. (For now we pass-on the conf            PeerGroup g = PeerGroupFactory.newNetPeerGroup(pg);            g.startApp(null);            g.unref();            pg.unref();            return 0;        } catch(Exception anythingElse) {            anythingElse.printStackTrace();            return 1;        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -