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  package org.apache.mina.transport.tcp;
    20
    21  import javax.net.ssl.SSLContext;
    22
    23  import org.apache.mina.session.AbstractIoSessionConfig;
    24
    25  /**
    26   * Implementation for the socket session configuration.
    27   *
    28   * Will hold the values for the service in change of configuring this session (before the session opening).
    29   *
    30   * @author <a href="http://mina.apache.org">Apache MINA Project</a>
    31   */
    32  public class DefaultTcpSessionConfig extends AbstractIoSessionConfig implements TcpSessionConfig {
    33      /** The SSLContext instance */
    34      private SSLContext sslContext;
    35
    36      //=====================
    37      // socket options
    38      //=====================
    39      /** The TCP_NODELAY socket option */
    40      private Boolean tcpNoDelay = null;
    41
    42      /** The OOBINLINE socket option */
    43      private Boolean oobInline = null;
    44
    45      /** The SO_KEEPALIVE socket option */
    46      private Boolean keepAlive = null;
    47
    48      /** The SO_LINGER socket option */
    49      private Integer soLinger;
    50
    51      /**
    52       * {@inheritDoc}
    53       */
    54      @Override
    55      public Boolean isTcpNoDelay() {
    56          return tcpNoDelay;
    57      }
    58
    59      /**
    60       * {@inheritDoc}
    61       */
    62      @Override
    63      public void setTcpNoDelay(boolean tcpNoDelay) {
    64          this.tcpNoDelay = tcpNoDelay;
    65      }
    66
    67      /**
    68       * {@inheritDoc}
    69       */
    70      @Override
    71      public Boolean isKeepAlive() {
    72          return keepAlive;
    73      }
    74
    75      /**
    76       * {@inheritDoc}
    77       */
    78      @Override
    79      public void setKeepAlive(boolean keepAlive) {
    80          this.keepAlive = keepAlive;
    81      }
    82
    83      /**
    84       * {@inheritDoc}
    85       */
    86      @Override
    87      public Boolean isOobInline() {
    88          return oobInline;
    89      }
    90
    91      /**
    92       * {@inheritDoc}
    93       */
    94      @Override
    95      public void setOobInline(boolean oobInline) {
    96          this.oobInline = oobInline;
    97
    98      }
    99
    100     /**
    101      * {@inheritDoc}
    102      */
    103     @Override
    104     public Integer getSoLinger() {
    105         return soLinger;
    106     }
    107
    108     /**
    109      * {@inheritDoc}
    110      */
    111     @Override
    112     public void setSoLinger(int soLinger) {
    113         this.soLinger = soLinger;
    114     }
    115
    116     /**
    117      * Inject a {@link SSLContex} valid for the session. This {@link SSLContex} will be used
    118      * by the SSLEngine to handle secured connections.<br/>
    119      * The {@link SSLContex} must have been created and initialized before being injected in
    120      * the configuration.<br/>
    121      * By setting a {@link SSLContext}, the session switch to secured.
    122      * @param sslContext The configured {@link SSLContex}.
    123      */
    124     public void setSslContext(SSLContext sslContext) {
    125         this.sslContext = sslContext;
    126     }
    127
    128     /**
    129      * {@inheritDoc}
    130      */
    131     public SSLContext getSslContext() {
    132         return sslContext;
    133     }
    134
    135     /**
    136      * {@inheritDoc}
    137      */
    138     @Override
    139     public boolean isSecured() {
    140         return sslContext != null;
    141     }
    142 }