001 /**
002 * Copyright 2007 Mike Kroutikov.
003 *
004 * This program is free software; you can redistribute it and/or modify
005 * it under the terms of the Lesser GNU General Public License as
006 * published by the Free Software Foundation; either version 3 of
007 * the License, or (at your option) any later version.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012 * Lesser GNU General Public License for more details.
013 *
014 * You should have received a copy of the Lesser GNU General Public License
015 * along with this program. If not, see <http://www.gnu.org/licenses/>.
016 */
017
018 package org.otfeed.event;
019
020 /**
021 * Listener to monitor connection progress.
022 *
023 * Connection process goes thru the following states:
024 * <ol>
025 * <li> Connecting: a host/port has been picked from the
026 * pool and system is trying to connect.
027 * Next state could be either Error (if a fatal
028 * error occurs), Connected (if connectred successfully),
029 * or Connecting (if could not connect, but there are other
030 * hosts to try).
031 * <li> Connected: successfully connected and received login response.
032 * Next state could be Error (if login failed), Redirect
033 * (if we were asked to redirect to another host), or
034 * Login (if login succeeded). Note that login errors are
035 * fatal: system will not attempt to use another host in
036 * the pool.
037 * <li> Redirect: We were asked to re-direct to the different host.
038 * Next state would be Connecting.
039 * <li> Login: login was successfull. Next state is Error (when
040 * connection breaks due to communication error or
041 * user request to close/shutdown it).
042 * <li> Error: Final state. Always reached.
043 * </ol>
044 *
045 */
046 public interface IConnectionStateListener {
047
048 /**
049 * Is called when connection enters "Connecting" state.
050 *
051 * @param addr server address.
052 */
053 public void onConnecting(OTHost addr);
054
055 /**
056 * Is called when connection enters "Connected" state.
057 */
058 public void onConnected();
059
060 /**
061 * Is called when connection enters "Redirect" state.
062 *
063 * @param addr redirect address.
064 */
065 public void onRedirect(OTHost addr);
066
067 /**
068 * Is called when connection enters "Login" state.
069 */
070 public void onLogin();
071
072 /**
073 * Is called when connection terminates.
074 */
075 public void onError(OTError error);
076 }