Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/nio/ch/sctp/MessageInfoImpl.java
38919 views
/*1* Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package sun.nio.ch.sctp;2526import java.net.SocketAddress;27import com.sun.nio.sctp.MessageInfo;28import com.sun.nio.sctp.Association;2930/**31* An implementation of a MessageInfo.32*/33public class MessageInfoImpl extends MessageInfo {34private final SocketAddress address;35private final int bytes; /* 0 */3637private Association association;38private int assocId;39private int streamNumber;40private boolean complete = true;41private boolean unordered; /* false */42private long timeToLive; /* 0L */43private int ppid; /* 0 */4445public MessageInfoImpl(Association association,46SocketAddress address,47int streamNumber) {48this.association = association;49this.address = address;50this.streamNumber = streamNumber;51bytes = 0;52}5354/* Invoked from native */55private MessageInfoImpl(int assocId,56SocketAddress address,57int bytes,58int streamNumber,59boolean complete,60boolean unordered,61int ppid) {62this.assocId = assocId;63this.address = address;64this.bytes = bytes;65this.streamNumber = streamNumber;66this.complete = complete;67this.unordered = unordered;68this.ppid = ppid;69}7071@Override72public Association association() {73return association;74}7576/**77* MessageInfoImpl instances created from native will need to have their78* association set from the channel.79*/80void setAssociation(Association association) {81this.association = association;82}8384int associationID() {85return assocId;86}8788@Override89public SocketAddress address() {90return address;91}9293@Override94public int bytes() {95return bytes;96}9798@Override99public int streamNumber() {100return streamNumber;101}102103@Override104public MessageInfo streamNumber(int streamNumber) {105if (streamNumber < 0 || streamNumber > 65536)106throw new IllegalArgumentException("Invalid stream number");107108this.streamNumber = streamNumber;109return this;110}111112@Override113public int payloadProtocolID() {114return ppid;115}116117@Override118public MessageInfo payloadProtocolID(int ppid) {119this.ppid = ppid;120return this;121}122123@Override124public boolean isComplete() {125return complete;126}127128@Override129public MessageInfo complete(boolean complete) {130this.complete = complete;131return this;132}133134@Override135public boolean isUnordered() {136return unordered;137}138139@Override140public MessageInfo unordered(boolean unordered) {141this.unordered = unordered;142return this;143}144145@Override146public long timeToLive() {147return timeToLive;148}149150@Override151public MessageInfo timeToLive(long millis) {152timeToLive = millis;153return this;154}155156@Override157public String toString() {158StringBuilder sb = new StringBuilder(super.toString());159sb.append( "[Address: ").append(address)160.append(", Association: ").append(association)161.append(", Assoc ID: ").append(assocId)162.append(", Bytes: ").append(bytes)163.append(", Stream Number: ").append(streamNumber)164.append(", Complete: ").append(complete)165.append(", isUnordered: ").append(unordered)166.append("]");167return sb.toString();168}169}170171172