001/* 002 * Copyright 2002-2015 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.messaging.tcp; 018 019import org.springframework.messaging.Message; 020 021/** 022 * A contract for managing lifecycle events for a TCP connection including 023 * the handling of incoming messages. 024 * 025 * @author Rossen Stoyanchev 026 * @since 4.0 027 * @param <P> the type of payload for in and outbound messages 028 */ 029public interface TcpConnectionHandler<P> { 030 031 /** 032 * Invoked after a connection is successfully established. 033 * @param connection the connection 034 */ 035 void afterConnected(TcpConnection<P> connection); 036 037 /** 038 * Invoked on failure to connect. 039 * @param ex the exception 040 */ 041 void afterConnectFailure(Throwable ex); 042 043 /** 044 * Handle a message received from the remote host. 045 * @param message the message 046 */ 047 void handleMessage(Message<P> message); 048 049 /** 050 * Handle a failure on the connection. 051 * @param ex the exception 052 */ 053 void handleFailure(Throwable ex); 054 055 /** 056 * Invoked after the connection is closed. 057 */ 058 void afterConnectionClosed(); 059 060}