jdk/src/solaris/classes/sun/nio/ch/sctp/ResultContainer.java
author dxu
Thu, 04 Apr 2013 15:39:17 -0700
changeset 16734 da1901d79073
parent 14342 8435a30053c1
permissions -rw-r--r--
8000406: change files using @GenerateNativeHeader to use @Native Summary: Use @Native annotation to mark constants interested by native codes Reviewed-by: alanb, anthony, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     1
/*
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 14342
diff changeset
     2
 * Copyright (c) 2009, 2013, 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: 3072
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: 3072
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: 3072
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3072
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3072
diff changeset
    23
 * questions.
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    24
 */
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 5506
diff changeset
    25
package sun.nio.ch.sctp;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    26
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 14342
diff changeset
    27
import java.lang.annotation.Native;
12317
9670c1610c53 7074397: Build infrastructure changes (makefile re-write)
ohair
parents: 11823
diff changeset
    28
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    29
/**
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    30
 * Wraps the actual message or notification so that it can be
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    31
 * set and returned from the native receive implementation.
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    32
 */
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 5506
diff changeset
    33
public class ResultContainer {
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    34
    /* static final ints so that they can be referenced from native */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 14342
diff changeset
    35
    @Native static final int NOTHING = 0;
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 14342
diff changeset
    36
    @Native static final int MESSAGE = 1;
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 14342
diff changeset
    37
    @Native static final int SEND_FAILED = 2;
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 14342
diff changeset
    38
    @Native static final int ASSOCIATION_CHANGED = 3;
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 14342
diff changeset
    39
    @Native static final int PEER_ADDRESS_CHANGED = 4;
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 14342
diff changeset
    40
    @Native static final int SHUTDOWN = 5;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    41
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    42
    private Object value;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    43
    private int type;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    44
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    45
    int type() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    46
        return type;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    47
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    48
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    49
    boolean hasSomething() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    50
        return type() != NOTHING;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    51
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    52
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    53
    boolean isNotification() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    54
        return type() != MESSAGE && type() != NOTHING ? true : false;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    55
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    56
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    57
    void clear() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    58
        type = NOTHING;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    59
        value = null;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    60
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    61
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    62
    SctpNotification notification() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    63
        assert type() != MESSAGE && type() != NOTHING;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    64
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    65
        return (SctpNotification) value;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    66
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    67
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 5506
diff changeset
    68
    MessageInfoImpl getMessageInfo() {
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    69
        assert type() == MESSAGE;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    70
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 5506
diff changeset
    71
        if (value instanceof MessageInfoImpl)
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 5506
diff changeset
    72
            return (MessageInfoImpl) value;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    73
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    74
        return null;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    75
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    76
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 5506
diff changeset
    77
    SendFailed getSendFailed() {
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    78
        assert type() == SEND_FAILED;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    79
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 5506
diff changeset
    80
        if (value instanceof SendFailed)
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 5506
diff changeset
    81
            return (SendFailed) value;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    82
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    83
        return null;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    84
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    85
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 5506
diff changeset
    86
    AssociationChange getAssociationChanged() {
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    87
        assert type() == ASSOCIATION_CHANGED;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    88
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 5506
diff changeset
    89
        if (value instanceof AssociationChange)
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 5506
diff changeset
    90
            return (AssociationChange) value;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    91
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    92
        return null;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    93
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    94
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 5506
diff changeset
    95
    PeerAddrChange getPeerAddressChanged() {
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    96
        assert type() == PEER_ADDRESS_CHANGED;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    97
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 5506
diff changeset
    98
        if (value instanceof PeerAddrChange)
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 5506
diff changeset
    99
            return (PeerAddrChange) value;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   100
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   101
        return null;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   102
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   103
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 5506
diff changeset
   104
    Shutdown getShutdown() {
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   105
        assert type() == SHUTDOWN;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   106
11823
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 5506
diff changeset
   107
        if (value instanceof Shutdown)
ee83ae88512d 7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents: 5506
diff changeset
   108
            return (Shutdown) value;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   109
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   110
        return null;
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 String toString() {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   115
        StringBuilder sb = new StringBuilder();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   116
        sb.append("Type: ");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   117
        switch (type) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   118
            case NOTHING:              sb.append("NOTHING");             break;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   119
            case MESSAGE:              sb.append("MESSAGE");             break;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   120
            case SEND_FAILED:          sb.append("SEND FAILED");         break;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   121
            case ASSOCIATION_CHANGED:  sb.append("ASSOCIATION CHANGE");  break;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   122
            case PEER_ADDRESS_CHANGED: sb.append("PEER ADDRESS CHANGE"); break;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   123
            case SHUTDOWN:             sb.append("SHUTDOWN");            break;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   124
            default :                  sb.append("Unknown result type");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   125
        }
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   126
        sb.append(", Value: ");
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   127
        sb.append((value == null) ? "null" : value.toString());
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   128
        return sb.toString();
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   129
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   130
}