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.api; 21 22 import org.apache.mina.service.executor.IoHandlerExecutor; 23 24 /** 25 * Handle all the I/O events generated by a {@link IoService}. 26 * <p> 27 * You should handle your business logic in an IoHandler implementation. 28 * <p> 29 * The {@link IoFilter} is dedicated to message transformation, but the IoHandler is mean to be the core of your 30 * business logic. 31 * <p> 32 * If you need to implement blocking code in your {@link IoHandler}, then you need to add a {@link IoHandlerExecutor} in 33 * the enclosing {@link IoService}. 34 */ 35 public interface IoHandler { 36 37 /** 38 * Invoked when a connection has been opened. 39 * 40 * @param session {@link IoSession} associated with the invocation 41 */ 42 void sessionOpened(IoSession session); 43 44 /** 45 * Invoked when a connection is closed. 46 * 47 * @param session {@link IoSession} associated with the invocation 48 */ 49 void sessionClosed(IoSession session); 50 51 /** 52 * Invoked with the related {@link IdleStatus} when a connection becomes idle. 53 * 54 * @param session {@link IoSession} associated with the invocation 55 */ 56 void sessionIdle(IoSession session, IdleStatus status); 57 58 /** 59 * Invoked when a message is received. 60 * 61 * @param session {@link IoSession} associated with the invocation 62 * @param message the incoming message to process 63 */ 64 void messageReceived(IoSession session, Object message); 65 66 /** 67 * Invoked when a high level message was written to the low level O/S buffer. 68 * 69 * @param session {@link IoSession} associated with the invocation 70 * @param message the incoming message to process 71 */ 72 void messageSent(IoSession session, Object message); 73 74 /** 75 * Invoked when a new service is activated by an {@link IoService}. 76 * 77 * @param service the {@link IoService} 78 */ 79 void serviceActivated(IoService service); 80 81 /** 82 * Invoked when a service is inactivated by an {@link IoService}. 83 * 84 * @param service the {@link IoService} 85 */ 86 void serviceInactivated(IoService service); 87 88 /** 89 * Invoked when any runtime exception is thrown during session processing (filters, unexpected error, etc..). 90 * 91 * @param session the session related to the exception 92 * @param cause the caught exception 93 */ 94 void exceptionCaught(IoSession session, Exception cause); 95 }