/
MessageDao.java
219 lines (194 loc) · 7.44 KB
/
MessageDao.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openhubframework.openhub.core.common.dao;
import java.time.Duration;
import java.util.List;
import javax.annotation.Nullable;
import org.openhubframework.openhub.api.entity.ExternalSystemExtEnum;
import org.openhubframework.openhub.api.entity.Message;
import org.openhubframework.openhub.api.entity.MessageFilter;
import org.openhubframework.openhub.api.entity.MsgStateEnum;
import org.openhubframework.openhub.api.entity.Node;
/**
* DAO for {@link Message} entity.
*
* @author Petr Juza
*/
public interface MessageDao {
/**
* Inserts new message.
*
* @param msg the message
*/
void insert(Message msg);
/**
* Updates message.
*
* @param msg the message
*/
void update(Message msg);
/**
* Delete message.
*
* @param msg the message.
*/
void delete(Message msg);
/**
* Finds message by its ID.
*
* @param msgId the message ID
* @return message or {@code null} if not available
*/
@Nullable
Message findMessage(Long msgId);
/**
* Finds message by its ID with eager loading.
*
* @param msgId the message ID
* @return message or {@code null} if not available
*/
@Nullable
Message findEagerMessage(Long msgId);
/**
* Gets message by its ID.
*
* @param msgId the message ID
* @return message
*/
Message getMessage(Long msgId);
/**
* Finds all child messages of specified parent message.
*
* @param msg the message
* @return list of child messages
*/
List<Message> findChildMessages(Message msg);
/**
* Finds all child message for parent message.
*
* @param parentMessage parent message
* @return list of child messages
*/
List<Message> findChildMessagesForParent(Message parentMessage);
/**
* Finds message by source system and correlation ID.
*
* @param correlationId correlation ID
* @param sourceSystem the source system
* @return message or {@code null} if not available
*/
@Nullable
Message findByCorrelationId(String correlationId, @Nullable ExternalSystemExtEnum sourceSystem);
/**
* Finds ONE message in state {@link MsgStateEnum#PARTLY_FAILED}.
*
* @param interval Interval (in seconds) between two tries of partly failed messages.
* @return message or null if there is no any message
*/
@Nullable
Message findPartlyFailedMessage(Duration interval);
/**
* Finds ONE message in state {@link MsgStateEnum#POSTPONED}.
*
* @param interval Interval (in seconds) after that can be postponed message processed again
* @return message or null if there is no any message
*/
@Nullable
Message findPostponedMessage(Duration interval);
/**
* Finds ONE message in state {@link MsgStateEnum#POSTPONED} or {@link MsgStateEnum#PARTLY_FAILED}
*
* @param postponedInterval Interval (in seconds) after that can be postponed message processed again
* @param partiallyFailedInterval Interval (in seconds) after that can be partly failed message processed again
* @return message or null if there is no any message
*/
@Nullable
Message findPostponedOrPartlyFailedMessage(Duration postponedInterval, Duration partiallyFailedInterval);
/**
* Updates {@link Message} into state {@link MsgStateEnum#PROCESSING} (set start timestamp of processing)
* - gets lock for message.
*
* @param msg the message
* @param processingNode node that process message from parameter
* @return {@code true} when update was successful otherwise {@code false}
*/
boolean updateMessageProcessingUnderLock(Message msg, Node processingNode);
/**
* Updates {@link Message} into state {@link MsgStateEnum#IN_QUEUE} (set start timestamp in queue)
* - gets lock for message.
*
* @param msg the message
* @param processingNode node that process message from parameter
* @return {@code true} when update was successful otherwise {@code false}
*/
boolean updateMessageInQueueUnderLock(Message msg, Node processingNode);
/**
* Finds processing messages to repair process.
*
* @param interval Interval (in seconds) after that processing messages are probably in dead-lock
* @return list of messages
*/
List<Message> findProcessingMessages(Duration interval);
/**
* Gets count of messages in specified state
*
* @param state the state
* @param interval Interval (in seconds) after that messages must be updates; in other words get count
* of messages updated in specified interval
* @return count
*/
int getCountMessages(MsgStateEnum state, @Nullable Duration interval);
/**
* Gets count of processing messages (PROCESSING, WAITING, WAITING_FOR_RES) with same funnel value
* and for specified funnel ID.
*
* @param funnelValue the funnel value
* @param idleInterval interval (in seconds) that determines how long can be message processing
* @param funnelCompId the funnel component ID
* @return count of messages
*/
int getCountProcessingMessagesForFunnel(String funnelValue, Duration idleInterval, String funnelCompId);
/**
* Gets list of messages with specified funnel value for guaranteed processing order of whole routes.
*
* @param funnelValue the funnel value
* @param excludeFailedState {@link MsgStateEnum#FAILED FAILED} state is used by default;
* use {@code true} if you want to exclude FAILED state
* @return list of messages ordered by {@link Message#getMsgTimestamp() message timestamp}
*/
List<Message> getMessagesForGuaranteedOrderForRoute(String funnelValue, boolean excludeFailedState);
/**
* Gets list of messages with specified funnel value for guaranteed processing order of messages
* for specified funnel.
*
* @param funnelValue the funnel value
* @param idleInterval interval (in seconds) that determines how long can message be processing
* @param excludeFailedState {@link MsgStateEnum#FAILED FAILED} state is used by default;
* use {@code true} if you want to exclude FAILED state
* @param funnelCompId the funnel component ID
* @return list of messages ordered by {@link Message#getMsgTimestamp() message timestamp}
*/
List<Message> getMessagesForGuaranteedOrderForFunnel(String funnelValue, Duration idleInterval,
boolean excludeFailedState, String funnelCompId);
/**
* Finds messages by multiple fields, hold together in MessageFilter.
*
* @param messageFilter the filter.
* @param limit the limit of messages.
* @return list of messages.
*/
List<Message> findMessagesByFilter(MessageFilter messageFilter, long limit);
}