jdk/src/share/classes/sun/nio/ch/SctpMessageInfoImpl.java
author michaelm
Thu, 17 Mar 2011 18:26:50 -0700
changeset 8817 5351579c46a9
parent 5506 202f599c92aa
permissions -rw-r--r--
6981922: DNS cache poisoning by untrusted applets Reviewed-by: chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2542
diff changeset
     2
 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     4
 *
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2542
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2542
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    10
 *
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    15
 * accompanied this code).
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    16
 *
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2542
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2542
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2542
diff changeset
    23
 * questions.
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    24
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    25
package sun.nio.ch;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    26
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    27
import java.net.SocketAddress;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    28
import com.sun.nio.sctp.MessageInfo;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    29
import com.sun.nio.sctp.Association;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    30
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    31
/**
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    32
 * An implementation of a MessageInfo.
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    33
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    34
public class SctpMessageInfoImpl extends MessageInfo {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    35
    private final SocketAddress address;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    36
    private final int bytes;          /* 0 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    37
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    38
    private Association association;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    39
    private int assocId;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    40
    private int streamNumber;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    41
    private boolean complete = true;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    42
    private boolean unordered;  /* false */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    43
    private long timeToLive;    /* 0L */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    44
    private int ppid;           /* 0 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    45
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    46
    public SctpMessageInfoImpl(Association association,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    47
                               SocketAddress address,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    48
                               int streamNumber) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    49
        this.association = association;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    50
        this.address = address;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    51
        this.streamNumber = streamNumber;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    52
        bytes = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    53
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    54
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    55
    /* Invoked from native */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    56
    private SctpMessageInfoImpl(int assocId,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    57
                                SocketAddress address,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    58
                                int bytes,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    59
                                int streamNumber,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    60
                                boolean complete,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    61
                                boolean unordered,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    62
                                int ppid) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    63
        this.assocId = assocId;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    64
        this.address = address;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    65
        this.bytes = bytes;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    66
        this.streamNumber = streamNumber;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    67
        this.complete = complete;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    68
        this.unordered = unordered;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    69
        this.ppid = ppid;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    70
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    71
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    72
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    73
    public Association association() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    74
        return association;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    75
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    76
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    77
    /**
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    78
     * SctpMessageInfoImpl instances created from native will need to have their
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    79
     * association set from the channel.
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    80
     */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    81
    void setAssociation(Association association) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    82
        this.association = association;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    83
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    84
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    85
    int associationID() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    86
        return assocId;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    87
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    88
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    89
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    90
    public SocketAddress address() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    91
        return address;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    92
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    93
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    94
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    95
    public int bytes() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    96
        return bytes;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    97
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    98
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    99
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   100
    public int streamNumber() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   101
        return streamNumber;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   102
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   103
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   104
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   105
    public MessageInfo streamNumber(int streamNumber) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   106
        if (streamNumber < 0 || streamNumber > 65536)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   107
            throw new IllegalArgumentException("Invalid stream number");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   108
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   109
        this.streamNumber = streamNumber;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   110
        return this;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   111
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   112
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   113
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   114
    public int payloadProtocolID() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   115
        return ppid;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   116
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   117
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   118
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   119
    public MessageInfo payloadProtocolID(int ppid) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   120
        this.ppid = ppid;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   121
        return this;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   122
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   123
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   124
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   125
    public boolean isComplete() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   126
        return complete;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   127
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   128
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   129
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   130
    public MessageInfo complete(boolean complete) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   131
        this.complete = complete;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   132
        return this;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   133
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   134
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   135
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   136
    public boolean isUnordered() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   137
        return unordered;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   138
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   139
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   140
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   141
    public MessageInfo unordered(boolean unordered) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   142
        this.unordered = unordered;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   143
        return this;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   144
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   145
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   146
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   147
    public long timeToLive() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   148
        return timeToLive;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   149
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   150
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   151
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   152
    public MessageInfo timeToLive(long millis) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   153
        timeToLive = millis;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   154
        return this;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   155
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   156
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   157
    @Override
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   158
    public String toString() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   159
        StringBuilder sb = new StringBuilder(super.toString());
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   160
        sb.append( "[Address: ").append(address)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   161
          .append(", Association: ").append(association)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   162
          .append(", Assoc ID: ").append(assocId)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   163
          .append(", Bytes: ").append(bytes)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   164
          .append(", Stream Number: ").append(streamNumber)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   165
          .append(", Complete: ").append(complete)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   166
          .append(", isUnordered: ").append(unordered)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   167
          .append("]");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   168
        return sb.toString();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   169
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   170
}