1 /* 2 * Copyright 2002-2017 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 module hunt.stomp.simp.stomp.StompSessionHandler; 18 19 import hunt.stomp.simp.stomp.StompCommand; 20 import hunt.stomp.simp.stomp.StompFrameHandler; 21 import hunt.stomp.simp.stomp.StompHeaders; 22 import hunt.stomp.simp.stomp.StompSession; 23 24 /** 25 * A contract for client STOMP session lifecycle events including a callback 26 * when the session is established and notifications of transport or message 27 * handling failures. 28 * 29 * <p>This contract also extends {@link StompFrameHandler} in order to handle 30 * STOMP ERROR frames received from the broker. 31 * 32 * <p>Implementations of this interface should consider extending 33 * {@link StompSessionHandlerAdapter}. 34 * 35 * @author Rossen Stoyanchev 36 * @since 4.2 37 * @see StompSessionHandlerAdapter 38 */ 39 interface StompSessionHandler : StompFrameHandler { 40 41 /** 42 * Invoked when the session is ready to use, i.e. after the underlying 43 * transport (TCP, WebSocket) is connected and a STOMP CONNECTED frame is 44 * received from the broker. 45 * @param session the client STOMP session 46 * @param connectedHeaders the STOMP CONNECTED frame headers 47 */ 48 void afterConnected(StompSession session, StompHeaders connectedHeaders); 49 50 /** 51 * Handle any exception arising while processing a STOMP frame such as a 52 * failure to convert the payload or an unhandled exception in the 53 * application {@code StompFrameHandler}. 54 * @param session the client STOMP session 55 * @param command the STOMP command of the frame 56 * @param headers the headers 57 * @param payload the raw payload 58 * @param exception the exception 59 */ 60 void handleException(StompSession session, StompCommand command, 61 StompHeaders headers, byte[] payload, Throwable exception); 62 63 /** 64 * Handle a low level transport error which could be an I/O error or a 65 * failure to encode or decode a STOMP message. 66 * <p>Note that 67 * {@link hunt.stomp.simp.stomp.ConnectionLostException 68 * ConnectionLostException} will be passed into this method when the 69 * connection is lost rather than closed normally via 70 * {@link StompSession#disconnect()}. 71 * @param session the client STOMP session 72 * @param exception the exception that occurred 73 */ 74 void handleTransportError(StompSession session, Throwable exception); 75 76 }