Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/nio/ch/sctp/PeerAddrChange.java
32301 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.net.SocketAddress;27import com.sun.nio.sctp.Association;28import com.sun.nio.sctp.PeerAddressChangeNotification;29import java.lang.annotation.Native;3031/**32* An implementation of PeerAddressChangeNotification33*/34public class PeerAddrChange extends PeerAddressChangeNotification35implements SctpNotification36{37/* static final ints so that they can be referenced from native */38@Native private final static int SCTP_ADDR_AVAILABLE = 1;39@Native private final static int SCTP_ADDR_UNREACHABLE = 2;40@Native private final static int SCTP_ADDR_REMOVED = 3;41@Native private final static int SCTP_ADDR_ADDED = 4;42@Native private final static int SCTP_ADDR_MADE_PRIM = 5;43@Native private final static int SCTP_ADDR_CONFIRMED =6;4445private Association association;4647/* assocId is used to lookup the association before the notification is48* returned to user code */49private int assocId;50private SocketAddress address;51private AddressChangeEvent event;5253/* Invoked from native */54private PeerAddrChange(int assocId, SocketAddress address, int intEvent) {55switch (intEvent) {56case SCTP_ADDR_AVAILABLE :57this.event = AddressChangeEvent.ADDR_AVAILABLE;58break;59case SCTP_ADDR_UNREACHABLE :60this.event = AddressChangeEvent.ADDR_UNREACHABLE;61break;62case SCTP_ADDR_REMOVED :63this.event = AddressChangeEvent.ADDR_REMOVED;64break;65case SCTP_ADDR_ADDED :66this.event = AddressChangeEvent.ADDR_ADDED;67break;68case SCTP_ADDR_MADE_PRIM :69this.event = AddressChangeEvent.ADDR_MADE_PRIMARY;70break;71case SCTP_ADDR_CONFIRMED :72this.event = AddressChangeEvent.ADDR_CONFIRMED;73break;74default:75throw new AssertionError("Unknown event type");76}77this.assocId = assocId;78this.address = address;79}8081@Override82public int assocId() {83return assocId;84}8586@Override87public void setAssociation(Association association) {88this.association = association;89}9091@Override92public SocketAddress address() {93assert address != null;94return address;95}9697@Override98public Association association() {99assert association != null;100return association;101}102103@Override104public AddressChangeEvent event() {105assert event != null;106return event;107}108109@Override110public String toString() {111StringBuilder sb = new StringBuilder();112sb.append(super.toString()).append(" [");113sb.append("Address: ").append(address);114sb.append(", Association:").append(association);115sb.append(", Event: ").append(event).append("]");116return sb.toString();117}118}119120121122