View Javadoc

    1   /*
    2    *  Licensed to the Apache Software Foundation (ASF) under one
    3    *  or more contributor license agreements.  See the NOTICE file
    4    *  distributed with this work for additional information
    5    *  regarding copyright ownership.  The ASF licenses this file
    6    *  to you under the Apache License, Version 2.0 (the
    7    *  "License"); you may not use this file except in compliance
    8    *  with the License.  You may obtain a copy of the License at
    9    *
    10   *    http://www.apache.org/licenses/LICENSE-2.0
    11   *
    12   *  Unless required by applicable law or agreed to in writing,
    13   *  software distributed under the License is distributed on an
    14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    15   *  KIND, either express or implied.  See the License for the
    16   *  specific language governing permissions and limitations
    17   *  under the License.
    18   *
    19   */
    20  package org.apache.mina.transport.socket;
    21
    22  import java.net.DatagramSocket;
    23
    24  /**
    25   * A default implementation of {@link DatagramSessionConfig}.
    26   *
    27   * @author <a href="http://mina.apache.org">Apache MINA Project</a>
    28   */
    29  public class DefaultDatagramSessionConfig extends AbstractDatagramSessionConfig {
    30      private static boolean DEFAULT_BROADCAST = false;
    31
    32      private static boolean DEFAULT_REUSE_ADDRESS = false;
    33
    34      /* The SO_RCVBUF parameter. Set to -1 (ie, will default to OS default) */
    35      private static int DEFAULT_RECEIVE_BUFFER_SIZE = -1;
    36
    37      /* The SO_SNDBUF parameter. Set to -1 (ie, will default to OS default) */
    38      private static int DEFAULT_SEND_BUFFER_SIZE = -1;
    39
    40      private static int DEFAULT_TRAFFIC_CLASS = 0;
    41
    42      private boolean broadcast = DEFAULT_BROADCAST;
    43
    44      private boolean reuseAddress = DEFAULT_REUSE_ADDRESS;
    45
    46      private int receiveBufferSize = DEFAULT_RECEIVE_BUFFER_SIZE;
    47
    48      private int sendBufferSize = DEFAULT_SEND_BUFFER_SIZE;
    49
    50      private int trafficClass = DEFAULT_TRAFFIC_CLASS;
    51
    52      /**
    53       * Creates a new instance.
    54       */
    55      public DefaultDatagramSessionConfig() {
    56          // Do nothing
    57      }
    58
    59      /**
    60       * @see DatagramSocket#getBroadcast()
    61       */
    62      public boolean isBroadcast() {
    63          return broadcast;
    64      }
    65
    66      /**
    67       * @see DatagramSocket#setBroadcast(boolean)
    68       */
    69      public void setBroadcast(boolean broadcast) {
    70          this.broadcast = broadcast;
    71      }
    72
    73      /**
    74       * @see DatagramSocket#getReuseAddress()
    75       */
    76      public boolean isReuseAddress() {
    77          return reuseAddress;
    78      }
    79
    80      /**
    81       * @see DatagramSocket#setReuseAddress(boolean)
    82       */
    83      public void setReuseAddress(boolean reuseAddress) {
    84          this.reuseAddress = reuseAddress;
    85      }
    86
    87      /**
    88       * @see DatagramSocket#getReceiveBufferSize()
    89       */
    90      public int getReceiveBufferSize() {
    91          return receiveBufferSize;
    92      }
    93
    94      /**
    95       * @see DatagramSocket#setReceiveBufferSize(int)
    96       */
    97      public void setReceiveBufferSize(int receiveBufferSize) {
    98          this.receiveBufferSize = receiveBufferSize;
    99      }
    100
    101     /**
    102      * @see DatagramSocket#getSendBufferSize()
    103      */
    104     public int getSendBufferSize() {
    105         return sendBufferSize;
    106     }
    107
    108     /**
    109      * @see DatagramSocket#setSendBufferSize(int)
    110      */
    111     public void setSendBufferSize(int sendBufferSize) {
    112         this.sendBufferSize = sendBufferSize;
    113     }
    114
    115     /**
    116      * @see DatagramSocket#getTrafficClass()
    117      */
    118     public int getTrafficClass() {
    119         return trafficClass;
    120     }
    121
    122     /**
    123      * @see DatagramSocket#setTrafficClass(int)
    124      */
    125     public void setTrafficClass(int trafficClass) {
    126         this.trafficClass = trafficClass;
    127     }
    128
    129     @Override
    130     protected boolean isBroadcastChanged() {
    131         return broadcast != DEFAULT_BROADCAST;
    132     }
    133
    134     @Override
    135     protected boolean isReceiveBufferSizeChanged() {
    136         return receiveBufferSize != DEFAULT_RECEIVE_BUFFER_SIZE;
    137     }
    138
    139     @Override
    140     protected boolean isReuseAddressChanged() {
    141         return reuseAddress != DEFAULT_REUSE_ADDRESS;
    142     }
    143
    144     @Override
    145     protected boolean isSendBufferSizeChanged() {
    146         return sendBufferSize != DEFAULT_SEND_BUFFER_SIZE;
    147     }
    148
    149     @Override
    150     protected boolean isTrafficClassChanged() {
    151         return trafficClass != DEFAULT_TRAFFIC_CLASS;
    152     }
    153
    154 }