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   *
    21   */
    22  package org.apache.mina.session;
    23
    24  import org.apache.mina.api.IdleStatus;
    25  import org.apache.mina.api.IoSessionConfig;
    26
    27  /**
    28   * Base class for session configuration. Implements session configuration properties commons to all the different
    29   * transports.
    30   *
    31   * @author <a href="http://mina.apache.org">Apache MINA Project</a>
    32   */
    33  public abstract class AbstractIoSessionConfig implements IoSessionConfig {
    34      // =====================
    35      // idle management
    36      // =====================
    37      /** The delay we wait for a read before we consider the session is staled */
    38      private long idleTimeRead = -1;
    39
    40      /** The delay we wait for a write before we consider the session is staled */
    41      private long idleTimeWrite = -1;
    42
    43      /** The SO_RCVBUF socket option. The default buffer size used for Read */
    44      private Integer readBufferSize = null;
    45
    46      /** The SO_SNDBUF socket option. The default buffer size used for Write */
    47      private Integer sendBufferSize = null;
    48
    49      /** The ToS value */
    50      private TrafficClassEnum trafficClass = TrafficClassEnum.IPTOS_DEFAULT;
    51
    52      /** The SO_REUSEADDR socket option */
    53      private Boolean reuseAddress = null;
    54
    55      /** The SO_TIMEOUT socket option */
    56      private Integer timeout = null;
    57
    58      /**
    59       * {@inheritDoc}
    60       */
    61      @Override
    62      public long getIdleTimeInMillis(IdleStatus status) {
    63          switch (status) {
    64          case READ_IDLE:
    65              return idleTimeRead;
    66          case WRITE_IDLE:
    67              return idleTimeWrite;
    68          default:
    69              throw new IllegalStateException("unexpected excetion, unknown idle status : " + status);
    70          }
    71      }
    72
    73      /**
    74       * {@inheritDoc}
    75       */
    76      @Override
    77      public void setIdleTimeInMillis(IdleStatus status, long ildeTimeInMilli) {
    78          switch (status) {
    79          case READ_IDLE:
    80              this.idleTimeRead = ildeTimeInMilli;
    81              break;
    82          case WRITE_IDLE:
    83              this.idleTimeWrite = ildeTimeInMilli;
    84              break;
    85          default:
    86              throw new IllegalStateException("unexpected excetion, unknown idle status : " + status);
    87          }
    88      }
    89
    90      /**
    91       * {@inheritDoc}
    92       */
    93      @Override
    94      public Integer getReadBufferSize() {
    95          return readBufferSize;
    96      }
    97
    98      /**
    99       * {@inheritDoc}
    100      */
    101     @Override
    102     public void setReadBufferSize(int readBufferSize) {
    103         if (readBufferSize <= 0) {
    104             throw new IllegalArgumentException("readBufferSize: " + readBufferSize + " (expected: 1+)");
    105         }
    106         this.readBufferSize = readBufferSize;
    107     }
    108
    109     /**
    110      * {@inheritDoc}
    111      */
    112     @Override
    113     public Integer getSendBufferSize() {
    114         return sendBufferSize;
    115     }
    116
    117     /**
    118      * {@inheritDoc}
    119      */
    120     @Override
    121     public void setSendBufferSize(int sendBufferSize) {
    122         this.sendBufferSize = sendBufferSize;
    123     }
    124
    125     /**
    126      * {@inheritDoc}
    127      */
    128     @Override
    129     public int getTrafficClass() {
    130         return trafficClass.getValue();
    131     }
    132
    133     /**
    134      * {@inheritDoc}
    135      */
    136     @Override
    137     public void setTrafficClass(TrafficClassEnum trafficClass) {
    138         this.trafficClass = trafficClass;
    139     }
    140
    141     /**
    142      * {@inheritDoc}
    143      */
    144     @Override
    145     public void setTrafficClass(int trafficClass) {
    146         this.trafficClass = TrafficClassEnum.valueOf(trafficClass);
    147     }
    148
    149     /**
    150      * {@inheritDoc}
    151      */
    152     @Override
    153     public Boolean isReuseAddress() {
    154         return reuseAddress;
    155     }
    156
    157     /**
    158      * {@inheritDoc}
    159      */
    160     @Override
    161     public void setReuseAddress(boolean reuseAddress) {
    162         this.reuseAddress = reuseAddress;
    163     }
    164
    165     /**
    166      * {@inheritDoc}
    167      */
    168     @Override
    169     public Integer getTimeout() {
    170         return timeout;
    171     }
    172
    173     /**
    174      * {@inheritDoc}
    175      */
    176     @Override
    177     public void setTimeout(int timeout) {
    178         this.timeout = timeout;
    179     }
    180 }