<fix>[timeout]: add trace for api timeout
Use longer timeout when message timeout changed
Resolves:
@@ -392,24 +392,38 @@ public class ApiTimeoutManagerImpl implements ApiTimeoutManager, Component,
return mtd;
}
- // if no message timeout from context or context contains same timeout
- // no need to get a new message deadline
- boolean skipDeadlineCalculation = !TaskContext.containsTaskContext(TASK_CONTEXT_MESSAGE_TIMEOUT)
- || Long.parseLong((String) TaskContext.getTaskContext().get(TASK_CONTEXT_MESSAGE_TIMEOUT)) == messageTimeout;
- if (skipDeadlineCalculation) {
+ // no message timeout from context
+ boolean noMessageTimeoutInContext = !TaskContext.containsTaskContext(TASK_CONTEXT_MESSAGE_TIMEOUT);
+ if (noMessageTimeoutInContext) {
mtd.setMessageTimeout(getTimeout());
mtd.setMessageDeadline(calculateMessageDeadline(mtd.getMessageTimeout()));
return mtd;
}
+ // timeout from context not changed, keep the deadline with context
+ long messageTimeoutFromContext = Long.parseLong((String) TaskContext
+ .getTaskContext()
+ .get(TASK_CONTEXT_MESSAGE_TIMEOUT));
+ long originalDeadlineFromContext = Long.parseLong((String) TaskContext
+ .getTaskContext()
+ .get(TASK_CONTEXT_MESSAGE_DEADLINE));
+ if (messageTimeoutFromContext == messageTimeout) {
+ mtd.setMessageTimeout(messageTimeoutFromContext);
+ mtd.setMessageDeadline(originalDeadlineFromContext);
+ return mtd;
+ }
+
// in most cases message deadline is shared
- // only if message manually set a different message timeout, in this case choose a smaller timeout
- // to make sure all related messages will become timeout before deadline
- long originalMessageDeadline = Long.parseLong((String) TaskContext.getTaskContext().get(TASK_CONTEXT_MESSAGE_DEADLINE));
+ // only if message manually set a different message timeout or timeout changed
+ // due to ApiTimeoutExtensionPoint message deadline need to follow the rule
+ // that if message timeout longer than current message timeout, choose a longer
+ // message and if timeout shorter than current message timeout, choose a shorter
+ // deadline
long newMessageDeadline = timer.getCurrentTimeMillis() + messageTimeout;
-
mtd.setMessageTimeout(messageTimeout);
- mtd.setMessageDeadline(Math.min(originalMessageDeadline, newMessageDeadline));
+ mtd.setMessageDeadline(messageTimeout < messageTimeoutFromContext ?
+ Math.min(messageTimeoutFromContext, newMessageDeadline) :
+ Math.max(messageTimeoutFromContext, newMessageDeadline));
return mtd;
}
}
