|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.eventmesh.connector.http.sink.data; |
| 19 | + |
| 20 | +import lombok.Data; |
| 21 | + |
| 22 | +/** |
| 23 | + * Single HTTP retry event |
| 24 | + */ |
| 25 | +@Data |
| 26 | +public class HttpRetryEvent { |
| 27 | + |
| 28 | + public static final String PREFIX = "http-retry-event-"; |
| 29 | + |
| 30 | + private String parentId; |
| 31 | + |
| 32 | + private int maxRetries; |
| 33 | + |
| 34 | + private int currentRetries; |
| 35 | + |
| 36 | + private Throwable lastException; |
| 37 | + |
| 38 | + /** |
| 39 | + * Increase the current retries by 1 |
| 40 | + */ |
| 41 | + public void increaseCurrentRetries() { |
| 42 | + this.currentRetries++; |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Check if the current retries is greater than or equal to the max retries |
| 47 | + * @return true if the current retries is greater than or equal to the max retries |
| 48 | + */ |
| 49 | + public boolean isMaxRetriesReached() { |
| 50 | + return this.currentRetries >= this.maxRetries; |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Get the limited exception message with the default limit of 256 |
| 55 | + * @return the limited exception message |
| 56 | + */ |
| 57 | + public String getLimitedExceptionMessage() { |
| 58 | + return getLimitedExceptionMessage(256); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Get the limited exception message with the specified limit |
| 63 | + * @param maxLimit the maximum limit of the exception message |
| 64 | + * @return the limited exception message |
| 65 | + */ |
| 66 | + public String getLimitedExceptionMessage(int maxLimit) { |
| 67 | + if (lastException == null) { |
| 68 | + return ""; |
| 69 | + } |
| 70 | + String message = lastException.getMessage(); |
| 71 | + if (message == null) { |
| 72 | + return ""; |
| 73 | + } |
| 74 | + if (message.length() > maxLimit) { |
| 75 | + return message.substring(0, maxLimit); |
| 76 | + } |
| 77 | + return message; |
| 78 | + } |
| 79 | + |
| 80 | +} |
0 commit comments