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.handler.multiton;
    21
    22  import org.apache.mina.common.IdleStatus;
    23  import org.apache.mina.common.IoSession;
    24  import org.apache.mina.util.SessionUtil;
    25
    26  /**
    27   * Adapter class for implementors of the {@link SingleSessionIoHandler}
    28   * interface. The session to which the handler is assigned is accessible
    29   * through the {@link #getSession()} method.
    30   *
    31   * @author The Apache Directory Project (mina-dev@directory.apache.org)
    32   * @version $Rev: 555855 $, $Date: 2007-07-13 05:19:00 +0200 (Fri, 13 Jul 2007) $
    33   */
    34  public class SingleSessionIoHandlerAdapter implements SingleSessionIoHandler {
    35
    36      /**
    37       * The session to which the handler is assigned.
    38       */
    39      private final IoSession session;
    40
    41      /**
    42       * Creates a new instance that is assigned to the passed in session.
    43       *
    44       * @param session the session to which the handler is assigned
    45       */
    46      public SingleSessionIoHandlerAdapter(IoSession session) {
    47          if (session == null) {
    48              throw new NullPointerException("session");
    49          }
    50          this.session = session;
    51      }
    52
    53      /**
    54       * Retrieves the session to which this handler is assigned.
    55       *
    56       * @return the session
    57       */
    58      protected IoSession getSession() {
    59          return session;
    60      }
    61
    62      public void exceptionCaught(Throwable th) throws Exception {
    63      }
    64
    65      public void messageReceived(Object message) throws Exception {
    66      }
    67
    68      public void messageSent(Object message) throws Exception {
    69      }
    70
    71      public void sessionClosed() throws Exception {
    72      }
    73
    74      public void sessionCreated() throws Exception {
    75          SessionUtil.initialize(getSession());
    76      }
    77
    78      public void sessionIdle(IdleStatus status) throws Exception {
    79      }
    80
    81      public void sessionOpened() throws Exception {
    82      }
    83  }