From 000eb310f60f2fad46abe1ccf21a229065c21a01 Mon Sep 17 00:00:00 2001 From: sainadh777 <31940823+sainadh777@users.noreply.github.com> Date: Fri, 16 Oct 2026 09:11:23 -0700 Subject: [PATCH] Reuse UDP sender channels --- TODO.md | 10 ---- .../tribes/transport/AbstractSender.java | 4 +- .../TestAbstractSenderKeepAlive.java | 47 +++++++++++++++++++ webapps/docs/changelog.xml | 5 ++ 4 files changed, 53 insertions(+), 13 deletions(-) create mode 100644 test/org/apache/catalina/tribes/transport/TestAbstractSenderKeepAlive.java diff --git a/TODO.md b/TODO.md index 7e3dcc65363e..acdea27cc52c 100644 --- a/TODO.md +++ b/TODO.md @@ -775,16 +775,6 @@ These are bugs, correctness issues, or missing functionality that may affect pro --- -### 71. Tribes UDP Keepalive (1 item) - -| # | File:Line | Description | Fix Idea | Effort | Difficulty | -|---|-----------|-------------|----------|--------|------------| -| 71.1 | `AbstractSender.java:121` | UDP connections always disconnected; keepalive not optimized | Implement UDP keepalive by tracking last activity time and only disconnecting after idle timeout. | 1-2 days | Medium | - -**Total estimated effort: 1-2 days, Medium difficulty** - ---- - ### 72. Tribes NIO Optimization (2 items) | # | File:Line | Description | Fix Idea | Effort | Difficulty | diff --git a/java/org/apache/catalina/tribes/transport/AbstractSender.java b/java/org/apache/catalina/tribes/transport/AbstractSender.java index 7a1aa935f621..c7061ef7e0c7 100644 --- a/java/org/apache/catalina/tribes/transport/AbstractSender.java +++ b/java/org/apache/catalina/tribes/transport/AbstractSender.java @@ -122,9 +122,7 @@ public AbstractSender() { @Override public boolean keepalive() { boolean disconnect = false; - if (isUdpBased()) { - disconnect = true; // always disconnect UDP - } else if (keepAliveCount >= 0 && requestCount > keepAliveCount) { + if (keepAliveCount >= 0 && requestCount > keepAliveCount) { disconnect = true; } else if (keepAliveTime >= 0 && (System.currentTimeMillis() - connectTime) > keepAliveTime) { disconnect = true; diff --git a/test/org/apache/catalina/tribes/transport/TestAbstractSenderKeepAlive.java b/test/org/apache/catalina/tribes/transport/TestAbstractSenderKeepAlive.java new file mode 100644 index 000000000000..cb35816f88c6 --- /dev/null +++ b/test/org/apache/catalina/tribes/transport/TestAbstractSenderKeepAlive.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.catalina.tribes.transport; + +import org.junit.Assert; +import org.junit.Test; + +import org.apache.catalina.tribes.transport.nio.NioSender; + +public class TestAbstractSenderKeepAlive { + + @Test + public void testUdpKeepAlive() { + AbstractSender sender = new NioSender(); + sender.setUdpBased(true); + + Assert.assertFalse(sender.keepalive()); + + sender.setKeepAliveCount(0); + sender.setRequestCount(1); + Assert.assertTrue(sender.keepalive()); + } + + @Test + public void testUdpKeepAliveTime() { + AbstractSender sender = new NioSender(); + sender.setUdpBased(true); + sender.setKeepAliveTime(1000); + sender.setConnectTime(System.currentTimeMillis() - 2000); + + Assert.assertTrue(sender.keepalive()); + } +} diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 30a2281d7582..fcfd5a7c0488 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -688,6 +688,11 @@ + + Reuse UDP sender channels between messages and apply the configured + keepAliveCount and keepAliveTime limits rather + than closing the channel after every message. (sainadh777) + When the MessageDispatchInterceptor is configured with