diff --git a/exo.kernel.container.mt/pom.xml b/exo.kernel.container.mt/pom.xml deleted file mode 100644 index 8fd80b2d2..000000000 --- a/exo.kernel.container.mt/pom.xml +++ /dev/null @@ -1,164 +0,0 @@ - - - - 4.0.0 - - io.meeds.kernel - kernel-parent - 7.2.x-SNAPSHOT - - exo.kernel.container.mt - Meeds:: PLF:: Kernel :: Container Multi-Threaded - Implementation of Container Multi-Threaded for Exoplatform SAS 'eXo Kernel' project. - - 0.8 - - - - io.meeds.kernel - exo.kernel.container - - - io.meeds.kernel - exo.kernel.container - tests - test - - - javax.inject - javax.inject-tck - 1 - test - - - io.meeds.kernel - exo.kernel.commons.test - test - - - org.javassist - javassist - provided - - - - - - org.apache.maven.plugins - maven-dependency-plugin - - - unpack - generate-test-sources - - unpack - - - - - io.meeds.kernel - exo.kernel.container - test-sources - jar - false - - - **/TestContainer.java - ${project.build.directory}/kernel-container-tests - - - - - - org.codehaus.mojo - build-helper-maven-plugin - - - add-test-resource - generate-test-sources - - add-test-resource - - - - - ${project.build.directory}/kernel-container-tests - - **/TestContainer.java - - - - - - - add-test-source - generate-test-sources - - add-test-source - - - - ${project.build.directory}/kernel-container-tests - - - - - - - maven-antrun-plugin - - - prepare-test-policy - process-test-resources - - - Creating Access Policy for tests - - - - - - - - - - - - - - - - - run - - - - - - - - - debug - - -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y - - - - diff --git a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/CachingContainerMT.java b/exo.kernel.container.mt/src/main/java/org/exoplatform/container/CachingContainerMT.java deleted file mode 100644 index b80d47721..000000000 --- a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/CachingContainerMT.java +++ /dev/null @@ -1,114 +0,0 @@ -/** - * This file is part of the Meeds project (https://meeds.io/). - * - * Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.container; - -import org.exoplatform.container.spi.ContainerException; - -import java.util.Deque; - -public class CachingContainerMT extends CachingContainer -{ - - /** - * The serial version UID - */ - private static final long serialVersionUID = -448537861455415058L; - - /** - * Used to detect all the dependencies not properly defined - */ - protected final transient ThreadLocal> dependencyStacks = Mode - .hasMode(Mode.AUTO_SOLVE_DEP_ISSUES) ? new ThreadLocal>() : null; - - /** - * {@inheritDoc} - */ - @Override - public T getComponentInstanceOfType(Class componentType, boolean autoRegistration) - { - Deque stacks = dependencyStacks != null ? dependencyStacks.get() : null; - DependencyStack stack = null; - T instance; - try - { - if (stacks != null) - { - stack = stacks.getLast(); - stack.add(new DependencyByType(componentType)); - } - instance = super.getComponentInstanceOfType(componentType, autoRegistration); - } - finally - { - if (stack != null && !stack.isEmpty()) - { - stack.removeLast(); - } - } - return instance; - } - - /** - * {@inheritDoc} - */ - @Override - public T getComponentInstance(Object componentKey, Class bindType, boolean autoRegistration) - throws ContainerException - { - Deque stacks = dependencyStacks != null ? dependencyStacks.get() : null; - DependencyStack stack = null; - T instance; - try - { - if (stacks != null) - { - stack = stacks.getLast(); - if (componentKey instanceof String) - { - stack.add(new DependencyByName((String)componentKey, bindType)); - } - else if (componentKey instanceof Class) - { - Class type = (Class)componentKey; - if (type.isAnnotation()) - { - stack.add(new DependencyByQualifier(type, bindType)); - } - else - { - stack.add(new DependencyByType(type)); - } - } - else - { - stack = null; - } - } - instance = super.getComponentInstance(componentKey, bindType, autoRegistration); - } - finally - { - if (stack != null && !stack.isEmpty()) - { - stack.removeLast(); - } - } - return instance; - } -} diff --git a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/ComponentAdapterDependenciesAware.java b/exo.kernel.container.mt/src/main/java/org/exoplatform/container/ComponentAdapterDependenciesAware.java deleted file mode 100644 index 2a8054f7f..000000000 --- a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/ComponentAdapterDependenciesAware.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * This file is part of the Meeds project (https://meeds.io/). - * - * Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.container; - -import org.exoplatform.container.spi.ComponentAdapter; - -import java.util.Collection; - -/** - * This defines a kind of {@link ComponentAdapter} that is aware of its dependencies - * - */ -public interface ComponentAdapterDependenciesAware extends ComponentAdapter -{ - - /** - * Gives the create dependencies of the component - * @return a {@link Collection} of {@link Dependency} objects representing the - * dependencies of the component for the creation phase - */ - Collection getCreateDependencies(); - - /** - * Gives the initialization dependencies of the component - * @return a {@link Collection} of {@link Dependency} objects representing the - * dependencies of the component for the initialization phase - */ - Collection getInitDependencies(); -} diff --git a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/ComponentTask.java b/exo.kernel.container.mt/src/main/java/org/exoplatform/container/ComponentTask.java deleted file mode 100644 index 04d1d4cbd..000000000 --- a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/ComponentTask.java +++ /dev/null @@ -1,112 +0,0 @@ -/** - * This file is part of the Meeds project (https://meeds.io/). - * - * Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.container; - -import org.exoplatform.container.ConcurrentContainer.CreationalContextComponentAdapter; - -/** - * This class represents a task to be launched to change the state of a component - * - */ -public abstract class ComponentTask -{ - - /** - * The name of the task - */ - private final String name; - - /** - * The container that holds the component - */ - private final ConcurrentContainerMT container; - - /** - * The component that expects to be notified any time we - * try to access to a dependency non properly declared - */ - private final DependencyStackListener caller; - - /** - * The type of the task - */ - private final ComponentTaskType type; - - /** - * The main constructor of a task - */ - public ComponentTask(ConcurrentContainerMT container, DependencyStackListener caller, ComponentTaskType type) - { - this(null, container, caller, type); - } - - /** - * The main constructor of a task - */ - public ComponentTask(String name, ConcurrentContainerMT container, DependencyStackListener caller, - ComponentTaskType type) - { - this.name = name; - this.container = container; - this.caller = caller; - this.type = type; - } - - /** - * @return the name - */ - public String getName() - { - return name; - } - - /** - * @return the container - */ - public ConcurrentContainerMT getContainer() - { - return container; - } - - /** - * @return the caller - */ - public DependencyStackListener getCaller() - { - return caller; - } - - /** - * @return the type of the task - */ - public ComponentTaskType getType() - { - return type; - } - - public final T call(CreationalContextComponentAdapter cCtx) throws Exception - { - return container.execute(this, cCtx); - } - - /** - * This is what is actually executed - */ - protected abstract T execute(CreationalContextComponentAdapter cCtx) throws Exception; -} diff --git a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/ComponentTaskContext.java b/exo.kernel.container.mt/src/main/java/org/exoplatform/container/ComponentTaskContext.java deleted file mode 100644 index 206f60790..000000000 --- a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/ComponentTaskContext.java +++ /dev/null @@ -1,247 +0,0 @@ -/** - * This file is part of the Meeds project (https://meeds.io/). - * - * Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.container; - -import org.exoplatform.container.ConcurrentContainer.CreationalContextComponentAdapter; - -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.Map; - -import javax.enterprise.context.spi.CreationalContext; - -public class ComponentTaskContext -{ - /** - * A {@link LinkedHashSet} representing the dependency stack - */ - private final LinkedHashSet dependencies; - - /** - * The last dependency that has been added to the context - */ - private final ComponentTaskContextEntry lastDependency; - - /** - * The last task type known - */ - private final ComponentTaskType lastTaskType; - - /** - * Context used to keep in memory the components that are currently being created. - * This context is used to prevent cyclic resolution due to component plugins. - */ - private Map> depResolutionCtx; - - private ComponentTaskContext(LinkedHashSet dependencies, - Map> depResolutionCtx, ComponentTaskContextEntry lastDependency, - ComponentTaskType lastTaskType) - { - this.dependencies = dependencies; - this.depResolutionCtx = depResolutionCtx; - this.lastDependency = lastDependency; - this.lastTaskType = lastTaskType; - } - - /** - * Default constructor - */ - public ComponentTaskContext(Object componentKey, ComponentTaskType type) - { - LinkedHashSet dependencies = new LinkedHashSet(); - ComponentTaskContextEntry entry = new ComponentTaskContextEntry(componentKey, type); - dependencies.add(entry); - this.dependencies = dependencies; - this.lastDependency = entry; - this.lastTaskType = type; - } - - /** - * Defines explicitly the last task type known - */ - public ComponentTaskContext setLastTaskType(ComponentTaskType lastTaskType) - { - return new ComponentTaskContext(dependencies, depResolutionCtx == null ? null - : new HashMap>(depResolutionCtx), - lastDependency, lastTaskType); - } - - /** - * This method will call {@link #addToContext(Object, ComponentTaskType)} with the lastTaskType as type - */ - public ComponentTaskContext addToContext(Object componentKey) throws CyclicDependencyException - { - return addToContext(componentKey, lastTaskType); - } - - /** - * Creates a new {@link ComponentTaskContext} based on the given dependency and the - * already registered ones. If the dependency has already been registered - * a {@link CyclicDependencyException} will be thrown. - */ - public ComponentTaskContext addToContext(Object componentKey, ComponentTaskType type) - throws CyclicDependencyException - { - ComponentTaskContextEntry entry = new ComponentTaskContextEntry(componentKey, type); - checkDependency(entry); - LinkedHashSet dependencies = - new LinkedHashSet(this.dependencies); - dependencies.add(entry); - return new ComponentTaskContext(dependencies, depResolutionCtx == null ? null - : new HashMap>(depResolutionCtx), entry, type); - } - - /** - * Checks if the given dependency has already been defined, if so a {@link CyclicDependencyException} - * will be thrown. - */ - public void checkDependency(Object componentKey, ComponentTaskType type) throws CyclicDependencyException - { - ComponentTaskContextEntry entry = new ComponentTaskContextEntry(componentKey, type); - checkDependency(entry); - } - - /** - * Indicates whether the provided componentKey is the last dependency that has been added to the context. - * @return true if the dependency is the last, false otherwise. - */ - public boolean isLast(Object componentKey) - { - ComponentTaskContextEntry entry = new ComponentTaskContextEntry(componentKey, lastTaskType); - return lastDependency.equals(entry); - } - - /** - * Checks if the given dependency has already been defined, if so a {@link CyclicDependencyException} - * will be thrown. - */ - private void checkDependency(ComponentTaskContextEntry entry) - { - if (entry.getTaskType() == ComponentTaskType.CREATE - && dependencies.contains(entry) - && (depResolutionCtx == null || !depResolutionCtx.containsKey(entry.getComponentKey()) || depResolutionCtx - .get(entry.getComponentKey()).get() == null)) - { - boolean startToCheck = false; - Boolean sameType = null; - for (ComponentTaskContextEntry e : dependencies) - { - if (startToCheck) - { - if (e.getTaskType() != entry.getTaskType()) - { - sameType = Boolean.FALSE; - break; - } - sameType = Boolean.TRUE; - } - else if (entry.equals(e)) - { - startToCheck = true; - } - } - if (sameType != null && sameType.booleanValue()) - { - throw new CyclicDependencyException(entry, sameType); - } - } - } - - /** - * @return indicates whether the current context is the root context or not. - */ - public boolean isRoot() - { - return dependencies.size() == 1; - } - - /** - * Adds the {@link CreationalContext} of the component corresponding to the given key, to the dependency resolution - * context - * @param key The key of the component to add to the context - * @param ctx The {@link CreationalContext} of the component to add to the context - * @return {@link CreationalContextComponentAdapter} instance that has been put into the map - */ - @SuppressWarnings("unchecked") - public CreationalContextComponentAdapter addComponentToContext(Object key, - CreationalContextComponentAdapter ctx) - { - if (depResolutionCtx == null) - { - depResolutionCtx = new HashMap>(); - depResolutionCtx.put(key, ctx); - return ctx; - } - CreationalContextComponentAdapter prevValue = depResolutionCtx.get(key); - if (prevValue == null) - { - depResolutionCtx.put(key, ctx); - return ctx; - } - return (CreationalContextComponentAdapter)prevValue; - } - - /** - * Removes the {@link CreationalContext} of the component corresponding to the given key, from the dependency resolution - * context - * @param key The key of the component to remove from the context - */ - public CreationalContextComponentAdapter removeComponentFromContext(Object key) - { - if (depResolutionCtx == null) - return null; - return depResolutionCtx.remove(key); - } - - /** - * Tries to get the component related to the given from the context, if it can be found the current state of the component - * instance is returned, otherwise null is returned - */ - public T getComponentInstanceFromContext(Object key, Class bindType) - { - if (depResolutionCtx == null) - return null; - CreationalContextComponentAdapter ctx = depResolutionCtx.get(key); - return ctx == null ? null : bindType.cast(ctx.get()); - } - - /** - * Resets the dependencies but keeps the current dependency resolution context. - * @param key the key of the new first dependency - * @param type the type of the corresponding task - * @return a {@link ComponentTaskContext} instance with the dependencies reseted - */ - public ComponentTaskContext resetDependencies(Object key, ComponentTaskType type) - { - LinkedHashSet dependencies = new LinkedHashSet(); - ComponentTaskContextEntry entry = new ComponentTaskContextEntry(key, type); - dependencies.add(entry); - return new ComponentTaskContext(dependencies, depResolutionCtx == null ? null - : new HashMap>(depResolutionCtx), entry, type); - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() - { - return "ComponentTaskContext [dependencies=" + dependencies + ", depResolutionCtx=" + depResolutionCtx + "]"; - } -} diff --git a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/ComponentTaskContextEntry.java b/exo.kernel.container.mt/src/main/java/org/exoplatform/container/ComponentTaskContextEntry.java deleted file mode 100644 index 5901e92a1..000000000 --- a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/ComponentTaskContextEntry.java +++ /dev/null @@ -1,105 +0,0 @@ -/** - * This file is part of the Meeds project (https://meeds.io/). - * - * Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.container; - -public class ComponentTaskContextEntry -{ - - /** - * The key of the dependency - */ - private final Object componentKey; - - /** - * Indicates the type of the task for which the dependency is needed. - */ - private final ComponentTaskType type; - - /** - * Default constructor - */ - public ComponentTaskContextEntry(Object componentKey, ComponentTaskType type) - { - this.componentKey = componentKey; - this.type = type; - } - - /** - * @return the key of the dependency - */ - public Object getComponentKey() - { - return componentKey; - } - - /** - * @return the type of the task for which this dependency is needed. - */ - public ComponentTaskType getTaskType() - { - return type; - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = prime * result + ((componentKey == null) ? 0 : componentKey.hashCode()); - result = prime * result + ((type == null) ? 0 : type.hashCode()); - return result; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) - { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ComponentTaskContextEntry other = (ComponentTaskContextEntry)obj; - if (componentKey == null) - { - if (other.componentKey != null) - return false; - } - else if (!componentKey.equals(other.componentKey)) - return false; - if (type != other.type) - return false; - return true; - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() - { - return "ComponentTaskContextEntry [componentKey=" + componentKey + ", type=" + type + "]"; - } -} diff --git a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/ComponentTaskType.java b/exo.kernel.container.mt/src/main/java/org/exoplatform/container/ComponentTaskType.java deleted file mode 100644 index e66aa48e0..000000000 --- a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/ComponentTaskType.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * This file is part of the Meeds project (https://meeds.io/). - * - * Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.container; - -/** - * All the possible type of task that we can launch against a component - * - */ -public enum ComponentTaskType -{ - CREATE, INIT; -} diff --git a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/ConcurrentContainerMT.java b/exo.kernel.container.mt/src/main/java/org/exoplatform/container/ConcurrentContainerMT.java deleted file mode 100644 index 16e277c5b..000000000 --- a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/ConcurrentContainerMT.java +++ /dev/null @@ -1,1265 +0,0 @@ -/** - * This file is part of the Meeds project (https://meeds.io/). - * - * Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.container; - -import org.exoplatform.commons.utils.PropertyManager; -import org.exoplatform.container.management.ManageableComponentAdapterFactoryMT; -import org.exoplatform.container.spi.ComponentAdapter; -import org.exoplatform.container.spi.ComponentAdapterFactory; -import org.exoplatform.container.spi.ContainerException; -import org.exoplatform.container.util.ContainerUtil; -import org.exoplatform.container.xml.InitParams; -import org.exoplatform.services.log.ExoLogger; -import org.exoplatform.services.log.Log; -import org.picocontainer.Startable; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Deque; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.Callable; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.RunnableFuture; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Provider; -import javax.inject.Qualifier; - -public class ConcurrentContainerMT extends ConcurrentContainer implements TopExoContainerListener -{ - - /** - * The serial version UID - */ - private static final long serialVersionUID = -1059330085804288350L; - - private static final Log LOG = ExoLogger.getLogger("exo.kernel.container.mt.ConcurrentContainerMT"); - - private static volatile transient ThreadPoolExecutor EXECUTOR; - - private final transient ThreadLocal currentCtx = new ThreadLocal(); - - /** - * Needed to fix the deadlocks - */ - private final transient ConcurrentMap> sharedMemory = - new ConcurrentHashMap>(); - - /** - * The name of the system parameter to indicate the total amount of threads to use for the kernel - */ - public static final String THREAD_POOL_SIZE_PARAM_NAME = "org.exoplatform.container.mt.tps"; - - private static ThreadPoolExecutor getExecutor() - { - if (EXECUTOR == null && Mode.hasMode(Mode.MULTI_THREADED)) - { - synchronized (ConcurrentContainerMT.class) - { - if (EXECUTOR == null) - { - String sValue = PropertyManager.getProperty(THREAD_POOL_SIZE_PARAM_NAME); - int threadPoolSize; - if (sValue != null) - { - LOG.debug("A value for the thread pool size has been found, it has been set to '" + sValue + "'"); - threadPoolSize = Integer.parseInt(sValue); - } - else - { - threadPoolSize = Math.min(2 * Runtime.getRuntime().availableProcessors(), 30); - } - LOG.debug("The size of the thread pool used by the kernel has been set to " + threadPoolSize); - EXECUTOR = new KernelThreadPoolExecutor(threadPoolSize); - } - } - } - return EXECUTOR; - } - - /** - * Creates a new container with the default {@link ComponentAdapterFactory} and a parent container. - */ - public ConcurrentContainerMT() - { - } - - /** - * Creates a new container with the default {@link ComponentAdapterFactory} and a parent container. - * - * @param holder the holder of the container - * @param parent the parent container (used for component dependency lookups). - */ - public ConcurrentContainerMT(ExoContainer holder, ExoContainer parent) - { - setParent(parent); - setHolder(holder); - } - - /** - * {@inheritDoc} - */ - @Override - public void initialize() - { - if (holder instanceof TopExoContainer) - { - ((TopExoContainer)holder).addListener(this); - } - } - - @Override - protected ComponentAdapterFactory getDefaultComponentAdapterFactory() - { - return new ManageableComponentAdapterFactoryMT(holder, this); - } - - /** - * {@inheritDoc} - */ - @Override - protected T getComponentInstanceFromContext(ComponentAdapter componentAdapter, Class bindType) - { - ComponentTaskContext ctx = currentCtx.get(); - if (ctx != null) - { - T result = ctx.getComponentInstanceFromContext(componentAdapter.getComponentKey(), bindType); - if (result != null) - { - // Don't keep in cache a component that has not been created yet - getCache().disable(); - return result; - } - } - return null; - } - - /** - * Gives a value from the shared memory - */ - @SuppressWarnings("unchecked") - public T getComponentFromSharedMemory(Object key) - { - CreationalContextComponentAdapter ccca = sharedMemory.get(key); - return ccca == null ? null : (T)ccca.get(); - } - - /** - * {@inheritDoc} - */ - @Override - public CreationalContextComponentAdapter addComponentToCtx(Object key) - { - ComponentTaskContext ctx = currentCtx.get(); - CreationalContextComponentAdapter ccca = new CreationalContextComponentAdapter(); - sharedMemory.put(key, ccca); - return ctx.addComponentToContext(key, ccca); - } - - /** - * {@inheritDoc} - */ - @Override - public void removeComponentFromCtx(Object key) - { - ComponentTaskContext ctx = currentCtx.get(); - CreationalContextComponentAdapter ccca = ctx.removeComponentFromContext(key); - sharedMemory.remove(key, ccca); - } - - /** - * A multi-threaded implementation of the start method - */ - public List getComponentInstancesOfType(final Class componentType) throws ContainerException - { - if (componentType == null) - { - return Collections.emptyList(); - } - List> adapters = getComponentAdaptersOfType(componentType); - if (adapters == null || adapters.isEmpty()) - return Collections.emptyList(); - boolean enableMultiThreading = Mode.hasMode(Mode.MULTI_THREADED) && adapters.size() > 1; - List> submittedTasks = null; - final Map, Object> adapterToInstanceMap = - enableMultiThreading ? new ConcurrentHashMap, Object>() - : new HashMap, Object>(); - ThreadPoolExecutor executor = enableMultiThreading ? getExecutor() : null; - if (enableMultiThreading && executor == null) - { - enableMultiThreading = false; - } - for (final ComponentAdapter adapter : adapters) - { - if (enableMultiThreading && LockManager.getInstance().getTotalUncompletedTasks() < executor.getCorePoolSize() - && !(adapter instanceof InstanceComponentAdapter)) - { - final ExoContainer container = ExoContainerContext.getCurrentContainerIfPresent(); - final ClassLoader cl = Thread.currentThread().getContextClassLoader(); - Runnable task = new Runnable() - { - public void run() - { - ExoContainer oldContainer = ExoContainerContext.getCurrentContainerIfPresent(); - ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); - try - { - ExoContainerContext.setCurrentContainer(container); - Thread.currentThread().setContextClassLoader(cl); - Object o = getInstance(adapter, componentType, false); - if (o != null) - adapterToInstanceMap.put(adapter, o); - // This is to ensure all are added. (Indirect dependencies will be added - // from InstantiatingComponentAdapter). - addOrderedComponentAdapter(adapter); - } - finally - { - Thread.currentThread().setContextClassLoader(oldCl); - ExoContainerContext.setCurrentContainer(oldContainer); - } - } - }; - if (submittedTasks == null) - { - submittedTasks = new ArrayList>(); - } - submittedTasks.add(executor.submit(task)); - } - else if (enableMultiThreading) - { - Object o = getInstance(adapter, componentType, false); - if (o != null) - adapterToInstanceMap.put(adapter, o); - // This is to ensure all are added. (Indirect dependencies will be added - // from InstantiatingComponentAdapter). - addOrderedComponentAdapter(adapter); - } - else - { - adapterToInstanceMap.put(adapter, getInstance(adapter, componentType, false)); - // This is to ensure all are added. (Indirect dependencies will be added - // from InstantiatingComponentAdapter). - addOrderedComponentAdapter(adapter); - } - } - if (submittedTasks != null) - { - for (int i = 0, length = submittedTasks.size(); i < length; i++) - { - Future task = submittedTasks.get(i); - try - { - task.get(); - } - catch (ExecutionException e) - { - Throwable cause = e.getCause(); - if (cause instanceof RuntimeException) - { - throw (RuntimeException)cause; - } - throw new RuntimeException(cause); - } - catch (InterruptedException e) - { - Thread.currentThread().interrupt(); - } - } - } - List result = new ArrayList(); - for (Iterator> iterator = orderedComponentAdapters.iterator(); iterator.hasNext();) - { - Object componentAdapter = iterator.next(); - final Object componentInstance = adapterToInstanceMap.get(componentAdapter); - if (componentInstance != null) - { - // may be null in the case of the "implicit" adapter - // representing "this". - result.add(componentType.cast(componentInstance)); - } - } - return result; - } - - /** - * A multi-threaded implementation of the start method - */ - @Override - public void start() - { - // First we get the context manager to prevent deadlock - holder.getContextManager(); - // Then, create and initialize the components - getComponentInstancesOfType(Startable.class); - Object startables = getComponentAdaptersOfType(Startable.class); - @SuppressWarnings("unchecked") - List> adapters = (List>)startables; - final Map, Object> alreadyStarted = new ConcurrentHashMap, Object>(); - final AtomicReference error = new AtomicReference(); - // We first start all the non containers - start(adapters, alreadyStarted, new HashSet>(), error, true); - if (error.get() != null) - { - throw new RuntimeException("Could not start the container", error.get()); - } - // Then we start the sub containers - for (Iterator iterator = children.iterator(); iterator.hasNext();) - { - ExoContainer child = iterator.next(); - child.start(); - } - } - - /** - * Starts all the provided adapters - */ - protected void start(Collection> adapters, - final Map, Object> alreadyStarted, final Set> startInProgress, - final AtomicReference error, final boolean skippable) - { - if (adapters == null || adapters.isEmpty()) - return; - boolean enableMultiThreading = Mode.hasMode(Mode.MULTI_THREADED) && adapters.size() > 1; - List> submittedTasks = null; - ThreadPoolExecutor executor = enableMultiThreading ? getExecutor() : null; - if (enableMultiThreading && executor == null) - { - enableMultiThreading = false; - } - for (final ComponentAdapter adapter : adapters) - { - if (error.get() != null) - break; - if (ExoContainer.class.isAssignableFrom(adapter.getComponentImplementation())) - { - // Only non containers are expected and it is a container - continue; - } - else if (alreadyStarted.containsKey(adapter) || (skippable && startInProgress.contains(adapter))) - { - // The component has already been started or is in progress - continue; - } - if (enableMultiThreading && LockManager.getInstance().getTotalUncompletedTasks() < executor.getCorePoolSize() - && !(adapter instanceof InstanceComponentAdapter)) - { - final ExoContainer container = ExoContainerContext.getCurrentContainerIfPresent(); - final ClassLoader cl = Thread.currentThread().getContextClassLoader(); - Runnable task = new Runnable() - { - public void run() - { - if (error.get() != null) - { - return; - } - else if (alreadyStarted.containsKey(adapter) - || (skippable && startInProgress.contains(adapter))) - { - // The component has already been started or is in progress - return; - } - ExoContainer oldContainer = ExoContainerContext.getCurrentContainerIfPresent(); - ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); - try - { - ExoContainerContext.setCurrentContainer(container); - Thread.currentThread().setContextClassLoader(cl); - if (adapter instanceof ComponentAdapterDependenciesAware) - { - ComponentAdapterDependenciesAware cada = (ComponentAdapterDependenciesAware)adapter; - startDependencies(alreadyStarted, startInProgress, error, cada); - } - if (!Startable.class.isAssignableFrom(adapter.getComponentImplementation())) - { - alreadyStarted.put(adapter, adapter); - return; - } - else if (alreadyStarted.containsKey(adapter)) - { - // The component has already been started - return; - } - synchronized (adapter) - { - if (alreadyStarted.containsKey(adapter)) - { - // The component has already been started - return; - } - try - { - Startable startable = (Startable)adapter.getComponentInstance(); - startable.start(); - } - finally - { - alreadyStarted.put(adapter, adapter); - } - } - } - catch (Exception e) - { - error.compareAndSet(null, e); - } - finally - { - Thread.currentThread().setContextClassLoader(oldCl); - ExoContainerContext.setCurrentContainer(oldContainer); - } - } - }; - if (submittedTasks == null) - { - submittedTasks = new ArrayList>(); - } - submittedTasks.add(executor.submit(task)); - } - else - { - if (adapter instanceof ComponentAdapterDependenciesAware) - { - ComponentAdapterDependenciesAware cada = (ComponentAdapterDependenciesAware)adapter; - startDependencies(alreadyStarted, startInProgress, error, cada); - } - if (!Startable.class.isAssignableFrom(adapter.getComponentImplementation())) - { - alreadyStarted.put(adapter, adapter); - continue; - } - else if (alreadyStarted.containsKey(adapter)) - { - // The component has already been started - continue; - } - synchronized (adapter) - { - if (alreadyStarted.containsKey(adapter)) - { - // The component has already been started - continue; - } - try - { - Startable startable = (Startable)adapter.getComponentInstance(); - startable.start(); - } - catch (Exception e) - { - error.compareAndSet(null, e); - } - finally - { - alreadyStarted.put(adapter, adapter); - } - } - } - } - if (submittedTasks != null) - { - for (int i = 0, length = submittedTasks.size(); i < length; i++) - { - Future task = submittedTasks.get(i); - try - { - task.get(); - } - catch (ExecutionException e) - { - Throwable cause = e.getCause(); - if (cause instanceof RuntimeException) - { - throw (RuntimeException)cause; - } - throw new RuntimeException(cause); - } - catch (InterruptedException e) - { - Thread.currentThread().interrupt(); - } - } - } - } - - private Collection> getDependencies(Collection dependencies, boolean withLazy, - boolean withNonLazy) - { - if (dependencies == null || dependencies.isEmpty()) - return null; - Collection> result = new LinkedHashSet>(); - for (Dependency dep : dependencies) - { - if ((dep.isLazy() && !withLazy) || (!dep.isLazy() && !withNonLazy)) - continue; - ComponentAdapter adapter = dep.getAdapter(holder); - boolean isLocal = componentAdapters.contains(adapter); - if (!isLocal) - { - // To prevent infinite loop we assume that component adapters of - // parent container are already started so we skip them - continue; - } - result.add(adapter); - } - return result; - } - - @SuppressWarnings("unchecked") - public Constructor getConstructor(Class clazz, List dependencies) throws Exception - { - Constructor[] constructors = new Constructor[0]; - try - { - constructors = ContainerUtil.getSortedConstructors(clazz); - } - catch (NoClassDefFoundError err) - { - throw new Exception("Cannot resolve constructor for class " + clazz.getName(), err); - } - Class unknownParameter = null; - for (int k = 0; k < constructors.length; k++) - { - Constructor constructor = constructors[k]; - Class[] parameters = constructor.getParameterTypes(); - Object[] args = new Object[parameters.length]; - boolean constructorWithInject = constructors.length == 1 && constructor.isAnnotationPresent(Inject.class); - boolean satisfied = true; - String logMessagePrefix = null; - Type[] genericTypes = null; - Annotation[][] parameterAnnotations = null; - if (constructorWithInject) - { - genericTypes = constructor.getGenericParameterTypes(); - parameterAnnotations = constructor.getParameterAnnotations(); - } - if (LOG.isDebugEnabled() && constructorWithInject) - { - logMessagePrefix = "Could not call the constructor of the class " + clazz.getName(); - } - for (int i = 0; i < args.length; i++) - { - if (!parameters[i].equals(InitParams.class)) - { - if (constructorWithInject) - { - Object result = - resolveType(parameters[i], genericTypes[i], parameterAnnotations[i], logMessagePrefix, - dependencies); - if (!(result instanceof Integer)) - { - args[i] = result; - } - } - else - { - final Class componentType = parameters[i]; - args[i] = holder.getComponentAdapterOfType(componentType); - dependencies.add(new DependencyByType(componentType)); - } - if (args[i] == null) - { - satisfied = false; - unknownParameter = parameters[i]; - dependencies.clear(); - break; - } - } - } - if (satisfied) - { - if ((!Modifier.isPublic(constructor.getModifiers()) || !Modifier.isPublic(constructor.getDeclaringClass() - .getModifiers())) && !constructor.isAccessible()) - constructor.setAccessible(true); - return (Constructor)constructor; - } - } - throw new Exception("Cannot find a satisfying constructor for " + clazz + " with parameter " + unknownParameter); - } - - /** - * Initializes the instance by injecting objects into fields and the methods with the - * annotation {@link Inject} - * @return true if at least Inject annotation has been found, false otherwise - */ - public boolean initializeComponent(Class targetClass, List dependencies, - List> componentInitTasks, DependencyStackListener caller) - { - LinkedList> hierarchy = new LinkedList>(); - Class clazz = targetClass; - do - { - hierarchy.addFirst(clazz); - } - while (!(clazz = clazz.getSuperclass()).equals(Object.class)); - // Fields and methods in superclasses are injected before those in subclasses. - Map methodAlreadyRegistered = new HashMap(); - Map, Collection> methodsPerClass = new HashMap, Collection>(); - for (Class c : hierarchy) - { - addMethods(c, methodAlreadyRegistered, methodsPerClass); - } - boolean isInjectPresent = !methodAlreadyRegistered.isEmpty(); - for (Class c : hierarchy) - { - if (initializeFields(targetClass, c, dependencies, componentInitTasks, caller)) - { - isInjectPresent = true; - } - initializeMethods(targetClass, methodsPerClass.get(c), dependencies, componentInitTasks, caller); - } - return isInjectPresent; - } - - /** - * Initializes the instance by calling all the methods with the - * annotation {@link Inject} - */ - private void initializeMethods(final Class targetClass, Collection methods, - List dependencies, List> componentInitTasks, DependencyStackListener caller) - { - if (methods == null) - { - return; - } - main : for (final Method m : methods) - { - if (m.isAnnotationPresent(Inject.class)) - { - if (Modifier.isAbstract(m.getModifiers())) - { - LOG.warn("Could not call the method " + m.getName() + " of the class " + targetClass.getName() - + ": The method cannot be abstract"); - continue; - } - else if (Modifier.isStatic(m.getModifiers())) - { - LOG.warn("Could not call the method " + m.getName() + " of the class " + targetClass.getName() - + ": The method cannot be static"); - continue; - } - // The method is annotated with Inject and is not abstract and has not been called yet - Class[] paramTypes = m.getParameterTypes(); - final Object[] params = new Object[paramTypes.length]; - Type[] genericTypes = m.getGenericParameterTypes(); - Annotation[][] parameterAnnotations = m.getParameterAnnotations(); - String logMessagePrefix = null; - if (LOG.isDebugEnabled()) - { - logMessagePrefix = "Could not call the method " + m.getName() + " of the class " + targetClass.getName(); - } - for (int j = 0, l = paramTypes.length; j < l; j++) - { - Object result = - resolveType(paramTypes[j], genericTypes[j], parameterAnnotations[j], logMessagePrefix, dependencies); - if (result instanceof Integer) - { - int r = (Integer)result; - if (r == 1 || r == 2) - { - continue main; - } - params[j] = null; - continue; - } - else - { - params[j] = dependencies.get(dependencies.size() - 1); - } - } - try - { - if ((!Modifier.isPublic(m.getModifiers()) || !Modifier.isPublic(m.getDeclaringClass().getModifiers())) - && !m.isAccessible()) - m.setAccessible(true); - componentInitTasks.add(new ComponentTask("Call the method " + m.getName() + " of the class " - + targetClass.getName(), this, caller, ComponentTaskType.INIT) - { - public Void execute(CreationalContextComponentAdapter cCtx) throws Exception - { - try - { - loadArguments(params); - m.invoke(cCtx.get(), params); - } - catch (Exception e) - { - throw new RuntimeException("Could not call the method " + m.getName() + " of the class " - + targetClass.getName() + ": " + e.getMessage(), e); - } - return null; - } - }); - } - catch (Exception e) - { - throw new RuntimeException("Could not call the method " + m.getName() + " of the class " - + targetClass.getName() + ": " + e.getMessage(), e); - } - } - } - } - - /** - * Initializes the fields of the instance by injecting objects into fields with the - * annotation {@link Inject} for a given class - */ - private boolean initializeFields(final Class targetClass, Class clazz, List dependencies, - List> componentInitTasks, DependencyStackListener caller) - { - boolean isInjectPresent = false; - Field[] fields = clazz.getDeclaredFields(); - for (int i = 0, length = fields.length; i < length; i++) - { - final Field f = fields[i]; - if (f.isAnnotationPresent(Inject.class)) - { - isInjectPresent = true; - if (Modifier.isFinal(f.getModifiers())) - { - LOG.warn("Could not set a value to the field " + f.getName() + " of the class " + targetClass.getName() - + ": The field cannot be final"); - continue; - } - else if (Modifier.isStatic(f.getModifiers())) - { - LOG.warn("Could not set a value to the field " + f.getName() + " of the class " + targetClass.getName() - + ": The field cannot be static"); - continue; - } - // The field is annotated with Inject and is not final and/or static - try - { - if ((!Modifier.isPublic(f.getModifiers()) || !Modifier.isPublic(f.getDeclaringClass().getModifiers())) - && !f.isAccessible()) - f.setAccessible(true); - String logMessagePrefix = null; - if (LOG.isDebugEnabled()) - { - logMessagePrefix = - "Could not set a value to the field " + f.getName() + " of the class " + targetClass.getName(); - } - Object result = - resolveType(f.getType(), f.getGenericType(), f.getAnnotations(), logMessagePrefix, dependencies); - if (result instanceof Integer) - { - continue; - } - final Dependency dependency = dependencies.get(dependencies.size() - 1); - componentInitTasks.add(new ComponentTask("Set a value to the field " + f.getName() - + " of the class " + targetClass.getName(), this, caller, ComponentTaskType.INIT) - { - public Void execute(CreationalContextComponentAdapter cCtx) throws Exception - { - try - { - f.set(cCtx.get(), dependency.load(holder)); - } - catch (Exception e) - { - throw new RuntimeException("Could not set a value to the field " + f.getName() - + " of the class " + targetClass.getName() + ": " + e.getMessage(), e); - } - return null; - } - }); - } - catch (Exception e) - { - throw new RuntimeException("Could not set a value to the field " + f.getName() + " of the class " - + targetClass.getName() + ": " + e.getMessage(), e); - } - } - } - return isInjectPresent; - } - - /** - * Resolves the given type and generic type - */ - private Object resolveType(final Class type, Type genericType, Annotation[] annotations, String logMessagePrefix, - List dependencies) - { - if (type.isPrimitive()) - { - if (LOG.isDebugEnabled()) - { - LOG.debug(logMessagePrefix + ": Primitive types are not supported"); - } - return 1; - } - Named named = null; - Class qualifier = null; - for (int i = 0, length = annotations.length; i < length; i++) - { - Annotation a = annotations[i]; - if (a instanceof Named) - { - named = (Named)a; - break; - } - else if (a.annotationType().isAnnotationPresent(Qualifier.class)) - { - qualifier = a.annotationType(); - break; - } - } - if (type.isInterface() && type.equals(Provider.class)) - { - if (!(genericType instanceof ParameterizedType)) - { - if (LOG.isDebugEnabled()) - { - LOG.debug(logMessagePrefix + ": The generic type is not of type ParameterizedType"); - } - return 2; - } - ParameterizedType aType = (ParameterizedType)genericType; - Type[] typeVars = aType.getActualTypeArguments(); - Class expectedType = (Class)typeVars[0]; - final ComponentAdapter adapter; - final Object key; - if (named != null) - { - adapter = holder.getComponentAdapter(key = named.value(), expectedType); - } - else if (qualifier != null) - { - adapter = holder.getComponentAdapter(key = qualifier, expectedType); - } - else - { - key = expectedType; - adapter = holder.getComponentAdapterOfType(expectedType); - } - - if (adapter == null) - { - if (LOG.isDebugEnabled()) - { - LOG.debug(logMessagePrefix + ": We have no value to set so we skip it"); - } - return 3; - } - final Provider result = new Provider() - { - public Object get() - { - return adapter.getComponentInstance(); - } - }; - dependencies.add(new DependencyByProvider(key, expectedType, result, adapter)); - return result; - } - else - { - if (named != null) - { - final String name = named.value(); - dependencies.add(new DependencyByName(name, type)); - return holder.getComponentAdapter(name, type); - } - else if (qualifier != null) - { - dependencies.add(new DependencyByQualifier(qualifier, type)); - return holder.getComponentAdapter(qualifier, type); - } - else - { - dependencies.add(new DependencyByType(type)); - return holder.getComponentAdapterOfType(type); - } - } - } - - public T createComponent(Class clazz) throws Exception - { - return createComponent(clazz, null); - } - - public T createComponent(Class clazz, InitParams params) throws Exception - { - List dependencies = new ArrayList(); - Constructor constructor = getConstructor(clazz, dependencies); - final Object[] args = getArguments(constructor, params, dependencies); - loadArguments(args); - return constructor.getDeclaringClass().cast(constructor.newInstance(args)); - } - - public ComponentTask createComponentTask(final Constructor constructor, InitParams params, - List dependencies, DependencyStackListener caller) throws Exception - { - final Object[] args = getArguments(constructor, params, dependencies); - return new ComponentTask(this, caller, ComponentTaskType.CREATE) - { - public T execute(CreationalContextComponentAdapter cCtx) throws Exception - { - loadArguments(args); - return constructor.getDeclaringClass().cast(constructor.newInstance(args)); - } - }; - } - - public void loadArguments(Object[] args) - { - try - { - for (int i = 0, length = args.length; i < length; i++) - { - if (args[i] instanceof Dependency) - { - args[i] = ((Dependency)args[i]).load(holder); - } - } - } - catch (Exception e) - { - throw new RuntimeException("Could not load the arguments", e); - } - } - - public void loadDependencies(Object originalComponentKey, final ComponentTaskContext ctx, - Collection dependencies, final ComponentTaskType type) throws Exception - { - if (dependencies.isEmpty()) - return; - List> submittedTasks = null; - boolean enableMultiThreading = Mode.hasMode(Mode.MULTI_THREADED) && dependencies.size() > 1; - ThreadPoolExecutor executor = enableMultiThreading ? getExecutor() : null; - if (enableMultiThreading && executor == null) - { - enableMultiThreading = false; - } - for (final Dependency dependency : dependencies) - { - if (dependency.getKey().equals(originalComponentKey) || dependency.isLazy()) - { - // Prevent infinite loop - continue; - } - if (enableMultiThreading && LockManager.getInstance().getTotalUncompletedTasks() < executor.getCorePoolSize() - && !(dependency.getAdapter(holder) instanceof InstanceComponentAdapter)) - { - final ExoContainer container = ExoContainerContext.getCurrentContainerIfPresent(); - final ClassLoader cl = Thread.currentThread().getContextClassLoader(); - Runnable task = new Runnable() - { - public void run() - { - ExoContainer oldContainer = ExoContainerContext.getCurrentContainerIfPresent(); - ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); - ComponentTaskContext previousCtx = currentCtx.get(); - try - { - ExoContainerContext.setCurrentContainer(container); - Thread.currentThread().setContextClassLoader(cl); - currentCtx.set(ctx.addToContext(dependency.getKey(), type)); - dependency.load(holder); - } - finally - { - Thread.currentThread().setContextClassLoader(oldCl); - ExoContainerContext.setCurrentContainer(oldContainer); - currentCtx.set(previousCtx); - } - } - }; - if (submittedTasks == null) - { - submittedTasks = new ArrayList>(); - } - submittedTasks.add(executor.submit(task)); - } - else - { - ComponentTaskContext previousCtx = currentCtx.get(); - try - { - currentCtx.set(ctx.addToContext(dependency.getKey(), type)); - dependency.load(holder); - } - finally - { - currentCtx.set(previousCtx); - } - } - } - if (submittedTasks != null) - { - for (int i = 0, length = submittedTasks.size(); i < length; i++) - { - Future task = submittedTasks.get(i); - try - { - task.get(); - } - catch (ExecutionException e) - { - Throwable cause = e.getCause(); - if (cause instanceof Exception) - { - throw (Exception)cause; - } - throw new Exception(cause); - } - } - } - } - - /** - * Gives the current context - */ - public ComponentTaskContext getComponentTaskContext() - { - return currentCtx.get(); - } - - /** - * Set the current context - */ - public void setComponentTaskContext(ComponentTaskContext ctx) - { - currentCtx.set(ctx); - } - - protected T execute(ComponentTask task, CreationalContextComponentAdapter cCtx) throws Exception - { - Deque stacks = null; - CachingContainerMT cache = (CachingContainerMT)getCache(); - ThreadLocal> dependencyStacks = cache.dependencyStacks; - try - { - if (dependencyStacks != null) - { - stacks = dependencyStacks.get(); - if (stacks == null) - { - stacks = new LinkedList(); - dependencyStacks.set(stacks); - } - DependencyStack stack = new DependencyStack(task); - stacks.add(stack); - } - return task.execute(cCtx); - } - catch (InvocationTargetException e) - { - if (e.getCause() instanceof Exception) - { - throw (Exception)e.getCause(); - } - throw e; - } - finally - { - if (dependencyStacks != null) - { - stacks.removeLast(); - if (stacks.isEmpty()) - { - dependencyStacks.set(null); - } - } - } - } - - public Object[] getArguments(Constructor constructor, InitParams params, List dependencies) - { - Class[] parameters = constructor.getParameterTypes(); - Object[] args = new Object[parameters.length]; - if (args.length == 0) - return args; - Iterator tasks = dependencies.iterator(); - for (int i = 0; i < parameters.length; i++) - { - final Class parameter = parameters[i]; - if (parameter.equals(InitParams.class)) - { - args[i] = params; - continue; - } - args[i] = tasks.next(); - } - return args; - } - - /** - * {@inheritDoc} - */ - @Override - public String getId() - { - return "ConcurrentContainer"; - } - - /** - * {@inheritDoc} - */ - public void onStartupComplete() - { - if (Mode.removeModes(Mode.MULTI_THREADED, Mode.DISABLE_MT_ON_STARTUP_COMPLETE)) - { - synchronized (ConcurrentContainerMT.class) - { - // Both modes could be removed so we can shutdown the executor - ThreadPoolExecutor executor = EXECUTOR; - if (executor != null && !executor.isShutdown()) - { - executor.shutdown(); - // Release the executor for the GC - EXECUTOR = null; - } - } - } - } - - /** - * Starts all the dependencies of the adapter - */ - private void startDependencies(final Map, Object> alreadyStarted, - final Set> startInProgress, final AtomicReference error, - ComponentAdapterDependenciesAware cada) - { - if (cada.getCreateDependencies() != null) - { - // Start first the create dependencies - Collection> dep = getDependencies(cada.getCreateDependencies(), false, true); - if (dep != null && !dep.isEmpty()) - { - Set> startInProgressNew = new HashSet>(startInProgress); - startInProgressNew.add(cada); - start(dep, alreadyStarted, startInProgressNew, error, false); - } - dep = getDependencies(cada.getCreateDependencies(), true, false); - if (dep != null && !dep.isEmpty()) - { - Set> startInProgressNew = new HashSet>(startInProgress); - startInProgressNew.add(cada); - start(dep, alreadyStarted, startInProgressNew, error, true); - } - } - if (cada.getInitDependencies() != null) - { - // Then start the init dependencies - Collection> dep = getDependencies(cada.getInitDependencies(), true, true); - if (dep != null && !dep.isEmpty()) - { - Set> startInProgressNew = new HashSet>(startInProgress); - startInProgressNew.add(cada); - // remove the current adapter to prevent loop - dep.remove(cada); - start(dep, alreadyStarted, startInProgressNew, error, true); - } - } - } - - private static class KernelThreadFactory implements ThreadFactory - { - final ThreadGroup group; - - final AtomicInteger threadNumber = new AtomicInteger(1); - - final String namePrefix; - - KernelThreadFactory() - { - group = Thread.currentThread().getThreadGroup(); - namePrefix = "kernel-thread-"; - } - - /** - * {@inheritDoc} - */ - public Thread newThread(Runnable r) - { - Thread t = new Thread(group, r, namePrefix + threadNumber.getAndIncrement(), 0); - if (!t.isDaemon()) - t.setDaemon(true); - if (t.getPriority() != Thread.NORM_PRIORITY) - t.setPriority(Thread.NORM_PRIORITY); - return t; - } - } - - private static class KernelThreadPoolExecutor extends ThreadPoolExecutor - { - public KernelThreadPoolExecutor(int threadPoolSize) - { - super(threadPoolSize, threadPoolSize, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), - new KernelThreadFactory(), new ThreadPoolExecutor.CallerRunsPolicy()); - } - - /** - * {@inheritDoc} - */ - protected RunnableFuture newTaskFor(Runnable runnable, T value) - { - return LockManager.getInstance().createRunnableFuture(runnable, value); - } - - /** - * {@inheritDoc} - */ - protected RunnableFuture newTaskFor(Callable callable) - { - return LockManager.getInstance().createRunnableFuture(callable); - } - - /** - * {@inheritDoc} - */ - public Future submit(Runnable task) - { - if (task == null) - throw new NullPointerException(); - RunnableFuture ftask = newTaskFor(task, null); - if (LockManager.getInstance().incrementAndGetTotalUncompletedTasks() <= getCorePoolSize()) - execute(ftask); - else - ftask.run(); - return ftask; - } - } -} diff --git a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/CyclicDependencyException.java b/exo.kernel.container.mt/src/main/java/org/exoplatform/container/CyclicDependencyException.java deleted file mode 100644 index 035584080..000000000 --- a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/CyclicDependencyException.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * This file is part of the Meeds project (https://meeds.io/). - * - * Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.container; - -import org.exoplatform.container.spi.ContainerException; - -public class CyclicDependencyException extends ContainerException -{ - - /** - * The serial version id - */ - private static final long serialVersionUID = 9138676186744680652L; - - /** - * The dependency that causes the exception - */ - private final ComponentTaskContextEntry entry; - - /** - * Indicates whether the cycle of dependencies that causes this issue was of same type - */ - private final boolean sameType; - - public CyclicDependencyException(ComponentTaskContextEntry entry, boolean sameType) - { - super("The component corresponding to the key '" + entry.getComponentKey() + "' is already registered as a " - + entry.getTaskType() + " dependency"); - this.entry = entry; - this.sameType = sameType; - } - - /** - * @return the key of the dependency that causes the issue - */ - public Object getComponentKey() - { - return entry.getComponentKey(); - } - - /** - * @return the type of the task for which this dependency is needed. - */ - public ComponentTaskType getTaskType() - { - return entry.getTaskType(); - } - - /** - * @return the sameType - */ - public boolean isSameType() - { - return sameType; - } -} diff --git a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/Dependency.java b/exo.kernel.container.mt/src/main/java/org/exoplatform/container/Dependency.java deleted file mode 100644 index da67fc407..000000000 --- a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/Dependency.java +++ /dev/null @@ -1,136 +0,0 @@ -/** - * This file is part of the Meeds project (https://meeds.io/). - * - * Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.container; - -import org.exoplatform.container.spi.ComponentAdapter; - -/** - * This abstract class defines the main parts of a dependency - * - */ -public abstract class Dependency -{ - - /** - * The key of the corresponding component - */ - protected final Object key; - - /** - * The bind type - */ - protected final Class bindType; - - /** - * Indicates whether the dependency is lazy or not - */ - private final boolean lazy; - - public Dependency(Object key, Class bindType) - { - this(key, bindType, false); - } - - public Dependency(Object key, Class bindType, boolean lazy) - { - this.key = key; - this.bindType = bindType; - this.lazy = lazy; - } - - /** - * @return the key - */ - public Object getKey() - { - return key; - } - - /** - * @return the bindType - */ - public Class getBindType() - { - return bindType; - } - - /** - * @return the lazy - */ - public boolean isLazy() - { - return lazy; - } - - /** - * Loads a given dependency from the provided {@link ExoContainer} - */ - protected abstract Object load(ExoContainer holder); - - /** - * Gives the {@link ComponentAdapter} corresponding to this dependency - */ - protected abstract ComponentAdapter getAdapter(ExoContainer holder); - - /** - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = prime * result + ((bindType == null) ? 0 : bindType.hashCode()); - result = prime * result + ((key == null) ? 0 : key.hashCode()); - result = prime * result + (lazy ? 1231 : 1237); - return result; - } - - /** - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) - { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Dependency other = (Dependency)obj; - if (bindType == null) - { - if (other.bindType != null) - return false; - } - else if (!bindType.equals(other.bindType)) - return false; - if (key == null) - { - if (other.key != null) - return false; - } - else if (!key.equals(other.key)) - return false; - if (lazy != other.lazy) - return false; - return true; - } -} diff --git a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/DependencyByName.java b/exo.kernel.container.mt/src/main/java/org/exoplatform/container/DependencyByName.java deleted file mode 100644 index b2f10c55f..000000000 --- a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/DependencyByName.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * This file is part of the Meeds project (https://meeds.io/). - * - * Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.container; - -import org.exoplatform.container.spi.ComponentAdapter; - -/** - * This defines a dependency by name - * - */ -public class DependencyByName extends Dependency -{ - - public DependencyByName(String key, Class bindType) - { - super(key, bindType); - } - - /** - * {@inheritDoc} - */ - protected Object load(ExoContainer holder) - { - return holder.getComponentInstance(key, bindType); - } - - /** - * {@inheritDoc} - */ - @Override - protected ComponentAdapter getAdapter(ExoContainer holder) - { - return holder.getComponentAdapter(key, bindType); - } - - /** - * @see java.lang.Object#toString() - */ - @Override - public String toString() - { - return "DependencyByName [key=" + key + ", bindType=" + bindType + "]"; - } -} diff --git a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/DependencyByProvider.java b/exo.kernel.container.mt/src/main/java/org/exoplatform/container/DependencyByProvider.java deleted file mode 100644 index ad258842a..000000000 --- a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/DependencyByProvider.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * This file is part of the Meeds project (https://meeds.io/). - * - * Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.container; - -import org.exoplatform.container.spi.ComponentAdapter; - -import javax.inject.Provider; - -/** - * This defines a dependency by provider - * - */ -public class DependencyByProvider extends Dependency -{ - - private final Provider provider; - private final ComponentAdapter adapter; - - public DependencyByProvider(Object key, Class bindType, Provider provider, ComponentAdapter adapter) - { - super(key, bindType, true); - this.provider = provider; - this.adapter = adapter; - } - - /** - * {@inheritDoc} - */ - protected Object load(ExoContainer holder) - { - return provider; - } - - /** - * {@inheritDoc} - */ - @Override - protected ComponentAdapter getAdapter(ExoContainer holder) - { - return adapter; - } - - /** - * @see java.lang.Object#toString() - */ - @Override - public String toString() - { - return "DependencyByProvider [key=" + key + ", bindType=" + bindType + "]"; - } -} diff --git a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/DependencyByQualifier.java b/exo.kernel.container.mt/src/main/java/org/exoplatform/container/DependencyByQualifier.java deleted file mode 100644 index b266670b7..000000000 --- a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/DependencyByQualifier.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * This file is part of the Meeds project (https://meeds.io/). - * - * Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.container; - -import org.exoplatform.container.spi.ComponentAdapter; - -/** - * This defines a dependency by qualifier - * - */ -public class DependencyByQualifier extends Dependency -{ - - public DependencyByQualifier(Class key, Class bindType) - { - super(key, bindType); - } - - /** - * {@inheritDoc} - */ - protected Object load(ExoContainer holder) - { - return holder.getComponentInstance(key, bindType); - } - - /** - * {@inheritDoc} - */ - @Override - protected ComponentAdapter getAdapter(ExoContainer holder) - { - return holder.getComponentAdapter(key, bindType); - } - - /** - * @see java.lang.Object#toString() - */ - @Override - public String toString() - { - return "DependencyByQualifier [key=" + key + ", bindType=" + bindType + "]"; - } -} diff --git a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/DependencyByType.java b/exo.kernel.container.mt/src/main/java/org/exoplatform/container/DependencyByType.java deleted file mode 100644 index e399a4537..000000000 --- a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/DependencyByType.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * This file is part of the Meeds project (https://meeds.io/). - * - * Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.container; - -import org.exoplatform.container.spi.ComponentAdapter; - -/** - * This defines a dependency by type - * - */ -public class DependencyByType extends Dependency -{ - - public DependencyByType(Class key) - { - super(key, key); - } - - /** - * {@inheritDoc} - */ - protected Object load(ExoContainer holder) - { - return holder.getComponentInstanceOfType((Class)key); - } - - /** - * {@inheritDoc} - */ - @Override - protected ComponentAdapter getAdapter(ExoContainer holder) - { - return holder.getComponentAdapterOfType((Class)key); - } - - /** - * @see java.lang.Object#toString() - */ - @Override - public String toString() - { - return "DependencyByType [key=" + key + "]"; - } -} diff --git a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/DependencyStack.java b/exo.kernel.container.mt/src/main/java/org/exoplatform/container/DependencyStack.java deleted file mode 100644 index 83a43a733..000000000 --- a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/DependencyStack.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * This file is part of the Meeds project (https://meeds.io/). - * - * Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.container; - -import java.util.LinkedList; - -/** - * This class is used to be able to manage properly use cases where the constructor or the methods used - * to add and create plugin call {{getComponentInstanceOfType}} instead of properly adding it in the constructor - * directly - * - */ -public class DependencyStack extends LinkedList -{ - /** - * The serial version UID - */ - private static final long serialVersionUID = -3748924423444424832L; - - /** - * The task that is currently launched - */ - private final ComponentTask task; - - public DependencyStack(ComponentTask task) - { - this.task = task; - } - - @Override - public boolean add(Dependency dep) - { - if (isEmpty()) - task.getCaller().callDependency(task, dep); - return super.add(dep); - } -} diff --git a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/DependencyStackListener.java b/exo.kernel.container.mt/src/main/java/org/exoplatform/container/DependencyStackListener.java deleted file mode 100644 index f52664501..000000000 --- a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/DependencyStackListener.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * This file is part of the Meeds project (https://meeds.io/). - * - * Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.container; - -/** - * This class is used as a call back in order to trigger an exception when a new dependency - * has been detected - * - */ -public interface DependencyStackListener -{ - /** - * Used to trigger an action in case we are trying to call a dependency - */ - void callDependency(ComponentTask task, Dependency dep); -} diff --git a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/LockManager.java b/exo.kernel.container.mt/src/main/java/org/exoplatform/container/LockManager.java deleted file mode 100644 index c602351b9..000000000 --- a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/LockManager.java +++ /dev/null @@ -1,446 +0,0 @@ -/** - * This file is part of the Meeds project (https://meeds.io/). - * - * Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.container; - -import org.exoplatform.services.log.ExoLogger; -import org.exoplatform.services.log.Log; - -import java.util.concurrent.Callable; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.FutureTask; -import java.util.concurrent.RunnableFuture; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -/** - * This class is used to be aware of all the {@link Lock} currently used to prevent - * deadlocks - * - */ -public class LockManager -{ - - /** - * The logger - */ - private static final Log LOG = ExoLogger.getLogger("exo.kernel.container.mt.LockManager"); - - /** - * The singleton - */ - private static final LockManager INSTANCE = new LockManager(); - - /** - * Current lockable resources - */ - private final ConcurrentMap locks = new ConcurrentHashMap(); - - /** - * The total amount of uncompleted tasks - */ - private final AtomicInteger totalUncompletedTasks = new AtomicInteger(); - - private LockManager() - { - } - - /** - * The unique instance of the {@link LockManager} - */ - public static LockManager getInstance() - { - return INSTANCE; - } - - /** - * Gives a new {@link Lock} instance - */ - public Lock createLock() - { - return new InternalReentrantLock(); - } - - /** - * Creates a new {@link RunnableFuture} instance - */ - public RunnableFuture createRunnableFuture(Runnable runnable, T value) - { - return new InternalFutureTask(runnable, value); - } - - /** - * Creates a new {@link RunnableFuture} instance - */ - public RunnableFuture createRunnableFuture(Callable callable) - { - return new InternalFutureTask(callable); - } - - /** - * Gives the total amount of uncompleted tasks - */ - int getTotalUncompletedTasks() - { - return totalUncompletedTasks.get(); - } - - /** - * Increments and get the total amount of uncompleted tasks - */ - int incrementAndGetTotalUncompletedTasks() - { - return totalUncompletedTasks.incrementAndGet(); - } - - /** - * Indicates whether or not there are some remaining lockable resources - */ - boolean isEmpty() - { - return locks.isEmpty(); - } - - /** - * Registers a lockable resource for the current thread - */ - private void register(Lockable l) - { - locks.put(Thread.currentThread(), l); - } - - /** - * Unregisters a lockable resource for the current thread - */ - private void unregister(Lockable l) - { - locks.remove(Thread.currentThread(), l); - } - - /** - * Checks if there is a deadlock, if so an {@link InterruptedException} - * will be thrown. - *

- * When two threads enter lockInterruptibly() concurrently, each calls - * register() and then checkDeadLock() almost simultaneously. There is a - * window where thread A has already registered but thread B has not yet - * registered when A runs its check – so A sees an empty entry for B's - * thread and returns "no deadlock", then both threads block forever. - *

- * To close this window we retry the walk a few times with a brief yield - * between attempts. If the deadlock graph materialises within the retry - * budget we detect and break it; if it never materialises the lock owner - * really does not hold anything and we let the underlying primitive block - * normally. - */ - private void checkDeadLock(Lockable l) throws InterruptedException - { - if (!l.isLocked()) - { - LOG.trace("The lock is not locked so we cannot have a deadlock"); - return; - } - final Thread owner = l.getOwner(); - if (owner == null || owner == Thread.currentThread()) - { - LOG.trace("The lock is not locked or the lock owner is the current " - + "thread so we cannot have a deadlock"); - return; - } - // Retry loop: give concurrent threads a chance to complete their own - // register() call before we conclude there is no deadlock. - final int MAX_RETRIES = 10; - for (int attempt = 0; attempt < MAX_RETRIES; attempt++) - { - boolean conclusive = checkDeadLockOnce(l, owner); - if (conclusive) - return; // confirmed no deadlock - // Inconclusive: other thread hasn't registered yet. Yield and retry. - Thread.yield(); - } - LOG.trace("No deadlock detected after retries – treating as no deadlock"); - } - - /** - * Single deadlock-graph walk. Returns {@code true} when the walk concludes - * "no deadlock" with certainty (e.g. the lock became free, or owner chain - * does not loop back); returns {@code false} when the result is inconclusive - * because a concurrent thread has not yet completed its register() call - * (i.e. {@code locks.get(currentOwner)} returned null while the owner is - * actively running); throws {@link InterruptedException} when a deadlock is - * confirmed. - */ - private boolean checkDeadLockOnce(Lockable l, Thread owner) throws InterruptedException - { - Thread currentOwner = owner; - while (true) - { - Lockable lock = locks.get(currentOwner); - if (lock == null) - { - // The owner thread is not waiting on anything right now. - // This could mean it truly holds no other lock (no deadlock), - // OR it has not finished its register() call yet (inconclusive). - // We return false (inconclusive) so the caller retries. - LOG.trace("Owner has no registered lockable resource yet – result inconclusive, will retry"); - return false; - } - // We first check the locks - Thread lockToAcquireOwner = lock.getOwner(); - if (lockToAcquireOwner == null) - { - LOG.trace("The lockable resource has no owner anymore so we cannot have a deadlock"); - return true; - } - else if (lockToAcquireOwner == Thread.currentThread()) - { - // A potential deadlock has been detected - if (owner == l.getOwner() && l.isLocked()) - { - LOG.debug("A deadlock has been detected, both threads will be interrupted"); - // The owner did not change so we have a deadlock, so - // we will interrupt both threads - owner.interrupt(); - throw new InterruptedException(); - } - else - { - LOG.trace("The owner has changed or the resource is no more locked so we cannot have a deadlock"); - return true; - } - } - currentOwner = lockToAcquireOwner; - } - } - - /** - * Internal sub-class of {@link ReentrantLock} needed to be able to register - * and unregister all the locks automatically - */ - private class InternalReentrantLock extends ReentrantLock implements Lockable - { - - /** - * The serial version UID - */ - private static final long serialVersionUID = 1696442015918441687L; - - /** - * {@inheritDoc} - */ - public Thread getOwner() - { - return super.getOwner(); - } - - /** - * {@inheritDoc} - */ - @Override - public void lock() - { - register(this); - super.lock(); - unregister(this); - } - - /** - * {@inheritDoc} - */ - @Override - public void lockInterruptibly() throws InterruptedException - { - register(this); - try - { - checkDeadLock(this); - super.lockInterruptibly(); - } - finally - { - unregister(this); - } - } - - /** - * {@inheritDoc} - */ - @Override - public boolean tryLock() - { - register(this); - boolean result = super.tryLock(); - unregister(this); - return result; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException - { - register(this); - try - { - checkDeadLock(this); - return super.tryLock(timeout, unit); - } - finally - { - unregister(this); - } - } - } - - /** - * Internal sub-class of {@link FutureTask} needed to be able to register - * and unregister all the tasks automatically - */ - private class InternalFutureTask extends FutureTask implements Lockable - { - /** - * The current owner of exclusive mode synchronization. - */ - private final AtomicReference exclusiveOwnerThread = new AtomicReference(); - - /** - * {@inheritDoc} - */ - public InternalFutureTask(Callable callable) - { - super(callable); - } - - /** - * {@inheritDoc} - */ - public InternalFutureTask(Runnable runnable, V result) - { - super(runnable, result); - } - - /** - * Checks if there is a deadlock, if so it will interrupt the thread waiting for the lock - */ - private void checkDeadLock() - { - try - { - LockManager.this.checkDeadLock(this); - } - catch (InterruptedException e) - { - LOG.debug("An InterruptedException has been caught, but a task must not be interrupted"); - } - } - - - /** - * {@inheritDoc} - */ - @Override - public V get() throws InterruptedException, ExecutionException - { - register(this); - checkDeadLock(); - try - { - return super.get(); - } - finally - { - unregister(this); - } - } - - /** - * {@inheritDoc} - */ - @Override - public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - { - register(this); - checkDeadLock(); - try - { - return super.get(timeout, unit); - } - finally - { - unregister(this); - } - } - - /** - * {@inheritDoc} - */ - @Override - public void run() - { - exclusiveOwnerThread.compareAndSet(null, Thread.currentThread()); - try - { - super.run(); - } - finally - { - totalUncompletedTasks.decrementAndGet(); - exclusiveOwnerThread.compareAndSet(Thread.currentThread(), null); - } - } - - /** - * Gives the Owner of the task - */ - public Thread getOwner() - { - return exclusiveOwnerThread.get(); - } - - /** - * Indicates whether the task is locked or not, in practice it will be considered as locked if it is not done - */ - public boolean isLocked() - { - return !isDone(); - } - } - - /** - * Defines a lockable resource - */ - private static interface Lockable - { - /** - * Gives the owner in case the resource is locked - */ - Thread getOwner(); - - /** - * Indicates whether the resource is locked or not - */ - boolean isLocked(); - } -} diff --git a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/MTInterceptorChainFactory.java b/exo.kernel.container.mt/src/main/java/org/exoplatform/container/MTInterceptorChainFactory.java deleted file mode 100644 index 701ee9903..000000000 --- a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/MTInterceptorChainFactory.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * This file is part of the Meeds project (https://meeds.io/). - * - * Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.container; - -import org.exoplatform.container.management.ManageableContainer; -import org.exoplatform.container.spi.After; -import org.exoplatform.container.spi.Before; -import org.exoplatform.container.spi.Interceptor; -import org.exoplatform.container.spi.InterceptorChainFactory; - -import java.util.ArrayList; -import java.util.List; -import java.util.ServiceLoader; - -/** - * The "multi-threaded" implementation of a {@link InterceptorChainFactory}. This implementation - * uses 3 static {@link Interceptor} which are {@link ConcurrentContainerMT}, - * {@link CachingContainer} and {@link ManageableContainer} and uses a list of dynamic {@link Interceptor} - * that are retrieved thanks to the {@link ServiceLoader}. Then according to the annotations {@link Before} - * and {@link After} defined on the dynamic {@link Interceptor}, it will define an ordered list of {@link Interceptor} - * classes which will be used at each next calls of {@link #getInterceptorChain(ExoContainer, ExoContainer)} to - * re-create the exact same chain of {@link Interceptor}. - - */ -public class MTInterceptorChainFactory extends DefaultInterceptorChainFactory -{ - /** - * {@inheritDoc} - */ - protected List getStaticInterceptors(ExoContainer holder, ExoContainer parent) - { - List list = new ArrayList(4); - list.add(new ConcurrentContainerMT(holder, parent)); - list.add(new CachingContainerMT()); - list.add(new ManageableContainer(holder, parent)); - return list; - } -} diff --git a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/Mode.java b/exo.kernel.container.mt/src/main/java/org/exoplatform/container/Mode.java deleted file mode 100644 index fb11cb2c7..000000000 --- a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/Mode.java +++ /dev/null @@ -1,198 +0,0 @@ -/** - * This file is part of the Meeds project (https://meeds.io/). - * - * Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.container; - -import org.exoplatform.commons.utils.PropertyManager; -import org.exoplatform.services.log.ExoLogger; -import org.exoplatform.services.log.Log; - -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -/** - * This enumeration defines all the possible mode supported by the kernel. - * - */ -public enum Mode { - - /** - * Use this mode when you want to delegate several threads to the kernel to create, initialize and start components. - */ - MULTI_THREADED, - - /** - * Use this mode when you want to see the kernel automatically fixes dependency issues such as unexpected call to - * getComponentInstanceOfType() and/or getComponentInstance() - */ - AUTO_SOLVE_DEP_ISSUES, - - /** - * Indicates whether or not the multi-threading should be disabled on startup complete. - */ - DISABLE_MT_ON_STARTUP_COMPLETE; - - /** - * The logger - */ - private static final Log LOG = ExoLogger.getLogger("exo.kernel.container.mt.Mode"); - - /** - * The name of the system parameter to indicate that we want to enable the multi-threaded mode of the kernel - */ - public static final String MULTI_THREADED_PARAM_NAME = "org.exoplatform.container.mt.enabled"; - - /** - * The name of the system parameter to indicate that we want to enable the auto solve dependency issues mode - * of the kernel - */ - public static final String AUTO_SOLVE_DEP_ISSUES_PARAM_NAME = "org.exoplatform.container.as.enabled"; - - /** - * The name of the system parameter to indicate that we want to disable the multi-threaded mode - * once the {@link TopExoContainer} is fully started - */ - public static final String DISABLE_MT_ON_STARTUP_COMPLETE_PARAM_NAME = "org.exoplatform.container.dmtosc.enabled"; - - private static volatile Set MODES; - - static void setModes(Mode... modes) - { - Set sModes; - if (modes == null || modes.length == 0) - { - sModes = Collections.emptySet(); - } - else - { - sModes = new HashSet(Arrays.asList(modes)); - } - synchronized (Mode.class) - { - MODES = Collections.unmodifiableSet(sModes); - } - } - - static void clearModes() - { - // Clear to enforce reloading the default configuration - synchronized (Mode.class) - { - MODES = null; - } - } - - /** - * Indicates whether or not the given mode has been activated - */ - static boolean hasMode(Mode mode) - { - return getModes().contains(mode); - } - - /** - * Removes the provided modes if they are all defined, does nothing otherwise - * @param modes the modes to be removed - * @return true if the modes have been removed, false otherwise. - */ - static boolean removeModes(Mode... modes) - { - if (modes == null || modes.length == 0) - return false; - synchronized (Mode.class) - { - Set modesSet = new HashSet(getModes()); - for (Mode m : modes) - { - if (!modesSet.remove(m)) - { - return false; - } - } - MODES = Collections.unmodifiableSet(modesSet); - } - return true; - } - - private static Set getModes() - { - Set modes = MODES; - if (modes == null) - { - synchronized (Mode.class) - { - modes = MODES; - if (modes == null) - { - Set sModes = new HashSet(); - String sValue = PropertyManager.getProperty(MULTI_THREADED_PARAM_NAME); - if ((sValue == null || Boolean.valueOf(sValue)) && Runtime.getRuntime().availableProcessors() > 1) - { - sModes.add(MULTI_THREADED); - if (LOG.isDebugEnabled()) - { - LOG.debug("The 'multi-threaded' mode of the kernel has been enabled"); - } - sValue = PropertyManager.getProperty(DISABLE_MT_ON_STARTUP_COMPLETE_PARAM_NAME); - if (sValue == null || Boolean.valueOf(sValue)) - { - sModes.add(DISABLE_MT_ON_STARTUP_COMPLETE); - if (LOG.isDebugEnabled()) - { - LOG.debug("The 'multi-threaded' mode of the kernel will be disabled once fully started"); - } - } - else if (LOG.isDebugEnabled()) - { - LOG.debug("The 'multi-threaded' mode of the kernel won't be disabled once fully started"); - } - } - else if (LOG.isDebugEnabled()) - { - if (Runtime.getRuntime().availableProcessors() == 1) - { - LOG.debug("The 'multi-threaded' mode of the kernel is disabled since you must have more than one processor"); - } - else - { - LOG.debug("The 'multi-threaded' mode of the kernel is disabled"); - } - } - sValue = PropertyManager.getProperty(AUTO_SOLVE_DEP_ISSUES_PARAM_NAME); - if (sValue == null || Boolean.valueOf(sValue)) - { - sModes.add(AUTO_SOLVE_DEP_ISSUES); - if (LOG.isDebugEnabled()) - { - LOG.debug("The 'auto solve dependency issues' mode of the kernel has been enabled"); - } - } - else if (LOG.isDebugEnabled()) - { - LOG.debug("The 'auto solve dependency issues' mode of the kernel is disabled"); - } - modes = Collections.unmodifiableSet(sModes); - MODES = modes; - } - } - } - return modes; - } -} diff --git a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/jmx/MX4JComponentAdapterMT.java b/exo.kernel.container.mt/src/main/java/org/exoplatform/container/jmx/MX4JComponentAdapterMT.java deleted file mode 100644 index 3bc5485c4..000000000 --- a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/jmx/MX4JComponentAdapterMT.java +++ /dev/null @@ -1,662 +0,0 @@ -/** - * This file is part of the Meeds project (https://meeds.io/). - * - * Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.container.jmx; - -import org.exoplatform.commons.utils.ClassLoading; -import org.exoplatform.commons.utils.PropertyManager; -import org.exoplatform.container.ComponentAdapterDependenciesAware; -import org.exoplatform.container.ComponentTask; -import org.exoplatform.container.ComponentTaskContext; -import org.exoplatform.container.ComponentTaskType; -import org.exoplatform.container.ConcurrentContainer.CreationalContextComponentAdapter; -import org.exoplatform.container.ConcurrentContainerMT; -import org.exoplatform.container.CyclicDependencyException; -import org.exoplatform.container.Dependency; -import org.exoplatform.container.DependencyStackListener; -import org.exoplatform.container.ExoContainer; -import org.exoplatform.container.LockManager; -import org.exoplatform.container.component.ComponentLifecycle; -import org.exoplatform.container.component.ComponentPlugin; -import org.exoplatform.container.configuration.ConfigurationManager; -import org.exoplatform.container.util.ContainerUtil; -import org.exoplatform.container.xml.Component; -import org.exoplatform.container.xml.ExternalComponentPlugins; -import org.exoplatform.container.xml.InitParams; -import org.exoplatform.services.log.ExoLogger; -import org.exoplatform.services.log.Log; -import org.picocontainer.Startable; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.concurrent.Callable; -import java.util.concurrent.CopyOnWriteArraySet; -import java.util.concurrent.atomic.AtomicReference; - -import javax.enterprise.context.spi.Context; -import javax.enterprise.context.spi.CreationalContext; -import javax.inject.Singleton; - -public class MX4JComponentAdapterMT extends MX4JComponentAdapter implements DependencyStackListener, - ComponentAdapterDependenciesAware -{ - - /** - * Serial Version ID - */ - private static final long serialVersionUID = -9001193588034229411L; - - private transient final AtomicReference> createDependencies = - new AtomicReference>(); - - private transient final AtomicReference> initDependencies = - new AtomicReference>(); - - /** - * The task to use to create the component - */ - private transient final AtomicReference> createTask = new AtomicReference>(); - - /** - * The task to use to init the component - */ - private transient final AtomicReference>> initTasks = - new AtomicReference>>(); - - /** . */ - private transient final ConcurrentContainerMT container; - - private static final Log LOG = ExoLogger.getLogger("exo.kernel.container.mt.MX4JComponentAdapterMT"); - - public MX4JComponentAdapterMT(ExoContainer holder, ConcurrentContainerMT container, Object key, - Class implementation) - { - super(holder, container, key, implementation, LockManager.getInstance().createLock()); - this.container = container; - } - - private void addComponentPlugin(List> tasks, Set dependencies, boolean debug, - List plugins) throws Exception - { - if (plugins == null) - return; - for (org.exoplatform.container.xml.ComponentPlugin plugin : plugins) - { - try - { - Class pluginClass = ClassLoading.forName(plugin.getType(), this); - List lDependencies = new ArrayList(); - @SuppressWarnings("unchecked") - Constructor constructor = (Constructor)container.getConstructor(pluginClass, lDependencies); - dependencies.addAll(lDependencies); - tasks.add(createPlugin(this, container, pluginClass, debug, plugin, constructor, plugin.getInitParams(), - lDependencies)); - } - catch (CyclicDependencyException e) - { - throw e; - } - catch (Exception ex) - { - LOG.error("Failed to instanciate plugin " + plugin.getName() + " for component " - + getComponentImplementation() + ": " + ex.getMessage(), ex); - } - } - } - - /** - * {@inheritDoc} - */ - public Collection getCreateDependencies() - { - return createDependencies.get(); - } - - /** - * {@inheritDoc} - */ - public Collection getInitDependencies() - { - return initDependencies.get(); - } - - /** - * {@inheritDoc} - */ - public void callDependency(ComponentTask task, Dependency dep) - { - if (PropertyManager.isDevelopping()) - { - if (dep.getKey() instanceof String - || (dep.getKey() instanceof Class && ((Class)dep.getKey()).isAnnotation())) - { - LOG.warn("An unexpected call of getComponentInstance(" + dep.getKey() + "," + dep.getBindType().getName() - + ") has been detected please add the component in your constructor instead", new Exception( - "This is the stack trace allowing you to identify where the unexpected " - + "call of getComponentInstanceOfType has been done")); - } - else if (dep.getKey() instanceof Class) - { - LOG.warn("An unexpected call of getComponentInstanceOfType(" + ((Class)dep.getKey()).getName() - + ") has been detected please add the component in your constructor instead", new Exception( - "This is the stack trace allowing you to identify where the unexpected " - + "call of getComponentInstanceOfType has been done")); - } - } - if (dep.getKey().equals(getComponentKey())) - { - return; - } - if (task.getType() == ComponentTaskType.CREATE) - { - getCreateDependencies().add(dep); - } - else if (task.getType() == ComponentTaskType.INIT) - { - getInitDependencies().add(dep); - } - container.getComponentTaskContext().checkDependency(dep.getKey(), task.getType()); - } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - protected ComponentTask getCreateTask() - { - Component component = null; - String componentKey; - InitParams params = null; - boolean debug = false; - - // Get the component - Object key = getComponentKey(); - if (key instanceof String) - componentKey = (String)key; - else - componentKey = ((Class)key).getName(); - try - { - ConfigurationManager manager = - (ConfigurationManager)exocontainer.getComponentInstanceOfType(ConfigurationManager.class); - component = manager == null ? null : manager.getComponent(componentKey); - if (component != null) - { - params = component.getInitParams(); - debug = component.getShowDeployInfo(); - } - if (debug) - LOG.debug("==> get constructor of the component : " + getComponentImplementation()); - List lDependencies = new ArrayList(); - Constructor constructor = container.getConstructor(getComponentImplementation(), lDependencies); - setCreateDependencies(lDependencies); - if (debug) - LOG.debug("==> create component : " + getComponentImplementation()); - return (ComponentTask)container.createComponentTask(constructor, params, lDependencies, this); - } - catch (Exception e) - { - String msg = "Cannot instantiate component " + getComponentImplementation(); - if (component != null) - { - msg = - "Cannot instantiate component key=" + component.getKey() + " type=" + component.getType() + " found at " - + component.getDocumentURL(); - } - throw new RuntimeException(msg, e); - } - } - - protected void setCreateDependencies(List lDependencies) - { - if (createDependencies.get() == null) - { - createDependencies.compareAndSet(null, new CopyOnWriteArraySet(lDependencies)); - } - } - - /** - * {@inheritDoc} - */ - protected Collection> getInitTasks() - { - Component component = null; - String componentKey; - boolean debug = false; - - // Get the component - Object key = getComponentKey(); - if (key instanceof String) - componentKey = (String)key; - else - componentKey = ((Class)key).getName(); - try - { - ConfigurationManager manager = - (ConfigurationManager)exocontainer.getComponentInstanceOfType(ConfigurationManager.class); - component = manager == null ? null : manager.getComponent(componentKey); - if (component != null) - { - debug = component.getShowDeployInfo(); - } - List> tasks = new ArrayList>(); - Set dependencies = new HashSet(); - - final Class implementationClass = getComponentImplementation(); - boolean isSingleton = this.isSingleton; - boolean isInitialized = this.isInitialized; - if (debug) - LOG.debug("==> create component : " + implementationClass.getName()); - boolean hasInjectableConstructor = !isSingleton || ContainerUtil.hasInjectableConstructor(implementationClass); - boolean hasOnlyEmptyPublicConstructor = - !isSingleton || ContainerUtil.hasOnlyEmptyPublicConstructor(implementationClass); - if (hasInjectableConstructor || hasOnlyEmptyPublicConstructor) - { - // There is at least one constructor JSR 330 compliant or we already know - // that it is not a singleton such that the new behavior is expected - List lDependencies = new ArrayList(); - boolean isInjectPresent = container.initializeComponent(implementationClass, lDependencies, tasks, this); - dependencies.addAll(lDependencies); - isSingleton = manageScope(isSingleton, isInitialized, hasInjectableConstructor, isInjectPresent); - } - else if (!isInitialized) - { - // The adapter has not been initialized yet - // The old behavior is expected as there is no constructor JSR 330 compliant - isSingleton = this.isSingleton = true; - scope.set(Singleton.class); - } - if (component != null && component.getComponentPlugins() != null) - { - addComponentPlugin(tasks, dependencies, debug, component.getComponentPlugins()); - } - ExternalComponentPlugins ecplugins = - manager == null ? null : manager.getConfiguration().getExternalComponentPlugins(componentKey); - if (ecplugins != null) - { - addComponentPlugin(tasks, dependencies, debug, ecplugins.getComponentPlugins()); - } - initDependencies.compareAndSet(null, new CopyOnWriteArraySet(dependencies)); - tasks.add(new ComponentTask("initialize component " + getComponentImplementation().getName(), container, - this, ComponentTaskType.INIT) - { - public Void execute(CreationalContextComponentAdapter cCtx) throws Exception - { - // check if component implement the ComponentLifecycle - if (cCtx.get() instanceof ComponentLifecycle && exocontainer instanceof ExoContainer) - { - ComponentLifecycle lc = (ComponentLifecycle)cCtx.get(); - lc.initComponent((ExoContainer)exocontainer); - } - return null; - } - }); - if (!isInitialized) - { - this.isInitialized = true; - } - return tasks; - } - catch (Exception e) - { - String msg = "Cannot initialize component " + getComponentImplementation(); - if (component != null) - { - msg = - "Cannot initialize component key=" + component.getKey() + " type=" + component.getType() + " found at " - + component.getDocumentURL(); - } - throw new RuntimeException(msg, e); - } - } - - private ComponentTask createPlugin(final MX4JComponentAdapterMT caller, - final ConcurrentContainerMT exocontainer, final Class pluginClass, final boolean debug, - final org.exoplatform.container.xml.ComponentPlugin plugin, final Constructor constructor, InitParams params, - List lDependencies) throws Exception - { - final Object[] args = exocontainer.getArguments(constructor, params, lDependencies); - return new ComponentTask("create/add plugin " + plugin.getName() + " for component " - + getComponentImplementation().getName(), exocontainer, caller, ComponentTaskType.INIT) - { - public Void execute(final CreationalContextComponentAdapter cCtx) throws Exception - { - try - { - getContainer().loadArguments(args); - ComponentPlugin cplugin = (ComponentPlugin)constructor.newInstance(args); - cplugin.setName(plugin.getName()); - cplugin.setDescription(plugin.getDescription()); - Class clazz = getComponentImplementation(); - - final Method m = getSetMethod(clazz, plugin.getSetMethod(), pluginClass); - if (m == null) - { - LOG.error("Cannot find the method '" + plugin.getSetMethod() - + "' that has only one parameter of type '" + pluginClass.getName() + "' in the class '" - + clazz.getName() + "'."); - return null; - } - final Object[] params = {cplugin}; - - m.invoke(cCtx.get(), params); - - if (debug) - LOG.debug("==> add component plugin: " + cplugin); - - cplugin.setName(plugin.getName()); - cplugin.setDescription(plugin.getDescription()); - return null; - } - catch (InvocationTargetException e) - { - if (e.getCause() instanceof Exception) - { - throw (Exception)e.getCause(); - } - throw e; - } - } - }; - } - - protected T createInstance(final Context ctx) - { - T result = ctx.get(this); - if (result != null) - { - return result; - } - return create(new Callable() - { - public T call() throws Exception - { - try - { - return ctx.get(MX4JComponentAdapterMT.this, container. addComponentToCtx(getComponentKey())); - } - finally - { - container.removeComponentFromCtx(getComponentKey()); - } - } - }); - } - - /** - * Must be used to create Singleton or Prototype only - */ - protected T create() - { - return create(new Callable() - { - public T call() throws Exception - { - return doCreate(); - } - }); - } - - /** - * Must be used to create Singleton or Prototype only - */ - protected T doCreate() - { - return doCreate(false); - } - - /** - * Must be used to create Singleton or Prototype only - */ - protected T doCreate(boolean useSharedMemory) - { - if (instance_ != null) - { - return instance_; - } - boolean toBeLocked = isSingleton; - boolean skipFinally = false; - try - { - CreationalContextComponentAdapter ctx; - if (toBeLocked) - { - if (useSharedMemory) - { - T result = container. getComponentFromSharedMemory(getComponentKey()); - if (result != null) - { - LOG.debug("The value could be found from the shared memory"); - skipFinally = true; - return result; - } - LOG.debug("The value could not be found from the shared memory"); - } - if (!lock.tryLock()) - { - // The lock has already been acquired, let's make sure that we - // don't have any deadlocks - lock.lockInterruptibly(); - } - ctx = container. addComponentToCtx(getComponentKey()); - } - else - { - // Don't add to context non singleton - skipFinally = true; - ctx = new CreationalContextComponentAdapter(); - } - return create(ctx); - } - catch (InterruptedException e) - { - // We make sure that the state of the Thread is back to normal - Thread.interrupted(); - skipFinally = true; - LOG.debug("A deadlock has been detected, let's retry using the shared memory"); - return doCreate(true); - } - finally - { - if (!skipFinally) - { - lock.unlock(); - container.removeComponentFromCtx(getComponentKey()); - } - } - } - - private T create(Callable mainCreateTask) - { - ComponentTaskContext ctx = container.getComponentTaskContext(); - try - { - loadTasks(); - loadDependencies(ctx); - return mainCreateTask.call(); - } - catch (CyclicDependencyException e) - { - throw e; - } - catch (Exception e) - { - throw new RuntimeException("Cannot create component " + getComponentImplementation(), e); - } - finally - { - if (ctx == null) - { - container.setComponentTaskContext(null); - } - } - } - - private void loadDependencies(ComponentTaskContext ctx) throws Exception - { - ComponentTaskContext createCtx = ctx; - if (createCtx == null) - { - createCtx = new ComponentTaskContext(getComponentKey(), ComponentTaskType.CREATE); - container.setComponentTaskContext(createCtx); - } - else if (!createCtx.isLast(getComponentKey())) - { - createCtx = createCtx.addToContext(getComponentKey()); - container.setComponentTaskContext(createCtx); - } - container.loadDependencies(getComponentKey(), createCtx, getCreateDependencies(), ComponentTaskType.CREATE); - } - - /** - * {@inheritDoc} - */ - public T create(CreationalContext creationalContext) - { - CreationalContextComponentAdapter ctx = (CreationalContextComponentAdapter)creationalContext; - // Avoid to create duplicate instances if it is called at the same time by several threads - if (instance_ != null) - return instance_; - else if (ctx.get() != null) - return ctx.get(); - ComponentTaskContext taskCtx = container.getComponentTaskContext(); - boolean isRoot = taskCtx.isRoot(); - if (!isRoot) - { - container.setComponentTaskContext(taskCtx = taskCtx.setLastTaskType(ComponentTaskType.CREATE)); - } - try - { - ComponentTask task = createTask.get(); - T result = task.call(ctx); - if (instance_ != null) - { - // Avoid instantiating twice the same component in case of a cyclic reference due - // to component plugins - return instance_; - } - else if (ctx.get() != null) - return ctx.get(); - - ctx.push(result); - } - catch (CyclicDependencyException e) - { - throw e; - } - catch (Exception e) - { - throw new RuntimeException("Cannot create component " + getComponentImplementation(), e); - } - if (isRoot) - { - container.setComponentTaskContext(taskCtx = - taskCtx.resetDependencies(getComponentKey(), ComponentTaskType.INIT)); - } - else - { - container.setComponentTaskContext(taskCtx = taskCtx.setLastTaskType(ComponentTaskType.INIT)); - } - - Collection> tasks = initTasks.get(); - ComponentTask task = null; - try - { - if (tasks != null && !tasks.isEmpty()) - { - container.loadDependencies(getComponentKey(), taskCtx, getInitDependencies(), ComponentTaskType.INIT); - for (Iterator> it = tasks.iterator(); it.hasNext();) - { - task = it.next(); - task.call(ctx); - task = null; - } - } - if (instance_ != null) - { - return instance_; - } - else if (instance_ == null && isSingleton) - { - // In case of cyclic dependency the component could be already initialized - // so we need to recheck the state - instance_ = ctx.get(); - } - } - catch (CyclicDependencyException e) - { - throw e; - } - catch (Exception e) - { - if (task != null) - { - throw new RuntimeException("Cannot " + task.getName() + " for the component " - + getComponentImplementation(), e); - } - throw new RuntimeException("Cannot initialize component " + getComponentImplementation(), e); - } - if (ctx.get() instanceof Startable && exocontainer.canBeStopped()) - { - try - { - // Start the component if the container is already started - ((Startable)ctx.get()).start(); - } - catch (Exception e) - { - throw new RuntimeException("Cannot auto-start component " + getComponentImplementation(), e); - } - } - return ctx.get(); - } - - private void loadTasks() - { - - if (createTask.get() == null) - { - try - { - createTask.compareAndSet(null, getCreateTask()); - } - catch (RuntimeException e) - { - throw new RuntimeException("Cannot get the create task of the component " + getComponentImplementation(), e); - } - } - if (initTasks.get() == null) - { - try - { - initTasks.compareAndSet(null, getInitTasks()); - } - catch (RuntimeException e) - { - throw new RuntimeException("Cannot get the init tasks of the component " + getComponentImplementation(), e); - } - } - } -} diff --git a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/management/ManageableComponentAdapterFactoryMT.java b/exo.kernel.container.mt/src/main/java/org/exoplatform/container/management/ManageableComponentAdapterFactoryMT.java deleted file mode 100644 index ca25550fc..000000000 --- a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/management/ManageableComponentAdapterFactoryMT.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * This file is part of the Meeds project (https://meeds.io/). - * - * Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.container.management; - -import org.exoplatform.container.ConcurrentContainerMT; -import org.exoplatform.container.ExoContainer; -import org.exoplatform.container.spi.ComponentAdapter; -import org.exoplatform.container.spi.ComponentAdapterFactory; -import org.exoplatform.container.spi.ContainerException; - -public class ManageableComponentAdapterFactoryMT implements ComponentAdapterFactory -{ - - /** . */ - private final ExoContainer holder; - - /** . */ - private final ConcurrentContainerMT container; - - public ManageableComponentAdapterFactoryMT(ExoContainer holder, ConcurrentContainerMT container) - { - this.holder = holder; - this.container = container; - } - - public ComponentAdapter createComponentAdapter(Object componentKey, Class componentImplementation) - throws ContainerException - { - return new ManageableComponentAdapterMT(holder, container, componentKey, componentImplementation); - } -} diff --git a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/management/ManageableComponentAdapterMT.java b/exo.kernel.container.mt/src/main/java/org/exoplatform/container/management/ManageableComponentAdapterMT.java deleted file mode 100644 index 6742594e4..000000000 --- a/exo.kernel.container.mt/src/main/java/org/exoplatform/container/management/ManageableComponentAdapterMT.java +++ /dev/null @@ -1,138 +0,0 @@ -/** - * This file is part of the Meeds project (https://meeds.io/). - * - * Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.container.management; - -import org.exoplatform.container.ConcurrentContainerMT; -import org.exoplatform.container.ExoContainer; -import org.exoplatform.container.jmx.MX4JComponentAdapterMT; -import org.exoplatform.container.spi.Container; -import org.exoplatform.management.spi.ManagementProvider; -import org.exoplatform.services.log.ExoLogger; -import org.exoplatform.services.log.Log; - -import java.lang.annotation.Annotation; -import java.util.concurrent.atomic.AtomicBoolean; - -import javax.enterprise.context.Dependent; -import javax.enterprise.context.spi.CreationalContext; - -public class ManageableComponentAdapterMT extends MX4JComponentAdapterMT -{ - - /** - * The serial version UID - */ - private static final long serialVersionUID = 5165449586256525854L; - - /** . */ - private static final Log LOG = ExoLogger.getLogger("exo.kernel.container.mt.ManageableComponentAdapterMT"); - - /** . */ - private final AtomicBoolean registered = new AtomicBoolean(); - - public ManageableComponentAdapterMT(ExoContainer holder, ConcurrentContainerMT container, Object key, - Class implementation) - { - super(holder, container, key, implementation); - } - - protected void register(Container co, Object instance) - { - if (registered.compareAndSet(false, true)) - { - do - { - if (co instanceof ManageableContainer) - { - break; - } - } - while ((co = co.getSuccessor()) != null); - if (co instanceof ManageableContainer) - { - ManageableContainer container = (ManageableContainer)co; - if (container.managementContext != null) - { - // Register the instance against the management context - if (LOG.isDebugEnabled()) - LOG.debug("==> add " + instance + " to a mbean server"); - container.managementContext.register(instance); - - // Register if it is a management provider - if (instance instanceof ManagementProvider) - { - ManagementProvider provider = (ManagementProvider)instance; - container.addProvider(provider); - } - } - } - } - } - - /** - * {@inheritDoc} - */ - @Override - public T create(CreationalContext creationalContext) - { - T instance = super.create(creationalContext); - Class scope = null; - if (instance != null && (((scope = getScope()) != null && !scope.equals(Dependent.class))) || isSingleton()) - { - register(exocontainer, instance); - } - return instance; - } - - /** - * {@inheritDoc} - */ - @Override - public void destroy(T instance, CreationalContext creationalContext) - { - try - { - Container co = exocontainer; - do - { - if (co instanceof ManageableContainer) - { - break; - } - } - while ((co = co.getSuccessor()) != null); - if (co instanceof ManageableContainer) - { - ManageableContainer container = (ManageableContainer)co; - if (container.managementContext != null) - { - // UnRegister the instance against the management context - if (LOG.isDebugEnabled()) - LOG.debug("==> remove " + instance + " from a mbean server"); - container.managementContext.unregister(instance); - } - } - creationalContext.release(); - } - catch (Exception e) - { - LOG.error("Could not destroy the instance " + instance + ": " + e.getMessage()); - } - } -} \ No newline at end of file diff --git a/exo.kernel.container.mt/src/main/resources/META-INF/services/org.exoplatform.container.spi.InterceptorChainFactory b/exo.kernel.container.mt/src/main/resources/META-INF/services/org.exoplatform.container.spi.InterceptorChainFactory deleted file mode 100644 index 81f9c8013..000000000 --- a/exo.kernel.container.mt/src/main/resources/META-INF/services/org.exoplatform.container.spi.InterceptorChainFactory +++ /dev/null @@ -1 +0,0 @@ -org.exoplatform.container.MTInterceptorChainFactory \ No newline at end of file diff --git a/exo.kernel.container.mt/src/test/java/org/exoplatform/container/TestExoContainerMT.java b/exo.kernel.container.mt/src/test/java/org/exoplatform/container/TestExoContainerMT.java deleted file mode 100644 index c9e8e5e81..000000000 --- a/exo.kernel.container.mt/src/test/java/org/exoplatform/container/TestExoContainerMT.java +++ /dev/null @@ -1,392 +0,0 @@ -/** - * This file is part of the Meeds project (https://meeds.io/). - * - * Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.container; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import org.exoplatform.container.component.BaseComponentPlugin; -import org.exoplatform.container.jmx.AbstractTestContainer; -import org.exoplatform.container.jmx.MX4JComponentAdapterMT; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; -import org.picocontainer.Startable; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.util.Arrays; -import java.util.List; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Provider; -import javax.inject.Qualifier; -import javax.inject.Singleton; - -@RunWith(Parameterized.class) -public class TestExoContainerMT extends TestExoContainer -{ - private Mode[] modes; - public TestExoContainerMT(Mode... modes) - { - this.modes = modes; - } - - @Before - public void setUp() - { - Mode.setModes(modes); - } - - @After - public void tearDown() - { - Mode.clearModes(); - } - - @Parameters - public static List data() - { - return Arrays.asList(new Object[][]{{null}, {new Mode[]{Mode.MULTI_THREADED}}, - {new Mode[]{Mode.MULTI_THREADED, Mode.DISABLE_MT_ON_STARTUP_COMPLETE}}, {new Mode[]{Mode.AUTO_SOLVE_DEP_ISSUES}}, - {new Mode[]{Mode.MULTI_THREADED, Mode.AUTO_SOLVE_DEP_ISSUES}}, - {new Mode[]{Mode.MULTI_THREADED, Mode.AUTO_SOLVE_DEP_ISSUES, Mode.DISABLE_MT_ON_STARTUP_COMPLETE}}}); - } - - @Test - public void testBadCyclicRef() throws Exception - { - RootContainer container = AbstractTestContainer.createRootContainer(getClass(), "test-exo-container-mt.xml", "testBadCyclicRef"); - try - { - container.getComponentInstanceOfType(TestExoContainer.A1.class); - fail("A CyclicDependencyException was expected"); - } - catch (CyclicDependencyException e) - { - // expected exception - } - } - - @Test - public void testBadCyclicRef2() throws Exception - { - try - { - AbstractTestContainer.createRootContainer(getClass(), "test-exo-container-mt.xml", "testBadCyclicRef2"); - } - catch (CyclicDependencyException e) - { - // expected exception - } - } - - @Test - public void testBadCyclicRef3() throws Exception - { - RootContainer container = AbstractTestContainer.createRootContainer(getClass(), "test-exo-container-mt.xml", "testBadCyclicRef3"); - try - { - container.getComponentInstanceOfType(A1.class); - fail("A CyclicDependencyException was expected"); - } - catch (CyclicDependencyException e) - { - // expected exception - } - } - - @Test - public void testBadCyclicRef4() throws Exception - { - try - { - AbstractTestContainer.createRootContainer(getClass(), "test-exo-container-mt.xml", "testBadCyclicRef4"); - } - catch (CyclicDependencyException e) - { - // expected exception - } - } - - public static class A1 - { - public B1 b; - - public A1(ExoContainerContext ctx) - { - this.b = ctx.getContainer().getComponentInstanceOfType(B1.class); - } - } - - public static class B1 - { - public A1 a; - - public B1(ExoContainerContext ctx) - { - this.a = ctx.getContainer().getComponentInstanceOfType(A1.class); - } - } - - public static class A2 implements Startable - { - public B2 b; - - public A2(ExoContainerContext ctx) - { - this.b = ctx.getContainer().getComponentInstanceOfType(B2.class); - } - - public void start() - { - } - - public void stop() - { - } - } - - public static class B2 - { - public A2 a; - - public B2(ExoContainerContext ctx) - { - this.a = ctx.getContainer().getComponentInstanceOfType(A2.class); - } - } - - @Test - public void testBadCyclicRef5() throws Exception - { - RootContainer container = AbstractTestContainer.createRootContainer(getClass(), "test-exo-container-mt.xml", "testBadCyclicRef5"); - try - { - container.getComponentInstanceOfType(A3.class); - fail("A CyclicDependencyException was expected"); - } - catch (CyclicDependencyException e) - { - // expected exception - } - } - - @Test - public void testBadCyclicRef6() throws Exception - { - try - { - AbstractTestContainer.createRootContainer(getClass(), "test-exo-container-mt.xml", "testBadCyclicRef6"); - } - catch (CyclicDependencyException e) - { - // expected exception - } - } - - @Singleton - public static class A3 - { - public B3 b; - - @Inject - public A3(Provider p) - { - this.b = p.get(); - } - } - - @Singleton - public static class B3 - { - public A3 a; - - @Inject - public B3(Provider p) - { - this.a = p.get(); - } - } - - @Singleton - public static class A4 implements Startable - { - public B4 b; - - @Inject - public A4(Provider p) - { - this.b = p.get(); - } - - public void start() - { - } - - public void stop() - { - } - } - - @Singleton - public static class B4 - { - public A4 a; - - @Inject - public B4(Provider p) - { - this.a = p.get(); - } - } - - @Test - public void testAutoSolveDepIssues() - { - RootContainer container = AbstractTestContainer.createRootContainer(getClass(), "test-exo-container-mt.xml", "testAutoSolveDepIssues"); - MX4JComponentAdapterMT adapter1 = - (MX4JComponentAdapterMT)container.getComponentAdapterOfType(ASDI_1.class); - MX4JComponentAdapterMT adapter2 = - (MX4JComponentAdapterMT)container.getComponentAdapterOfType(ASDI_2.class); - MX4JComponentAdapterMT adapter3 = - (MX4JComponentAdapterMT)container.getComponentAdapterOfType(ASDI_2_2.class); - if (Mode.hasMode(Mode.AUTO_SOLVE_DEP_ISSUES)) - { - assertEquals(2, adapter1.getCreateDependencies().size()); - assertEquals(3, adapter1.getInitDependencies().size()); - assertEquals(4, adapter2.getCreateDependencies().size()); - assertEquals(4, adapter2.getInitDependencies().size()); - } - else - { - assertEquals(1, adapter1.getCreateDependencies().size()); - assertEquals(1, adapter1.getInitDependencies().size()); - assertEquals(1, adapter2.getCreateDependencies().size()); - assertEquals(1, adapter2.getInitDependencies().size()); - } - assertEquals(3, adapter3.getCreateDependencies().size()); - for (Dependency dep : adapter3.getCreateDependencies()) - { - assertTrue(dep.isLazy()); - } - assertEquals(3, adapter3.getInitDependencies().size()); - for (Dependency dep : adapter3.getInitDependencies()) - { - assertTrue(dep.isLazy()); - } - } - - public static class ASDI_1 implements Startable - { - private ExoContainer container; - - public ASDI_1(ExoContainerContext ctx) - { - container = ctx.getContainer(); - container.getComponentInstanceOfType(ASDI_2.class); - } - - public void addPlugin(ASDI_1Plugin plugin) - { - container.getComponentInstanceOfType(ASDI_2.class); - } - - public void start() - { - } - - public void stop() - { - } - } - - public static class ASDI_1Plugin extends BaseComponentPlugin - { - public ASDI_1Plugin(ExoContainerContext ctx) - { - ctx.getContainer().getComponentInstanceOfType(ASDI_2_2.class); - } - } - - @Singleton - public static class ASDI_2 - { - @Inject - public ASDI_2(ExoContainerContext ctx) - { - ctx.getContainer().getComponentInstanceOfType(ASDI_3.class); - ctx.getContainer().getComponentInstance("ASDI_4", ASDI_4.class); - ctx.getContainer().getComponentInstance(ASDI_5Qualifier.class, ASDI_5.class); - } - - @Inject - public void init(ExoContainerContext ctx) - { - ctx.getContainer().getComponentInstanceOfType(ASDI_3.class); - ctx.getContainer().getComponentInstance("ASDI_4", ASDI_4.class); - ctx.getContainer().getComponentInstance(ASDI_5Qualifier.class, ASDI_5.class); - } - } - - @Singleton - public static class ASDI_2_2 - { - @Inject - public ASDI_2_2(Provider p1, @Named("ASDI_4") Provider p2, @ASDI_5Qualifier Provider p3) - { - p1.get(); - p2.get(); - p3.get(); - } - - @Inject - public void init(Provider p1, @Named("ASDI_4") Provider p2, @ASDI_5Qualifier Provider p3) - { - p1.get(); - p2.get(); - p3.get(); - } - } - - public static class ASDI_3 - { - - } - - public static class ASDI_4 - { - - } - - public static class ASDI_5 - { - - } - - @Retention(RetentionPolicy.RUNTIME) - @Qualifier - public static @interface ASDI_5Qualifier { - } -} \ No newline at end of file diff --git a/exo.kernel.container.mt/src/test/java/org/exoplatform/container/TestKernelExtensionMT.java b/exo.kernel.container.mt/src/test/java/org/exoplatform/container/TestKernelExtensionMT.java deleted file mode 100644 index 6f39b65cd..000000000 --- a/exo.kernel.container.mt/src/test/java/org/exoplatform/container/TestKernelExtensionMT.java +++ /dev/null @@ -1,422 +0,0 @@ -/** - * This file is part of the Meeds project (https://meeds.io/). - * - * Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.container; - -import junit.framework.TestCase; - -import org.exoplatform.container.spi.After; -import org.exoplatform.container.spi.Before; -import org.exoplatform.container.spi.ComponentAdapter; -import org.exoplatform.container.spi.Container; - -import java.util.concurrent.Callable; - -public class TestKernelExtensionMT extends TestCase -{ - @Override - public void setUp() { - ExoContainer topContainer = ExoContainerContext.getTopContainer(); - if(topContainer != null) { - topContainer.stop(); - } - PortalContainer.setInstance(null); - RootContainer.setInstance(null); - ExoContainerContext.setCurrentContainer(null); - } - - public void testInterceptors() - { - Callable task = new Callable() - { - public Void call() throws Exception - { - ExoContainer parent = new ExoContainer(); - testInterceptorsInternal(parent); - // Make sure that it is consistent - testInterceptorsInternal(parent); - return null; - } - - }; - execute(task, (Mode[])null); - execute(task, Mode.MULTI_THREADED); - execute(task, Mode.MULTI_THREADED, Mode.DISABLE_MT_ON_STARTUP_COMPLETE); - execute(task, Mode.AUTO_SOLVE_DEP_ISSUES); - execute(task, Mode.MULTI_THREADED, Mode.AUTO_SOLVE_DEP_ISSUES); - execute(task, Mode.MULTI_THREADED, Mode.AUTO_SOLVE_DEP_ISSUES, Mode.DISABLE_MT_ON_STARTUP_COMPLETE); - } - - private void testInterceptorsInternal(ExoContainer parent) - { - MockInterceptor1 i1 = null; - MockInterceptor2 i2 = null; - MockInterceptor3 i3 = null; - MockInterceptor4 i4 = null; - MockInterceptor5 i5 = null; - MockInterceptor6 i6 = null; - MockInterceptor7 i7 = null; - MockInterceptor8 i8 = null; - MockInterceptor9 i9 = null; - ExoContainer holder = new ExoContainer(parent); - Container container = holder; - while ((container = container.getSuccessor()) != null) - { - if (container instanceof MockInterceptor1) - { - i1 = (MockInterceptor1)container; - } - else if (container instanceof MockInterceptor2) - { - i2 = (MockInterceptor2)container; - } - else if (container instanceof MockInterceptor3) - { - i3 = (MockInterceptor3)container; - } - else if (container instanceof MockInterceptor4) - { - i4 = (MockInterceptor4)container; - } - else if (container instanceof MockInterceptor5) - { - i5 = (MockInterceptor5)container; - } - else if (container instanceof MockInterceptor6) - { - i6 = (MockInterceptor6)container; - } - else if (container instanceof MockInterceptor7) - { - i7 = (MockInterceptor7)container; - } - else if (container instanceof MockInterceptor8) - { - i8 = (MockInterceptor8)container; - } - else if (container instanceof MockInterceptor9) - { - i9 = (MockInterceptor9)container; - } - } - assertNotNull(i1); - assertNotNull(i1.getSuccessor()); - assertSame(parent, i1.getParent()); - assertSame(holder, i1.getHolder()); - assertEquals("MockInterceptor1", i1.getId()); - assertNotNull(i2); - assertNotNull(i2.getSuccessor()); - assertSame(parent, i2.getParent()); - assertSame(holder, i2.getHolder()); - assertEquals("MockInterceptor2", i2.getId()); - assertNotNull(i3); - assertNotNull(i3.getSuccessor()); - assertSame(parent, i3.getParent()); - assertSame(holder, i3.getHolder()); - assertEquals("MockInterceptor3", i3.getId()); - assertNotNull(i4); - assertNotNull(i4.getSuccessor()); - assertSame(parent, i4.getParent()); - assertSame(holder, i4.getHolder()); - assertEquals("MockInterceptor4", i4.getId()); - assertNotNull(i5); - assertNotNull(i5.getSuccessor()); - assertSame(parent, i5.getParent()); - assertSame(holder, i5.getHolder()); - assertEquals("MockInterceptor5", i5.getId()); - assertNotNull(i6); - assertNotNull(i6.getSuccessor()); - assertSame(parent, i6.getParent()); - assertSame(holder, i6.getHolder()); - assertEquals("MockInterceptor6", i6.getId()); - assertNotNull(i7); - assertNotNull(i7.getSuccessor()); - assertSame(parent, i7.getParent()); - assertSame(holder, i7.getHolder()); - assertEquals("MockInterceptor7", i7.getId()); - assertNotNull(i8); - assertNull(i8.getSuccessor()); - assertSame(parent, i8.getParent()); - assertSame(holder, i8.getHolder()); - assertEquals("MockInterceptor8", i8.getId()); - assertNotNull(i9); - assertNotNull(i9.getSuccessor()); - assertSame(parent, i9.getParent()); - assertSame(holder, i9.getHolder()); - assertEquals("MockInterceptor9", i9.getId()); - Test0 t0I = new Test0(); - Test1 t1I = new Test1(); - Test2 t2I = new Test2(); - Test3 t3I = new Test3(); - holder.registerComponentInstance(Test0.class, t0I); - holder.registerComponentInstance(Test1.class, t1I); - holder.registerComponentInstance(Test2.class, t2I); - holder.registerComponentInstance(Test3.class, t3I); - holder.registerComponentImplementation(Test5.class); - assertSame(t0I, holder.getComponentInstanceOfType(Test0.class)); - Test1 t1FC = holder.getComponentInstanceOfType(Test1.class); - assertNotSame(t1I, t1FC); - // A new instance is created at each call so it must not be the same as before - assertNotSame(t1FC, holder.getComponentInstanceOfType(Test1.class)); - Test2 t2FC = holder.getComponentInstanceOfType(Test2.class); - assertNotSame(t2I, t2FC); - // It comes from the cache so it must be the same than before - assertSame(t2FC, holder.getComponentInstanceOfType(Test2.class)); - Test3 t3FC = holder.getComponentInstanceOfType(Test3.class); - assertSame(MockInterceptor1.TEST, t3FC); - Test5 t4FC = holder.getComponentInstanceOfType(Test5.class); - assertSame(t0I, t4FC.t0); - assertNotSame(t1I, t4FC.t1); - assertNotSame(t2I, t4FC.t2); - assertSame(t3FC, t4FC.t3); - } - - @SuppressWarnings("serial") - @Before(value = "Cache") - public static class MockInterceptor1 extends AbstractInterceptor - { - public static final Test3 TEST = new Test3(); - - ExoContainer getParent() - { - return parent; - } - - ExoContainer getHolder() - { - return holder; - } - - @SuppressWarnings("unchecked") - @Override - public ComponentAdapter getComponentAdapterOfType(Class componentType, boolean autoRegistration) - { - if (componentType.equals(Test4.class)) - { - return (ComponentAdapter)new InstanceComponentAdapter(Test4.class, new Test4()); - } - return super.getComponentAdapterOfType(componentType, autoRegistration); - } - - @Override - public T getComponentInstanceOfType(Class componentType, boolean autoRegistration) - { - if (componentType.equals(Test1.class)) - { - return componentType.cast(new Test1()); - } - else if (componentType.equals(Test3.class)) - { - return componentType.cast(TEST); - } - else if (componentType.equals(Test4.class)) - { - return componentType.cast(new Test4()); - } - return super.getComponentInstanceOfType(componentType, autoRegistration); - } - } - - @SuppressWarnings("serial") - @After(value = "Cache") - public static class MockInterceptor2 extends AbstractInterceptor - { - ExoContainer getParent() - { - return parent; - } - - ExoContainer getHolder() - { - return holder; - } - - @Override - public T getComponentInstanceOfType(Class componentType, boolean autoRegistration) - { - if (componentType.equals(Test2.class)) - { - return componentType.cast(new Test2()); - } - return super.getComponentInstanceOfType(componentType, autoRegistration); - } - } - - @SuppressWarnings("serial") - public static class MockInterceptor3 extends AbstractInterceptor - { - ExoContainer getParent() - { - return parent; - } - - ExoContainer getHolder() - { - return holder; - } - } - - @SuppressWarnings("serial") - @After(value = "Fake") - public static class MockInterceptor4 extends AbstractInterceptor - { - ExoContainer getParent() - { - return parent; - } - - ExoContainer getHolder() - { - return holder; - } - } - - @SuppressWarnings("serial") - @Before(value = "Fake") - public static class MockInterceptor5 extends AbstractInterceptor - { - ExoContainer getParent() - { - return parent; - } - - ExoContainer getHolder() - { - return holder; - } - } - - @SuppressWarnings("serial") - @After(value = "") - public static class MockInterceptor6 extends AbstractInterceptor - { - ExoContainer getParent() - { - return parent; - } - - ExoContainer getHolder() - { - return holder; - } - } - - @SuppressWarnings("serial") - @Before(value = "") - public static class MockInterceptor7 extends AbstractInterceptor - { - ExoContainer getParent() - { - return parent; - } - - ExoContainer getHolder() - { - return holder; - } - } - - @SuppressWarnings("serial") - @After(value = "ConcurrentContainer") - public static class MockInterceptor8 extends AbstractInterceptor - { - ExoContainer getParent() - { - return parent; - } - - ExoContainer getHolder() - { - return holder; - } - } - - @SuppressWarnings("serial") - @Before(value = "MockInterceptor5") - public static class MockInterceptor9 extends AbstractInterceptor - { - ExoContainer getParent() - { - return parent; - } - - ExoContainer getHolder() - { - return holder; - } - } - - private static class Test0 - { - }; - - private static class Test1 - { - }; - - private static class Test2 - { - }; - - private static class Test3 - { - }; - - private static class Test4 - { - }; - - public static class Test5 - { - public Test0 t0; - - public Test1 t1; - - public Test2 t2; - - public Test3 t3; - - public Test4 t4; - - public Test5(Test0 t0, Test1 t1, Test2 t2, Test3 t3, Test4 t4) - { - this.t0 = t0; - this.t1 = t1; - this.t2 = t2; - this.t3 = t3; - this.t4 = t4; - } - }; - - private static void execute(Callable task, Mode... modes) - { - try - { - Mode.setModes(modes); - task.call(); - } - catch (Exception e) - { - throw new RuntimeException(e); - } - finally - { - Mode.clearModes(); - } - } -} diff --git a/exo.kernel.container.mt/src/test/java/org/exoplatform/container/TestLockManager.java b/exo.kernel.container.mt/src/test/java/org/exoplatform/container/TestLockManager.java deleted file mode 100644 index 0121946a4..000000000 --- a/exo.kernel.container.mt/src/test/java/org/exoplatform/container/TestLockManager.java +++ /dev/null @@ -1,419 +0,0 @@ -/** - * This file is part of the Meeds project (https://meeds.io/). - * - * Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.exoplatform.container; - -import junit.framework.TestCase; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.CyclicBarrier; -import java.util.concurrent.RunnableFuture; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; -import java.util.concurrent.locks.Lock; - -public class TestLockManager extends TestCase -{ - private LockManager manager; - - /** - * @see junit.framework.TestCase#setUp() - */ - @Override - protected void setUp() throws Exception - { - manager = LockManager.getInstance(); - } - - /** - * @see junit.framework.TestCase#tearDown() - */ - @Override - protected void tearDown() throws Exception - { - manager = null; - } - - public void testNoDeadLock() throws Exception - { - int threadCount = 10; - final CountDownLatch startSignal = new CountDownLatch(1); - final CountDownLatch endSignal = new CountDownLatch(threadCount); - final AtomicReference ex = new AtomicReference(); - Runnable r = new Runnable() - { - public void run() - { - try - { - startSignal.await(); - Lock l = manager.createLock(); - l.lock(); - l.unlock(); - l.lockInterruptibly(); - l.unlock(); - if (l.tryLock()) - l.unlock(); - else - throw new Exception("Could not lock the node using tryLock"); - if (l.tryLock(10, TimeUnit.MILLISECONDS)) - l.unlock(); - else - throw new Exception("Could not lock the node using tryLock with timeout"); - } - catch (Exception e) - { - ex.set(e); - } - finally - { - endSignal.countDown(); - } - } - }; - for (int i = 0; i < threadCount; i++) - new Thread(r).start(); - startSignal.countDown(); - if (!endSignal.await(30, TimeUnit.SECONDS)) - fail("testNoDeadLock timed out – possible deadlock or hang in worker threads"); - if (ex.get() != null) - throw ex.get(); - assertTrue(manager.isEmpty()); - } - - public void testDeadlockWith2Threads() throws Exception - { - final CyclicBarrier startSignal = new CyclicBarrier(2); - final CountDownLatch endSignal = new CountDownLatch(2); - final AtomicReference ex = new AtomicReference(); - final Lock l1 = manager.createLock(); - final Lock l2 = manager.createLock(); - Thread t1 = new Thread() - { - public void run() - { - try - { - l1.lock(); - startSignal.await(); - l2.lockInterruptibly(); - throw new Exception("Should not occur"); - } - catch (InterruptedException e) - { - // expected - } - catch (Exception e) - { - ex.set(e); - } - finally - { - l1.unlock(); - endSignal.countDown(); - } - } - }; - t1.start(); - Thread t2 = new Thread() - { - public void run() - { - try - { - l2.lock(); - startSignal.await(); - l1.lockInterruptibly(); - throw new Exception("Should not occur"); - } - catch (InterruptedException e) - { - // expected - } - catch (Exception e) - { - ex.set(e); - } - finally - { - l2.unlock(); - endSignal.countDown(); - } - } - }; - t2.start(); - if (!endSignal.await(30, TimeUnit.SECONDS)) fail("testDeadlockWith2Threads timed out – deadlock not resolved"); - if (ex.get() != null) - throw ex.get(); - assertTrue(manager.isEmpty()); - } - - - public void testDeadlockWith3Threads() throws Exception - { - final CyclicBarrier startSignal = new CyclicBarrier(3); - final CountDownLatch endSignal = new CountDownLatch(3); - final AtomicReference ex = new AtomicReference(); - final List exceptions = Collections.synchronizedList(new ArrayList()); - final Lock l1 = manager.createLock(); - final Lock l2 = manager.createLock(); - final Lock l3 = manager.createLock(); - Thread t1 = new Thread() - { - public void run() - { - try - { - l1.lock(); - startSignal.await(); - l2.lockInterruptibly(); - } - catch (InterruptedException e) - { - // expected - exceptions.add(e); - } - catch (Exception e) - { - ex.set(e); - } - finally - { - l1.unlock(); - endSignal.countDown(); - } - } - }; - t1.start(); - Thread t2 = new Thread() - { - public void run() - { - try - { - l2.lock(); - startSignal.await(); - l3.lockInterruptibly(); - } - catch (InterruptedException e) - { - // expected - exceptions.add(e); - } - catch (Exception e) - { - ex.set(e); - } - finally - { - l2.unlock(); - endSignal.countDown(); - } - } - }; - t2.start(); - Thread t3 = new Thread() - { - public void run() - { - try - { - l3.lock(); - startSignal.await(); - l1.lockInterruptibly(); - } - catch (InterruptedException e) - { - // expected - exceptions.add(e); - } - catch (Exception e) - { - ex.set(e); - } - finally - { - l3.unlock(); - endSignal.countDown(); - } - } - }; - t3.start(); - if (!endSignal.await(30, TimeUnit.SECONDS)) fail("testDeadlockWith3Threads timed out – deadlock not resolved"); - if (ex.get() != null) - throw ex.get(); - assertTrue(exceptions.size() >= 2); - assertTrue(manager.isEmpty()); - } - - public void testDeadlockWithLockNTaskGetFirst() throws Exception - { - final CountDownLatch endSignal = new CountDownLatch(2); - final AtomicReference ex = new AtomicReference(); - final Lock l = manager.createLock(); - final RunnableFuture task = manager.createRunnableFuture(new Callable() - { - public Void call() throws Exception - { - try - { - l.lockInterruptibly(); - } - catch (InterruptedException e) - { - // expected - } - catch (Exception e) - { - ex.set(e); - } - return null; - } - - }); - Thread t1 = new Thread() - { - public void run() - { - try - { - l.lock(); - task.get(); - } - catch (InterruptedException e) - { - // expected - } - catch (Exception e) - { - ex.set(e); - } - finally - { - l.unlock(); - endSignal.countDown(); - } - } - }; - t1.start(); - Thread t2 = new Thread() - { - public void run() - { - try - { - Thread.sleep(100); - task.run(); - } - catch (Exception e) - { - ex.set(e); - } - finally - { - endSignal.countDown(); - } - } - }; - t2.start(); - if (!endSignal.await(30, TimeUnit.SECONDS)) fail("testDeadlockWithLockNTaskGetFirst timed out – deadlock not resolved"); - if (ex.get() != null) - throw ex.get(); - assertTrue(manager.isEmpty()); - } - - public void testDeadlockWithLockNTaskRunFirst() throws Exception - { - final CountDownLatch endSignal = new CountDownLatch(2); - final AtomicReference ex = new AtomicReference(); - final Lock l = manager.createLock(); - final RunnableFuture task = manager.createRunnableFuture(new Callable() - { - public Void call() throws Exception - { - try - { - l.lockInterruptibly(); - } - catch (InterruptedException e) - { - // expected - } - catch (Exception e) - { - ex.set(e); - } - return null; - } - - }); - Thread t1 = new Thread() - { - public void run() - { - try - { - l.lock(); - Thread.sleep(100); - task.get(); - } - catch (InterruptedException e) - { - // expected - } - catch (Exception e) - { - ex.set(e); - } - finally - { - l.unlock(); - endSignal.countDown(); - } - } - }; - t1.start(); - Thread t2 = new Thread() - { - public void run() - { - try - { - task.run(); - } - catch (Exception e) - { - ex.set(e); - } - finally - { - endSignal.countDown(); - } - } - }; - t2.start(); - if (!endSignal.await(30, TimeUnit.SECONDS)) fail("testDeadlockWithLockNTaskRunFirst timed out – deadlock not resolved"); - if (ex.get() != null) - throw ex.get(); - assertTrue(manager.isEmpty()); - } -} diff --git a/exo.kernel.container.mt/src/test/resources/META-INF/services/org.exoplatform.container.spi.Interceptor b/exo.kernel.container.mt/src/test/resources/META-INF/services/org.exoplatform.container.spi.Interceptor deleted file mode 100644 index 413a0662f..000000000 --- a/exo.kernel.container.mt/src/test/resources/META-INF/services/org.exoplatform.container.spi.Interceptor +++ /dev/null @@ -1,9 +0,0 @@ -org.exoplatform.container.TestKernelExtensionMT$MockInterceptor1 -org.exoplatform.container.TestKernelExtensionMT$MockInterceptor2 -org.exoplatform.container.TestKernelExtensionMT$MockInterceptor3 -org.exoplatform.container.TestKernelExtensionMT$MockInterceptor4 -org.exoplatform.container.TestKernelExtensionMT$MockInterceptor5 -org.exoplatform.container.TestKernelExtensionMT$MockInterceptor6 -org.exoplatform.container.TestKernelExtensionMT$MockInterceptor7 -org.exoplatform.container.TestKernelExtensionMT$MockInterceptor8 -org.exoplatform.container.TestKernelExtensionMT$MockInterceptor9 \ No newline at end of file diff --git a/exo.kernel.container.mt/src/test/resources/META-INF/services/org.exoplatform.container.spi.InterceptorChainFactory b/exo.kernel.container.mt/src/test/resources/META-INF/services/org.exoplatform.container.spi.InterceptorChainFactory deleted file mode 100644 index 81f9c8013..000000000 --- a/exo.kernel.container.mt/src/test/resources/META-INF/services/org.exoplatform.container.spi.InterceptorChainFactory +++ /dev/null @@ -1 +0,0 @@ -org.exoplatform.container.MTInterceptorChainFactory \ No newline at end of file diff --git a/exo.kernel.container.mt/src/test/resources/org/exoplatform/container/test-exo-container-mt.xml b/exo.kernel.container.mt/src/test/resources/org/exoplatform/container/test-exo-container-mt.xml deleted file mode 100644 index d68afce77..000000000 --- a/exo.kernel.container.mt/src/test/resources/org/exoplatform/container/test-exo-container-mt.xml +++ /dev/null @@ -1,85 +0,0 @@ - - - - - org.exoplatform.container.TestExoContainer$A1 - - - org.exoplatform.container.TestExoContainer$B1 - - - org.exoplatform.container.TestExoContainer$A2 - - - org.exoplatform.container.TestExoContainer$B2 - - - org.exoplatform.container.TestExoContainerMT$A1 - - - org.exoplatform.container.TestExoContainerMT$B1 - - - org.exoplatform.container.TestExoContainerMT$A2 - - - org.exoplatform.container.TestExoContainerMT$B2 - - - org.exoplatform.container.TestExoContainerMT$A3 - - - org.exoplatform.container.TestExoContainerMT$B3 - - - org.exoplatform.container.TestExoContainerMT$A4 - - - org.exoplatform.container.TestExoContainerMT$B4 - - - org.exoplatform.container.TestExoContainerMT$ASDI_1 - - - testAutoSolveDepIssues-test-plugin - addPlugin - org.exoplatform.container.TestExoContainerMT$ASDI_1Plugin - - - - - org.exoplatform.container.TestExoContainerMT$ASDI_2 - - - org.exoplatform.container.TestExoContainerMT$ASDI_2_2 - - - org.exoplatform.container.TestExoContainerMT$ASDI_3 - - - ASDI_4 - org.exoplatform.container.TestExoContainerMT$ASDI_4 - - - org.exoplatform.container.TestExoContainerMT$ASDI_5Qualifier - org.exoplatform.container.TestExoContainerMT$ASDI_5 - - \ No newline at end of file diff --git a/exo.kernel.container.mt/src/test/resources/test.policy b/exo.kernel.container.mt/src/test/resources/test.policy deleted file mode 100644 index bc4f37568..000000000 --- a/exo.kernel.container.mt/src/test/resources/test.policy +++ /dev/null @@ -1,31 +0,0 @@ -grant codeBase "@MAVEN_REPO@-"{ - permission java.security.AllPermission; -}; - -grant codeBase "@MAIN_CLASSES@-"{ - permission java.security.AllPermission; -}; - -grant codeBase "@TEST_CLASSES@-"{ - permission java.lang.RuntimePermission "manageContainer"; - permission java.lang.RuntimePermission "manageComponent"; - permission java.lang.RuntimePermission "manageThreadLocal"; - // Permissions needed for ContainerBuilder - permission java.lang.reflect.ReflectPermission "suppressAccessChecks"; - permission java.lang.RuntimePermission "createClassLoader"; - permission java.lang.RuntimePermission "setContextClassLoader"; - //Permissions needed for TestStandaloneContainer - permission java.lang.RuntimePermission "modifyThread"; -}; - -grant codeBase "@MAIN_CLASSES@../../../exo.kernel.commons.test/-"{ - permission java.security.AllPermission; -}; - -grant codeBase "@MAIN_CLASSES@../../../exo.kernel.commons/-"{ - permission java.security.AllPermission; -}; - -grant codeBase "@MAIN_CLASSES@../../../exo.kernel.container/-"{ - permission java.security.AllPermission; -}; diff --git a/exo.kernel.container.mt/src/test/resources/tsm-excludes.properties b/exo.kernel.container.mt/src/test/resources/tsm-excludes.properties deleted file mode 100644 index 5fe297a84..000000000 --- a/exo.kernel.container.mt/src/test/resources/tsm-excludes.properties +++ /dev/null @@ -1,5 +0,0 @@ -org.exoplatform.container.TestPortalContainer.testGetConfigurationXML=getConfigurationXML -org.exoplatform.container.ar.TestArchive.testGetConfigurationURL=getConfigurationURL -org.exoplatform.container.ar.TestArchive.testURL=parse -org.exoplatform.container.ar.TestArchive.testConnect=parse,connect -org.exoplatform.container.ar.TestArchive.testGetStream=parse \ No newline at end of file diff --git a/pom.xml b/pom.xml index 7dc18250e..09482328a 100644 --- a/pom.xml +++ b/pom.xml @@ -56,7 +56,6 @@ exo.kernel.container - exo.kernel.container.mt exo.kernel.commons exo.kernel.commons.test exo.kernel.component.common