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

📄 pingreplyhandler.java

📁 Java p2p程序设计2002年版
💻 JAVA
字号:
package net.jxta.impl.shell.bin.ping;import java.io.*;import net.jxta.exception.*;import net.jxta.discovery.*;import net.jxta.endpoint.*;import net.jxta.pipe.*;import net.jxta.peergroup.*;import net.jxta.document.*;import net.jxta.id.*;import net.jxta.protocol.*;import java.util.*;/** * This handler class listens on a supplied pipe for ping reply messages * and notifies its listeners when one does. */public class PingReplyHandler extends AbstractPingHandler implements Runnable {        Vector listeners = new Vector();        public PingReplyHandler(InputPipe pipe) {        super(pipe);    }            /**     * Notify listeners of a ping reply event.     * @param event The PingReplyEvent     */    protected void notifyListeners(PingReplyEvent event) {        for(int i=0;i<listeners.size();i++)            ((PingReplyListener)listeners.elementAt(i)).pingReply(event);    }        public void addPingReplyListener(PingReplyListener ppml) {        listeners.addElement(ppml);    }        public void removePingReplyListener(PingReplyListener ppml) {        listeners.removeElement(ppml);    }            /**     * This key method is abstractly declared in AbstractPingHandler which     * delegates to subclasses here.     * @param msg The Message object received on the pipe     * @param timestamp The timestamp the message was received on the pipe     */    protected void deliverMessage(Message msg, long timestamp) {            Enumeration enum = msg.getNames();            if ((enum == null) || (!enum.hasMoreElements())) {                // Empty message                return;            }            byte[] buffer = null;                        try {                buffer = msg.getBytes("reply");                String message = new String(buffer);                StringTokenizer st = new StringTokenizer(message,":");                                // The peer's name                String peername = st.nextToken();                                // Time it took for original ping request to reach peer.                long time = new Long(st.nextToken()).longValue();                                // Time the ping was received on the peer                long tstamp = new Long(st.nextToken()).longValue();                                PingReplyEvent pr = new PingReplyEvent(this,time,tstamp,timestamp,peername);                notifyListeners(pr);                                } catch (Exception e) {                // No user information            }                        }    }

⌨️ 快捷键说明

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