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

📄 statuscommand.java

📁 用jxse开发的一个p2p通讯软件 有聊天 文件共享 视频3大功能
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/**  Copyright (c) 2001 Sun Microsystems, Inc.  All rights*  reserved.**  Redistribution and use in source and binary forms, with or without*  modification, are permitted provided that the following conditions*  are met:**  1. Redistributions of source code must retain the above copyright*  notice, this list of conditions and the following disclaimer.**  2. Redistributions in binary form must reproduce the above copyright*  notice, this list of conditions and the following discalimer in*  the documentation and/or other materials provided with the*  distribution.**  3. The end-user documentation included with the redistribution,*  if any, must include the following acknowledgment:*  "This product includes software developed by the*  Sun Microsystems, Inc. for Project JXTA."*  Alternately, this acknowledgment may appear in the software itself,*  if and wherever such third-party acknowledgments normally appear.**  4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA"*  must not be used to endorse or promote products derived from this*  software without prior written permission. For written*  permission, please contact Project JXTA at http://www.jxta.org.**  5. Products derived from this software may not be called "JXTA",*  nor may "JXTA" appear in their name, without prior written*  permission of Sun.**  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED*  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES*  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE*  DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR*  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF*  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND*  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,*  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT*  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF*  SUCH DAMAGE.*  ====================================================================**  This software consists of voluntary contributions made by many*  individuals on behalf of Project JXTA.  For more*  information on Project JXTA, please see*  <http://www.jxta.org/>.**  This license is based on the BSD license adopted by the Apache Foundation.**  $Id: StatusCommand.java,v 1.24 2007/04/16 20:14:05 nano Exp $*/package net.jxta.myjxta.dialog.commands;import net.jxta.discovery.DiscoveryService;import net.jxta.endpoint.EndpointService;import net.jxta.endpoint.MessageTransport;import net.jxta.id.ID;import net.jxta.impl.endpoint.relay.RelayClient;import net.jxta.impl.endpoint.relay.RelayServer;import net.jxta.impl.rendezvous.PeerConnection;import net.jxta.impl.rendezvous.RendezVousServiceInterface;import net.jxta.impl.rendezvous.RendezVousServiceProvider;import net.jxta.impl.rendezvous.StdRendezVousService;import net.jxta.impl.rendezvous.rpv.PeerView;import net.jxta.impl.rendezvous.rpv.PeerViewElement;import net.jxta.logging.Logging;import net.jxta.myjxta.MyJXTA;import net.jxta.myjxta.dialog.Dialog;import net.jxta.myjxta.dialog.DialogMessage;import net.jxta.myjxta.util.AuthenticationUtil;import net.jxta.peer.PeerID;import net.jxta.peergroup.PeerGroup;import net.jxta.peergroup.PeerGroupID;import net.jxta.protocol.AccessPointAdvertisement;import net.jxta.protocol.PeerAdvertisement;import net.jxta.protocol.PeerGroupAdvertisement;import net.jxta.protocol.RdvAdvertisement;import net.jxta.rendezvous.RendezVousService;import java.io.IOException;import java.text.SimpleDateFormat;import java.util.Date;import java.util.Enumeration;import java.util.Iterator;import java.util.Vector;import java.util.logging.Level;import java.util.logging.Logger;/** * The The base Dialog for Group Chats. * * @version $Id: StatusCommand.java,v 1.24 2007/04/16 20:14:05 nano Exp $ * * @author james todd [gonzo at jxta dot org] * @author mike mcangus [mcangus at jxta dot org] * */public class StatusCommandextends AbstractCommand {        public static final String ID = StatusCommand.class.getName();    public static final String STATUS = "status";    public static final String PROFILE = "profile";    public static final String VERSION = "version";    public static final String TIME = "time";    public static final String JAVA_VERSION = "java.version";    public static final String JAVA_VENDOR = "java.vendor";    public static final String OS_NAME = "os.name";    public static final String OS_ARCHITECTURE = "os.architecture";    public static final String PROCESSORS = "processors";    public static final String JXTA_HOME = "jxta.home";    public static final String FREE_MEMORY = "memory.free";    public static final String MAXIMUM_MEMORY = "memory.maximum";    public static final String TOTAL_MEMORY = "memory.total";    public static final String RENDEZVOUS = "rendezvous";    public static final String ROLE = "role";    public static final String NAME = "name";    public static final String UID = "id";    public static final String GROUP_ID = "groupId";    public static final String TYPE = "type";    public static final String PEER = "peer";    public static final String IS_AUTHENTICATED = "isAuthenticated";    public static final String GROUP = "group";    public static final String IS_ALIVE = "isAlive";    public static final String IS_IN_PEER_VIEW = "isInPeerView";    public static final String IS_THROTTLING = "isThrottling";    public static final String NUMBER_OF_CONNECTED_PEERS = "numberOfConnectedPeers";    public static final String START_TIME = "startTime";    public static final String CREATE_TIME = "createTime";    public static final String UPDATE_TIME = "updateTime";    public static final String DIRECTION = "direction";    public static final String ADDRESS = "address";    public static final String UP = "up";    public static final String DOWN = "down";    public static final String CLIENT = "client";    public static final String CLIENT_IS_CONNECTED = "isConnected";    public static final String LEASE_TIME = "leaseTime";    public static final String RELAYS = "relays";    public static final String SERVER = "server";        private static final String TIME_STAMP = "EEE MMM dd hh:mm:ss z yyyy";    private static final SimpleDateFormat DATE_FORMATTER =        new SimpleDateFormat(TIME_STAMP);    private static final String ELEMENT_OPEN_PREAMBLE = "<";    private static final String ELEMENT_OPEN_POSTAMBLE = ">";    private static final String ELEMENT_OPEN_EMPTY_POSTAMBLE = "/" +        ELEMENT_OPEN_POSTAMBLE;    private static final String ELEMENT_CLOSE_PREAMBLE = "</";    private static final String ELEMENT_CLOSE_POSTAMBLE = ELEMENT_OPEN_POSTAMBLE;    private static final char EQUALS = '=';    private static final char SPACE = ' ';    private static final char QUOTE = '\"';    private static final char SLASH = '\\';    private static final char COMMA = ',';    private static final char COLON = ':';    private static final String UNICODE_ESCAPE= "/u";    private static final int MAX_ASCII = 0x00007f;    private static final String UNKNOWN = "unknown";    private static final String PEER_TYPE_ID = "PID";    private static final String GROUP_TYPE_ID = "GID";    private static final Logger LOG = Logger.getLogger(StatusCommand.class.getName());    public String getId() {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("In getID()");        }        return ID;    }        public boolean process(Dialog dialog, DialogMessage msg) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("Begin process(Dialog, DialogMessage)");        }        String cmd = msg != null ? msg.getCommand() : null;        PeerGroup pg = dialog.getGroup().getPeerGroup();        DialogMessage dm = new DialogMessage(pg.getPeerName(), null,            pg.getPeerGroupID().toString(), pg.getPeerGroupName());        if (cmd != null &&            cmd.length() > 0) {            setCommand(cmd);            setReply(getResponse(pg));            setStatus(true);                        dm.setCommand(getResponse());        }                dialog.dispatch(dm);        boolean retStatus = getStatus();                if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("status = " + retStatus);            LOG.fine("End   process(Dialog, DialogMessage)");        }        return retStatus;    }        public String getResponse(PeerGroup pg) {        if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {            LOG.fine("Begin getResponse(PeerGroup)");        }        StringBuffer sb = new StringBuffer();        Runtime rt = Runtime.getRuntime();                sb.append(open(STATUS) + ELEMENT_OPEN_POSTAMBLE + NEW_LINE);                sb.append(TAB + open(PROFILE));        sb.append(SPACE + attribute(VERSION, toUnicodeEncoded(MyJXTA.VERSION)));        sb.append(SPACE + attribute(TIME,            toUnicodeEncoded(DATE_FORMATTER.format(new Date(System.currentTimeMillis())))));        sb.append(SPACE + attribute(JAVA_VERSION,            toUnicodeEncoded(System.getProperty("java.version"))));        sb.append(SPACE + attribute(JAVA_VENDOR,            toUnicodeEncoded(System.getProperty("java.vendor"))));        sb.append(SPACE + attribute(OS_NAME,            toUnicodeEncoded(System.getProperty("os.name"))));        sb.append(SPACE + attribute(OS_ARCHITECTURE,            toUnicodeEncoded(System.getProperty("os.arch"))));        sb.append(SPACE + attribute(PROCESSORS, rt.availableProcessors()));        sb.append(SPACE + attribute(JXTA_HOME, "***")); //Env.getHome()));        sb.append(SPACE + attribute(FREE_MEMORY, formatBytes(rt.freeMemory())));        sb.append(SPACE + attribute(MAXIMUM_MEMORY, formatBytes(rt.maxMemory())));        sb.append(SPACE + attribute(TOTAL_MEMORY, formatBytes(rt.totalMemory())));        sb.append(close(PROFILE, false) + NEW_LINE);                sb.append(TAB + open(PEER));        sb.append(SPACE + attribute(UID, toUnicodeEncoded(pg.getPeerID().toString())));        sb.append(SPACE + attribute(NAME, toUnicodeEncoded(pg.getPeerName())));        sb.append(SPACE + attribute(IS_AUTHENTICATED,            String.valueOf(AuthenticationUtil.isAuthenticated(pg))));        sb.append(close(PEER, false) + NEW_LINE);                RendezVousService rdv = pg != null ? pg.getRendezVousService() : null;                if (rdv != null) {            sb.append(TAB + open(RENDEZVOUS) + SPACE +                attribute(ROLE, toUnicodeEncoded(rdv.getRendezVousStatus().toString().toLowerCase())) +                ELEMENT_CLOSE_POSTAMBLE + NEW_LINE);            StdRendezVousService srs = null;                    if (rdv instanceof RendezVousServiceInterface) {                RendezVousServiceInterface rsi = (RendezVousServiceInterface)rdv;                        if (rsi != null) {                    RendezVousServiceProvider rsp = rsi.getRendezvousProvider();                                if (rsp instanceof StdRendezVousService) {                        srs = (StdRendezVousService)rsp;                    }                }                PeerView rpv = rsi.getPeerView();                if (rpv!=null){                    PeerViewElement[] pv = (PeerViewElement[])rpv.getView().toArray(new PeerViewElement[0]);                    for (int pvi = pv.length - 1; pvi >= 0; pvi--) {                        PeerViewElement pve = pv[pvi];                        PeerData pd = new PeerData(pve.toString());                        sb.append(TAB + TAB + open(PEER));                        RdvAdvertisement ra = pve.getRdvAdvertisement();                        String pid = ra != null ? ra.getPeerID().toString() : null;                        if (pid != null) {                            sb.append(SPACE + attribute(UID, toUnicodeEncoded(pid)));                        }                        sb.append(SPACE + attribute(NAME, toUnicodeEncoded(pd.getName())));                        String gid = ra != null ? ra.getGroupID().toString() : null;                        if (gid != null) {                            sb.append(SPACE + attribute(GROUP_ID, toUnicodeEncoded(gid)));                        }                        sb.append(SPACE + attribute(IS_ALIVE,                            toUnicodeEncoded(String.valueOf(pd.isAlive()))));                        sb.append(SPACE + attribute(IS_IN_PEER_VIEW,                            toUnicodeEncoded(String.valueOf(pd.isInPeerView()))));                        sb.append(SPACE + attribute(IS_THROTTLING,                            toUnicodeEncoded(String.valueOf(pd.isThrottling()))));                        sb.append(SPACE + attribute(NUMBER_OF_CONNECTED_PEERS,                            toUnicodeEncoded(String.valueOf(pd.getNumberOfConnectedPeers()))));                        sb.append(SPACE + attribute(START_TIME,                            toUnicodeEncoded(String.valueOf(pd.getStartTime()))));                        sb.append(SPACE + attribute(CREATE_TIME,                            toUnicodeEncoded(String.valueOf(pd.getCreateTime()))));                        sb.append(SPACE + attribute(UPDATE_TIME,                            toUnicodeEncoded(String.valueOf(pd.getUpdateTime()))));                        String d = getDirection(pve, rpv);                        if (d != null &&                            d.trim().length() > 0) {                            sb.append(SPACE + attribute(DIRECTION, toUnicodeEncoded(d)));                        }                        sb.append(close(PEER, false) + NEW_LINE);                    }                }            }                        DiscoveryService dsc = pg.getDiscoveryService();                    if (rdv.isRendezVous()) {                for (Enumeration ce = rdv.getConnectedPeers();                    ce.hasMoreElements(); ) {                    ID id = (ID)ce.nextElement();                    if (srs != null) {                        sb.append(toUnicodeEncoded(getClientStatus(srs.getPeerConnection(id))));                    } else {                        sb.append(toUnicodeEncoded(getClientStatus(dsc, id)));                    }                }

⌨️ 快捷键说明

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