001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.mina.core.service; 021 022import org.apache.mina.core.session.IdleStatus; 023import org.apache.mina.core.session.IoSession; 024import org.slf4j.Logger; 025import org.slf4j.LoggerFactory; 026 027/** 028 * An adapter class for {@link IoHandler}. You can extend this 029 * class and selectively override required event handler methods only. All 030 * methods do nothing by default. 031 * 032 * @author <a href="http://mina.apache.org">Apache MINA Project</a> 033 */ 034public class IoHandlerAdapter implements IoHandler { 035 private static final Logger LOGGER = LoggerFactory.getLogger(IoHandlerAdapter.class); 036 037 /** 038 * {@inheritDoc} 039 */ 040 public void sessionCreated(IoSession session) throws Exception { 041 // Empty handler 042 } 043 044 /** 045 * {@inheritDoc} 046 */ 047 public void sessionOpened(IoSession session) throws Exception { 048 // Empty handler 049 } 050 051 /** 052 * {@inheritDoc} 053 */ 054 public void sessionClosed(IoSession session) throws Exception { 055 // Empty handler 056 } 057 058 /** 059 * {@inheritDoc} 060 */ 061 public void sessionIdle(IoSession session, IdleStatus status) throws Exception { 062 // Empty handler 063 } 064 065 /** 066 * {@inheritDoc} 067 */ 068 public void exceptionCaught(IoSession session, Throwable cause) throws Exception { 069 if (LOGGER.isWarnEnabled()) { 070 LOGGER.warn("EXCEPTION, please implement " + getClass().getName() 071 + ".exceptionCaught() for proper handling:", cause); 072 } 073 } 074 075 /** 076 * {@inheritDoc} 077 */ 078 public void messageReceived(IoSession session, Object message) throws Exception { 079 // Empty handler 080 } 081 082 /** 083 * {@inheritDoc} 084 */ 085 public void messageSent(IoSession session, Object message) throws Exception { 086 // Empty handler 087 } 088 089 /** 090 * {@inheritDoc} 091 */ 092 public void inputClosed(IoSession session) throws Exception { 093 session.closeNow(); 094 } 095}