📄 pinghandler.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.*;/** * A concrete implementation of AbstractPingHandler that listens for only * inbound ping requests. */public class PingHandler extends AbstractPingHandler implements Runnable { // PingListeners Vector listeners = new Vector(); public PingHandler(InputPipe pipe) { super(pipe); } /** * 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 { //ping.println2("got ping msg "+msg); buffer = msg.getBytes("ping"); String message = new String(buffer); // Parse values out of ping message StringTokenizer st = new StringTokenizer(message,":"); String name = st.nextToken(); String timestr = (String)st.nextToken(); long ostamp = new Long(timestr).longValue(); PingEvent pr = new PingEvent(this,name,ostamp,timestamp); // notify listeners notifyListeners(pr); } catch (Exception e) { e.printStackTrace(); pipe.close(); } } /** * Notify interested listeners that a PingEvent has occured and send the * ping event. */ private void notifyListeners(PingEvent event) { for(int i=0;i<listeners.size();i++) ((PingListener)listeners.elementAt(i)).pingEvent(event); } public void addPingListener(PingListener ppml) { listeners.addElement(ppml); } public void removePingListener(PingListener ppml) { listeners.removeElement(ppml); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -