1 // $Id: ITimeoutHandler.java 1324 2007-06-13 06:06:02Z grro $ 2 3 /* 4 * Copyright (c) xsocket.org, 2006 - 2007. All rights reserved. 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 * 20 * Please refer to the LGPL license at: http://www.gnu.org/copyleft/lesser.txt 21 * The latest copy of this software may be found on http://www.xsocket.org/ 22 */ 23 24 25 package org.xsocket.stream; 26 27 import java.io.IOException; 28 29 30 31 32 /** 33 * Handles timeout. The timeouts will be defined by the server. To modify the timeouts 34 * the proper server methods has to be called. E.g.<br> 35 * <pre> 36 * ... 37 * IMultithreadedServer server = new MultithreadedServer(new MyHandler()); 38 * server.setIdleTimeoutSec(60); 39 * StreamUtils.start(server); 40 * ... 41 * 42 * 43 * class MyHandler implements ITimeoutHandler { 44 * 45 * public boolean onConnectionTimeout(INonBlockingConnection connection) throws IOException { 46 * ... 47 * connection.close(); 48 * return true; // true -> event has been handled 49 * } 50 * 51 * public boolean onIdleTimeout(INonBlockingConnection connection) throws IOException { 52 * ... 53 * connection.close(); 54 * return true; // true -> event has been handled 55 * } 56 * } 57 * </pre> 58 * 59 * @author grro@xsocket.org 60 */ 61 public interface ITimeoutHandler extends IHandler { 62 63 /** 64 * handles the idle timeout. 65 * 66 * @param connection the underlying connection 67 * @return true if the timeout event has been handled (in case of false the connection will be closed by the server) 68 * @throws IOException if an error occurs. Throwing this exception causes that the underlying connection will be closed. 69 */ 70 public boolean onIdleTimeout(INonBlockingConnection connection) throws IOException ; 71 72 73 /** 74 * handles the connection timeout. 75 * 76 * @param connection the underlying connection 77 * @return true if the timeout event has been handled (in case of false the connection will be closed by the server) 78 * @throws IOException if an error occurs. Throwing this exception causes that the underlying connection will be closed. 79 */ 80 public boolean onConnectionTimeout(INonBlockingConnection connection) throws IOException ; 81 } 82