📄 peerinforesponsemessage.java
字号:
/*
* 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 disclaimer 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 SUN MICROSYSTEMS 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: PeerInfoResponseMessage.java,v 1.2 2002/03/04 20:19:21 echtcherbina Exp $
*/
package net.jxta.protocol;
import java.util.Hashtable;
import java.util.Enumeration;
import net.jxta.document.Document;
import net.jxta.document.Element;
import net.jxta.document.MimeMediaType;
import net.jxta.document.StructuredDocument;
import net.jxta.document.StructuredDocumentUtils;
import net.jxta.id.ID;
/**
* This abstract class define the PeerInfoService advertisement
* <p>This message is part of the Peer PeerInfoService protocol
*
* <pre>
* <xs:element name="<classname>PeerInfoResponse</classname>" type="jxta:PeerInfoResponse"/>
*
* <xs:complexType name="PeerInfoResponse">
* <xs:element name="sourcePid" type="xs:anyURI"/>
* <xs:element name="targetPid" type="xs:anyURI"/>
* <xs:element name="uptime" type="xs:unsignedLong" minOccurs="0"/>
* <xs:element name="timestamp" type="xs:unsignedLong" minOccurs="0"/>
* <xs:element name="response" type="xs:anyType" minOccurs="0"/>
* <xs:element name="traffic" type="jxta:piptraffic" minOccurs="0"/>
* </xs:complexType>
*
* <xs:complexType name="piptraffic">
* <xs:element name="lastIncomingMessageAt" type="xs:unsignedLong" minOccurs="0"/>
* <xs:element name="lastOutgoingMessageAt" type="xs:unsignedLong" minOccurs="0"/>
* <xs:element name="in" type="jxta:piptrafficinfo" minOccurs="0"/>
* <xs:element name="out" type="jxta:piptrafficinfo" minOccurs="0"/>
* </xs:complexType>
*
* <xs:complexType name="piptrafficinfo">
* <xs:element name="transport" type="xs:unsignedLong" maxOccurs="unbounded">
* <xs:attribute name="endptaddr" type="xs:anyURI"/>
* </xs:element>
* </xs:complexType>
* </pre>
*
* @since JXTA 1.0
*/
public abstract class PeerInfoResponseMessage {
/**
* The Sender's (or Querying) Peer Id.
*/
private ID spid = ID.nullID;
/**
* Peer Id of the peer which published this advertisement.
*/
private ID tpid = ID.nullID;
/** String representing response */
private StructuredDocument response = null;
/**
* Time in seconds since this peer was started.
*/
private long uptime = 0;
/**
* Time in milliseconds when this peer was last polled since
* "the epoch", namely January 1, 1970, 00:00:00 GMT.
*/
private long timestamp = 0;
/**
* Time in milliseconds since midnight, January 1, 1970 UTC and when
* this peer last recieved a message.
**/
private long lastIncomingMessageTime = 0;
/**
* Time in milliseconds since midnight, January 1, 1970 UTC and when
* this peer last sent a message out.
**/
private long lastOutgoingMessageTime = 0;
/**
* A set of key-value pairs representing the traffic on this
* peer. The keys represent service names and the values are
* java.lang.Long objects representing total bytes transferred in
* or out to/from this peer.
**/
private Hashtable incomingTraffic = new Hashtable();
/**
* A set of key-value pairs representing the traffic on this
* peer. The keys represent service names and the values are
* java.lang.Long objects representing total bytes transferred in
* or out to/from this peer.
**/
private Hashtable outgoingTraffic = new Hashtable();
public PeerInfoResponseMessage() {
super();
}
/**
* returns the Message type
* @return a string
*
* @since JXTA 1.0
**/
public static String getMessageType() {
return "jxta:PeerInfoResponseMessage";
}
/**
* returns the sender's pid
*
* @return a string representing the peer's id
*
* @since JXTA 1.0
*/
public ID getSourcePid() {
return spid;
}
/**
* sets the sender's pid
*
* @param pid a string representing a peer's id
*
* @since JXTA 1.0
*/
public void setSourcePid(ID pid) {
this.spid = pid;
}
/**
* returns the target pid
*
* @return a string representing the peer's id
*
* @since JXTA 1.0
*/
public ID getTargetPid() {
return tpid;
}
/**
* sets the target's pid
*
* @param pid a string representing a peer's id
*
* @since JXTA 1.0
*/
public void setTargetPid(ID pid) {
this.tpid = pid;
}
/**
* returns the response
*
* @return a structured document representing request
*
* @since JXTA 1.0
*/
public Element getResponse() {
if( null != response )
return StructuredDocumentUtils.copyAsDocument( response );
else
return null;
}
/**
* sets the request
*
* @param request a structured document representing a peerinfo request
*
* @since JXTA 1.0
*/
public void setResponse(Element response) {
if( null != response )
this.response = StructuredDocumentUtils.copyAsDocument( response );
else
this.response = null;
}
/**
* returns the number of milliseconds since this peer was started
* @return the number of milliseconds
*
* @since JXTA 1.0
*/
public long getUptime() {
return uptime;
}
/**
* sets the number of milliseconds since this peer was started
* @param milliseconds the number of milliseconds since this peer was started
*
* @since JXTA 1.0
*/
public void setUptime(long milliseconds) {
this.uptime = milliseconds;
}
/**
* returns the time when this peer was last polled
*
* @return long time in milliseconds when this peer was last polled in
* milliseconds since "the epoch", namely January 1, 1970, 00:00:00
* GMT.
*
* @since JXTA 1.0
*/
public long getTimestamp() {
return timestamp;
}
/**
* sets the time when this peer was last polled
*
* @param milliseconds time in milliseconds when this peer was last polled
* in milliseconds since "the epoch", namely January 1, 1970, 00:00:00
* GMT.
*
* @since JXTA 1.0
*/
public void setTimestamp(long milliseconds) {
this.timestamp = milliseconds;
}
/**
* Get the time in milliseconds since this peer last recieved a message
* in milliseconds since "the epoch", namely January 1, 1970, 00:00:00
* GMT.
*
* @return time in milliseconds
*/
public long getLastIncomingMessageTime() {
return lastIncomingMessageTime;
}
/**
* Set the time in milliseconds since this peer last recieved a message
* in milliseconds since "the epoch", namely January 1, 1970, 00:00:00
* GMT.
*
* @param t time in milliseconds
*/
public void setLastIncomingMessageTime(long t) {
lastIncomingMessageTime = t;
}
/**
* Get the time in milliseconds since this peer last sent a message
* in milliseconds since "the epoch", namely January 1, 1970, 00:00:00
* GMT.
*
* @return time in milliseconds
*/
public long getLastOutgoingMessageTime() {
return lastOutgoingMessageTime;
}
/**
* Set the time in milliseconds since this peer last sent a message
* in milliseconds since "the epoch", namely January 1, 1970, 00:00:00
* GMT.
*
* @param t time in milliseconds
*/
public void setLastOutgoingMessageTime(long t) {
lastOutgoingMessageTime = t;
}
/**
* Get an enumeration of incoming traffic channels on this peer. A
* channel represents traffic generated by a particular service. A
* service may open more than one data channel.
*
* @return an enumeration of String
*/
public Enumeration getIncomingTrafficChannels() {
return incomingTraffic.keys();
}
/**
* Get the number of bytes recieved on the specified channel.
*
* @return number of bytes recieved
**/
public long getIncomingTrafficOnChannel(String channel) {
Long ret = (Long) incomingTraffic.get(channel);
if (ret != null)
return ret.longValue();
return 0;
}
/**
* Set the number of bytes recieved on the specified channel.
*
* @param channel service name
* @param long number of bytes recieved
*/
public void setIncomingTrafficElement(String channel, long bytes) {
incomingTraffic.put(channel, new Long(bytes));
}
/**
* Get an enumeration of outgoing traffic channels on this peer. A
* channel represents traffic generated by a particular service. A
* service may open more than one data channel.
*
* @return an enumeration of String
**/
public Enumeration getOutgoingTrafficChannels() {
return outgoingTraffic.keys();
}
/**
* Get the number of bytes sent on the specified channel.
*
* @return number of bytes sent
**/
public long getOutgoingTrafficOnChannel(String channel) {
Long ret = (Long) outgoingTraffic.get(channel);
if (ret != null)
return ret.longValue();
return 0;
}
/**
* Set the number of bytes sent on the specified channel.
*
* @param channel service name
* @param long number of bytes sent
**/
public void setOutgoingTrafficElement(String channel, long bytes) {
outgoingTraffic.put(channel, new Long(bytes));
}
public abstract Document getDocument(MimeMediaType encodeAs);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -