This is an automated email from the ASF dual-hosted git repository.
rzo1 pushed a commit to branch tomee-10.x
in repository https://gitbox.apache.org/repos/asf/tomee.git
The following commit(s) were added to refs/heads/tomee-10.x by this push:
new f99af2ac5f TOMEE-2044 - let KeepAliveServer find the ServicePool of a
plain service (#3013)
f99af2ac5f is described below
commit f99af2ac5fe19c8a761112c26af2643a7d1bdf96
Author: Richard Zowalla <[email protected]>
AuthorDate: Sun Oct 4 19:33:28 2026 +0200
TOMEE-2044 - let KeepAliveServer find the ServicePool of a plain service
(#3013)
EjbServer hands itself to KeepAliveServer, but the ServicePool wraps
EjbServer from the outside and EjbServer is not Unwrappable, so
getQueue() always returned null and inactive keep-alive sessions were
never closed when the pool queue backed up.
Look the pool up in the ServicePool.Registry instead, matching the pool
that wraps this exact service instance so ejbd, ejbds and httpejbd each
get their own queue.
---
.../openejb/server/ejbd/KeepAliveServer.java | 28 +++++++-
.../server/ejbd/KeepAliveServerPoolTest.java | 83 ++++++++++++++++++++++
2 files changed, 110 insertions(+), 1 deletion(-)
diff --git
a/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/KeepAliveServer.java
b/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/KeepAliveServer.java
index 3ac0f6be18..f9a8b0f08f 100644
---
a/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/KeepAliveServer.java
+++
b/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/KeepAliveServer.java
@@ -18,6 +18,7 @@ package org.apache.openejb.server.ejbd;
import org.apache.openejb.client.FlushableGZIPOutputStream;
import org.apache.openejb.client.KeepAliveStyle;
+import org.apache.openejb.loader.SystemInstance;
import org.apache.openejb.server.ServerService;
import org.apache.openejb.server.ServiceException;
import org.apache.openejb.server.ServicePool;
@@ -161,7 +162,7 @@ public class KeepAliveServer implements ServerService {
private BlockingQueue<Runnable> getQueue() {
if (this.threadQueue == null) {
// this can be null if timer fires before service is fully
initialized
- final ServicePool incoming = Unwrappable.class.isInstance(service)
? Unwrappable.class.cast(service).unwrap(ServicePool.class) : null;
+ final ServicePool incoming = findPool(service);
if (incoming == null) {
return null;
}
@@ -171,6 +172,31 @@ public class KeepAliveServer implements ServerService {
return this.threadQueue;
}
+ /**
+ * Finds the {@link ServicePool} running the given service. The pool wraps
the service,
+ * so a plain service (like {@link EjbServer}) cannot unwrap it and is
looked up among
+ * the started pools instead, matching by identity so each service gets
its own pool.
+ */
+ static ServicePool findPool(final ServerService service) {
+ if (Unwrappable.class.isInstance(service)) {
+ final ServicePool pool =
Unwrappable.class.cast(service).unwrap(ServicePool.class);
+ if (pool != null) {
+ return pool;
+ }
+ }
+
+ final ServicePool.Registry registry =
SystemInstance.get().getComponent(ServicePool.Registry.class);
+ if (registry == null) {
+ return null;
+ }
+ for (final ServicePool pool : registry.getPools()) {
+ if (pool.unwrap(service.getClass()) == service) {
+ return pool;
+ }
+ }
+ return null;
+ }
+
/**
*
* @param session
diff --git
a/server/openejb-ejbd/src/test/java/org/apache/openejb/server/ejbd/KeepAliveServerPoolTest.java
b/server/openejb-ejbd/src/test/java/org/apache/openejb/server/ejbd/KeepAliveServerPoolTest.java
new file mode 100644
index 0000000000..9b26f1cb9f
--- /dev/null
+++
b/server/openejb-ejbd/src/test/java/org/apache/openejb/server/ejbd/KeepAliveServerPoolTest.java
@@ -0,0 +1,83 @@
+/**
+ * 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.openejb.server.ejbd;
+
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.server.ServerServiceFilter;
+import org.apache.openejb.server.ServicePool;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Properties;
+
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+
+public class KeepAliveServerPoolTest {
+
+ @Before
+ public void init() throws Exception {
+ SystemInstance.init(new Properties());
+ }
+
+ @After
+ public void reset() {
+ SystemInstance.reset();
+ }
+
+ @Test
+ public void eachServerFindsItsOwnPool() throws Exception {
+ final EjbServer ejbd = new EjbServer();
+ final EjbServer ejbds = new EjbServer();
+ final ServicePool ejbdPool = new ServicePool(ejbd, 1);
+ final ServicePool ejbdsPool = new ServicePool(new
ServerServiceFilter(ejbds), 1);
+ try {
+ ejbdPool.start();
+ ejbdsPool.start();
+
+ assertSame(ejbdPool, KeepAliveServer.findPool(ejbd));
+ assertSame(ejbdsPool, KeepAliveServer.findPool(ejbds));
+ } finally {
+ ejbdPool.stop();
+ ejbdsPool.stop();
+ ejbdPool.getThreadPool().shutdownNow();
+ ejbdsPool.getThreadPool().shutdownNow();
+ }
+ }
+
+ @Test
+ public void noPoolBeforeStart() {
+ final EjbServer ejbd = new EjbServer();
+ final ServicePool pool = new ServicePool(ejbd, 1);
+ try {
+ assertNull(KeepAliveServer.findPool(ejbd));
+ } finally {
+ pool.getThreadPool().shutdownNow();
+ }
+ }
+
+ @Test
+ public void unwrappableServiceUsesItsPool() {
+ final ServicePool pool = new ServicePool(new EjbServer(), 1);
+ try {
+ assertSame(pool, KeepAliveServer.findPool(pool));
+ } finally {
+ pool.getThreadPool().shutdownNow();
+ }
+ }
+}