001: /*
002: * Copyright (c) 2000 by Matt Welsh and The Regents of the University of
003: * California. All rights reserved.
004: *
005: * Permission to use, copy, modify, and distribute this software and its
006: * documentation for any purpose, without fee, and without written agreement is
007: * hereby granted, provided that the above copyright notice and the following
008: * two paragraphs appear in all copies of this software.
009: *
010: * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
011: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
012: * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
013: * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
014: *
015: * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
016: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
017: * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
018: * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
019: * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
020: *
021: * Author: Matt Welsh <mdw@cs.berkeley.edu>
022: *
023: */
024:
025: package seda.sandStorm.lib.aSocket;
026:
027: import seda.sandStorm.api.*;
028: import seda.sandStorm.core.*;
029: import java.net.*;
030:
031: /**
032: * An AUdpInPacket represents a packet which was received from a
033: * datagram socket.
034: *
035: * @author Matt Welsh
036: */
037: public class AUdpInPacket implements QueueElementIF {
038:
039: private AUdpSocket sock;
040: private DatagramPacket packet;
041: // package access
042: long seqNum;
043:
044: public AUdpInPacket(AUdpSocket sock, DatagramPacket packet) {
045: this .sock = sock;
046: this .packet = packet;
047: this .seqNum = 0;
048: }
049:
050: public AUdpInPacket(AUdpSocket sock, DatagramPacket packet,
051: long seqNum) {
052: this .sock = sock;
053: this .packet = packet;
054: this .seqNum = seqNum;
055: }
056:
057: /**
058: * Return the socket from which this packet was received.
059: */
060: public AUdpSocket getSocket() {
061: return sock;
062: }
063:
064: /**
065: * Return the DatagramPacket.
066: */
067: public DatagramPacket getPacket() {
068: return packet;
069: }
070:
071: /**
072: * Return the packet data.
073: */
074: public byte[] getBytes() {
075: return packet.getData();
076: }
077:
078: /**
079: * Return the size of the packet data.
080: */
081: public int size() {
082: return packet.getLength();
083: }
084:
085: /**
086: * Return the sequence number associated with this packet.
087: * Sequence numbers range from 1 to Long.MAX_VALUE, then wrap
088: * around to Long.MIN_VALUE. A sequence number of 0 indicates that
089: * no sequence number was associated with this packet when it was
090: * created.
091: */
092: public long getSequenceNumber() {
093: return seqNum;
094: }
095:
096: public String toString() {
097: return "AUdpInPacket [sock=" + sock + ", size="
098: + packet.getLength() + "]";
099: }
100:
101: }
|