1 /*
   2  * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package sun.nio.ch.sctp;
  26 
  27 import java.nio.ByteBuffer;
  28 import java.net.SocketAddress;
  29 import com.sun.nio.sctp.Association;
  30 import com.sun.nio.sctp.SendFailedNotification;
  31 
  32 /**
  33  * An implementation of SendFailedNotification
  34  */
  35 public class SctpSendFailed extends SendFailedNotification
  36     implements SctpNotification
  37 {
  38     private Association association;
  39     /* assocId is used to lookup the association before the notification is
  40      * returned to user code */
  41     private int assocId;
  42     private SocketAddress address;
  43     private ByteBuffer buffer;
  44     private int errorCode;
  45     private int streamNumber;
  46 
  47     /* Invoked from native */
  48     private SctpSendFailed(int assocId,
  49                            SocketAddress address,
  50                            ByteBuffer buffer,
  51                            int errorCode,
  52                            int streamNumber) {
  53         this.assocId = assocId;
  54         this.errorCode = errorCode;
  55         this.streamNumber = streamNumber;
  56         this.address = address;
  57         this.buffer = buffer;
  58     }
  59 
  60     @Override
  61     public int assocId() {
  62         return assocId;
  63     }
  64 
  65     @Override
  66     public void setAssociation(Association association) {
  67         this.association = association;
  68     }
  69 
  70     @Override
  71     public Association association() {
  72         /* may be null */
  73         return association;
  74     }
  75 
  76     @Override
  77     public SocketAddress address() {
  78         assert address != null;
  79         return address;
  80     }
  81 
  82     @Override
  83     public ByteBuffer buffer() {
  84         assert buffer != null;
  85         return buffer;
  86     }
  87 
  88     @Override
  89     public int errorCode() {
  90         return errorCode;
  91     }
  92 
  93     @Override
  94     public int streamNumber() {
  95         return streamNumber;
  96     }
  97 
  98     @Override
  99     public String toString() {
 100         StringBuilder sb = new StringBuilder();
 101         sb.append(super.toString()).append(" [");
 102         sb.append("Association:").append(association);
 103         sb.append(", Address: ").append(address);
 104         sb.append(", buffer: ").append(buffer);
 105         sb.append(", errorCode: ").append(errorCode);
 106         sb.append(", streamNumber: ").append(streamNumber);
 107         sb.append("]");
 108         return sb.toString();
 109     }
 110 }