Repository: tomee Updated Branches: refs/heads/tomee-1.7.x 32340af1e -> 8b2ef1f4a
fix conflicts Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/fdc49211 Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/fdc49211 Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/fdc49211 Branch: refs/heads/tomee-1.7.x Commit: fdc492112a8b61f0eb2c32046210c5d11c95b5ef Parents: 778a257 Author: Ivan Junckes Filho <[email protected]> Authored: Thu Dec 14 18:52:59 2017 -0200 Committer: Thiago Veronezi <[email protected]> Committed: Wed Jan 17 11:27:58 2018 -0500 ---------------------------------------------------------------------- .../openejb/core/mdb/EndpointFactory.java | 17 ++- .../apache/openejb/core/mdb/MdbContainer.java | 2 +- .../openejb/core/mdb/MdbInstanceManager.java | 5 +- .../openejb/core/mdb/MdbPoolContainer.java | 6 +- .../openejb/core/mdb/PoolEndpointFactory.java | 122 ------------------- .../openejb/core/mdb/PoolEndpointHandler.java | 2 +- .../META-INF/org.apache.openejb/service-jar.xml | 38 +++--- 7 files changed, 40 insertions(+), 152 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/fdc49211/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/EndpointFactory.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/EndpointFactory.java b/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/EndpointFactory.java index 2bae424..cc0b0e2 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/EndpointFactory.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/EndpointFactory.java @@ -28,6 +28,7 @@ import javax.resource.spi.UnavailableException; import javax.resource.spi.endpoint.MessageEndpoint; import javax.resource.spi.endpoint.MessageEndpointFactory; import javax.transaction.xa.XAResource; +import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; @@ -38,21 +39,24 @@ public class EndpointFactory implements MessageEndpointFactory { private final BaseMdbContainer container; private final BeanContext beanContext; private final MdbInstanceFactory instanceFactory; + private final MdbInstanceManager instanceManager; private final ClassLoader classLoader; private final Class[] interfaces; private final XAResourceWrapper xaResourceWrapper; protected final List<ObjectName> jmxNames = new ArrayList<ObjectName>(); private final Class<?> proxy; + private final boolean usePool; - public EndpointFactory(final ActivationSpec activationSpec, final BaseMdbContainer container, final BeanContext beanContext, final MdbInstanceFactory instanceFactory, final XAResourceWrapper xaResourceWrapper) { + public EndpointFactory(final ActivationSpec activationSpec, final BaseMdbContainer container, final BeanContext beanContext, final MdbInstanceFactory instanceFactory, final MdbInstanceManager instanceManager, final XAResourceWrapper xaResourceWrapper, boolean usePool) { this.activationSpec = activationSpec; this.container = container; this.beanContext = beanContext; this.instanceFactory = instanceFactory; + this.instanceManager = instanceManager; classLoader = container.getMessageListenerInterface().getClassLoader(); interfaces = new Class[]{container.getMessageListenerInterface(), MessageEndpoint.class}; this.xaResourceWrapper = xaResourceWrapper; - + this.usePool = usePool; final BeanContext.ProxyClass proxyClass = beanContext.get(BeanContext.ProxyClass.class); if (proxyClass == null) { proxy = LocalBeanProxyFactory.createProxy(beanContext.getBeanClass(), beanContext.getClassLoader(), interfaces); @@ -75,7 +79,14 @@ public class EndpointFactory implements MessageEndpointFactory { if (xaResource != null && xaResourceWrapper != null) { xaResource = xaResourceWrapper.wrap(xaResource, container.getContainerID().toString()); } - final EndpointHandler endpointHandler = new EndpointHandler(container, beanContext, instanceFactory, xaResource); + + InvocationHandler endpointHandler = null; + if (usePool) { + endpointHandler = new PoolEndpointHandler(container, beanContext, instanceManager, xaResource); + } else { + endpointHandler = new EndpointHandler(container, beanContext, instanceFactory, xaResource); + } + try { return (MessageEndpoint) LocalBeanProxyFactory.constructProxy(proxy, endpointHandler); } catch (final InternalError e) { // should be useless http://git-wip-us.apache.org/repos/asf/tomee/blob/fdc49211/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java b/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java index 709439e..1b5548b 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java @@ -170,7 +170,7 @@ public class MdbContainer implements RpcContainer, BaseMdbContainer { final int instanceLimit = options.get("InstanceLimit", this.instanceLimit); // create the message endpoint final MdbInstanceFactory instanceFactory = new MdbInstanceFactory(beanContext, securityService, instanceLimit); - final EndpointFactory endpointFactory = new EndpointFactory(activationSpec, this, beanContext, instanceFactory, xaResourceWrapper); + final EndpointFactory endpointFactory = new EndpointFactory(activationSpec, this, beanContext, instanceFactory, null, xaResourceWrapper, false); // update the data structures // this must be done before activating the endpoint since the ra may immedately begin delivering messages http://git-wip-us.apache.org/repos/asf/tomee/blob/fdc49211/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbInstanceManager.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbInstanceManager.java b/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbInstanceManager.java index 5e6b627..ba255be 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbInstanceManager.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbInstanceManager.java @@ -22,7 +22,6 @@ import org.apache.openejb.OpenEJBException; import org.apache.openejb.core.instance.InstanceCreatorRunnable; import org.apache.openejb.core.instance.InstanceManager; import org.apache.openejb.core.instance.InstanceManagerData; -import org.apache.openejb.core.stateless.StatelessContext; import org.apache.openejb.loader.Options; import org.apache.openejb.monitoring.LocalMBeanServer; import org.apache.openejb.monitoring.ManagedMBean; @@ -93,7 +92,7 @@ public class MdbInstanceManager extends InstanceManager { } - public void deploy(final BeanContext beanContext, final ActivationSpec activationSpec, final PoolEndpointFactory endpointFactory) + public void deploy(final BeanContext beanContext, final ActivationSpec activationSpec, final EndpointFactory endpointFactory) throws OpenEJBException{ if (inboundRecovery != null) { inboundRecovery.recover(resourceAdapter, activationSpec, containerID.toString()); @@ -213,7 +212,7 @@ public class MdbInstanceManager extends InstanceManager { } public void undeploy(final BeanContext beanContext){ - final PoolEndpointFactory endpointFactory = (PoolEndpointFactory) beanContext.getContainerData(); + final EndpointFactory endpointFactory = (EndpointFactory) beanContext.getContainerData(); if (endpointFactory != null) { final ObjectName jmxBeanToRemove = mbeanNames.remove(beanContext); http://git-wip-us.apache.org/repos/asf/tomee/blob/fdc49211/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbPoolContainer.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbPoolContainer.java b/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbPoolContainer.java index 7fdc651..6fac7da 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbPoolContainer.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbPoolContainer.java @@ -172,7 +172,7 @@ public class MdbPoolContainer implements RpcContainer, BaseMdbContainer { // create the activation spec final ActivationSpec activationSpec = createActivationSpec(beanContext); - final PoolEndpointFactory endpointFactory = new PoolEndpointFactory(activationSpec, this, beanContext, instanceManager, xaResourceWrapper); + final EndpointFactory endpointFactory = new EndpointFactory(activationSpec, this, beanContext, null, instanceManager, xaResourceWrapper, true); // update the data structures // this must be done before activating the endpoint since the ra may immedately begin delivering messages @@ -437,12 +437,12 @@ public class MdbPoolContainer implements RpcContainer, BaseMdbContainer { private final ClassLoader classLoader; private final BeanContext beanContext; private final ResourceAdapter resourceAdapter; - private final PoolEndpointFactory endpointFactory; + private final EndpointFactory endpointFactory; private final ActivationSpec activationSpec; private AtomicBoolean started = new AtomicBoolean(false); - public MdbActivationContext(final ClassLoader classLoader, final BeanContext beanContext, final ResourceAdapter resourceAdapter, final PoolEndpointFactory endpointFactory, final ActivationSpec activationSpec) { + public MdbActivationContext(final ClassLoader classLoader, final BeanContext beanContext, final ResourceAdapter resourceAdapter, final EndpointFactory endpointFactory, final ActivationSpec activationSpec) { this.classLoader = classLoader; this.beanContext = beanContext; this.resourceAdapter = resourceAdapter; http://git-wip-us.apache.org/repos/asf/tomee/blob/fdc49211/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/PoolEndpointFactory.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/PoolEndpointFactory.java b/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/PoolEndpointFactory.java deleted file mode 100644 index 0804b52..0000000 --- a/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/PoolEndpointFactory.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.openejb.core.mdb; - -import org.apache.openejb.BeanContext; -import org.apache.openejb.OpenEJBException; -import org.apache.openejb.core.transaction.TransactionType; -import org.apache.openejb.resource.XAResourceWrapper; -import org.apache.openejb.util.proxy.LocalBeanProxyFactory; - -import javax.resource.spi.ActivationSpec; -import javax.resource.spi.UnavailableException; -import javax.resource.spi.endpoint.MessageEndpoint; -import javax.resource.spi.endpoint.MessageEndpointFactory; -import javax.transaction.xa.XAResource; -import java.lang.reflect.Method; - -public class PoolEndpointFactory implements MessageEndpointFactory { - - private final ActivationSpec activationSpec; - private final BaseMdbContainer container; - private final BeanContext beanContext; - private final MdbInstanceManager instanceManager; - private final ClassLoader classLoader; - private final Class[] interfaces; - private final XAResourceWrapper xaResourceWrapper; - private final Class<?> proxy; - - public PoolEndpointFactory(final ActivationSpec activationSpec, final BaseMdbContainer container, final BeanContext beanContext, final MdbInstanceManager instanceManager, final XAResourceWrapper xaResourceWrapper) { - this.activationSpec = activationSpec; - this.container = container; - this.beanContext = beanContext; - this.instanceManager = instanceManager; - classLoader = container.getMessageListenerInterface().getClassLoader(); - interfaces = new Class[]{container.getMessageListenerInterface(), MessageEndpoint.class}; - this.xaResourceWrapper = xaResourceWrapper; - - final BeanContext.ProxyClass proxyClass = beanContext.get(BeanContext.ProxyClass.class); - if (proxyClass == null) { - proxy = LocalBeanProxyFactory.createProxy(beanContext.getBeanClass(), beanContext.getClassLoader(), interfaces); - beanContext.set(BeanContext.ProxyClass.class, new BeanContext.ProxyClass(beanContext, interfaces)); - } else { - proxy = proxyClass.getProxy(); - } - } - - public ActivationSpec getActivationSpec() { - return activationSpec; - } - - @Override - public MessageEndpoint createEndpoint(XAResource xaResource) throws UnavailableException { - if (xaResource != null && xaResourceWrapper != null) { - xaResource = xaResourceWrapper.wrap(xaResource, container.getContainerID().toString()); - } - PoolEndpointHandler endpointHandler = null; - try { - endpointHandler = new PoolEndpointHandler(container, beanContext, instanceManager, xaResource); - return (MessageEndpoint) LocalBeanProxyFactory.constructProxy(proxy, endpointHandler); - } catch (final InternalError e) { // should be useless - //try to create the proxy with tccl once again. - try { - return MessageEndpoint.class.cast(LocalBeanProxyFactory.newProxyInstance(Thread.currentThread().getContextClassLoader(), endpointHandler, beanContext.getBeanClass(), interfaces)); - } catch (final InternalError ie) { - try { - return MessageEndpoint.class.cast(LocalBeanProxyFactory.newProxyInstance(classLoader, endpointHandler, beanContext.getBeanClass(), interfaces)); - } catch (final InternalError ie2) { - // no-op - } - } - throw e; - } catch (OpenEJBException e){ - throw new UnavailableException(e); - } - } - - @Override - public MessageEndpoint createEndpoint(final XAResource xaResource, final long timeout) throws UnavailableException { - if (timeout <= 0) { - return createEndpoint(xaResource); - } - - final long end = System.currentTimeMillis() + timeout; - MessageEndpoint messageEndpoint = null; - - while (System.currentTimeMillis() <= end) { - try { - messageEndpoint = createEndpoint(xaResource); - break; - } catch (final Exception ex) { - // ignore so we can keep trying - } - } - - if (messageEndpoint != null) { - return messageEndpoint; - } else { - throw new UnavailableException("Unable to create end point within the specified timeout " + timeout); - } - } - - @Override - public boolean isDeliveryTransacted(final Method method) throws NoSuchMethodException { - final TransactionType transactionType = beanContext.getTransactionType(method); - return TransactionType.Required == transactionType; - } -} http://git-wip-us.apache.org/repos/asf/tomee/blob/fdc49211/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/PoolEndpointHandler.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/PoolEndpointHandler.java b/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/PoolEndpointHandler.java index 874e1a9..9f9f5b7 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/PoolEndpointHandler.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/PoolEndpointHandler.java @@ -77,7 +77,7 @@ public class PoolEndpointHandler implements InvocationHandler, MessageEndpoint { private State state = State.NONE; private Object instance; private ThreadContext callContext; - public PoolEndpointHandler(final BaseMdbContainer container, final BeanContext deployment, final MdbInstanceManager instanceManager, final XAResource xaResource) throws OpenEJBException, UnavailableException { + public PoolEndpointHandler(final BaseMdbContainer container, final BeanContext deployment, final MdbInstanceManager instanceManager, final XAResource xaResource) throws UnavailableException { this.container = container; this.deployment = deployment; this.instanceManager = instanceManager; http://git-wip-us.apache.org/repos/asf/tomee/blob/fdc49211/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml b/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml index f72ccaa..fd0411a 100644 --- a/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml +++ b/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml @@ -459,7 +459,7 @@ --> <ServiceProvider - id="Pool MDB Container" + id="Default MDB Container" service="Container" types="MESSAGE" factory-name="create" @@ -479,35 +479,35 @@ </ServiceProvider> - <ServiceProvider - id="Default MDB Container" - service="Container" - types="MESSAGE" - constructor="id, securityService, ResourceAdapter, MessageListenerInterface, ActivationSpecClass, InstanceLimit, FailOnUnknownActivationSpec" - class-name="org.apache.openejb.core.mdb.MdbContainer"> + <!--<ServiceProvider--> + <!--id="Default MDB Container"--> + <!--service="Container"--> + <!--types="MESSAGE"--> + <!--constructor="id, securityService, ResourceAdapter, MessageListenerInterface, ActivationSpecClass, InstanceLimit, FailOnUnknownActivationSpec"--> + <!--class-name="org.apache.openejb.core.mdb.MdbContainer">--> - # The resource adapter delivers messages to the container + <!--# The resource adapter delivers messages to the container--> - ResourceAdapter Default JMS Resource Adapter + <!--ResourceAdapter Default JMS Resource Adapter--> - # Specifies the message listener interface handled by this container + <!--# Specifies the message listener interface handled by this container--> - MessageListenerInterface javax.jms.MessageListener + <!--MessageListenerInterface javax.jms.MessageListener--> - # Specifies the activation spec class + <!--# Specifies the activation spec class--> - ActivationSpecClass org.apache.activemq.ra.ActiveMQActivationSpec + <!--ActivationSpecClass org.apache.openejb.resource.activemq.TomEEMessageActivationSpec--> - # Specifies the maximum number of bean instances that are - # allowed to exist for each MDB deployment. + <!--# Specifies the maximum number of bean instances that are--> + <!--# allowed to exist for each MDB deployment.--> - InstanceLimit 10 + <!--InstanceLimit 10--> - # log a warning if false or throw an exception if true is an activation spec can't be respected + <!--# log a warning if true or throw an exception if false is an activation spec can't be respected--> - FailOnUnknownActivationSpec = true + <!--FailOnUnknownActivationSpec = true--> - </ServiceProvider> + <!--</ServiceProvider>--> <!-- # ================================================
