1 /*
2  * Copyright 2002-2018 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.Message;
18 
19 import hunt.stomp.MessageHeaders;
20 import hunt.util.Common;
21 
22 /**
23 * See_also:
24 *	https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#websocket-stomp-message-flow
25 */
26 interface MessageBase {
27 
28 	TypeInfo  payloadType();
29 
30 	/**
31 	 * Return message headers for the message (never {@code null} but may be empty).
32 	 */
33 	MessageHeaders getHeaders();
34 
35 }
36 
37 /**
38  * A generic message representation with headers and body.
39  *
40  * @author Mark Fisher
41  * @author Arjen Poutsma
42  * @since 4.0
43  * @param (T) the payload type
44  * @see hunt.stomp.support.MessageBuilder
45  */
46 interface Message(T) : MessageBase {
47 
48 	/**
49 	 * Return the message payload.
50 	 */
51 	T getPayload();
52 
53 	/**
54 	 * Return message headers for the message (never {@code null} but may be empty).
55 	 */
56 	// MessageHeaders getHeaders();
57 }
58 
59 /**
60  * Contract for handling a {@link Message}.
61  *
62  * @author Mark Fisher
63  * @author Iwein Fuld
64  * @since 4.0
65  */
66 interface MessageHandler {
67 
68 	/**
69 	 * Handle the given message.
70 	 * @param message the message to be handled
71 	 * @throws MessagingException if the handler failed to process the message
72 	 */
73 	void handleMessage(MessageBase message);
74 
75 	int opCmp(MessageHandler o);
76 }
77 
78 
79 /**
80  * Extension of the {@link Runnable} interface with methods to obtain the
81  * {@link MessageHandler} and {@link Message} to be handled.
82  *
83  * @author Rossen Stoyanchev
84  * @since 4.1.1
85  */
86 interface MessageHandlingRunnable : Runnable {
87 
88 	/**
89 	 * Return the Message that will be handled.
90 	 */
91 	MessageBase getMessage();
92 
93 	/**
94 	 * Return the MessageHandler that will be used to handle the message.
95 	 */
96 	MessageHandler getMessageHandler();
97 
98 }