Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/nio/ch/sctp/ResultContainer.java
32300 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 sun.nio.ch.sctp;2526import java.lang.annotation.Native;2728/**29* Wraps the actual message or notification so that it can be30* set and returned from the native receive implementation.31*/32public class ResultContainer {33/* static final ints so that they can be referenced from native */34@Native static final int NOTHING = 0;35@Native static final int MESSAGE = 1;36@Native static final int SEND_FAILED = 2;37@Native static final int ASSOCIATION_CHANGED = 3;38@Native static final int PEER_ADDRESS_CHANGED = 4;39@Native static final int SHUTDOWN = 5;4041private Object value;42private int type;4344int type() {45return type;46}4748boolean hasSomething() {49return type() != NOTHING;50}5152boolean isNotification() {53return type() != MESSAGE && type() != NOTHING ? true : false;54}5556void clear() {57type = NOTHING;58value = null;59}6061SctpNotification notification() {62assert type() != MESSAGE && type() != NOTHING;6364return (SctpNotification) value;65}6667MessageInfoImpl getMessageInfo() {68assert type() == MESSAGE;6970if (value instanceof MessageInfoImpl)71return (MessageInfoImpl) value;7273return null;74}7576SendFailed getSendFailed() {77assert type() == SEND_FAILED;7879if (value instanceof SendFailed)80return (SendFailed) value;8182return null;83}8485AssociationChange getAssociationChanged() {86assert type() == ASSOCIATION_CHANGED;8788if (value instanceof AssociationChange)89return (AssociationChange) value;9091return null;92}9394PeerAddrChange getPeerAddressChanged() {95assert type() == PEER_ADDRESS_CHANGED;9697if (value instanceof PeerAddrChange)98return (PeerAddrChange) value;99100return null;101}102103Shutdown getShutdown() {104assert type() == SHUTDOWN;105106if (value instanceof Shutdown)107return (Shutdown) value;108109return null;110}111112@Override113public String toString() {114StringBuilder sb = new StringBuilder();115sb.append("Type: ");116switch (type) {117case NOTHING: sb.append("NOTHING"); break;118case MESSAGE: sb.append("MESSAGE"); break;119case SEND_FAILED: sb.append("SEND FAILED"); break;120case ASSOCIATION_CHANGED: sb.append("ASSOCIATION CHANGE"); break;121case PEER_ADDRESS_CHANGED: sb.append("PEER ADDRESS CHANGE"); break;122case SHUTDOWN: sb.append("SHUTDOWN"); break;123default : sb.append("Unknown result type");124}125sb.append(", Value: ");126sb.append((value == null) ? "null" : value.toString());127return sb.toString();128}129}130131132