📄 routemessage.java
字号:
/*************************************************************************"FreePastry" Peer-to-Peer Application Development Substrate Copyright 2002, Rice University. All rights reserved.Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions aremet:- Redistributions of source code must retain the above copyrightnotice, this list of conditions and the following disclaimer.- Redistributions in binary form must reproduce the above copyrightnotice, this list of conditions and the following disclaimer in thedocumentation and/or other materials provided with the distribution.- Neither the name of Rice University (RICE) nor the names of itscontributors may be used to endorse or promote products derived fromthis software without specific prior written permission.This software is provided by RICE and the contributors on an "as is"basis, without any representations or warranties of any kind, expressor implied including, but not limited to, representations orwarranties of non-infringement, merchantability or fitness for aparticular purpose. In no event shall RICE or contributors be liablefor any direct, indirect, incidental, special, exemplary, orconsequential damages (including, but not limited to, procurement ofsubstitute goods or services; loss of use, data, or profits; orbusiness interruption) however caused and on any theory of liability,whether in contract, strict liability, or tort (including negligenceor otherwise) arising in any way out of the use of this software, evenif advised of the possibility of such damage.********************************************************************************/package rice.pastry.routing;import rice.p2p.commonapi.rawserialization.*;import rice.pastry.*;import rice.pastry.commonapi.PastryEndpointMessage;import rice.pastry.messaging.*;import java.io.*;/** * A route message contains a pastry message that has been wrapped to be sent to * another pastry node. * * @version $Id: RouteMessage.java 3274 2006-05-15 16:17:47Z jeffh $ * @author Andrew Ladd */public class RouteMessage extends PRawMessage implements Serializable, rice.p2p.commonapi.RouteMessage { private Id target; private NodeHandle prevNode; private transient SendOptions opts; private int auxAddress; /** * DESCRIBE THE FIELD */ public transient NodeHandle nextHop; private Message internalMsg; // optimization to not use instanceof in the normal new case private PRawMessage rawInternalMsg = null; private InputBuffer serializedMsg; private NodeHandleFactory nhf; PastryNode pn; private RMDeserializer endpointDeserializer = new RMDeserializer(); private final static long serialVersionUID = 3492981895989180093L; /** * DESCRIBE THE FIELD */ public final static short TYPE = -23525; /** * Constructor. * * @param target this is id of the node the message will be routed to. * @param msg the wrapped message. */ public RouteMessage(Id target, Message msg) { this(target, msg, null, null); } /** * Constructor. * * @param target this is id of the node the message will be routed to. * @param msg the wrapped message. * @param opts the send options for the message. */ public RouteMessage(Id target, Message msg, SendOptions opts) { this(target, msg, null, opts); } /** * Constructor. * * @param dest the node this message will be routed to * @param msg the wrapped message. * @param opts the send options for the message. */ public RouteMessage(NodeHandle dest, Message msg, SendOptions opts) { this(dest.getNodeId(), msg, dest, opts); } /** * Constructor. * * @param target this is id of the node the message will be routed to. * @param msg the wrapped message. * @param firstHop the nodeHandle of the first hop destination */ public RouteMessage(Id target, Message msg, NodeHandle firstHop) { this(target, msg, firstHop, null); } /** * Constructor for RouteMessage. * * @param target DESCRIBE THE PARAMETER * @param msg DESCRIBE THE PARAMETER * @param firstHop DESCRIBE THE PARAMETER * @param opts DESCRIBE THE PARAMETER */ public RouteMessage(Id target, PRawMessage msg, NodeHandle firstHop, SendOptions opts) { this(target, (Message) msg, firstHop, opts); rawInternalMsg = msg; } /** * Constructor. * * @param target this is id of the node the message will be routed to. * @param msg the wrapped message. * @param firstHop the nodeHandle of the first hop destination * @param opts the send options for the message. */ public RouteMessage(Id target, Message msg, NodeHandle firstHop, SendOptions opts) { super(RouterAddress.getCode()); this.target = (Id) target; internalMsg = msg; nextHop = firstHop; this.opts = opts; if (this.opts == null) { this.opts = new SendOptions(); } if (msg != null) { // can be null on the deserialization, but that ctor properly sets auxAddress auxAddress = msg.getDestination(); } } /** * Constructor for RouteMessage. * * @param target DESCRIBE THE PARAMETER * @param auxAddress DESCRIBE THE PARAMETER * @param prev DESCRIBE THE PARAMETER * @param buf DESCRIBE THE PARAMETER * @param nhf DESCRIBE THE PARAMETER * @param pn DESCRIBE THE PARAMETER */ public RouteMessage(Id target, int auxAddress, NodeHandle prev, InputBuffer buf, NodeHandleFactory nhf, PastryNode pn) { this(target, null, null, null); prevNode = prev; serializedMsg = buf; this.nhf = nhf; this.pn = pn; this.auxAddress = auxAddress; } /** * Gets the target node id of this message. * * @return the target node id. */ public Id getTarget() { return target; } /** * Gets the PrevNode attribute of the RouteMessage object * * @return The PrevNode value */ public NodeHandle getPrevNode() { return prevNode; } /** * Gets the NextHop attribute of the RouteMessage object * * @return The NextHop value */ public NodeHandle getNextHop() { return nextHop; } /** * Get priority * * @return the priority of this message. */ public byte getPriority() { return internalMsg.getPriority(); } /** * Get receiver address. * * @return the address. */ public int getDestination() { if (nextHop == null || auxAddress == 0) { return super.getDestination(); } return auxAddress; } /** * Get transmission options. * * @return the options. */ public SendOptions getOptions() { if (opts == null) { opts = new SendOptions(); } return opts; } // Common API Support /** * Gets the DestinationId attribute of the RouteMessage object * * @return The DestinationId value */ public rice.p2p.commonapi.Id getDestinationId() { return getTarget(); } /** * Gets the NextHopHandle attribute of the RouteMessage object * * @return The NextHopHandle value */ public rice.p2p.commonapi.NodeHandle getNextHopHandle() { return nextHop; } /** * Gets the Message attribute of the RouteMessage object * * @return The Message value */ public rice.p2p.commonapi.Message getMessage() { return ((PastryEndpointMessage) unwrap()).getMessage(); } /** * Gets the Message attribute of the RouteMessage object * * @param md DESCRIBE THE PARAMETER * @return The Message value * @exception IOException DESCRIBE THE EXCEPTION */ public rice.p2p.commonapi.Message getMessage(MessageDeserializer md) throws IOException { endpointDeserializer.setSubDeserializer(md); return ((PastryEndpointMessage) unwrap(endpointDeserializer)).getMessage(); } /** * Gets the Type attribute of the RouteMessage object * * @return The Type value */ public short getType() { return TYPE; } /** * Gets the AuxAddress attribute of the RouteMessage object * * @return The AuxAddress value */ public int getAuxAddress() { return auxAddress; } /** * Gets the InternalType attribute of the RouteMessage object * * @return The InternalType value */ public short getInternalType() { if (rawInternalMsg != null) { return rawInternalMsg.getType(); } if (internalMsg != null) { if (internalMsg instanceof RawMessage) { return ((RawMessage) internalMsg).getType();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -