Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/nio/sctp/MessageInfo.java
38923 views
/*1* Copyright (c) 2009, 2013, 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 com.sun.nio.sctp;2526import java.net.SocketAddress;2728/**29* The {@code MessageInfo} class provides additional ancillary information about30* messages.31*32* <P> Received SCTP messages, returned by33* {@link SctpChannel#receive SctpChannel.receive} and {@link34* SctpMultiChannel#receive SctpMultiChannel.receive},35* return a {@code MessageInfo} instance that can be queried to determine36* ancillary information about the received message. Messages being sent should37* use one of the {@link #createOutgoing(java.net.SocketAddress,int)38* createOutgoing} methods to provide ancillary data for the message being39* sent, and may use the appropriate setter methods to override the default40* values provided for {@link #isUnordered() unordered}, {@link #timeToLive()41* timeToLive}, {@link #isComplete() complete} and {@link #payloadProtocolID()42* payloadProtocolID}, before sending the message.43*44* <P> For out going messages the {@code timeToLive} parameter is a time period45* that the sending side SCTP stack may expire the message if it has not been46* sent. This time period is an indication to the stack that the message is no47* longer required to be sent after the time period expires. It is not a hard48* timeout and may be influenced by whether the association supports the partial49* reliability extension, <a href=http://www.ietf.org/rfc/rfc3758.txt>RFC 375850* </a>.51*52* <P> {@code MessageInfo} instances are not safe for use by multiple concurrent53* threads. If a MessageInfo is to be used by more than one thread then access54* to the MessageInfo should be controlled by appropriate synchronization.55*56* @since 1.757*/58@jdk.Exported59public abstract class MessageInfo {60/**61* Initializes a new instance of this class.62*/63protected MessageInfo() {}6465/**66* Creates a {@code MessageInfo} instance suitable for use when67* sending a message.68*69* <P> The returned instance will have its {@link #isUnordered() unordered}70* value set to {@code false}, its {@link #timeToLive() timeToLive} value71* set to {@code 0}, its {@link #isComplete() complete} value set72* to {@code true}, and its {@link #payloadProtocolID() payloadProtocolID}73* value set to {@code 0}. These values, if required, can be set through74* the appropriate setter method before sending the message.75*76* @param address77* For a connected {@code SctpChannel} the address is the78* preferred peer address of the association to send the message79* to, or {@code null} to use the peer primary address. For an80* {@code SctpMultiChannel} the address is used to determine81* the association, or if no association exists with a peer of that82* address then one is setup.83*84* @param streamNumber85* The stream number that the message will be sent on86*87* @return The outgoing message info88*89* @throws IllegalArgumentException90* If the streamNumber is negative or greater than {@code 65536}91*/92public static MessageInfo createOutgoing(SocketAddress address,93int streamNumber) {94if (streamNumber < 0 || streamNumber > 65536)95throw new IllegalArgumentException("Invalid stream number");9697return new sun.nio.ch.sctp.MessageInfoImpl(null, address, streamNumber);98}99/**100* Creates a {@code MessageInfo} instance suitable for use when101* sending a message to a given association. Typically used for102* {@code SctpMultiChannel} when an association has already been setup.103*104* <P> The returned instance will have its {@link #isUnordered() unordered}105* value set to {@code false}, its {@link #timeToLive() timeToLive} value106* set to {@code 0}, its {@link #isComplete() complete} value set107* to {@code true}, and its {@link #payloadProtocolID() payloadProtocolID}108* value set to {@code 0}. These values, if required, can be set through109* the appropriate setter method before sending the message.110*111* @param association112* The association to send the message on113*114* @param address115* The preferred peer address of the association to send the message116* to, or {@code null} to use the peer primary address117*118* @param streamNumber119* The stream number that the message will be sent on.120*121* @return The outgoing message info122*123* @throws IllegalArgumentException124* If {@code association} is {@code null}, or the streamNumber is125* negative or greater than {@code 65536}126*/127public static MessageInfo createOutgoing(Association association,128SocketAddress address,129int streamNumber) {130if (association == null)131throw new IllegalArgumentException("association cannot be null");132133if (streamNumber < 0 || streamNumber > 65536)134throw new IllegalArgumentException("Invalid stream number");135136return new sun.nio.ch.sctp.MessageInfoImpl(association,137address, streamNumber);138}139140/**141* Returns the source socket address if the message has been received,142* otherwise the preferred destination of the message to be sent.143*144* @return The socket address, or {@code null} if this instance is to be145* used for sending a message and has been construced without146* specifying a preferred destination address147*148*/149public abstract SocketAddress address();150151/**152* Returns the association that the message was received on, if the message153* has been received, otherwise the association that the message is to be154* sent on.155*156* @return The association, or {@code null} if this instance is to be157* used for sending a message and has been construced using the158* the {@link #createOutgoing(SocketAddress,int)159* createOutgoing(SocketAddress,int)} static factory method160*/161public abstract Association association();162163/**164* Returns the number of bytes read for the received message.165*166* <P> This method is only appicable for received messages, it has no167* meaning for messages being sent.168*169* @return The number of bytes read, {@code -1} if the channel is an {@link170* SctpChannel} that has reached end-of-stream, otherwise171* {@code 0}172*/173public abstract int bytes();174175/**176* Tells whether or not the message is complete.177*178* <P> For received messages {@code true} indicates that the message was179* completely received. For messages being sent {@code true} indicates that180* the message is complete, {@code false} indicates that the message is not181* complete. How the send channel interprets this value depends on the value182* of its {@link SctpStandardSocketOptions#SCTP_EXPLICIT_COMPLETE183* SCTP_EXPLICIT_COMPLETE} socket option.184*185* @return {@code true} if, and only if, the message is complete186*/187public abstract boolean isComplete();188189/**190* Sets whether or not the message is complete.191*192* <P> For messages being sent {@code true} indicates that193* the message is complete, {@code false} indicates that the message is not194* complete. How the send channel interprets this value depends on the value195* of its {@link SctpStandardSocketOptions#SCTP_EXPLICIT_COMPLETE196* SCTP_EXPLICIT_COMPLETE} socket option.197*198* @param complete199* {@code true} if, and only if, the message is complete200*201* @return This MessageInfo202*203* @see MessageInfo#isComplete()204*/205public abstract MessageInfo complete(boolean complete);206207/**208* Tells whether or not the message is unordered. For received messages209* {@code true} indicates that the message was sent non-ordered. For210* messages being sent {@code true} requests the un-ordered delivery of the211* message, {@code false} indicates that the message is ordered.212*213* @return {@code true} if the message is unordered, otherwise214* {@code false}215*/216public abstract boolean isUnordered();217218/**219* Sets whether or not the message is unordered.220*221* @param unordered222* {@code true} requests the un-ordered delivery of the message,223* {@code false} indicates that the message is ordered.224*225* @return This MessageInfo226*227* @see MessageInfo#isUnordered()228*/229public abstract MessageInfo unordered(boolean unordered);230231/**232* Returns the payload protocol Identifier.233*234* <P> A value indicating the type of payload protocol data being235* transmitted/received. This value is passed as opaque data by SCTP.236* {@code 0} indicates an unspecified payload protocol identifier.237*238* @return The Payload Protocol Identifier239*/240public abstract int payloadProtocolID();241242/**243* Sets the payload protocol Identifier.244*245* <P> A value indicating the type of payload protocol data being246* transmitted. This value is passed as opaque data by SCTP.247*248* @param ppid249* The Payload Protocol Identifier, or {@code 0} indicate an250* unspecified payload protocol identifier.251*252* @return This MessageInfo253*254* @see MessageInfo#payloadProtocolID()255*/256public abstract MessageInfo payloadProtocolID(int ppid);257258/**259* Returns the stream number that the message was received on, if the260* message has been received, otherwise the stream number that the message261* is to be sent on.262*263* @return The stream number264*/265public abstract int streamNumber();266267/**268* Sets the stream number that the message is to be sent on.269*270* @param streamNumber271* The stream number272*273* @throws IllegalArgumentException274* If the streamNumber is negative or greater than {@code 65536}275*276* @return This MessageInfo277*/278public abstract MessageInfo streamNumber(int streamNumber);279280/**281* The time period that the sending side may expire the message if it has282* not been sent, or {@code 0} to indicate that no timeout should occur. This283* value is only applicable for messages being sent, it has no meaning for284* received messages.285*286* @return The time period in milliseconds, or {@code 0}287*/288public abstract long timeToLive();289290/**291* Sets the time period that the sending side may expire the message if it292* has not been sent.293*294* @param millis295* The time period in milliseconds, or {@code 0} to indicate that no296* timeout should occur297*298* @return This MessageInfo299*300* @see MessageInfo#timeToLive()301*/302public abstract MessageInfo timeToLive(long millis);303}304305306