Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Reduce component instance overhead and add some checks that EJB metho…

…ds are public
  • Loading branch information...
commit 44cb24a7679d23a52dff8f5ba19683e071defb4d 1 parent 4652201
@stuartwdouglas stuartwdouglas authored bstansberry committed
Showing with 113 additions and 68 deletions.
  1. +8 −1 ee/src/main/java/org/jboss/as/ee/component/BasicComponentCreateService.java
  2. +33 −28 ejb3/src/main/java/org/jboss/as/ejb3/EjbMessages.java
  3. +41 −25 ejb3/src/main/java/org/jboss/as/ejb3/component/EJBComponentCreateService.java
  4. +9 −2 ejb3/src/main/java/org/jboss/as/ejb3/component/entity/EntityBeanHomeViewConfigurator.java
  5. +4 −0 ejb3/src/main/java/org/jboss/as/ejb3/component/entity/EntityBeanObjectViewConfigurator.java
  6. +5 −0 ejb3/src/main/java/org/jboss/as/ejb3/component/session/SessionBeanObjectViewConfigurator.java
  7. +1 −1  ...uite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/entity/cmp/commerce/AddressBean.java
  8. +1 −1  ...ite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/entity/cmp/commerce/LineItemBean.java
  9. +1 −1  testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/entity/cmp/commerce/OrderBean.java
  10. +1 −1  ...egration/basic/src/test/java/org/jboss/as/test/integration/ejb/entity/cmp/commerce/ProductCategoryBean.java
  11. +1 −1  ...tegration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/entity/cmp/commerce/AddressBean.java
  12. +1 −1  ...egration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/entity/cmp/commerce/LineItemBean.java
  13. +6 −5 ...integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/entity/cmp/commerce/OrderBean.java
  14. +1 −1  ...n/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/entity/cmp/commerce/ProductCategoryBean.java
View
9 ee/src/main/java/org/jboss/as/ee/component/BasicComponentCreateService.java
@@ -23,6 +23,7 @@
package org.jboss.as.ee.component;
import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import java.util.IdentityHashMap;
import java.util.Map;
@@ -70,13 +71,19 @@ public BasicComponentCreateService(final ComponentConfiguration componentConfigu
preDestroy = Interceptors.getChainedInterceptorFactory(componentConfiguration.getPreDestroyInterceptors());
final IdentityHashMap<Method, InterceptorFactory> componentInterceptors = new IdentityHashMap<Method, InterceptorFactory>();
for (Method method : componentConfiguration.getDefinedComponentMethods()) {
- componentInterceptors.put(method, Interceptors.getChainedInterceptorFactory(componentConfiguration.getComponentInterceptors(method)));
+ if(requiresInterceptors(method, componentConfiguration)) {
+ componentInterceptors.put(method, Interceptors.getChainedInterceptorFactory(componentConfiguration.getComponentInterceptors(method)));
+ }
}
componentClass = componentConfiguration.getComponentClass();
this.componentInterceptors = componentInterceptors;
this.namespaceContextSelector = componentConfiguration.getNamespaceContextSelector();
}
+ protected boolean requiresInterceptors(final Method method, final ComponentConfiguration componentConfiguration) {
+ return Modifier.isPublic(method.getModifiers()) && componentConfiguration.getComponentDescription().isIntercepted();
+ }
+
/**
* {@inheritDoc}
*/
View
61 ejb3/src/main/java/org/jboss/as/ejb3/EjbMessages.java
@@ -1,11 +1,37 @@
package org.jboss.as.ejb3;
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.rmi.RemoteException;
+import java.util.Set;
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import javax.ejb.ConcurrentAccessTimeoutException;
+import javax.ejb.EJBAccessException;
+import javax.ejb.EJBException;
+import javax.ejb.IllegalLoopbackException;
+import javax.ejb.LockType;
+import javax.ejb.NoMoreTimeoutsException;
+import javax.ejb.NoSuchEJBException;
+import javax.ejb.NoSuchEntityException;
+import javax.ejb.NoSuchObjectLocalException;
+import javax.ejb.ObjectNotFoundException;
+import javax.ejb.RemoveException;
+import javax.ejb.ScheduleExpression;
+import javax.ejb.TimerHandle;
+import javax.interceptor.InvocationContext;
+import javax.naming.Context;
+import javax.transaction.xa.Xid;
+import javax.xml.stream.Location;
+
import org.jboss.as.controller.PathAddress;
import org.jboss.as.ee.component.Component;
import org.jboss.as.ee.component.ComponentCreateServiceFactory;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.ComponentInstance;
-import org.jboss.as.ejb3.cache.Identifiable;
import org.jboss.as.ejb3.component.EJBComponent;
import org.jboss.as.ejb3.component.EJBComponentDescription;
import org.jboss.as.ejb3.component.EJBViewDescription;
@@ -18,7 +44,6 @@
import org.jboss.as.naming.context.NamespaceContextSelector;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
-import org.jboss.ejb.client.SessionID;
import org.jboss.invocation.InterceptorContext;
import org.jboss.logging.Cause;
import org.jboss.logging.Message;
@@ -28,32 +53,6 @@
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.StartException;
-import javax.ejb.ConcurrentAccessTimeoutException;
-import javax.ejb.EJBAccessException;
-import javax.ejb.EJBException;
-import javax.ejb.IllegalLoopbackException;
-import javax.ejb.LockType;
-import javax.ejb.NoMoreTimeoutsException;
-import javax.ejb.NoSuchEJBException;
-import javax.ejb.NoSuchEntityException;
-import javax.ejb.NoSuchObjectLocalException;
-import javax.ejb.ObjectNotFoundException;
-import javax.ejb.RemoveException;
-import javax.ejb.ScheduleExpression;
-import javax.ejb.TimerHandle;
-import javax.interceptor.InvocationContext;
-import javax.naming.Context;
-import javax.transaction.xa.Xid;
-import javax.xml.stream.Location;
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.rmi.RemoteException;
-import java.util.Set;
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
/**
* This module is using message IDs in the range 14100-14599. This file is using the subset 14300-14599 for
* non-logger messages. See http://community.jboss.org/docs/DOC-16810 for the full list of currently reserved
@@ -2066,6 +2065,12 @@
@Message(id = 14577, value = "Unsupported marshalling version: %d")
IllegalArgumentException unsupportedMarshallingVersion(int version);
+ @Message(id = 14578, value = "%s method %s must be public")
+ DeploymentUnitProcessingException ejbMethodMustBePublic(final String type, final Method method);
+
+ @Message(id = 14579, value = "EJB business method %s must be public")
+ DeploymentUnitProcessingException ejbBusinessMethodMustBePublic(final Method method);
+
// STOP!!! Don't add message ids greater that 14599!!! If you need more first check what EjbLogger is
// using and take more (lower) numbers from the available range for this module. If the range for the module is
// all used, go to https://community.jboss.org/docs/DOC-16810 and allocate another block for this subsystem
View
66 ejb3/src/main/java/org/jboss/as/ejb3/component/EJBComponentCreateService.java
@@ -22,6 +22,18 @@
package org.jboss.as.ejb3.component;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.IdentityHashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ejb.TimerService;
+import javax.ejb.TransactionAttributeType;
+import javax.ejb.TransactionManagementType;
+
import org.jboss.as.ee.component.BasicComponentCreateService;
import org.jboss.as.ee.component.ComponentConfiguration;
import org.jboss.as.ee.component.ViewConfiguration;
@@ -39,17 +51,6 @@
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.value.InjectedValue;
-import javax.ejb.TimerService;
-import javax.ejb.TransactionAttributeType;
-import javax.ejb.TransactionManagementType;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.IdentityHashMap;
-import java.util.List;
-import java.util.Map;
-
/**
* @author Jaikiran Pai
*/
@@ -116,10 +117,12 @@ public EJBComponentCreateService(final ComponentConfiguration componentConfigura
if (ejbComponentDescription.isTimerServiceApplicable()) {
Map<Method, InterceptorFactory> timeoutInterceptors = new IdentityHashMap<Method, InterceptorFactory>();
for (Method method : componentConfiguration.getDefinedComponentMethods()) {
- final InterceptorFactory interceptorFactory = Interceptors.getChainedInterceptorFactory(componentConfiguration.getAroundTimeoutInterceptors(method));
- timeoutInterceptors.put(method, interceptorFactory);
+ if ((ejbComponentDescription.getTimeoutMethod() != null && ejbComponentDescription.getTimeoutMethod().equals(method)) ||
+ ejbComponentDescription.getScheduleMethods().containsKey(method)) {
+ final InterceptorFactory interceptorFactory = Interceptors.getChainedInterceptorFactory(componentConfiguration.getAroundTimeoutInterceptors(method));
+ timeoutInterceptors.put(method, interceptorFactory);
+ }
}
-
this.timeoutInterceptors = timeoutInterceptors;
} else {
timeoutInterceptors = Collections.emptyMap();
@@ -130,19 +133,19 @@ public EJBComponentCreateService(final ComponentConfiguration componentConfigura
for (ViewConfiguration view : views) {
//TODO: Move this into a configurator
final EJBViewConfiguration ejbView = (EJBViewConfiguration) view;
- final MethodIntf viewType = ejbView.getMethodIntf();
- for (Method method : view.getProxyFactory().getCachedMethods()) {
- // TODO: proxy factory exposes non-public methods, is this a bug in the no-interface view?
- if (!Modifier.isPublic(method.getModifiers()))
- continue;
- final Method componentMethod = getComponentMethod(componentConfiguration, method.getName(), method.getParameterTypes());
- if (componentMethod != null) {
- this.processTxAttr(ejbComponentDescription, viewType, componentMethod);
- } else {
- this.processTxAttr(ejbComponentDescription, viewType, method);
- }
+ final MethodIntf viewType = ejbView.getMethodIntf();
+ for (Method method : view.getProxyFactory().getCachedMethods()) {
+ // TODO: proxy factory exposes non-public methods, is this a bug in the no-interface view?
+ if (!Modifier.isPublic(method.getModifiers()))
+ continue;
+ final Method componentMethod = getComponentMethod(componentConfiguration, method.getName(), method.getParameterTypes());
+ if (componentMethod != null) {
+ this.processTxAttr(ejbComponentDescription, viewType, componentMethod);
+ } else {
+ this.processTxAttr(ejbComponentDescription, viewType, method);
}
}
+ }
}
this.timeoutMethod = ejbComponentDescription.getTimeoutMethod();
@@ -175,6 +178,19 @@ public EJBComponentCreateService(final ComponentConfiguration componentConfigura
this.shutDownInterceptorFactory = ejbComponentDescription.getShutDownInterceptorFactory();
}
+ @Override
+ protected boolean requiresInterceptors(final Method method, final ComponentConfiguration componentConfiguration) {
+ if(super.requiresInterceptors(method, componentConfiguration)) {
+ return true;
+ }
+ final EJBComponentDescription ejbComponentDescription = (EJBComponentDescription)componentConfiguration.getComponentDescription();
+ if ((ejbComponentDescription.getTimeoutMethod() != null && ejbComponentDescription.getTimeoutMethod().equals(method)) ||
+ ejbComponentDescription.getScheduleMethods().containsKey(method)) {
+ return true;
+ }
+ return false;
+ }
+
private static Method getComponentMethod(final ComponentConfiguration componentConfiguration, final String name, final Class<?>[] parameterTypes) {
try {
return componentConfiguration.getComponentClass().getMethod(name, parameterTypes);
View
11 ejb3/src/main/java/org/jboss/as/ejb3/component/entity/EntityBeanHomeViewConfigurator.java
@@ -22,6 +22,7 @@
package org.jboss.as.ejb3.component.entity;
import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import java.util.Collection;
import javax.ejb.Handle;
@@ -35,6 +36,7 @@
import org.jboss.as.ee.component.ViewDescription;
import org.jboss.as.ee.component.interceptors.InterceptorOrder;
import org.jboss.as.ejb3.EjbLogger;
+import org.jboss.as.ejb3.EjbMessages;
import org.jboss.as.ejb3.component.EJBViewDescription;
import org.jboss.as.ejb3.component.EjbHomeViewDescription;
import org.jboss.as.ejb3.component.MethodIntf;
@@ -109,7 +111,9 @@ public void configureDependency(final ServiceBuilder<?> serviceBuilder, final Co
} else if (method.getName().startsWith("find")) {
final Method ejbFind = resolveEjbFinderMethod(componentConfiguration.getComponentClass(), deploymentReflectionIndex, method, componentConfiguration.getComponentName(), componentDescription.getPersistenceType());
-
+ if(!Modifier.isPublic(ejbFind.getModifiers())) {
+ throw EjbMessages.MESSAGES.ejbMethodMustBePublic("ejbFind", ejbFind);
+ }
final EntityBeanHomeFinderInterceptorFactory interceptorFactory = createHomeFindInterceptorFactory(ejbFind, localHome);
componentConfiguration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {
@Override
@@ -147,10 +151,13 @@ public void configureDependency(final ServiceBuilder<?> serviceBuilder, final Co
configuration.addViewInterceptor(method, factory, InterceptorOrder.View.HOME_METHOD_INTERCEPTOR);
} else if (method.getName().equals("getHomeHandle") && method.getParameterTypes().length == 0) {
- // TODO: impl
+ //handled elsewhere
} else {
//we have a home business method
Method home = resolveEjbHomeBusinessMethod(componentConfiguration.getComponentClass(), deploymentReflectionIndex, method, componentConfiguration.getComponentName());
+ if(!Modifier.isPublic(home.getModifiers())) {
+ throw EjbMessages.MESSAGES.ejbMethodMustBePublic("ejbHome", home);
+ }
configuration.addViewInterceptor(method, new EntityBeanHomeMethodInterceptorFactory(home), InterceptorOrder.View.COMPONENT_DISPATCHER);
}
}
View
4 ejb3/src/main/java/org/jboss/as/ejb3/component/entity/EntityBeanObjectViewConfigurator.java
@@ -22,6 +22,7 @@
package org.jboss.as.ejb3.component.entity;
import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import javax.ejb.EJBLocalObject;
import javax.ejb.EJBObject;
@@ -118,6 +119,9 @@ public void configureDependency(final ServiceBuilder<?> serviceBuilder, final Co
if (componentMethod == null) {
handleNonBeanMethod(componentConfiguration, configuration, index, method);
} else {
+ if(!Modifier.isPublic(componentMethod.getModifiers())) {
+ throw EjbMessages.MESSAGES.ejbBusinessMethodMustBePublic(componentMethod);
+ }
configuration.addViewInterceptor(method, new ImmediateInterceptorFactory(new ComponentDispatcherInterceptor(componentMethod)), InterceptorOrder.View.COMPONENT_DISPATCHER);
configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
}
View
5 ejb3/src/main/java/org/jboss/as/ejb3/component/session/SessionBeanObjectViewConfigurator.java
@@ -22,6 +22,7 @@
package org.jboss.as.ejb3.component.session;
import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import javax.ejb.EJBException;
import javax.ejb.EJBLocalObject;
@@ -102,7 +103,11 @@ public void configureDependency(final ServiceBuilder<?> serviceBuilder, final Co
handleIsIdenticalMethod(componentConfiguration, configuration, index, method);
} else {
final Method componentMethod = ClassReflectionIndexUtil.findMethod(index, componentConfiguration.getComponentClass(), MethodIdentifier.getIdentifierForMethod(method));
+
if (componentMethod != null) {
+ if(!Modifier.isPublic(componentMethod.getModifiers())) {
+ throw EjbMessages.MESSAGES.ejbBusinessMethodMustBePublic(componentMethod);
+ }
configuration.addViewInterceptor(method, new ImmediateInterceptorFactory(new ComponentDispatcherInterceptor(componentMethod)), InterceptorOrder.View.COMPONENT_DISPATCHER);
configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
} else if(method.getDeclaringClass() != Object.class && method.getDeclaringClass() != WriteReplaceInterface.class) {
View
2  ...e/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/entity/cmp/commerce/AddressBean.java
@@ -103,7 +103,7 @@ public void ejbStore() {
public void ejbRemove() {
}
- void ejbHomeResetId() {
+ public void ejbHomeResetId() {
id = 0;
}
}
View
2  .../integration/basic/src/test/java/org/jboss/as/test/integration/ejb/entity/cmp/commerce/LineItemBean.java
@@ -115,7 +115,7 @@ public void ejbStore() {
public void ejbRemove() {
}
- void ejbHomeResetId() {
+ public void ejbHomeResetId() {
id = 0;
}
}
View
2  ...ite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/entity/cmp/commerce/OrderBean.java
@@ -154,7 +154,7 @@ public void ejbStore() {
public void ejbRemove() {
}
- void ejbHomeResetId() {
+ public void ejbHomeResetId() {
id = 0;
}
}
View
2  ...ation/basic/src/test/java/org/jboss/as/test/integration/ejb/entity/cmp/commerce/ProductCategoryBean.java
@@ -95,7 +95,7 @@ public void ejbStore() {
public void ejbRemove() {
}
- void ejbHomeResetId() {
+ public void ejbHomeResetId() {
id = 0;
}
}
View
2  ...ration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/entity/cmp/commerce/AddressBean.java
@@ -103,7 +103,7 @@ public void ejbStore() {
public void ejbRemove() {
}
- void ejbHomeResetId() {
+ public void ejbHomeResetId() {
id = 0;
}
}
View
2  ...ation/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/entity/cmp/commerce/LineItemBean.java
@@ -139,7 +139,7 @@ public void ejbStore() {
public void ejbRemove() {
}
- void ejbHomeResetId() {
+ public void ejbHomeResetId() {
id = 0;
}
View
11 ...egration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/entity/cmp/commerce/OrderBean.java
@@ -23,12 +23,13 @@
import java.util.Collection;
import java.util.Set;
+
import javax.ejb.CreateException;
-import javax.ejb.EJBException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.FinderException;
import javax.naming.InitialContext;
+
import static org.junit.Assert.fail;
public abstract class OrderBean implements EntityBean {
@@ -138,16 +139,16 @@ public void setEntityContext(EntityContext ctx) {
this.ctx = ctx;
}
- void setShippingAddressId(Long id) throws FinderException {
+ public void setShippingAddressId(Long id) throws FinderException {
setShippingAddress(getAddressHome().findByPrimaryKey(id));
System.out.println(getShippingAddress());
}
- void setBillingAddressId(Long id) throws FinderException {
+ public void setBillingAddressId(Long id) throws FinderException {
setBillingAddress(getAddressHome().findByPrimaryKey(id));
}
- void addLineItemId(Long id) throws FinderException {
+ public void addLineItemId(Long id) throws FinderException {
getLineItems().add(getLineItemHome().findByPrimaryKey(id));
}
@@ -170,7 +171,7 @@ public void ejbStore() {
public void ejbRemove() {
}
- void ejbHomeResetId() {
+ public void ejbHomeResetId() {
id = 0;
}
View
2  ...asic/src/test/java/org/jboss/as/test/integration/ejb/remote/entity/cmp/commerce/ProductCategoryBean.java
@@ -111,7 +111,7 @@ public void ejbStore() {
public void ejbRemove() {
}
- void ejbHomeResetId() {
+ public void ejbHomeResetId() {
id = 0;
}
Please sign in to comment.
Something went wrong with that request. Please try again.