From 450be135a69520e4c951cf3a64d397325f5c4c1b Mon Sep 17 00:00:00 2001 From: Boubaker Khanfir Date: Thu, 21 Dec 2023 06:24:56 +0100 Subject: [PATCH] feat: Cleanup Dependencies to rely on Spring Dependencies Tree - Meeds-io/MIPs#57 --- exo.kernel.component.cache/pom.xml | 4 ++-- .../services/cache/impl/CacheServiceImpl.java | 2 +- exo.kernel.component.common/pom.xml | 10 -------- .../jdbc/impl/CloseableDataSource.java | 4 ++++ .../pom.xml | 4 ---- .../container/AbstractContainer.java | 5 ++++ .../container/ConcurrentContainer.java | 9 +++++++ .../container/component/RequestLifeCycle.java | 24 +++++++++++++++++++ .../exoplatform/container/spi/Container.java | 7 ++++++ .../java/org/picocontainer/Startable.java | 4 ++-- 10 files changed, 54 insertions(+), 19 deletions(-) diff --git a/exo.kernel.component.cache/pom.xml b/exo.kernel.component.cache/pom.xml index ea5ccec22..6ab9552e4 100644 --- a/exo.kernel.component.cache/pom.xml +++ b/exo.kernel.component.cache/pom.xml @@ -49,8 +49,8 @@ exo.kernel.component.common - commons-lang - commons-lang + org.apache.commons + commons-lang3 org.exoplatform.kernel diff --git a/exo.kernel.component.cache/src/main/java/org/exoplatform/services/cache/impl/CacheServiceImpl.java b/exo.kernel.component.cache/src/main/java/org/exoplatform/services/cache/impl/CacheServiceImpl.java index 355b06592..3260074fa 100644 --- a/exo.kernel.component.cache/src/main/java/org/exoplatform/services/cache/impl/CacheServiceImpl.java +++ b/exo.kernel.component.cache/src/main/java/org/exoplatform/services/cache/impl/CacheServiceImpl.java @@ -18,7 +18,7 @@ */ package org.exoplatform.services.cache.impl; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.exoplatform.commons.utils.ClassLoading; import org.exoplatform.container.component.ComponentPlugin; import org.exoplatform.container.xml.InitParams; diff --git a/exo.kernel.component.common/pom.xml b/exo.kernel.component.common/pom.xml index 8a5a643d7..f80ecf5c4 100644 --- a/exo.kernel.component.common/pom.xml +++ b/exo.kernel.component.common/pom.xml @@ -119,16 +119,6 @@ commons-dbcp commons-dbcp test - - - xerces - xercesImpl - - - commons-pool - commons-pool - - commons-pool diff --git a/exo.kernel.component.common/src/main/java/org/exoplatform/services/jdbc/impl/CloseableDataSource.java b/exo.kernel.component.common/src/main/java/org/exoplatform/services/jdbc/impl/CloseableDataSource.java index b912050e0..331b3a85b 100644 --- a/exo.kernel.component.common/src/main/java/org/exoplatform/services/jdbc/impl/CloseableDataSource.java +++ b/exo.kernel.component.common/src/main/java/org/exoplatform/services/jdbc/impl/CloseableDataSource.java @@ -75,6 +75,10 @@ public CloseableDataSource(DataSource ds) this.ds = ds; } + public DataSource getDataSource() { + return ds; + } + /** * {@inheritDoc} */ diff --git a/exo.kernel.component.ext.cache.impl.infinispan.v8/pom.xml b/exo.kernel.component.ext.cache.impl.infinispan.v8/pom.xml index 4d2429b9c..111ad2205 100644 --- a/exo.kernel.component.ext.cache.impl.infinispan.v8/pom.xml +++ b/exo.kernel.component.ext.cache.impl.infinispan.v8/pom.xml @@ -88,10 +88,6 @@ org.exoplatform.kernel exo.kernel.container - - commons-lang - commons-lang - diff --git a/exo.kernel.container/src/main/java/org/exoplatform/container/AbstractContainer.java b/exo.kernel.container/src/main/java/org/exoplatform/container/AbstractContainer.java index aecf8fcbe..ae9194978 100644 --- a/exo.kernel.container/src/main/java/org/exoplatform/container/AbstractContainer.java +++ b/exo.kernel.container/src/main/java/org/exoplatform/container/AbstractContainer.java @@ -181,6 +181,11 @@ public ComponentAdapter unregisterComponent(Object componentKey) return delegate.unregisterComponent(componentKey); } + @Override + public void registerComponentAdapter(ComponentAdapter componentAdapter) { + delegate.registerComponentAdapter(componentAdapter); + } + /** * {@inheritDoc} */ diff --git a/exo.kernel.container/src/main/java/org/exoplatform/container/ConcurrentContainer.java b/exo.kernel.container/src/main/java/org/exoplatform/container/ConcurrentContainer.java index 1f6de66ff..b8f15b750 100644 --- a/exo.kernel.container/src/main/java/org/exoplatform/container/ConcurrentContainer.java +++ b/exo.kernel.container/src/main/java/org/exoplatform/container/ConcurrentContainer.java @@ -212,6 +212,15 @@ public List> getComponentAdaptersOfType(Class compone return found; } + @Override + public void registerComponentAdapter(ComponentAdapter componentAdapter) { + Object componentKey = componentAdapter.getComponentKey(); + if (componentKeyToAdapterCache.putIfAbsent(componentKey, componentAdapter) != null) { + throw new ContainerException("Key " + componentKey + " duplicated"); + } + componentAdapters.add(componentAdapter); + } + /** * Register a component via a ComponentAdapter. Use this if you need fine grained control over what * ComponentAdapter to use for a specific component. diff --git a/exo.kernel.container/src/main/java/org/exoplatform/container/component/RequestLifeCycle.java b/exo.kernel.container/src/main/java/org/exoplatform/container/component/RequestLifeCycle.java index b74eebb97..81622909a 100644 --- a/exo.kernel.container/src/main/java/org/exoplatform/container/component/RequestLifeCycle.java +++ b/exo.kernel.container/src/main/java/org/exoplatform/container/component/RequestLifeCycle.java @@ -19,6 +19,7 @@ package org.exoplatform.container.component; import org.exoplatform.container.ExoContainer; +import org.exoplatform.container.ExoContainerContext; import java.util.IdentityHashMap; import java.util.List; @@ -168,6 +169,29 @@ public static Map end() throws IllegalStateException return result; } + protected void restartTransaction() { + restartTransaction(ExoContainerContext.getCurrentContainer()); + } + + protected void restartTransaction(ExoContainer container) { + int i = 0; + // Close transactions until no encapsulated transaction + boolean success = true; + do { + try { + end(); + i++; + } catch (IllegalStateException e) { + success = false; + } + } while (success); + + // Restart transactions with the same number of encapsulations + for (int j = 0; j < i; j++) { + begin(container); + } + } + /** * Check Component Request Lifecycle status * diff --git a/exo.kernel.container/src/main/java/org/exoplatform/container/spi/Container.java b/exo.kernel.container/src/main/java/org/exoplatform/container/spi/Container.java index faa3ef8d2..79690a89d 100644 --- a/exo.kernel.container/src/main/java/org/exoplatform/container/spi/Container.java +++ b/exo.kernel.container/src/main/java/org/exoplatform/container/spi/Container.java @@ -179,6 +179,13 @@ ComponentAdapter registerComponentInstance(Object componentKey, T compone */ ComponentAdapter unregisterComponent(Object componentKey); + /** + * Register a component adapter. + * + * @param componentAdapter ComponentAdapter to register. + */ + void registerComponentAdapter(ComponentAdapter componentAdapter); + /** * Gives the corresponding {@link ManagementContext} */ diff --git a/exo.kernel.container/src/main/java/org/picocontainer/Startable.java b/exo.kernel.container/src/main/java/org/picocontainer/Startable.java index 2977ddca4..e52c28699 100644 --- a/exo.kernel.container/src/main/java/org/picocontainer/Startable.java +++ b/exo.kernel.container/src/main/java/org/picocontainer/Startable.java @@ -37,11 +37,11 @@ public interface Startable /** * Start this component. Called initially at the begin of the lifecycle. It can be called again after a stop. */ - void start(); + default void start() {} /** * Stop this component. Called near the end of the lifecycle. It can be called again after a further start. Implement * {@link Disposable} if you need a single call at the definite end of the lifecycle. */ - void stop(); + default void stop() {} }