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

📄 statuscommand.java

📁 用jxse开发的一个p2p通讯软件 有聊天 文件共享 视频3大功能
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            } else {                for (Enumeration ce = rdv.getConnectedRendezVous();                    ce.hasMoreElements(); ) {                    ID id = (ID)ce.nextElement();                    if (srs != null) {                        sb.append(toUnicodeEncoded(getRendezVousStatus(srs.getPeerConnection(id))));                    } else {                        sb.append(toUnicodeEncoded(getRendezVousStatus(dsc, id)));                    }                }                                            for (Enumeration re = rdv.getDisconnectedRendezVous();                    re.hasMoreElements(); ) {                    ID id = (ID)re.nextElement();                                            sb.append(toUnicodeEncoded(getClientStatus(dsc, id)));                }            }            sb.append(TAB + close(RENDEZVOUS) + NEW_LINE);        }        EndpointService es = pg.getEndpointService();                sb.append(TAB + open(RELAYS) + ELEMENT_CLOSE_POSTAMBLE + NEW_LINE);                            for (Iterator mti = es.getAllMessageTransports(); mti.hasNext(); ) {            MessageTransport mt = (MessageTransport)mti.next();                        if (mt instanceof RelayClient) {                Vector activeRelays = ((RelayClient) mt).getActiveRelays(null);                if (activeRelays!=null){                    for (Iterator ri = activeRelays.iterator(); ri.hasNext(); ) {                        AccessPointAdvertisement ap = (AccessPointAdvertisement)ri.next();                        String pid = ap.getPeerID().toString();                        String pn = getPeerName(mt, ap);                        sb.append(TAB + TAB + open(CLIENT));                        sb.append(SPACE + attribute(UID, toUnicodeEncoded(pid)));                        if (! pn.equals(pid)) {                            sb.append(SPACE + attribute(NAME,                                toUnicodeEncoded(getPeerName(mt, ap))));                        }                        sb.append(close(CLIENT, false) + NEW_LINE);                    }                }            } else if (mt instanceof RelayServer) {                for (Iterator ri =                    ((RelayServer)mt).getRelayedClients().iterator();                    ri.hasNext(); ) {                    String s = (String)ri.next();                    String pid = net.jxta.id.ID.URIEncodingName + COLON +                        net.jxta.id.ID.URNNamespace + COLON +                        s.substring(0, s.indexOf(COMMA));                    String pn = getPeerName(mt, pid);                                                sb.append(TAB + TAB + open(SERVER));                    sb.append(SPACE + attribute(UID, toUnicodeEncoded(pid)));                                        if (! pn.equals(pid)) {                        sb.append(SPACE + attribute(NAME, toUnicodeEncoded(pn)));                    }                                        sb.append(close(SERVER, false) + NEW_LINE);                }            }        }                sb.append(TAB + close(RELAYS) + NEW_LINE);        sb.append(close(STATUS));        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("response = \'" + sb + "\'");            LOG.fine("End   getResponse(PeerGroup)");        }        return sb.toString();    }    private String formatBytes(long l) {        return ""+l/(float)1000+" kByte";    }    private String getDirection(PeerViewElement pve, PeerView pv) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("In getDirection(PeerViewElement, PeerView)");        }        String d = "";        if (pve == pv.getUpPeer()) {            d = UP;        } else if (pve == pv.getDownPeer()) {            d = DOWN;        }        return d;    }            private String getClientStatus(PeerConnection pc) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("In getClientStatus(PeerConnection)");        }        return getStatus(pc, CLIENT);    }    private String getClientStatus(DiscoveryService dsc, ID id) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("In getClientStatus(DiscoveryService, ID)");        }        return getStatus(dsc, id, CLIENT);    }        private String getRendezVousStatus(PeerConnection pc) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("In getRendezVousStatus(PeerConnection)");        }        return getStatus(pc, RENDEZVOUS);    }        private String getRendezVousStatus(DiscoveryService dsc, ID id) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("In getRendezVousStatus(DiscoveryService, ID)");        }        return getStatus(dsc, id, RENDEZVOUS);    }    private String getStatus(PeerConnection pc, String e) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("Begin getStatus(PeerConnection, String)");        }        StringBuffer sb = new StringBuffer();                if (pc != null) {            sb.append(TAB + TAB + open(e));            sb.append(SPACE + attribute(UID, pc.getPeerID().toString()));            sb.append(SPACE + attribute(NAME, pc.getPeerName()));            sb.append(SPACE + attribute(TYPE, PEER));            sb.append(SPACE + attribute(CLIENT_IS_CONNECTED,                String.valueOf(pc.isConnected())));            sb.append(SPACE + attribute(LEASE_TIME,                String.valueOf(pc.getLeaseEnd())));            sb.append(close(e, false) + NEW_LINE);        }        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("status = \'" + sb + "\'");            LOG.fine("End   getStatus(PeerConnection, String)");        }        return sb.toString();    }        private String getStatus(DiscoveryService dsc, ID id, String e) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("Begin getStatus(PeerConnection, ID, String)");        }        StringBuffer sb = new StringBuffer();                if (dsc != null &&            id != null) {            String n = getIdName(dsc, id);            String t = getIdType(id);                        sb.append(TAB + open(e));            sb.append(SPACE + attribute(UID, id.toString()));                        if (n != null) {                sb.append(SPACE + attribute(NAME, n));            }                        if (t != null) {                sb.append(SPACE + attribute(TYPE, t));            }                        sb.append(close(e, false) + NEW_LINE);        }        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("status = \'" + sb + "\'");            LOG.fine("End   getStatus(PeerConnection, ID, String)");        }        return sb.toString();    }        private String getIdName(DiscoveryService dsc, ID id) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("Begin getIdName(DiscoveryService, ID)");        }        String n = null;        String t = getIdType(id);                if (t != null) {            Enumeration e = null;            if (t.equals(PEER)) {                try {                    e = dsc.getLocalAdvertisements(DiscoveryService.PEER,                                                   PEER_TYPE_ID, id.toString());                }                catch (IOException ioe) {                    if (Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) {                        LOG.log(Level.SEVERE, "Caught unexpected exception ", ioe);                    }                }                if (e != null && e.hasMoreElements()) {                    n = ((PeerAdvertisement) e.nextElement()).getName();                }            } else if (t.equals(GROUP)) {                try {                    e = dsc.getLocalAdvertisements(DiscoveryService.GROUP,                                                   GROUP_TYPE_ID, id.toString());                }                catch (IOException ioe) {                    if (Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) {                        LOG.log(Level.SEVERE, "Caught unexpected exception ", ioe);                    }                }                if (e != null && e.hasMoreElements()) {                    n = ((PeerGroupAdvertisement) e.nextElement()).getName();                }            }        }        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("name = \'" + n + "\'");            LOG.fine("End   getIdName(DiscoveryService, ID)");        }        return n != null ? n : UNKNOWN;    }        private String getIdType(ID id) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("Begin getIdType(DiscoveryService, ID)");        }        String t = null;                if (id != null) {            if (id instanceof PeerID) {                t = PEER;            } else if (id instanceof PeerGroupID) {                t = GROUP;            }        }                if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("type = \'" + t + "\'");            LOG.fine("End   getIdType(DiscoveryService, ID)");        }        return t != null ? t : UNKNOWN;    }        private String getPeerName(MessageTransport mt, AccessPointAdvertisement adv ) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("Begin getPeerName(MessageTransport, AccessPointAdvertisement)");        }        String pn = adv.getPeerID().toString();        EndpointService es = mt.getEndpointService();        DiscoveryService ds = es != null ?            es.getGroup().getDiscoveryService() : null;                try {            for (Enumeration lae = ds.getLocalAdvertisements(DiscoveryService.PEER,                "PID", pn);                lae.hasMoreElements(); ) {                pn = ((PeerAdvertisement)lae.nextElement()).getName();                                break;            }        } catch (IOException ioe) {            if (Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) {                LOG.log(Level.SEVERE, "Caught unexpected exception ", ioe);            }        }        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("peerName = \'" + pn + "\'");            LOG.fine("End   getPeerName(MessageTransport, AccessPointAdvertisement)");        }        return pn != null ? pn : UNKNOWN;    }        private String getPeerName(MessageTransport mt, String pid) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("Begin getPeerName(MessageTransport, String)");        }        String pn = null;        EndpointService es = mt.getEndpointService();        DiscoveryService ds = es != null ?            es.getGroup().getDiscoveryService() : null;                if (ds != null) {            try {                for (Enumeration lae = ds.getLocalAdvertisements(DiscoveryService.PEER,                    "PID", pid);                    lae.hasMoreElements(); ) {                    pn = ((PeerAdvertisement)lae.nextElement()).getName();                                        break;                }            } catch (IOException ioe) {                if (Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) {                    LOG.log(Level.SEVERE, "Caught unexpected exception ", ioe);                }            }        }        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {

⌨️ 快捷键说明

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