|
| 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.shenyu.admin.config.properties; |
| 19 | + |
| 20 | +import org.springframework.boot.context.properties.ConfigurationProperties; |
| 21 | + |
| 22 | +import java.time.Duration; |
| 23 | + |
| 24 | +/** |
| 25 | + * Properties of the opt-in server-issued registration lease |
| 26 | + * ({@code registration-lease-v1}). When disabled, the {@code /instance/beat} |
| 27 | + * endpoint keeps its exact legacy v1 behavior. |
| 28 | + */ |
| 29 | +@ConfigurationProperties(prefix = "shenyu.register.lease") |
| 30 | +public class RegistrationLeaseProperties { |
| 31 | + |
| 32 | + /** |
| 33 | + * Default heartbeat interval when the client does not propose one. |
| 34 | + */ |
| 35 | + private static final Duration DEFAULT_INTERVAL = Duration.ofSeconds(5); |
| 36 | + |
| 37 | + /** |
| 38 | + * Default multiple of the heartbeat interval used as the offline deadline. |
| 39 | + */ |
| 40 | + private static final int DEFAULT_EXPIRY_FACTOR = 3; |
| 41 | + |
| 42 | + /** |
| 43 | + * Whether the registration lease is enabled. When false, no capability is |
| 44 | + * advertised and beats keep the legacy v1 semantics. |
| 45 | + */ |
| 46 | + private boolean enabled; |
| 47 | + |
| 48 | + /** |
| 49 | + * Heartbeat interval issued to clients that do not propose one, and the fallback |
| 50 | + * for proposals outside the accepted bounds. |
| 51 | + */ |
| 52 | + private Duration interval = DEFAULT_INTERVAL; |
| 53 | + |
| 54 | + /** |
| 55 | + * Smallest heartbeat interval the server is willing to negotiate. |
| 56 | + */ |
| 57 | + private Duration minInterval = Duration.ofSeconds(2); |
| 58 | + |
| 59 | + /** |
| 60 | + * Largest heartbeat interval the server is willing to negotiate. |
| 61 | + */ |
| 62 | + private Duration maxInterval = Duration.ofSeconds(60); |
| 63 | + |
| 64 | + /** |
| 65 | + * Multiple of the negotiated interval used as the offline deadline: an instance |
| 66 | + * whose lease is not renewed within {@code expiryFactor * interval} is marked |
| 67 | + * offline. |
| 68 | + */ |
| 69 | + private int expiryFactor = DEFAULT_EXPIRY_FACTOR; |
| 70 | + |
| 71 | + /** |
| 72 | + * Whether the lease is enabled. |
| 73 | + * |
| 74 | + * @return whether enabled |
| 75 | + */ |
| 76 | + public boolean isEnabled() { |
| 77 | + return enabled; |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * Set whether the lease is enabled. |
| 82 | + * |
| 83 | + * @param enabled whether enabled |
| 84 | + */ |
| 85 | + public void setEnabled(final boolean enabled) { |
| 86 | + this.enabled = enabled; |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Get the default heartbeat interval. |
| 91 | + * |
| 92 | + * @return the default interval |
| 93 | + */ |
| 94 | + public Duration getInterval() { |
| 95 | + return interval; |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * Set the default heartbeat interval. |
| 100 | + * |
| 101 | + * @param interval the default interval |
| 102 | + */ |
| 103 | + public void setInterval(final Duration interval) { |
| 104 | + this.interval = interval; |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Get the smallest negotiable heartbeat interval. |
| 109 | + * |
| 110 | + * @return the minimum interval |
| 111 | + */ |
| 112 | + public Duration getMinInterval() { |
| 113 | + return minInterval; |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * Set the smallest negotiable heartbeat interval. |
| 118 | + * |
| 119 | + * @param minInterval the minimum interval |
| 120 | + */ |
| 121 | + public void setMinInterval(final Duration minInterval) { |
| 122 | + this.minInterval = minInterval; |
| 123 | + } |
| 124 | + |
| 125 | + /** |
| 126 | + * Get the largest negotiable heartbeat interval. |
| 127 | + * |
| 128 | + * @return the maximum interval |
| 129 | + */ |
| 130 | + public Duration getMaxInterval() { |
| 131 | + return maxInterval; |
| 132 | + } |
| 133 | + |
| 134 | + /** |
| 135 | + * Set the largest negotiable heartbeat interval. |
| 136 | + * |
| 137 | + * @param maxInterval the maximum interval |
| 138 | + */ |
| 139 | + public void setMaxInterval(final Duration maxInterval) { |
| 140 | + this.maxInterval = maxInterval; |
| 141 | + } |
| 142 | + |
| 143 | + /** |
| 144 | + * Get the expiry factor applied to the negotiated interval. |
| 145 | + * |
| 146 | + * @return the expiry factor |
| 147 | + */ |
| 148 | + public int getExpiryFactor() { |
| 149 | + return expiryFactor; |
| 150 | + } |
| 151 | + |
| 152 | + /** |
| 153 | + * Set the expiry factor applied to the negotiated interval. |
| 154 | + * |
| 155 | + * @param expiryFactor the expiry factor |
| 156 | + */ |
| 157 | + public void setExpiryFactor(final int expiryFactor) { |
| 158 | + this.expiryFactor = expiryFactor; |
| 159 | + } |
| 160 | +} |
0 commit comments